Commit | Line | Data |
---|---|---|
252b5132 RH |
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! */ | |
5 | ||
6 | /* emulate the original gld for the given ${EMULATION_NAME} | |
5e2f1575 | 7 | Copyright 1991, 1993, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, |
3db64b00 | 8 | 2004, 2005, 2007 Free Software Foundation, Inc. |
252b5132 RH |
9 | Written by Steve Chamberlain steve@cygnus.com |
10 | ||
11 | This file is part of GLD, the Gnu Linker. | |
12 | ||
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. | |
17 | ||
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. | |
22 | ||
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 | |
75be928b | 25 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ |
252b5132 RH |
26 | |
27 | #define TARGET_IS_${EMULATION_NAME} | |
28 | ||
252b5132 | 29 | #include "sysdep.h" |
3db64b00 | 30 | #include "bfd.h" |
252b5132 RH |
31 | #include "bfdlink.h" |
32 | #include "getopt.h" | |
33 | ||
34 | #include "ld.h" | |
35 | #include "ldmain.h" | |
252b5132 RH |
36 | #include "ldmisc.h" |
37 | ||
38 | #include "ldexp.h" | |
39 | #include "ldlang.h" | |
b71e2778 AM |
40 | #include "ldfile.h" |
41 | #include "ldemul.h" | |
252b5132 | 42 | |
0c7a8e5a AM |
43 | /* If TRUE, then interworking stubs which support calls to old, |
44 | non-interworking aware ARM code should be generated. */ | |
252b5132 RH |
45 | |
46 | static int support_old_code = 0; | |
6f798e5c | 47 | static char * thumb_entry_symbol = NULL; |
252b5132 RH |
48 | |
49 | #define OPTION_SUPPORT_OLD_CODE 300 | |
6f798e5c | 50 | #define OPTION_THUMB_ENTRY 301 |
252b5132 | 51 | |
3bcf5557 | 52 | static void |
0c7a8e5a AM |
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) | |
252b5132 | 57 | { |
3bcf5557 AM |
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} | |
62 | }; | |
63 | ||
0c7a8e5a AM |
64 | *longopts = xrealloc (*longopts, |
65 | nl * sizeof (struct option) + sizeof (xtra_long)); | |
3bcf5557 AM |
66 | memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long)); |
67 | } | |
252b5132 RH |
68 | |
69 | static void | |
0c7a8e5a | 70 | gld${EMULATION_NAME}_list_options (FILE *file) |
252b5132 RH |
71 | { |
72 | fprintf (file, _(" --support-old-code Support interworking with old code\n")); | |
6f798e5c | 73 | fprintf (file, _(" --thumb-entry=<sym> Set the entry point to be Thumb symbol <sym>\n")); |
252b5132 RH |
74 | } |
75 | ||
3bcf5557 | 76 | static bfd_boolean |
0c7a8e5a | 77 | gld${EMULATION_NAME}_handle_option (int optc) |
252b5132 | 78 | { |
252b5132 RH |
79 | switch (optc) |
80 | { | |
81 | default: | |
3bcf5557 | 82 | return FALSE; |
252b5132 RH |
83 | |
84 | case OPTION_SUPPORT_OLD_CODE: | |
85 | support_old_code = 1; | |
86 | break; | |
6f798e5c NC |
87 | |
88 | case OPTION_THUMB_ENTRY: | |
89 | thumb_entry_symbol = optarg; | |
90 | break; | |
252b5132 | 91 | } |
0c7a8e5a | 92 | |
3bcf5557 | 93 | return TRUE; |
252b5132 RH |
94 | } |
95 | \f | |
96 | static void | |
0c7a8e5a | 97 | gld${EMULATION_NAME}_before_parse (void) |
252b5132 RH |
98 | { |
99 | #ifndef TARGET_ /* I.e., if not generic. */ | |
5e2f1575 | 100 | ldfile_set_output_arch ("`echo ${ARCH}`", bfd_arch_unknown); |
252b5132 RH |
101 | #endif /* not TARGET_ */ |
102 | } | |
103 | ||
104 | /* This is called after the sections have been attached to output | |
105 | sections, but before any sizes or addresses have been set. */ | |
106 | ||
107 | static void | |
0c7a8e5a | 108 | gld${EMULATION_NAME}_before_allocation (void) |
252b5132 RH |
109 | { |
110 | /* we should be able to set the size of the interworking stub section */ | |
111 | ||
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 */ | |
114 | { | |
115 | LANG_FOR_EACH_INPUT_STATEMENT (is) | |
116 | { | |
117 | if (! bfd_arm_process_before_allocation | |
118 | (is->the_bfd, & link_info, support_old_code)) | |
119 | { | |
120 | /* xgettext:c-format */ | |
121 | einfo (_("Errors encountered processing file %s"), is->filename); | |
122 | } | |
123 | } | |
124 | } | |
125 | ||
126 | /* We have seen it all. Allocate it, and carry on */ | |
127 | bfd_arm_allocate_interworking_sections (& link_info); | |
8423293d | 128 | |
1e035701 | 129 | before_allocation_default (); |
252b5132 RH |
130 | } |
131 | ||
132 | static void | |
0c7a8e5a | 133 | gld${EMULATION_NAME}_after_open (void) |
252b5132 | 134 | { |
f11523b0 | 135 | if (strstr (bfd_get_target (output_bfd), "arm") == NULL) |
252b5132 | 136 | { |
f11523b0 NC |
137 | /* The arm backend needs special fields in the output hash structure. |
138 | These will only be created if the output format is an arm format, | |
139 | hence we do not support linking and changing output formats at the | |
140 | same time. Use a link followed by objcopy to change output formats. */ | |
141 | einfo ("%F%X%P: error: cannot change output format whilst linking ARM binaries\n"); | |
142 | return; | |
252b5132 | 143 | } |
0c7a8e5a | 144 | |
f11523b0 NC |
145 | { |
146 | LANG_FOR_EACH_INPUT_STATEMENT (is) | |
147 | { | |
148 | if (bfd_arm_get_bfd_for_interworking (is->the_bfd, & link_info)) | |
149 | break; | |
150 | } | |
151 | } | |
252b5132 RH |
152 | } |
153 | ||
6f798e5c | 154 | static void |
0c7a8e5a | 155 | gld${EMULATION_NAME}_finish (void) |
6f798e5c | 156 | { |
74541ad4 | 157 | if (thumb_entry_symbol != NULL) |
6f798e5c | 158 | { |
74541ad4 AM |
159 | struct bfd_link_hash_entry * h; |
160 | ||
161 | h = bfd_link_hash_lookup (link_info.hash, thumb_entry_symbol, | |
162 | FALSE, FALSE, TRUE); | |
163 | ||
164 | if (h != (struct bfd_link_hash_entry *) NULL | |
165 | && (h->type == bfd_link_hash_defined | |
166 | || h->type == bfd_link_hash_defweak) | |
167 | && h->u.def.section->output_section != NULL) | |
168 | { | |
169 | static char buffer[32]; | |
170 | bfd_vma val; | |
171 | ||
172 | /* Special procesing is required for a Thumb entry symbol. The | |
173 | bottom bit of its address must be set. */ | |
174 | val = (h->u.def.value | |
175 | + bfd_get_section_vma (output_bfd, | |
176 | h->u.def.section->output_section) | |
177 | + h->u.def.section->output_offset); | |
178 | ||
179 | val |= 1; | |
180 | ||
181 | /* Now convert this value into a string and store it in entry_symbol | |
182 | where the lang_finish() function will pick it up. */ | |
183 | buffer[0] = '0'; | |
184 | buffer[1] = 'x'; | |
185 | ||
186 | sprintf_vma (buffer + 2, val); | |
187 | ||
188 | if (entry_symbol.name != NULL && entry_from_cmdline) | |
189 | einfo (_("%P: warning: '--thumb-entry %s' is overriding '-e %s'\n"), | |
190 | thumb_entry_symbol, entry_symbol.name); | |
191 | entry_symbol.name = buffer; | |
192 | } | |
193 | else | |
194 | einfo (_("%P: warning: connot find thumb start symbol %s\n"), | |
195 | thumb_entry_symbol); | |
6f798e5c | 196 | } |
1e035701 AM |
197 | |
198 | finish_default (); | |
6f798e5c NC |
199 | } |
200 | ||
252b5132 | 201 | static char * |
0c7a8e5a | 202 | gld${EMULATION_NAME}_get_script (int *isfile) |
252b5132 RH |
203 | EOF |
204 | ||
205 | if test -n "$COMPILE_IN" | |
206 | then | |
207 | # Scripts compiled in. | |
208 | ||
209 | # sed commands to quote an ld script as a C string. | |
597e2591 | 210 | sc="-f stringify.sed" |
252b5132 RH |
211 | |
212 | cat >>e${EMULATION_NAME}.c <<EOF | |
0c7a8e5a | 213 | { |
252b5132 RH |
214 | *isfile = 0; |
215 | ||
1049f94e | 216 | if (link_info.relocatable && config.build_constructors) |
252b5132 RH |
217 | return |
218 | EOF | |
b34976b6 | 219 | sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c |
1049f94e | 220 | echo ' ; else if (link_info.relocatable) return' >> e${EMULATION_NAME}.c |
b34976b6 AM |
221 | sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c |
222 | echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c | |
223 | sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c | |
224 | echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c | |
225 | sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c | |
226 | echo ' ; else return' >> e${EMULATION_NAME}.c | |
227 | sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c | |
228 | echo '; }' >> e${EMULATION_NAME}.c | |
252b5132 RH |
229 | |
230 | else | |
231 | # Scripts read from the filesystem. | |
232 | ||
233 | cat >>e${EMULATION_NAME}.c <<EOF | |
0c7a8e5a | 234 | { |
252b5132 RH |
235 | *isfile = 1; |
236 | ||
1049f94e | 237 | if (link_info.relocatable && config.build_constructors) |
252b5132 | 238 | return "ldscripts/${EMULATION_NAME}.xu"; |
1049f94e | 239 | else if (link_info.relocatable) |
252b5132 RH |
240 | return "ldscripts/${EMULATION_NAME}.xr"; |
241 | else if (!config.text_read_only) | |
242 | return "ldscripts/${EMULATION_NAME}.xbn"; | |
243 | else if (!config.magic_demand_paged) | |
244 | return "ldscripts/${EMULATION_NAME}.xn"; | |
245 | else | |
246 | return "ldscripts/${EMULATION_NAME}.x"; | |
247 | } | |
248 | EOF | |
249 | ||
250 | fi | |
251 | ||
252 | cat >>e${EMULATION_NAME}.c <<EOF | |
253 | ||
0c7a8e5a | 254 | struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation = |
252b5132 RH |
255 | { |
256 | gld${EMULATION_NAME}_before_parse, | |
257 | syslib_default, | |
258 | hll_default, | |
259 | after_parse_default, | |
260 | gld${EMULATION_NAME}_after_open, | |
261 | after_allocation_default, | |
262 | set_output_arch_default, | |
263 | ldemul_default_target, | |
264 | gld${EMULATION_NAME}_before_allocation, | |
265 | gld${EMULATION_NAME}_get_script, | |
266 | "${EMULATION_NAME}", | |
267 | "${OUTPUT_FORMAT}", | |
e1c47aa4 AM |
268 | gld${EMULATION_NAME}_finish, |
269 | NULL, /* create output section statements */ | |
270 | NULL, /* open dynamic archive */ | |
271 | NULL, /* place orphan */ | |
272 | NULL, /* set symbols */ | |
3bcf5557 AM |
273 | NULL, /* parse_args */ |
274 | gld${EMULATION_NAME}_add_options, | |
275 | gld${EMULATION_NAME}_handle_option, | |
e1c47aa4 AM |
276 | NULL, /* unrecognised file */ |
277 | gld${EMULATION_NAME}_list_options, | |
40d109bf | 278 | NULL, /* recognized file */ |
fac1652d AM |
279 | NULL, /* find_potential_libraries */ |
280 | NULL /* new_vers_pattern */ | |
252b5132 RH |
281 | }; |
282 | EOF |