1 # This shell script emits a C file. -*- C -*-
2 # It does some substitutions.
3 cat >e${EMULATION_NAME}.c <<EOF
4 /* This file is is generated by a shell script. DO NOT EDIT! */
6 /* emulate the original gld for the given ${EMULATION_NAME}
7 Copyright 1991, 1993, 1996, 1997, 1998, 1999, 2000, 2001, 2002
8 Free Software Foundation, Inc.
9 Written by Steve Chamberlain steve@cygnus.com
11 This file is part of GLD, the Gnu Linker.
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
27 #define TARGET_IS_${EMULATION_NAME}
43 static void gld${EMULATION_NAME}_before_parse PARAMS ((void));
44 static void gld${EMULATION_NAME}_before_allocation PARAMS ((void));
45 static char *gld${EMULATION_NAME}_get_script PARAMS ((int *isfile));
46 static int gld${EMULATION_NAME}_parse_args PARAMS((int, char **));
47 static void gld${EMULATION_NAME}_list_options PARAMS ((FILE *));
48 static void gld${EMULATION_NAME}_finish PARAMS ((void));
49 static void gld${EMULATION_NAME}_after_open PARAMS ((void));
51 /* If TRUE, then interworking stubs which support calls to old, non-interworking
52 aware ARM code should be generated. */
54 static int support_old_code = 0;
55 static char * thumb_entry_symbol = NULL;
57 #define OPTION_SUPPORT_OLD_CODE 300
58 #define OPTION_THUMB_ENTRY 301
60 static struct option longopts[] =
62 {"support-old-code", no_argument, NULL, OPTION_SUPPORT_OLD_CODE},
63 {"thumb-entry", required_argument, NULL, OPTION_THUMB_ENTRY},
64 {NULL, no_argument, NULL, 0}
68 gld${EMULATION_NAME}_list_options (file)
71 fprintf (file, _(" --support-old-code Support interworking with old code\n"));
72 fprintf (file, _(" --thumb-entry=<sym> Set the entry point to be Thumb symbol <sym>\n"));
76 gld${EMULATION_NAME}_parse_args (argc, argv)
82 int prevoptind = optind;
83 int prevopterr = opterr;
85 static int lastoptind = -1;
87 if (lastoptind != optind)
93 optc = getopt_long_only (argc, argv, "-", longopts, & longind);
104 case OPTION_SUPPORT_OLD_CODE:
105 support_old_code = 1;
108 case OPTION_THUMB_ENTRY:
109 thumb_entry_symbol = optarg;
117 gld${EMULATION_NAME}_before_parse ()
119 #ifndef TARGET_ /* I.e., if not generic. */
120 ldfile_set_output_arch ("`echo ${ARCH}`");
121 #endif /* not TARGET_ */
124 /* This is called after the sections have been attached to output
125 sections, but before any sizes or addresses have been set. */
128 gld${EMULATION_NAME}_before_allocation ()
130 /* we should be able to set the size of the interworking stub section */
132 /* Here we rummage through the found bfds to collect glue information */
133 /* FIXME: should this be based on a command line option? krk@cygnus.com */
135 LANG_FOR_EACH_INPUT_STATEMENT (is)
137 if (! bfd_arm_process_before_allocation
138 (is->the_bfd, & link_info, support_old_code))
140 /* xgettext:c-format */
141 einfo (_("Errors encountered processing file %s"), is->filename);
146 /* We have seen it all. Allocate it, and carry on */
147 bfd_arm_allocate_interworking_sections (& link_info);
151 gld${EMULATION_NAME}_after_open ()
153 if (strstr (bfd_get_target (output_bfd), "arm") == NULL)
155 /* The arm backend needs special fields in the output hash structure.
156 These will only be created if the output format is an arm format,
157 hence we do not support linking and changing output formats at the
158 same time. Use a link followed by objcopy to change output formats. */
159 einfo ("%F%X%P: error: cannot change output format whilst linking ARM binaries\n");
164 LANG_FOR_EACH_INPUT_STATEMENT (is)
166 if (bfd_arm_get_bfd_for_interworking (is->the_bfd, & link_info))
173 gld${EMULATION_NAME}_finish PARAMS((void))
175 struct bfd_link_hash_entry * h;
177 if (thumb_entry_symbol == NULL)
180 h = bfd_link_hash_lookup (link_info.hash, thumb_entry_symbol,
183 if (h != (struct bfd_link_hash_entry *) NULL
184 && (h->type == bfd_link_hash_defined
185 || h->type == bfd_link_hash_defweak)
186 && h->u.def.section->output_section != NULL)
188 static char buffer[32];
191 /* Special procesing is required for a Thumb entry symbol. The
192 bottom bit of its address must be set. */
193 val = (h->u.def.value
194 + bfd_get_section_vma (output_bfd,
195 h->u.def.section->output_section)
196 + h->u.def.section->output_offset);
200 /* Now convert this value into a string and store it in entry_symbol
201 where the lang_finish() function will pick it up. */
205 sprintf_vma (buffer + 2, val);
207 if (entry_symbol.name != NULL && entry_from_cmdline)
208 einfo (_("%P: warning: '--thumb-entry %s' is overriding '-e %s'\n"),
209 thumb_entry_symbol, entry_symbol.name);
210 entry_symbol.name = buffer;
213 einfo (_("%P: warning: connot find thumb start symbol %s\n"), thumb_entry_symbol);
217 gld${EMULATION_NAME}_get_script (isfile)
221 if test -n "$COMPILE_IN"
223 # Scripts compiled in.
225 # sed commands to quote an ld script as a C string.
226 sc="-f stringify.sed"
228 cat >>e${EMULATION_NAME}.c <<EOF
232 if (link_info.relocateable && config.build_constructors)
235 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
236 echo ' ; else if (link_info.relocateable) return' >> e${EMULATION_NAME}.c
237 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
238 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
239 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
240 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
241 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
242 echo ' ; else return' >> e${EMULATION_NAME}.c
243 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
244 echo '; }' >> e${EMULATION_NAME}.c
247 # Scripts read from the filesystem.
249 cat >>e${EMULATION_NAME}.c <<EOF
253 if (link_info.relocateable && config.build_constructors)
254 return "ldscripts/${EMULATION_NAME}.xu";
255 else if (link_info.relocateable)
256 return "ldscripts/${EMULATION_NAME}.xr";
257 else if (!config.text_read_only)
258 return "ldscripts/${EMULATION_NAME}.xbn";
259 else if (!config.magic_demand_paged)
260 return "ldscripts/${EMULATION_NAME}.xn";
262 return "ldscripts/${EMULATION_NAME}.x";
268 cat >>e${EMULATION_NAME}.c <<EOF
270 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
272 gld${EMULATION_NAME}_before_parse,
276 gld${EMULATION_NAME}_after_open,
277 after_allocation_default,
278 set_output_arch_default,
279 ldemul_default_target,
280 gld${EMULATION_NAME}_before_allocation,
281 gld${EMULATION_NAME}_get_script,
284 gld${EMULATION_NAME}_finish,
285 NULL, /* create output section statements */
286 NULL, /* open dynamic archive */
287 NULL, /* place orphan */
288 NULL, /* set symbols */
289 gld${EMULATION_NAME}_parse_args,
290 NULL, /* unrecognised file */
291 gld${EMULATION_NAME}_list_options,
292 NULL, /* recognized file */
293 NULL, /* find_potential_libraries */
294 NULL /* new_vers_pattern */