]>
Commit | Line | Data |
---|---|---|
8b351884 | 1 | # This shell script emits a C file. -*- C -*- |
b90efa5b | 2 | # Copyright (C) 2010-2015 Free Software Foundation, Inc. |
8b351884 TG |
3 | # |
4 | # This file is part of the GNU Binutils. | |
5 | # | |
6 | # This program is free software; you can redistribute it and/or modify | |
7 | # it under the terms of the GNU General Public License as published by | |
8 | # the Free Software Foundation; either version 3 of the License, or | |
9 | # (at your option) any later version. | |
10 | # | |
11 | # This program is distributed in the hope that it will be useful, | |
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | # GNU General Public License for more details. | |
15 | # | |
16 | # You should have received a copy of the GNU General Public License | |
17 | # along with this program; if not, write to the Free Software | |
18 | # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, | |
19 | # MA 02110-1301, USA. | |
20 | # | |
21 | ||
22 | # This file is sourced from generic.em. | |
23 | ||
24 | fragment <<EOF | |
45cfb56c TG |
25 | #include "getopt.h" |
26 | ||
8b351884 TG |
27 | static void |
28 | gld${EMULATION_NAME}_before_parse (void) | |
29 | { | |
30 | ldfile_set_output_arch ("${ARCH}", bfd_arch_`echo ${ARCH} | sed -e 's/:.*//'`); | |
66be1055 | 31 | input_flags.dynamic = TRUE; |
8b351884 | 32 | config.has_shared = FALSE; /* Not yet. */ |
202e2356 NC |
33 | |
34 | /* For ia64, harmless for alpha. */ | |
35 | link_info.emit_hash = FALSE; | |
36 | link_info.spare_dynamic_tags = 0; | |
8b351884 TG |
37 | } |
38 | ||
39 | /* This is called before the input files are opened. We add the | |
40 | standard library. */ | |
41 | ||
42 | static void | |
43 | gld${EMULATION_NAME}_create_output_section_statements (void) | |
44 | { | |
45 | lang_add_input_file ("imagelib", lang_input_file_is_l_enum, NULL); | |
46 | lang_add_input_file ("starlet", lang_input_file_is_l_enum, NULL); | |
47 | lang_add_input_file ("sys\$public_vectors", lang_input_file_is_l_enum, NULL); | |
48 | } | |
49 | ||
50 | /* Try to open a dynamic archive. This is where we know that VMS | |
51 | shared images (dynamic libraries) have an extension of .exe. */ | |
52 | ||
53 | static bfd_boolean | |
54 | gld${EMULATION_NAME}_open_dynamic_archive (const char *arch ATTRIBUTE_UNUSED, | |
55 | search_dirs_type *search, | |
56 | lang_input_statement_type *entry) | |
57 | { | |
58 | char *string; | |
59 | ||
d4ae5fb0 | 60 | if (! entry->flags.maybe_archive || entry->flags.full_name_provided) |
8b351884 TG |
61 | return FALSE; |
62 | ||
63 | string = (char *) xmalloc (strlen (search->name) | |
64 | + strlen (entry->filename) | |
65 | + sizeof "/.exe"); | |
66 | ||
67 | sprintf (string, "%s/%s.exe", search->name, entry->filename); | |
68 | ||
69 | if (! ldfile_try_open_bfd (string, entry)) | |
70 | { | |
71 | free (string); | |
72 | return FALSE; | |
73 | } | |
74 | ||
75 | entry->filename = string; | |
76 | ||
77 | return TRUE; | |
78 | } | |
79 | ||
80 | static int | |
81 | gld${EMULATION_NAME}_find_potential_libraries | |
82 | (char *name, lang_input_statement_type *entry) | |
83 | { | |
84 | return ldfile_open_file_search (name, entry, "", ".olb"); | |
85 | } | |
86 | ||
87 | /* Place an orphan section. We use this to put random OVR sections. | |
88 | Much borrowed from elf32.em. */ | |
89 | ||
90 | static lang_output_section_statement_type * | |
91 | vms_place_orphan (asection *s, | |
92 | const char *secname ATTRIBUTE_UNUSED, | |
93 | int constraint ATTRIBUTE_UNUSED) | |
94 | { | |
95 | static struct orphan_save hold_data = | |
96 | { | |
97 | "\$DATA\$", | |
98 | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_DATA, | |
99 | 0, 0, 0, 0 | |
100 | }; | |
101 | ||
46d00b8a TG |
102 | /* We have nothing to say for anything other than a final link or an excluded |
103 | section. */ | |
0e1862bb | 104 | if (bfd_link_relocatable (&link_info) |
8b351884 TG |
105 | || (s->flags & (SEC_EXCLUDE | SEC_LOAD)) != SEC_LOAD) |
106 | return NULL; | |
107 | ||
46d00b8a TG |
108 | /* FIXME: we should place sections by VMS program section flags. */ |
109 | ||
8b351884 TG |
110 | /* Only handle data sections. */ |
111 | if ((s->flags & SEC_DATA) == 0) | |
112 | return NULL; | |
113 | ||
114 | if (hold_data.os == NULL) | |
115 | hold_data.os = lang_output_section_find (hold_data.name); | |
116 | ||
117 | if (hold_data.os != NULL) | |
118 | { | |
b9c361e0 | 119 | lang_add_section (&hold_data.os->children, s, NULL, hold_data.os); |
8b351884 TG |
120 | return hold_data.os; |
121 | } | |
122 | else | |
123 | return NULL; | |
124 | } | |
45cfb56c TG |
125 | |
126 | /* VMS specific options. */ | |
127 | #define OPTION_IDENTIFICATION (300 + 1) | |
128 | ||
129 | static void | |
130 | gld${EMULATION_NAME}_add_options | |
131 | (int ns ATTRIBUTE_UNUSED, | |
132 | char **shortopts ATTRIBUTE_UNUSED, | |
133 | int nl, | |
134 | struct option **longopts, | |
135 | int nrl ATTRIBUTE_UNUSED, | |
136 | struct option **really_longopts ATTRIBUTE_UNUSED) | |
137 | { | |
202e2356 NC |
138 | static const struct option xtra_long[] = |
139 | { | |
45cfb56c TG |
140 | {"identification", required_argument, NULL, OPTION_IDENTIFICATION}, |
141 | {NULL, no_argument, NULL, 0} | |
142 | }; | |
143 | ||
144 | *longopts | |
145 | = xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long)); | |
146 | memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long)); | |
147 | } | |
148 | ||
149 | static void | |
150 | gld${EMULATION_NAME}_list_options (FILE *file) | |
151 | { | |
152 | fprintf (file, _(" --identification <string> Set the identification of the output\n")); | |
153 | } | |
154 | ||
155 | static bfd_boolean | |
156 | gld${EMULATION_NAME}_handle_option (int optc) | |
157 | { | |
158 | switch (optc) | |
159 | { | |
160 | default: | |
161 | return FALSE; | |
162 | ||
163 | case OPTION_IDENTIFICATION: | |
164 | /* Currently ignored. */ | |
165 | break; | |
166 | } | |
167 | ||
168 | return TRUE; | |
169 | } | |
170 | ||
8b351884 TG |
171 | EOF |
172 | ||
202e2356 NC |
173 | if test "$OUTPUT_FORMAT" = "elf64-ia64-vms"; then |
174 | ||
175 | fragment <<EOF | |
176 | #include "elf-bfd.h" | |
177 | EOF | |
178 | ||
179 | source_em ${srcdir}/emultempl/elf-generic.em | |
180 | ||
181 | fragment <<EOF | |
182 | ||
183 | /* This is called after the sections have been attached to output | |
184 | sections, but before any sizes or addresses have been set. */ | |
185 | ||
186 | static void | |
187 | gld${EMULATION_NAME}_before_allocation (void) | |
188 | { | |
189 | const struct elf_backend_data *bed; | |
190 | ||
191 | if (!is_elf_hash_table (link_info.hash)) | |
192 | return; | |
193 | ||
194 | bed = get_elf_backend_data (link_info.output_bfd); | |
195 | ||
196 | /* The backend must work out the sizes of all the other dynamic | |
197 | sections. */ | |
198 | if (elf_hash_table (&link_info)->dynamic_sections_created | |
199 | && bed->elf_backend_size_dynamic_sections | |
200 | && ! (*bed->elf_backend_size_dynamic_sections) (link_info.output_bfd, | |
201 | &link_info)) | |
202 | einfo ("%P%F: failed to set dynamic section sizes: %E\n"); | |
203 | ||
204 | before_allocation_default (); | |
205 | } | |
206 | ||
207 | static void | |
208 | gld${EMULATION_NAME}_after_allocation (void) | |
209 | { | |
75938853 AM |
210 | int need_layout = bfd_elf_discard_info (link_info.output_bfd, &link_info); |
211 | ||
212 | if (need_layout < 0) | |
213 | einfo ("%X%P: .eh_frame/.stab edit: %E\n"); | |
214 | else | |
215 | gld${EMULATION_NAME}_map_segments (need_layout); | |
202e2356 NC |
216 | } |
217 | ||
218 | static void | |
219 | gld${EMULATION_NAME}_after_parse (void) | |
220 | { | |
221 | link_info.relax_pass = 2; | |
222 | after_parse_default (); | |
223 | } | |
224 | EOF | |
225 | ||
226 | LDEMUL_BEFORE_ALLOCATION=gld"$EMULATION_NAME"_before_allocation | |
227 | LDEMUL_AFTER_ALLOCATION=gld"$EMULATION_NAME"_after_allocation | |
228 | ||
229 | LDEMUL_AFTER_PARSE=gld${EMULATION_NAME}_after_parse | |
230 | source_em ${srcdir}/emultempl/needrelax.em | |
231 | fi | |
232 | ||
8b351884 TG |
233 | LDEMUL_PLACE_ORPHAN=vms_place_orphan |
234 | LDEMUL_BEFORE_PARSE=gld"$EMULATION_NAME"_before_parse | |
235 | LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS=gld"$EMULATION_NAME"_create_output_section_statements | |
236 | LDEMUL_FIND_POTENTIAL_LIBRARIES=gld"$EMULATION_NAME"_find_potential_libraries | |
237 | LDEMUL_OPEN_DYNAMIC_ARCHIVE=gld"$EMULATION_NAME"_open_dynamic_archive | |
45cfb56c TG |
238 | LDEMUL_ADD_OPTIONS=gld"$EMULATION_NAME"_add_options |
239 | LDEMUL_HANDLE_OPTION=gld"$EMULATION_NAME"_handle_option | |
240 | LDEMUL_LIST_OPTIONS=gld"$EMULATION_NAME"_list_options |