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, 2003,
8 2004, 2005 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 /* If TRUE, then interworking stubs which support calls to old,
44 non-interworking aware ARM code should be generated. */
46 static int support_old_code = 0;
47 static char * thumb_entry_symbol = NULL;
49 #define OPTION_SUPPORT_OLD_CODE 300
50 #define OPTION_THUMB_ENTRY 301
53 gld${EMULATION_NAME}_add_options
54 (int ns ATTRIBUTE_UNUSED, char **shortopts ATTRIBUTE_UNUSED, int nl,
55 struct option **longopts, int nrl ATTRIBUTE_UNUSED,
56 struct option **really_longopts ATTRIBUTE_UNUSED)
58 static const struct option xtra_long[] = {
59 {"support-old-code", no_argument, NULL, OPTION_SUPPORT_OLD_CODE},
60 {"thumb-entry", required_argument, NULL, OPTION_THUMB_ENTRY},
61 {NULL, no_argument, NULL, 0}
64 *longopts = xrealloc (*longopts,
65 nl * sizeof (struct option) + sizeof (xtra_long));
66 memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
70 gld${EMULATION_NAME}_list_options (FILE *file)
72 fprintf (file, _(" --support-old-code Support interworking with old code\n"));
73 fprintf (file, _(" --thumb-entry=<sym> Set the entry point to be Thumb symbol <sym>\n"));
77 gld${EMULATION_NAME}_handle_option (int optc)
84 case OPTION_SUPPORT_OLD_CODE:
88 case OPTION_THUMB_ENTRY:
89 thumb_entry_symbol = optarg;
97 gld${EMULATION_NAME}_before_parse (void)
99 #ifndef TARGET_ /* I.e., if not generic. */
100 ldfile_set_output_arch ("`echo ${ARCH}`", bfd_arch_unknown);
101 #endif /* not TARGET_ */
104 /* This is called after the sections have been attached to output
105 sections, but before any sizes or addresses have been set. */
108 gld${EMULATION_NAME}_before_allocation (void)
110 /* we should be able to set the size of the interworking stub section */
112 /* Here we rummage through the found bfds to collect glue information */
113 /* FIXME: should this be based on a command line option? krk@cygnus.com */
115 LANG_FOR_EACH_INPUT_STATEMENT (is)
117 if (! bfd_arm_process_before_allocation
118 (is->the_bfd, & link_info, support_old_code))
120 /* xgettext:c-format */
121 einfo (_("Errors encountered processing file %s"), is->filename);
126 /* We have seen it all. Allocate it, and carry on */
127 bfd_arm_allocate_interworking_sections (& link_info);
129 if (!link_info.relocatable)
130 strip_excluded_output_sections ();
134 gld${EMULATION_NAME}_after_open (void)
136 if (strstr (bfd_get_target (output_bfd), "arm") == NULL)
138 /* The arm backend needs special fields in the output hash structure.
139 These will only be created if the output format is an arm format,
140 hence we do not support linking and changing output formats at the
141 same time. Use a link followed by objcopy to change output formats. */
142 einfo ("%F%X%P: error: cannot change output format whilst linking ARM binaries\n");
147 LANG_FOR_EACH_INPUT_STATEMENT (is)
149 if (bfd_arm_get_bfd_for_interworking (is->the_bfd, & link_info))
156 gld${EMULATION_NAME}_finish (void)
158 struct bfd_link_hash_entry * h;
160 if (thumb_entry_symbol == NULL)
163 h = bfd_link_hash_lookup (link_info.hash, thumb_entry_symbol,
166 if (h != (struct bfd_link_hash_entry *) NULL
167 && (h->type == bfd_link_hash_defined
168 || h->type == bfd_link_hash_defweak)
169 && h->u.def.section->output_section != NULL)
171 static char buffer[32];
174 /* Special procesing is required for a Thumb entry symbol. The
175 bottom bit of its address must be set. */
176 val = (h->u.def.value
177 + bfd_get_section_vma (output_bfd,
178 h->u.def.section->output_section)
179 + h->u.def.section->output_offset);
183 /* Now convert this value into a string and store it in entry_symbol
184 where the lang_finish() function will pick it up. */
188 sprintf_vma (buffer + 2, val);
190 if (entry_symbol.name != NULL && entry_from_cmdline)
191 einfo (_("%P: warning: '--thumb-entry %s' is overriding '-e %s'\n"),
192 thumb_entry_symbol, entry_symbol.name);
193 entry_symbol.name = buffer;
196 einfo (_("%P: warning: connot find thumb start symbol %s\n"), thumb_entry_symbol);
200 gld${EMULATION_NAME}_get_script (int *isfile)
203 if test -n "$COMPILE_IN"
205 # Scripts compiled in.
207 # sed commands to quote an ld script as a C string.
208 sc="-f stringify.sed"
210 cat >>e${EMULATION_NAME}.c <<EOF
214 if (link_info.relocatable && config.build_constructors)
217 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
218 echo ' ; else if (link_info.relocatable) return' >> e${EMULATION_NAME}.c
219 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
220 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
221 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
222 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
223 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
224 echo ' ; else return' >> e${EMULATION_NAME}.c
225 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
226 echo '; }' >> e${EMULATION_NAME}.c
229 # Scripts read from the filesystem.
231 cat >>e${EMULATION_NAME}.c <<EOF
235 if (link_info.relocatable && config.build_constructors)
236 return "ldscripts/${EMULATION_NAME}.xu";
237 else if (link_info.relocatable)
238 return "ldscripts/${EMULATION_NAME}.xr";
239 else if (!config.text_read_only)
240 return "ldscripts/${EMULATION_NAME}.xbn";
241 else if (!config.magic_demand_paged)
242 return "ldscripts/${EMULATION_NAME}.xn";
244 return "ldscripts/${EMULATION_NAME}.x";
250 cat >>e${EMULATION_NAME}.c <<EOF
252 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
254 gld${EMULATION_NAME}_before_parse,
258 gld${EMULATION_NAME}_after_open,
259 after_allocation_default,
260 set_output_arch_default,
261 ldemul_default_target,
262 gld${EMULATION_NAME}_before_allocation,
263 gld${EMULATION_NAME}_get_script,
266 gld${EMULATION_NAME}_finish,
267 NULL, /* create output section statements */
268 NULL, /* open dynamic archive */
269 NULL, /* place orphan */
270 NULL, /* set symbols */
271 NULL, /* parse_args */
272 gld${EMULATION_NAME}_add_options,
273 gld${EMULATION_NAME}_handle_option,
274 NULL, /* unrecognised file */
275 gld${EMULATION_NAME}_list_options,
276 NULL, /* recognized file */
277 NULL, /* find_potential_libraries */
278 NULL /* new_vers_pattern */