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 (C) 1991, 93, 96, 97, 98, 1999 Free Software Foundation, Inc.
8 Written by Steve Chamberlain steve@cygnus.com
10 This file is part of GLD, the Gnu Linker.
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
26 #define TARGET_IS_${EMULATION_NAME}
42 static void gld${EMULATION_NAME}_before_parse PARAMS ((void));
43 static void gld${EMULATION_NAME}_before_allocation PARAMS ((void));
44 static char *gld${EMULATION_NAME}_get_script PARAMS ((int *isfile));
45 static int gld${EMULATION_NAME}_parse_args PARAMS((int, char **));
46 static void gld${EMULATION_NAME}_list_options PARAMS ((FILE *));
47 static void gld${EMULATION_NAME}_finish PARAMS ((void));
49 /* If true, then interworking stubs which support calls to old, non-interworking
50 aware ARM code should be generated. */
52 static int support_old_code = 0;
53 static char * thumb_entry_symbol = NULL;
55 #define OPTION_SUPPORT_OLD_CODE 300
56 #define OPTION_THUMB_ENTRY 301
58 static struct option longopts[] =
60 {"support-old-code", no_argument, NULL, OPTION_SUPPORT_OLD_CODE},
61 {"thumb-entry", required_argument, NULL, OPTION_THUMB_ENTRY},
62 {NULL, no_argument, NULL, 0}
66 gld${EMULATION_NAME}_list_options (file)
69 fprintf (file, _(" --support-old-code Support interworking with old code\n"));
70 fprintf (file, _(" --thumb-entry=<sym> Set the entry point to be Thumb symbol <sym>\n"));
74 gld${EMULATION_NAME}_parse_args (argc, argv)
80 int prevoptind = optind;
81 int prevopterr = opterr;
83 static int lastoptind = -1;
85 if (lastoptind != optind)
91 optc = getopt_long_only (argc, argv, "-", longopts, & longind);
102 case OPTION_SUPPORT_OLD_CODE:
103 support_old_code = 1;
106 case OPTION_THUMB_ENTRY:
107 thumb_entry_symbol = optarg;
115 gld${EMULATION_NAME}_before_parse ()
117 #ifndef TARGET_ /* I.e., if not generic. */
118 ldfile_set_output_arch ("`echo ${ARCH}`");
119 #endif /* not TARGET_ */
122 /* This is called after the sections have been attached to output
123 sections, but before any sizes or addresses have been set. */
126 gld${EMULATION_NAME}_before_allocation ()
128 /* we should be able to set the size of the interworking stub section */
130 /* Here we rummage through the found bfds to collect glue information */
131 /* FIXME: should this be based on a command line option? krk@cygnus.com */
133 LANG_FOR_EACH_INPUT_STATEMENT (is)
135 if (! bfd_arm_process_before_allocation
136 (is->the_bfd, & link_info, support_old_code))
138 /* xgettext:c-format */
139 einfo (_("Errors encountered processing file %s"), is->filename);
144 /* We have seen it all. Allocate it, and carry on */
145 bfd_arm_allocate_interworking_sections (& link_info);
149 gld${EMULATION_NAME}_after_open ()
151 if (strstr (bfd_get_target (output_bfd), "arm") == NULL)
153 /* The arm backend needs special fields in the output hash structure.
154 These will only be created if the output format is an arm format,
155 hence we do not support linking and changing output formats at the
156 same time. Use a link followed by objcopy to change output formats. */
157 einfo ("%F%X%P: error: cannot change output format whilst linking ARM binaries\n");
162 LANG_FOR_EACH_INPUT_STATEMENT (is)
164 if (bfd_arm_get_bfd_for_interworking (is->the_bfd, & link_info))
171 gld${EMULATION_NAME}_finish PARAMS((void))
173 struct bfd_link_hash_entry * h;
175 if (thumb_entry_symbol == NULL)
178 h = bfd_link_hash_lookup (link_info.hash, thumb_entry_symbol, false, false, true);
180 if (h != (struct bfd_link_hash_entry *) NULL
181 && (h->type == bfd_link_hash_defined
182 || h->type == bfd_link_hash_defweak)
183 && h->u.def.section->output_section != NULL)
185 static char buffer[32];
188 /* Special procesing is required for a Thumb entry symbol. The
189 bottom bit of its address must be set. */
190 val = (h->u.def.value
191 + bfd_get_section_vma (output_bfd,
192 h->u.def.section->output_section)
193 + h->u.def.section->output_offset);
197 /* Now convert this value into a string and store it in entry_symbol
198 where the lang_finish() function will pick it up. */
202 sprintf_vma (buffer + 2, val);
204 if (entry_symbol != NULL && entry_from_cmdline)
205 einfo (_("%P: warning: '--thumb-entry %s' is overriding '-e %s'\n"),
206 thumb_entry_symbol, entry_symbol);
207 entry_symbol = buffer;
210 einfo (_("%P: warning: connot find thumb start symbol %s\n"), thumb_entry_symbol);
214 gld${EMULATION_NAME}_get_script (isfile)
218 if test -n "$COMPILE_IN"
220 # Scripts compiled in.
222 # sed commands to quote an ld script as a C string.
223 sc="-f stringify.sed"
225 cat >>e${EMULATION_NAME}.c <<EOF
229 if (link_info.relocateable == true && config.build_constructors == true)
232 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
233 echo ' ; else if (link_info.relocateable == true) return' >> e${EMULATION_NAME}.c
234 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
235 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
236 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
237 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
238 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
239 echo ' ; else return' >> e${EMULATION_NAME}.c
240 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
241 echo '; }' >> e${EMULATION_NAME}.c
244 # Scripts read from the filesystem.
246 cat >>e${EMULATION_NAME}.c <<EOF
250 if (link_info.relocateable == true && config.build_constructors == true)
251 return "ldscripts/${EMULATION_NAME}.xu";
252 else if (link_info.relocateable == true)
253 return "ldscripts/${EMULATION_NAME}.xr";
254 else if (!config.text_read_only)
255 return "ldscripts/${EMULATION_NAME}.xbn";
256 else if (!config.magic_demand_paged)
257 return "ldscripts/${EMULATION_NAME}.xn";
259 return "ldscripts/${EMULATION_NAME}.x";
265 cat >>e${EMULATION_NAME}.c <<EOF
267 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
269 gld${EMULATION_NAME}_before_parse,
273 gld${EMULATION_NAME}_after_open,
274 after_allocation_default,
275 set_output_arch_default,
276 ldemul_default_target,
277 gld${EMULATION_NAME}_before_allocation,
278 gld${EMULATION_NAME}_get_script,
281 gld${EMULATION_NAME}_finish,
282 NULL, /* create output section statements */
283 NULL, /* open dynamic archive */
284 NULL, /* place orphan */
285 NULL, /* set symbols */
286 gld${EMULATION_NAME}_parse_args,
287 NULL, /* unrecognised file */
288 gld${EMULATION_NAME}_list_options,
289 NULL, /* recognized file */
290 NULL /* find_potential_libraries */