Commit | Line | Data |
---|---|---|
252b5132 | 1 | # This shell script emits a C file. -*- C -*- |
aef6203b | 2 | # Copyright 1991, 1993, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, |
f13a99db | 3 | # 2004, 2005, 2007, 2008 |
41392f03 AM |
4 | # Free Software Foundation, Inc. |
5 | # | |
f96b4a7b | 6 | # This file is part of the GNU Binutils. |
41392f03 AM |
7 | # |
8 | # This program is free software; you can redistribute it and/or modify | |
9 | # it under the terms of the GNU General Public License as published by | |
f96b4a7b | 10 | # the Free Software Foundation; either version 3 of the License, or |
41392f03 AM |
11 | # (at your option) any later version. |
12 | # | |
13 | # This program is distributed in the hope that it will be useful, | |
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | # GNU General Public License for more details. | |
17 | # | |
18 | # You should have received a copy of the GNU General Public License | |
19 | # along with this program; if not, write to the Free Software | |
f96b4a7b NC |
20 | # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
21 | # MA 02110-1301, USA. | |
41392f03 AM |
22 | # |
23 | ||
24 | # This file is sourced from elf32.em, and defines extra arm-elf | |
25 | # specific routines. | |
26 | # | |
a82644e2 | 27 | test -z "$TARGET2_TYPE" && TARGET2_TYPE="rel" |
92b93329 | 28 | fragment <<EOF |
7ca69e9e | 29 | |
1d022697 PB |
30 | #include "elf/arm.h" |
31 | ||
88f7bcd5 NC |
32 | static char *thumb_entry_symbol = NULL; |
33 | static bfd *bfd_for_interwork; | |
e489d0ae | 34 | static int byteswap_code = 0; |
9c504268 | 35 | static int target1_is_rel = 0${TARGET1_IS_REL}; |
3674e28a | 36 | static char *target2_type = "${TARGET2_TYPE}"; |
319850b4 | 37 | static int fix_v4bx = 0; |
33bfe774 | 38 | static int use_blx = 0; |
c6dd86c6 | 39 | static bfd_arm_vfp11_fix vfp11_denorm_fix = BFD_ARM_VFP11_FIX_DEFAULT; |
bf21ed78 | 40 | static int no_enum_size_warning = 0; |
27e55c4d | 41 | static int pic_veneer = 0; |
7ca69e9e | 42 | |
252b5132 | 43 | static void |
0c7a8e5a | 44 | gld${EMULATION_NAME}_before_parse (void) |
252b5132 RH |
45 | { |
46 | #ifndef TARGET_ /* I.e., if not generic. */ | |
5e2f1575 | 47 | ldfile_set_output_arch ("`echo ${ARCH}`", bfd_arch_unknown); |
252b5132 | 48 | #endif /* not TARGET_ */ |
b34976b6 AM |
49 | config.dynamic_link = ${DYNAMIC_LINK-TRUE}; |
50 | config.has_shared = `if test -n "$GENERATE_SHLIB_SCRIPT" ; then echo TRUE ; else echo FALSE ; fi`; | |
252b5132 RH |
51 | } |
52 | ||
1220a729 | 53 | static void |
0c7a8e5a | 54 | arm_elf_after_open (void) |
1220a729 | 55 | { |
f13a99db | 56 | if (strstr (bfd_get_target (link_info.output_bfd), "arm") == NULL) |
1220a729 | 57 | { |
f11523b0 NC |
58 | /* The arm backend needs special fields in the output hash structure. |
59 | These will only be created if the output format is an arm format, | |
60 | hence we do not support linking and changing output formats at the | |
61 | same time. Use a link followed by objcopy to change output formats. */ | |
62 | einfo ("%F%X%P: error: cannot change output format whilst linking ARM binaries\n"); | |
63 | return; | |
1220a729 NC |
64 | } |
65 | ||
f11523b0 NC |
66 | { |
67 | LANG_FOR_EACH_INPUT_STATEMENT (is) | |
68 | { | |
8afb0e02 | 69 | bfd_elf32_arm_add_glue_sections_to_bfd (is->the_bfd, & link_info); |
f11523b0 NC |
70 | } |
71 | } | |
72 | ||
41392f03 AM |
73 | /* Call the standard elf routine. */ |
74 | gld${EMULATION_NAME}_after_open (); | |
1220a729 NC |
75 | } |
76 | ||
8afb0e02 | 77 | static void |
0c7a8e5a | 78 | arm_elf_set_bfd_for_interworking (lang_statement_union_type *statement) |
8afb0e02 | 79 | { |
7b986e99 | 80 | if (statement->header.type == lang_input_section_enum) |
8afb0e02 | 81 | { |
88f7bcd5 | 82 | asection *i = statement->input_section.section; |
8afb0e02 | 83 | |
7b986e99 AM |
84 | if (!((lang_input_statement_type *) i->owner->usrdata)->just_syms_flag |
85 | && (i->flags & SEC_EXCLUDE) == 0) | |
8afb0e02 | 86 | { |
7b986e99 AM |
87 | asection *output_section = i->output_section; |
88 | ||
f13a99db | 89 | ASSERT (output_section->owner == link_info.output_bfd); |
7b986e99 AM |
90 | |
91 | /* Don't attach the interworking stubs to a dynamic object, to | |
92 | an empty section, etc. */ | |
93 | if ((output_section->flags & SEC_HAS_CONTENTS) != 0 | |
94 | && (i->flags & SEC_NEVER_LOAD) == 0 | |
95 | && ! (i->owner->flags & DYNAMIC) | |
96 | && ! i->owner->output_has_begun) | |
97 | { | |
98 | bfd_for_interwork = i->owner; | |
99 | bfd_for_interwork->output_has_begun = TRUE; | |
100 | } | |
8afb0e02 NC |
101 | } |
102 | } | |
103 | } | |
1220a729 | 104 | |
1220a729 | 105 | static void |
0c7a8e5a | 106 | arm_elf_before_allocation (void) |
1220a729 | 107 | { |
88f7bcd5 | 108 | bfd *tem; |
8afb0e02 | 109 | |
2004afbc NC |
110 | if (link_info.input_bfds != NULL) |
111 | { | |
112 | /* The interworking bfd must be the last one in the link. */ | |
113 | bfd_for_interwork = NULL; | |
114 | for (tem = link_info.input_bfds; tem != NULL; tem = tem->link_next) | |
b34976b6 | 115 | tem->output_has_begun = FALSE; |
252b5132 | 116 | |
2004afbc | 117 | lang_for_each_statement (arm_elf_set_bfd_for_interworking); |
2004afbc | 118 | for (tem = link_info.input_bfds; tem != NULL; tem = tem->link_next) |
b34976b6 | 119 | tem->output_has_begun = FALSE; |
8afb0e02 | 120 | |
06aa7234 NC |
121 | /* If bfd_for_interwork is NULL, then there are no loadable sections |
122 | with real contents to be linked, so we are not going to have to | |
123 | create any interworking stubs, so it is OK not to call | |
124 | bfd_elf32_arm_get_bfd_for_interworking. */ | |
125 | if (bfd_for_interwork != NULL) | |
126 | bfd_elf32_arm_get_bfd_for_interworking (bfd_for_interwork, &link_info); | |
2004afbc | 127 | } |
8afb0e02 | 128 | |
d504ffc8 DJ |
129 | bfd_elf32_arm_set_byteswap_code (&link_info, byteswap_code); |
130 | ||
c6dd86c6 JB |
131 | /* Choose type of VFP11 erratum fix, or warn if specified fix is unnecessary |
132 | due to architecture version. */ | |
f13a99db | 133 | bfd_elf32_arm_set_vfp11_fix (link_info.output_bfd, &link_info); |
c6dd86c6 | 134 | |
d504ffc8 DJ |
135 | /* We should be able to set the size of the interworking stub section. We |
136 | can't do it until later if we have dynamic sections, though. */ | |
137 | if (! elf_hash_table (&link_info)->dynamic_sections_created) | |
138 | { | |
139 | /* Here we rummage through the found bfds to collect glue information. */ | |
140 | LANG_FOR_EACH_INPUT_STATEMENT (is) | |
141 | { | |
c6dd86c6 JB |
142 | /* Initialise mapping tables for code/data. */ |
143 | bfd_elf32_arm_init_maps (is->the_bfd); | |
144 | ||
d504ffc8 | 145 | if (!bfd_elf32_arm_process_before_allocation (is->the_bfd, |
c6dd86c6 JB |
146 | &link_info) |
147 | || !bfd_elf32_arm_vfp11_erratum_scan (is->the_bfd, &link_info)) | |
252b5132 RH |
148 | /* xgettext:c-format */ |
149 | einfo (_("Errors encountered processing file %s"), is->filename); | |
d504ffc8 DJ |
150 | } |
151 | } | |
252b5132 | 152 | |
063d4ee1 AM |
153 | /* Call the standard elf routine. */ |
154 | gld${EMULATION_NAME}_before_allocation (); | |
155 | ||
8afb0e02 | 156 | /* We have seen it all. Allocate it, and carry on. */ |
252b5132 RH |
157 | bfd_elf32_arm_allocate_interworking_sections (& link_info); |
158 | } | |
159 | ||
c6dd86c6 JB |
160 | static void |
161 | arm_elf_after_allocation (void) | |
162 | { | |
163 | /* Call the standard elf routine. */ | |
164 | after_allocation_default (); | |
165 | ||
166 | { | |
167 | LANG_FOR_EACH_INPUT_STATEMENT (is) | |
168 | { | |
169 | /* Figure out where VFP11 erratum veneers (and the labels returning | |
170 | from same) have been placed. */ | |
171 | bfd_elf32_arm_vfp11_fix_veneer_locations (is->the_bfd, &link_info); | |
172 | } | |
173 | } | |
174 | } | |
175 | ||
6f798e5c | 176 | static void |
0c7a8e5a | 177 | arm_elf_finish (void) |
6f798e5c NC |
178 | { |
179 | struct bfd_link_hash_entry * h; | |
180 | ||
c56feb2b AM |
181 | /* Call the elf32.em routine. */ |
182 | gld${EMULATION_NAME}_finish (); | |
183 | ||
1d022697 PB |
184 | if (thumb_entry_symbol) |
185 | { | |
186 | h = bfd_link_hash_lookup (link_info.hash, thumb_entry_symbol, | |
187 | FALSE, FALSE, TRUE); | |
188 | } | |
189 | else | |
190 | { | |
191 | struct elf_link_hash_entry * eh; | |
192 | ||
193 | if (!entry_symbol.name) | |
194 | return; | |
195 | ||
196 | h = bfd_link_hash_lookup (link_info.hash, entry_symbol.name, | |
197 | FALSE, FALSE, TRUE); | |
198 | eh = (struct elf_link_hash_entry *)h; | |
199 | if (!h || ELF_ST_TYPE(eh->type) != STT_ARM_TFUNC) | |
200 | return; | |
201 | } | |
0c7a8e5a | 202 | |
6f798e5c NC |
203 | |
204 | if (h != (struct bfd_link_hash_entry *) NULL | |
205 | && (h->type == bfd_link_hash_defined | |
206 | || h->type == bfd_link_hash_defweak) | |
207 | && h->u.def.section->output_section != NULL) | |
208 | { | |
209 | static char buffer[32]; | |
88f7bcd5 | 210 | bfd_vma val; |
0c7a8e5a | 211 | |
88f7bcd5 NC |
212 | /* Special procesing is required for a Thumb entry symbol. The |
213 | bottom bit of its address must be set. */ | |
214 | val = (h->u.def.value | |
f13a99db | 215 | + bfd_get_section_vma (link_info.output_bfd, |
88f7bcd5 NC |
216 | h->u.def.section->output_section) |
217 | + h->u.def.section->output_offset); | |
0c7a8e5a | 218 | |
88f7bcd5 | 219 | val |= 1; |
6f798e5c | 220 | |
88f7bcd5 | 221 | /* Now convert this value into a string and store it in entry_symbol |
0c7a8e5a | 222 | where the lang_finish() function will pick it up. */ |
88f7bcd5 NC |
223 | buffer[0] = '0'; |
224 | buffer[1] = 'x'; | |
0c7a8e5a | 225 | |
88f7bcd5 | 226 | sprintf_vma (buffer + 2, val); |
6f798e5c | 227 | |
1d022697 PB |
228 | if (thumb_entry_symbol != NULL && entry_symbol.name != NULL |
229 | && entry_from_cmdline) | |
88f7bcd5 NC |
230 | einfo (_("%P: warning: '--thumb-entry %s' is overriding '-e %s'\n"), |
231 | thumb_entry_symbol, entry_symbol.name); | |
232 | entry_symbol.name = buffer; | |
6f798e5c | 233 | } |
88f7bcd5 | 234 | else |
6241fe3d | 235 | einfo (_("%P: warning: cannot find thumb start symbol %s\n"), |
88f7bcd5 | 236 | thumb_entry_symbol); |
6f798e5c NC |
237 | } |
238 | ||
bf21ed78 | 239 | /* This is a convenient point to tell BFD about target specific flags. |
3674e28a PB |
240 | After the output has been created, but before inputs are read. */ |
241 | static void | |
242 | arm_elf_create_output_section_statements (void) | |
243 | { | |
f13a99db AM |
244 | bfd_elf32_arm_set_target_relocs (link_info.output_bfd, &link_info, |
245 | target1_is_rel, | |
bf21ed78 | 246 | target2_type, fix_v4bx, use_blx, |
27e55c4d PB |
247 | vfp11_denorm_fix, no_enum_size_warning, |
248 | pic_veneer); | |
3674e28a PB |
249 | } |
250 | ||
252b5132 RH |
251 | EOF |
252 | ||
41392f03 AM |
253 | # Define some shell vars to insert bits of code into the standard elf |
254 | # parse_args and list_options functions. | |
255 | # | |
256 | PARSE_AND_LIST_PROLOGUE=' | |
257 | #define OPTION_THUMB_ENTRY 301 | |
e489d0ae | 258 | #define OPTION_BE8 302 |
9c504268 PB |
259 | #define OPTION_TARGET1_REL 303 |
260 | #define OPTION_TARGET1_ABS 304 | |
3674e28a | 261 | #define OPTION_TARGET2 305 |
33bfe774 JB |
262 | #define OPTION_FIX_V4BX 306 |
263 | #define OPTION_USE_BLX 307 | |
c6dd86c6 | 264 | #define OPTION_VFP11_DENORM_FIX 308 |
bf21ed78 | 265 | #define OPTION_NO_ENUM_SIZE_WARNING 309 |
27e55c4d | 266 | #define OPTION_PIC_VENEER 310 |
845b51d6 | 267 | #define OPTION_FIX_V4BX_INTERWORKING 311 |
41392f03 | 268 | ' |
252b5132 | 269 | |
ef5bdbd1 | 270 | PARSE_AND_LIST_SHORTOPTS=p |
252b5132 | 271 | |
41392f03 AM |
272 | PARSE_AND_LIST_LONGOPTS=' |
273 | { "no-pipeline-knowledge", no_argument, NULL, '\'p\''}, | |
274 | { "thumb-entry", required_argument, NULL, OPTION_THUMB_ENTRY}, | |
e489d0ae | 275 | { "be8", no_argument, NULL, OPTION_BE8}, |
9c504268 PB |
276 | { "target1-rel", no_argument, NULL, OPTION_TARGET1_REL}, |
277 | { "target1-abs", no_argument, NULL, OPTION_TARGET1_ABS}, | |
3674e28a | 278 | { "target2", required_argument, NULL, OPTION_TARGET2}, |
319850b4 | 279 | { "fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX}, |
845b51d6 | 280 | { "fix-v4bx-interworking", no_argument, NULL, OPTION_FIX_V4BX_INTERWORKING}, |
33bfe774 | 281 | { "use-blx", no_argument, NULL, OPTION_USE_BLX}, |
c6dd86c6 | 282 | { "vfp11-denorm-fix", required_argument, NULL, OPTION_VFP11_DENORM_FIX}, |
bf21ed78 | 283 | { "no-enum-size-warning", no_argument, NULL, OPTION_NO_ENUM_SIZE_WARNING}, |
27e55c4d | 284 | { "pic-veneer", no_argument, NULL, OPTION_PIC_VENEER}, |
41392f03 | 285 | ' |
252b5132 | 286 | |
41392f03 | 287 | PARSE_AND_LIST_OPTIONS=' |
442996ee AM |
288 | fprintf (file, _(" --thumb-entry=<sym> Set the entry point to be Thumb symbol <sym>\n")); |
289 | fprintf (file, _(" --be8 Oputput BE8 format image\n")); | |
290 | fprintf (file, _(" --target1=rel Interpret R_ARM_TARGET1 as R_ARM_REL32\n")); | |
291 | fprintf (file, _(" --target1=abs Interpret R_ARM_TARGET1 as R_ARM_ABS32\n")); | |
292 | fprintf (file, _(" --target2=<type> Specify definition of R_ARM_TARGET2\n")); | |
293 | fprintf (file, _(" --fix-v4bx Rewrite BX rn as MOV pc, rn for ARMv4\n")); | |
845b51d6 | 294 | fprintf (file, _(" --fix-v4bx-interworking Rewrite BX rn branch to ARMv4 interworking veneer\n")); |
442996ee AM |
295 | fprintf (file, _(" --use-blx Enable use of BLX instructions\n")); |
296 | fprintf (file, _(" --vfp11-denorm-fix Specify how to fix VFP11 denorm erratum\n")); | |
297 | fprintf (file, _(" --no-enum-size-warning Don'\''t warn about objects with incompatible" | |
298 | " enum sizes\n")); | |
299 | fprintf (file, _(" --pic-veneer Always generate PIC interworking veneers\n")); | |
41392f03 | 300 | ' |
252b5132 | 301 | |
41392f03 AM |
302 | PARSE_AND_LIST_ARGS_CASES=' |
303 | case '\'p\'': | |
dea514f5 | 304 | /* Only here for backwards compatibility. */ |
41392f03 | 305 | break; |
252b5132 | 306 | |
41392f03 AM |
307 | case OPTION_THUMB_ENTRY: |
308 | thumb_entry_symbol = optarg; | |
309 | break; | |
e489d0ae PB |
310 | |
311 | case OPTION_BE8: | |
312 | byteswap_code = 1; | |
313 | break; | |
9c504268 PB |
314 | |
315 | case OPTION_TARGET1_REL: | |
316 | target1_is_rel = 1; | |
317 | break; | |
318 | ||
319 | case OPTION_TARGET1_ABS: | |
320 | target1_is_rel = 0; | |
321 | break; | |
3674e28a PB |
322 | |
323 | case OPTION_TARGET2: | |
324 | target2_type = optarg; | |
325 | break; | |
319850b4 JB |
326 | |
327 | case OPTION_FIX_V4BX: | |
328 | fix_v4bx = 1; | |
329 | break; | |
33bfe774 | 330 | |
845b51d6 PB |
331 | case OPTION_FIX_V4BX_INTERWORKING: |
332 | fix_v4bx = 2; | |
333 | break; | |
334 | ||
33bfe774 JB |
335 | case OPTION_USE_BLX: |
336 | use_blx = 1; | |
337 | break; | |
92b93329 | 338 | |
c6dd86c6 JB |
339 | case OPTION_VFP11_DENORM_FIX: |
340 | if (strcmp (optarg, "none") == 0) | |
341 | vfp11_denorm_fix = BFD_ARM_VFP11_FIX_NONE; | |
342 | else if (strcmp (optarg, "scalar") == 0) | |
343 | vfp11_denorm_fix = BFD_ARM_VFP11_FIX_SCALAR; | |
344 | else if (strcmp (optarg, "vector") == 0) | |
345 | vfp11_denorm_fix = BFD_ARM_VFP11_FIX_VECTOR; | |
346 | else | |
347 | einfo (_("Unrecognized VFP11 fix type '\''%s'\''.\n"), optarg); | |
348 | break; | |
bf21ed78 MS |
349 | |
350 | case OPTION_NO_ENUM_SIZE_WARNING: | |
351 | no_enum_size_warning = 1; | |
352 | break; | |
27e55c4d PB |
353 | |
354 | case OPTION_PIC_VENEER: | |
355 | pic_veneer = 1; | |
356 | break; | |
41392f03 | 357 | ' |
252b5132 | 358 | |
41392f03 AM |
359 | # We have our own after_open and before_allocation functions, but they call |
360 | # the standard routines, so give them a different name. | |
361 | LDEMUL_AFTER_OPEN=arm_elf_after_open | |
362 | LDEMUL_BEFORE_ALLOCATION=arm_elf_before_allocation | |
c6dd86c6 | 363 | LDEMUL_AFTER_ALLOCATION=arm_elf_after_allocation |
3674e28a | 364 | LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS=arm_elf_create_output_section_statements |
252b5132 | 365 | |
41392f03 AM |
366 | # Replace the elf before_parse function with our own. |
367 | LDEMUL_BEFORE_PARSE=gld"${EMULATION_NAME}"_before_parse | |
252b5132 | 368 | |
41392f03 | 369 | # Call the extra arm-elf function |
a48ca7f2 | 370 | LDEMUL_FINISH=arm_elf_finish |