1 # This shell script emits a C file. -*- C -*-
2 # Copyright 1991, 1993, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 # Free Software Foundation, Inc.
6 # This file is part of the GNU Binutils.
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
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
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.
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
20 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
24 # This file is sourced from elf32.em, and defines extra arm-elf
27 test -z "$TARGET2_TYPE" && TARGET2_TYPE="rel"
28 cat >>e${EMULATION_NAME}.c <<EOF
32 static char *thumb_entry_symbol = NULL;
33 static bfd *bfd_for_interwork;
34 static int byteswap_code = 0;
35 static int target1_is_rel = 0${TARGET1_IS_REL};
36 static char *target2_type = "${TARGET2_TYPE}";
37 static int fix_v4bx = 0;
38 static int use_blx = 0;
39 static bfd_arm_vfp11_fix vfp11_denorm_fix = BFD_ARM_VFP11_FIX_DEFAULT;
40 static int no_enum_size_warning = 0;
41 static int pic_veneer = 0;
44 gld${EMULATION_NAME}_before_parse (void)
46 #ifndef TARGET_ /* I.e., if not generic. */
47 ldfile_set_output_arch ("`echo ${ARCH}`", bfd_arch_unknown);
48 #endif /* not TARGET_ */
49 config.dynamic_link = ${DYNAMIC_LINK-TRUE};
50 config.has_shared = `if test -n "$GENERATE_SHLIB_SCRIPT" ; then echo TRUE ; else echo FALSE ; fi`;
54 arm_elf_after_open (void)
56 if (strstr (bfd_get_target (output_bfd), "arm") == NULL)
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");
67 LANG_FOR_EACH_INPUT_STATEMENT (is)
69 bfd_elf32_arm_add_glue_sections_to_bfd (is->the_bfd, & link_info);
73 /* Call the standard elf routine. */
74 gld${EMULATION_NAME}_after_open ();
78 arm_elf_set_bfd_for_interworking (lang_statement_union_type *statement)
80 if (statement->header.type == lang_input_section_enum)
82 asection *i = statement->input_section.section;
84 if (!((lang_input_statement_type *) i->owner->usrdata)->just_syms_flag
85 && (i->flags & SEC_EXCLUDE) == 0)
87 asection *output_section = i->output_section;
89 ASSERT (output_section->owner == output_bfd);
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)
98 bfd_for_interwork = i->owner;
99 bfd_for_interwork->output_has_begun = TRUE;
106 arm_elf_before_allocation (void)
110 if (link_info.input_bfds != NULL)
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)
115 tem->output_has_begun = FALSE;
117 lang_for_each_statement (arm_elf_set_bfd_for_interworking);
118 for (tem = link_info.input_bfds; tem != NULL; tem = tem->link_next)
119 tem->output_has_begun = FALSE;
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);
129 bfd_elf32_arm_set_byteswap_code (&link_info, byteswap_code);
131 /* Choose type of VFP11 erratum fix, or warn if specified fix is unnecessary
132 due to architecture version. */
133 bfd_elf32_arm_set_vfp11_fix (output_bfd, &link_info);
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)
139 /* Here we rummage through the found bfds to collect glue information. */
140 LANG_FOR_EACH_INPUT_STATEMENT (is)
142 /* Initialise mapping tables for code/data. */
143 bfd_elf32_arm_init_maps (is->the_bfd);
145 if (!bfd_elf32_arm_process_before_allocation (is->the_bfd,
147 || !bfd_elf32_arm_vfp11_erratum_scan (is->the_bfd, &link_info))
148 /* xgettext:c-format */
149 einfo (_("Errors encountered processing file %s"), is->filename);
153 /* Call the standard elf routine. */
154 gld${EMULATION_NAME}_before_allocation ();
156 /* We have seen it all. Allocate it, and carry on. */
157 bfd_elf32_arm_allocate_interworking_sections (& link_info);
161 arm_elf_after_allocation (void)
163 /* Call the standard elf routine. */
164 after_allocation_default ();
167 LANG_FOR_EACH_INPUT_STATEMENT (is)
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);
177 arm_elf_finish (void)
179 struct bfd_link_hash_entry * h;
181 /* Call the elf32.em routine. */
182 gld${EMULATION_NAME}_finish ();
184 if (thumb_entry_symbol)
186 h = bfd_link_hash_lookup (link_info.hash, thumb_entry_symbol,
191 struct elf_link_hash_entry * eh;
193 if (!entry_symbol.name)
196 h = bfd_link_hash_lookup (link_info.hash, entry_symbol.name,
198 eh = (struct elf_link_hash_entry *)h;
199 if (!h || ELF_ST_TYPE(eh->type) != STT_ARM_TFUNC)
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)
209 static char buffer[32];
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
215 + bfd_get_section_vma (output_bfd,
216 h->u.def.section->output_section)
217 + h->u.def.section->output_offset);
221 /* Now convert this value into a string and store it in entry_symbol
222 where the lang_finish() function will pick it up. */
226 sprintf_vma (buffer + 2, val);
228 if (thumb_entry_symbol != NULL && entry_symbol.name != NULL
229 && entry_from_cmdline)
230 einfo (_("%P: warning: '--thumb-entry %s' is overriding '-e %s'\n"),
231 thumb_entry_symbol, entry_symbol.name);
232 entry_symbol.name = buffer;
235 einfo (_("%P: warning: connot find thumb start symbol %s\n"),
239 /* This is a convenient point to tell BFD about target specific flags.
240 After the output has been created, but before inputs are read. */
242 arm_elf_create_output_section_statements (void)
244 bfd_elf32_arm_set_target_relocs (output_bfd, &link_info, target1_is_rel,
245 target2_type, fix_v4bx, use_blx,
246 vfp11_denorm_fix, no_enum_size_warning,
252 # Define some shell vars to insert bits of code into the standard elf
253 # parse_args and list_options functions.
255 PARSE_AND_LIST_PROLOGUE='
256 #define OPTION_THUMB_ENTRY 301
257 #define OPTION_BE8 302
258 #define OPTION_TARGET1_REL 303
259 #define OPTION_TARGET1_ABS 304
260 #define OPTION_TARGET2 305
261 #define OPTION_FIX_V4BX 306
262 #define OPTION_USE_BLX 307
263 #define OPTION_VFP11_DENORM_FIX 308
264 #define OPTION_NO_ENUM_SIZE_WARNING 309
265 #define OPTION_PIC_VENEER 310
268 PARSE_AND_LIST_SHORTOPTS=p
270 PARSE_AND_LIST_LONGOPTS='
271 { "no-pipeline-knowledge", no_argument, NULL, '\'p\''},
272 { "thumb-entry", required_argument, NULL, OPTION_THUMB_ENTRY},
273 { "be8", no_argument, NULL, OPTION_BE8},
274 { "target1-rel", no_argument, NULL, OPTION_TARGET1_REL},
275 { "target1-abs", no_argument, NULL, OPTION_TARGET1_ABS},
276 { "target2", required_argument, NULL, OPTION_TARGET2},
277 { "fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
278 { "use-blx", no_argument, NULL, OPTION_USE_BLX},
279 { "vfp11-denorm-fix", required_argument, NULL, OPTION_VFP11_DENORM_FIX},
280 { "no-enum-size-warning", no_argument, NULL, OPTION_NO_ENUM_SIZE_WARNING},
281 { "pic-veneer", no_argument, NULL, OPTION_PIC_VENEER},
284 PARSE_AND_LIST_OPTIONS='
285 fprintf (file, _(" --thumb-entry=<sym> Set the entry point to be Thumb symbol <sym>\n"));
286 fprintf (file, _(" --be8 Oputput BE8 format image\n"));
287 fprintf (file, _(" --target1=rel Interpret R_ARM_TARGET1 as R_ARM_REL32\n"));
288 fprintf (file, _(" --target1=abs Interpret R_ARM_TARGET1 as R_ARM_ABS32\n"));
289 fprintf (file, _(" --target2=<type> Specify definition of R_ARM_TARGET2\n"));
290 fprintf (file, _(" --fix-v4bx Rewrite BX rn as MOV pc, rn for ARMv4\n"));
291 fprintf (file, _(" --use-blx Enable use of BLX instructions\n"));
292 fprintf (file, _(" --vfp11-denorm-fix Specify how to fix VFP11 denorm erratum\n"));
293 fprintf (file, _(" --no-enum-size-warning Don'\''t warn about objects with incompatible enum sizes\n"));
294 fprintf (file, _(" --pic-veneer Always generate PIC interworking veneers\n"));
297 PARSE_AND_LIST_ARGS_CASES='
299 /* Only here for backwards compatibility. */
302 case OPTION_THUMB_ENTRY:
303 thumb_entry_symbol = optarg;
310 case OPTION_TARGET1_REL:
314 case OPTION_TARGET1_ABS:
319 target2_type = optarg;
322 case OPTION_FIX_V4BX:
330 case OPTION_VFP11_DENORM_FIX:
331 if (strcmp (optarg, "none") == 0)
332 vfp11_denorm_fix = BFD_ARM_VFP11_FIX_NONE;
333 else if (strcmp (optarg, "scalar") == 0)
334 vfp11_denorm_fix = BFD_ARM_VFP11_FIX_SCALAR;
335 else if (strcmp (optarg, "vector") == 0)
336 vfp11_denorm_fix = BFD_ARM_VFP11_FIX_VECTOR;
338 einfo (_("Unrecognized VFP11 fix type '\''%s'\''.\n"), optarg);
341 case OPTION_NO_ENUM_SIZE_WARNING:
342 no_enum_size_warning = 1;
345 case OPTION_PIC_VENEER:
350 # We have our own after_open and before_allocation functions, but they call
351 # the standard routines, so give them a different name.
352 LDEMUL_AFTER_OPEN=arm_elf_after_open
353 LDEMUL_BEFORE_ALLOCATION=arm_elf_before_allocation
354 LDEMUL_AFTER_ALLOCATION=arm_elf_after_allocation
355 LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS=arm_elf_create_output_section_statements
357 # Replace the elf before_parse function with our own.
358 LDEMUL_BEFORE_PARSE=gld"${EMULATION_NAME}"_before_parse
360 # Call the extra arm-elf function
361 LDEMUL_FINISH=arm_elf_finish