Commit | Line | Data |
---|---|---|
252b5132 RH |
1 | # This shell script emits a C file. -*- C -*- |
2 | # It does some substitutions. | |
3 | # This file is now misnamed, because it supports both 32 bit and 64 bit | |
4 | # ELF emulations. | |
5 | test -z "${ELFSIZE}" && ELFSIZE=32 | |
86af25fe L |
6 | if [ -z "$MACHINE" ]; then |
7 | OUTPUT_ARCH=${ARCH} | |
8 | else | |
9 | OUTPUT_ARCH=${ARCH}:${MACHINE} | |
10 | fi | |
252b5132 RH |
11 | cat >e${EMULATION_NAME}.c <<EOF |
12 | /* This file is is generated by a shell script. DO NOT EDIT! */ | |
13 | ||
14 | /* ${ELFSIZE} bit ELF emulation code for ${EMULATION_NAME} | |
a2b64bed | 15 | Copyright 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 |
87f2a346 | 16 | Free Software Foundation, Inc. |
252b5132 RH |
17 | Written by Steve Chamberlain <sac@cygnus.com> |
18 | ELF support by Ian Lance Taylor <ian@cygnus.com> | |
19 | ||
20 | This file is part of GLD, the Gnu Linker. | |
21 | ||
22 | This program is free software; you can redistribute it and/or modify | |
23 | it under the terms of the GNU General Public License as published by | |
24 | the Free Software Foundation; either version 2 of the License, or | |
25 | (at your option) any later version. | |
26 | ||
27 | This program is distributed in the hope that it will be useful, | |
28 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
29 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
30 | GNU General Public License for more details. | |
31 | ||
32 | You should have received a copy of the GNU General Public License | |
33 | along with this program; if not, write to the Free Software | |
34 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
35 | ||
36 | #define TARGET_IS_${EMULATION_NAME} | |
37 | ||
38 | #include "bfd.h" | |
39 | #include "sysdep.h" | |
1c9acd94 | 40 | #include "libiberty.h" |
252b5132 RH |
41 | |
42 | #include <ctype.h> | |
43 | ||
44 | #include "bfdlink.h" | |
45 | ||
46 | #include "ld.h" | |
47 | #include "ldmain.h" | |
252b5132 RH |
48 | #include "ldmisc.h" |
49 | #include "ldexp.h" | |
50 | #include "ldlang.h" | |
b71e2778 AM |
51 | #include "ldfile.h" |
52 | #include "ldemul.h" | |
252b5132 | 53 | #include "ldgram.h" |
e0ee487b | 54 | #include "elf/common.h" |
252b5132 RH |
55 | |
56 | static void gld${EMULATION_NAME}_before_parse PARAMS ((void)); | |
04925e1e | 57 | static void gld${EMULATION_NAME}_vercheck |
252b5132 RH |
58 | PARAMS ((lang_input_statement_type *)); |
59 | static void gld${EMULATION_NAME}_stat_needed | |
60 | PARAMS ((lang_input_statement_type *)); | |
04925e1e | 61 | static boolean gld${EMULATION_NAME}_try_needed PARAMS ((const char *, int)); |
252b5132 RH |
62 | static boolean gld${EMULATION_NAME}_search_needed |
63 | PARAMS ((const char *, const char *, int)); | |
04925e1e | 64 | static void gld${EMULATION_NAME}_check_needed |
252b5132 | 65 | PARAMS ((lang_input_statement_type *)); |
04925e1e AM |
66 | static void gld${EMULATION_NAME}_after_open PARAMS ((void)); |
67 | static void gld${EMULATION_NAME}_find_exp_assignment PARAMS ((etree_type *)); | |
252b5132 RH |
68 | static void gld${EMULATION_NAME}_find_statement_assignment |
69 | PARAMS ((lang_statement_union_type *)); | |
04925e1e AM |
70 | static void gld${EMULATION_NAME}_before_allocation PARAMS ((void)); |
71 | static boolean gld${EMULATION_NAME}_open_dynamic_archive | |
72 | PARAMS ((const char *, search_dirs_type *, lang_input_statement_type *)); | |
73 | static lang_output_section_statement_type *output_rel_find PARAMS ((void)); | |
73810896 AM |
74 | static asection *output_prev_sec_find |
75 | PARAMS ((lang_output_section_statement_type *)); | |
252b5132 RH |
76 | static boolean gld${EMULATION_NAME}_place_orphan |
77 | PARAMS ((lang_input_statement_type *, asection *)); | |
252b5132 RH |
78 | static char *gld${EMULATION_NAME}_get_script PARAMS ((int *isfile)); |
79 | ||
41392f03 AM |
80 | EOF |
81 | ||
82 | # Import any needed special functions and/or overrides. | |
83 | # | |
84 | if test -n "$EXTRA_EM_FILE" ; then | |
85 | . ${srcdir}/emultempl/${EXTRA_EM_FILE}.em | |
86 | fi | |
87 | ||
f813923c | 88 | # Functions in this file can be overridden by setting the LDEMUL_* shell |
41392f03 AM |
89 | # variables. If the name of the overriding function is the same as is |
90 | # defined in this file, then don't output this file's version. | |
91 | # If a different overriding name is given then output the standard function | |
92 | # as presumably it is called from the overriding function. | |
93 | # | |
94 | if test x"$LDEMUL_BEFORE_PARSE" != xgld"$EMULATION_NAME"_before_parse; then | |
95 | cat >>e${EMULATION_NAME}.c <<EOF | |
96 | ||
252b5132 | 97 | static void |
41392f03 | 98 | gld${EMULATION_NAME}_before_parse () |
252b5132 | 99 | { |
86af25fe L |
100 | const bfd_arch_info_type *arch = bfd_scan_arch ("${OUTPUT_ARCH}"); |
101 | if (arch) | |
102 | { | |
103 | ldfile_output_architecture = arch->arch; | |
104 | ldfile_output_machine = arch->mach; | |
105 | ldfile_output_machine_name = arch->printable_name; | |
106 | } | |
107 | else | |
108 | ldfile_output_architecture = bfd_arch_`echo ${ARCH} | sed -e 's/:.*//'`; | |
252b5132 RH |
109 | config.dynamic_link = ${DYNAMIC_LINK-true}; |
110 | config.has_shared = `if test -n "$GENERATE_SHLIB_SCRIPT" ; then echo true ; else echo false ; fi`; | |
111 | } | |
112 | ||
41392f03 AM |
113 | EOF |
114 | fi | |
115 | ||
116 | cat >>e${EMULATION_NAME}.c <<EOF | |
252b5132 RH |
117 | |
118 | /* These variables are required to pass information back and forth | |
119 | between after_open and check_needed and stat_needed and vercheck. */ | |
120 | ||
121 | static struct bfd_link_needed_list *global_needed; | |
122 | static struct stat global_stat; | |
123 | static boolean global_found; | |
124 | static struct bfd_link_needed_list *global_vercheck_needed; | |
125 | static boolean global_vercheck_failed; | |
126 | ||
252b5132 | 127 | |
04925e1e AM |
128 | /* On Linux, it's possible to have different versions of the same |
129 | shared library linked against different versions of libc. The | |
130 | dynamic linker somehow tags which libc version to use in | |
131 | /etc/ld.so.cache, and, based on the libc that it sees in the | |
132 | executable, chooses which version of the shared library to use. | |
252b5132 | 133 | |
04925e1e AM |
134 | We try to do a similar check here by checking whether this shared |
135 | library needs any other shared libraries which may conflict with | |
136 | libraries we have already included in the link. If it does, we | |
137 | skip it, and try to find another shared library farther on down the | |
138 | link path. | |
252b5132 | 139 | |
04925e1e AM |
140 | This is called via lang_for_each_input_file. |
141 | GLOBAL_VERCHECK_NEEDED is the list of objects needed by the object | |
f813923c | 142 | which we are checking. This sets GLOBAL_VERCHECK_FAILED if we find |
04925e1e | 143 | a conflicting version. */ |
252b5132 | 144 | |
04925e1e AM |
145 | static void |
146 | gld${EMULATION_NAME}_vercheck (s) | |
147 | lang_input_statement_type *s; | |
148 | { | |
1c9acd94 | 149 | const char *soname; |
04925e1e | 150 | struct bfd_link_needed_list *l; |
252b5132 | 151 | |
04925e1e AM |
152 | if (global_vercheck_failed) |
153 | return; | |
154 | if (s->the_bfd == NULL | |
155 | || (bfd_get_file_flags (s->the_bfd) & DYNAMIC) == 0) | |
156 | return; | |
252b5132 | 157 | |
04925e1e AM |
158 | soname = bfd_elf_get_dt_soname (s->the_bfd); |
159 | if (soname == NULL) | |
1c9acd94 | 160 | soname = basename (bfd_get_filename (s->the_bfd)); |
04925e1e AM |
161 | |
162 | for (l = global_vercheck_needed; l != NULL; l = l->next) | |
163 | { | |
164 | const char *suffix; | |
165 | ||
1c9acd94 | 166 | if (strcmp (soname, l->name) == 0) |
04925e1e AM |
167 | { |
168 | /* Probably can't happen, but it's an easy check. */ | |
169 | continue; | |
252b5132 RH |
170 | } |
171 | ||
04925e1e | 172 | if (strchr (l->name, '/') != NULL) |
252b5132 RH |
173 | continue; |
174 | ||
04925e1e AM |
175 | suffix = strstr (l->name, ".so."); |
176 | if (suffix == NULL) | |
177 | continue; | |
178 | ||
179 | suffix += sizeof ".so." - 1; | |
180 | ||
1c9acd94 | 181 | if (strncmp (soname, l->name, suffix - l->name) == 0) |
04925e1e AM |
182 | { |
183 | /* Here we know that S is a dynamic object FOO.SO.VER1, and | |
184 | the object we are considering needs a dynamic object | |
185 | FOO.SO.VER2, and VER1 and VER2 are different. This | |
186 | appears to be a version mismatch, so we tell the caller | |
187 | to try a different version of this library. */ | |
188 | global_vercheck_failed = true; | |
189 | return; | |
190 | } | |
252b5132 RH |
191 | } |
192 | } | |
193 | ||
252b5132 | 194 | |
04925e1e AM |
195 | /* See if an input file matches a DT_NEEDED entry by running stat on |
196 | the file. */ | |
197 | ||
198 | static void | |
199 | gld${EMULATION_NAME}_stat_needed (s) | |
200 | lang_input_statement_type *s; | |
252b5132 | 201 | { |
04925e1e AM |
202 | struct stat st; |
203 | const char *suffix; | |
204 | const char *soname; | |
252b5132 | 205 | |
04925e1e AM |
206 | if (global_found) |
207 | return; | |
208 | if (s->the_bfd == NULL) | |
209 | return; | |
210 | ||
211 | if (bfd_stat (s->the_bfd, &st) != 0) | |
252b5132 | 212 | { |
04925e1e AM |
213 | einfo ("%P:%B: bfd_stat failed: %E\n", s->the_bfd); |
214 | return; | |
215 | } | |
252b5132 | 216 | |
04925e1e AM |
217 | if (st.st_dev == global_stat.st_dev |
218 | && st.st_ino == global_stat.st_ino) | |
219 | { | |
220 | global_found = true; | |
221 | return; | |
222 | } | |
252b5132 | 223 | |
04925e1e AM |
224 | /* We issue a warning if it looks like we are including two |
225 | different versions of the same shared library. For example, | |
226 | there may be a problem if -lc picks up libc.so.6 but some other | |
227 | shared library has a DT_NEEDED entry of libc.so.5. This is a | |
f813923c | 228 | heuristic test, and it will only work if the name looks like |
04925e1e AM |
229 | NAME.so.VERSION. FIXME: Depending on file names is error-prone. |
230 | If we really want to issue warnings about mixing version numbers | |
231 | of shared libraries, we need to find a better way. */ | |
252b5132 | 232 | |
04925e1e AM |
233 | if (strchr (global_needed->name, '/') != NULL) |
234 | return; | |
235 | suffix = strstr (global_needed->name, ".so."); | |
236 | if (suffix == NULL) | |
237 | return; | |
238 | suffix += sizeof ".so." - 1; | |
252b5132 | 239 | |
04925e1e AM |
240 | soname = bfd_elf_get_dt_soname (s->the_bfd); |
241 | if (soname == NULL) | |
1c9acd94 | 242 | soname = basename (s->filename); |
252b5132 | 243 | |
1c9acd94 L |
244 | if (strncmp (soname, global_needed->name, |
245 | suffix - global_needed->name) == 0) | |
04925e1e | 246 | einfo ("%P: warning: %s, needed by %B, may conflict with %s\n", |
1c9acd94 | 247 | global_needed->name, global_needed->by, soname); |
252b5132 RH |
248 | } |
249 | ||
04925e1e | 250 | |
252b5132 RH |
251 | /* This function is called for each possible name for a dynamic object |
252 | named by a DT_NEEDED entry. The FORCE parameter indicates whether | |
253 | to skip the check for a conflicting version. */ | |
254 | ||
255 | static boolean | |
256 | gld${EMULATION_NAME}_try_needed (name, force) | |
257 | const char *name; | |
258 | int force; | |
259 | { | |
260 | bfd *abfd; | |
ec4eb78a | 261 | const char *soname; |
252b5132 RH |
262 | |
263 | abfd = bfd_openr (name, bfd_get_target (output_bfd)); | |
264 | if (abfd == NULL) | |
265 | return false; | |
266 | if (! bfd_check_format (abfd, bfd_object)) | |
267 | { | |
268 | (void) bfd_close (abfd); | |
269 | return false; | |
270 | } | |
271 | if ((bfd_get_file_flags (abfd) & DYNAMIC) == 0) | |
272 | { | |
273 | (void) bfd_close (abfd); | |
274 | return false; | |
275 | } | |
276 | ||
277 | /* Check whether this object would include any conflicting library | |
278 | versions. If FORCE is set, then we skip this check; we use this | |
279 | the second time around, if we couldn't find any compatible | |
280 | instance of the shared library. */ | |
281 | ||
282 | if (! force) | |
283 | { | |
284 | struct bfd_link_needed_list *needed; | |
285 | ||
286 | if (! bfd_elf_get_bfd_needed_list (abfd, &needed)) | |
287 | einfo ("%F%P:%B: bfd_elf_get_bfd_needed_list failed: %E\n", abfd); | |
288 | ||
289 | if (needed != NULL) | |
290 | { | |
291 | global_vercheck_needed = needed; | |
292 | global_vercheck_failed = false; | |
293 | lang_for_each_input_file (gld${EMULATION_NAME}_vercheck); | |
294 | if (global_vercheck_failed) | |
295 | { | |
296 | (void) bfd_close (abfd); | |
297 | /* Return false to force the caller to move on to try | |
298 | another file on the search path. */ | |
299 | return false; | |
300 | } | |
301 | ||
302 | /* But wait! It gets much worse. On Linux, if a shared | |
303 | library does not use libc at all, we are supposed to skip | |
304 | it the first time around in case we encounter a shared | |
305 | library later on with the same name which does use the | |
306 | version of libc that we want. This is much too horrible | |
307 | to use on any system other than Linux. */ | |
308 | ||
309 | EOF | |
310 | case ${target} in | |
311 | *-*-linux-gnu*) | |
312 | cat >>e${EMULATION_NAME}.c <<EOF | |
313 | { | |
314 | struct bfd_link_needed_list *l; | |
315 | ||
316 | for (l = needed; l != NULL; l = l->next) | |
317 | if (strncmp (l->name, "libc.so", 7) == 0) | |
318 | break; | |
319 | if (l == NULL) | |
320 | { | |
321 | (void) bfd_close (abfd); | |
322 | return false; | |
323 | } | |
324 | } | |
325 | ||
326 | EOF | |
327 | ;; | |
328 | esac | |
329 | cat >>e${EMULATION_NAME}.c <<EOF | |
330 | } | |
331 | } | |
332 | ||
333 | /* We've found a dynamic object matching the DT_NEEDED entry. */ | |
334 | ||
04925e1e AM |
335 | /* We have already checked that there is no other input file of the |
336 | same name. We must now check again that we are not including the | |
337 | same file twice. We need to do this because on many systems | |
338 | libc.so is a symlink to, e.g., libc.so.1. The SONAME entry will | |
339 | reference libc.so.1. If we have already included libc.so, we | |
340 | don't want to include libc.so.1 if they are the same file, and we | |
341 | can only check that using stat. */ | |
342 | ||
343 | if (bfd_stat (abfd, &global_stat) != 0) | |
344 | einfo ("%F%P:%B: bfd_stat failed: %E\n", abfd); | |
ec4eb78a L |
345 | |
346 | /* First strip off everything before the last '/'. */ | |
1c9acd94 | 347 | soname = basename (abfd->filename); |
ec4eb78a L |
348 | |
349 | if (trace_file_tries) | |
350 | info_msg (_("found %s at %s\n"), soname, name); | |
351 | ||
04925e1e AM |
352 | global_found = false; |
353 | lang_for_each_input_file (gld${EMULATION_NAME}_stat_needed); | |
354 | if (global_found) | |
355 | { | |
356 | /* Return true to indicate that we found the file, even though | |
357 | we aren't going to do anything with it. */ | |
358 | return true; | |
359 | } | |
360 | ||
41392f03 | 361 | /* Tell the ELF backend that we don't want the output file to have a |
04925e1e AM |
362 | DT_NEEDED entry for this file. */ |
363 | bfd_elf_set_dt_needed_name (abfd, ""); | |
364 | ||
c2a1a436 DB |
365 | /* Previos basename call was clobbered in lang_for_each_input_file. */ |
366 | soname = basename (abfd->filename); | |
367 | ||
04925e1e AM |
368 | /* Tell the ELF backend that the output file needs a DT_NEEDED |
369 | entry for this file if it is used to resolve the reference in | |
370 | a regular object. */ | |
ec4eb78a | 371 | bfd_elf_set_dt_needed_soname (abfd, soname); |
04925e1e AM |
372 | |
373 | /* Add this file into the symbol table. */ | |
374 | if (! bfd_link_add_symbols (abfd, &link_info)) | |
375 | einfo ("%F%B: could not read symbols: %E\n", abfd); | |
376 | ||
377 | return true; | |
378 | } | |
379 | ||
380 | ||
381 | /* Search for a needed file in a path. */ | |
382 | ||
383 | static boolean | |
384 | gld${EMULATION_NAME}_search_needed (path, name, force) | |
385 | const char *path; | |
386 | const char *name; | |
387 | int force; | |
388 | { | |
389 | const char *s; | |
390 | size_t len; | |
391 | ||
cc5ce052 UD |
392 | if (name[0] == '/') |
393 | return gld${EMULATION_NAME}_try_needed (name, force); | |
394 | ||
04925e1e AM |
395 | if (path == NULL || *path == '\0') |
396 | return false; | |
397 | len = strlen (name); | |
398 | while (1) | |
399 | { | |
400 | char *filename, *sset; | |
401 | ||
402 | s = strchr (path, ':'); | |
403 | if (s == NULL) | |
404 | s = path + strlen (path); | |
405 | ||
406 | filename = (char *) xmalloc (s - path + len + 2); | |
407 | if (s == path) | |
408 | sset = filename; | |
409 | else | |
410 | { | |
411 | memcpy (filename, path, s - path); | |
412 | filename[s - path] = '/'; | |
413 | sset = filename + (s - path) + 1; | |
414 | } | |
415 | strcpy (sset, name); | |
416 | ||
417 | if (gld${EMULATION_NAME}_try_needed (filename, force)) | |
418 | return true; | |
419 | ||
420 | free (filename); | |
421 | ||
422 | if (*s == '\0') | |
423 | break; | |
424 | path = s + 1; | |
425 | } | |
426 | ||
427 | return false; | |
428 | } | |
429 | ||
430 | EOF | |
431 | if [ "x${host}" = "x${target}" ] ; then | |
432 | case " ${EMULATION_LIBPATH} " in | |
433 | *" ${EMULATION_NAME} "*) | |
482e8b32 DB |
434 | case ${target} in |
435 | *-*-linux-gnu*) | |
436 | cat >>e${EMULATION_NAME}.c <<EOF | |
04925e1e AM |
437 | |
438 | /* For a native linker, check the file /etc/ld.so.conf for directories | |
439 | in which we may find shared libraries. /etc/ld.so.conf is really | |
482e8b32 | 440 | only meaningful on Linux. */ |
04925e1e AM |
441 | |
442 | static boolean gld${EMULATION_NAME}_check_ld_so_conf | |
443 | PARAMS ((const char *, int)); | |
444 | ||
445 | static boolean | |
446 | gld${EMULATION_NAME}_check_ld_so_conf (name, force) | |
447 | const char *name; | |
448 | int force; | |
449 | { | |
450 | static boolean initialized; | |
451 | static char *ld_so_conf; | |
452 | ||
453 | if (! initialized) | |
454 | { | |
455 | FILE *f; | |
456 | ||
457 | f = fopen ("/etc/ld.so.conf", FOPEN_RT); | |
458 | if (f != NULL) | |
459 | { | |
460 | char *b; | |
461 | size_t len, alloc; | |
462 | int c; | |
463 | ||
464 | len = 0; | |
465 | alloc = 100; | |
466 | b = (char *) xmalloc (alloc); | |
467 | ||
468 | while ((c = getc (f)) != EOF) | |
469 | { | |
470 | if (len + 1 >= alloc) | |
471 | { | |
472 | alloc *= 2; | |
473 | b = (char *) xrealloc (b, alloc); | |
474 | } | |
475 | if (c != ':' | |
476 | && c != ' ' | |
477 | && c != '\t' | |
478 | && c != '\n' | |
479 | && c != ',') | |
480 | { | |
481 | b[len] = c; | |
482 | ++len; | |
483 | } | |
484 | else | |
485 | { | |
486 | if (len > 0 && b[len - 1] != ':') | |
487 | { | |
488 | b[len] = ':'; | |
489 | ++len; | |
490 | } | |
491 | } | |
492 | } | |
493 | ||
494 | if (len > 0 && b[len - 1] == ':') | |
495 | --len; | |
252b5132 | 496 | |
04925e1e AM |
497 | if (len > 0) |
498 | b[len] = '\0'; | |
499 | else | |
500 | { | |
501 | free (b); | |
502 | b = NULL; | |
503 | } | |
252b5132 | 504 | |
04925e1e | 505 | fclose (f); |
252b5132 | 506 | |
04925e1e AM |
507 | ld_so_conf = b; |
508 | } | |
49e56c49 | 509 | |
04925e1e AM |
510 | initialized = true; |
511 | } | |
49e56c49 | 512 | |
04925e1e AM |
513 | if (ld_so_conf == NULL) |
514 | return false; | |
252b5132 | 515 | |
04925e1e | 516 | return gld${EMULATION_NAME}_search_needed (ld_so_conf, name, force); |
252b5132 RH |
517 | } |
518 | ||
04925e1e | 519 | EOF |
482e8b32 DB |
520 | # Linux |
521 | ;; | |
522 | esac | |
04925e1e AM |
523 | esac |
524 | fi | |
525 | cat >>e${EMULATION_NAME}.c <<EOF | |
526 | ||
252b5132 RH |
527 | /* See if an input file matches a DT_NEEDED entry by name. */ |
528 | ||
529 | static void | |
530 | gld${EMULATION_NAME}_check_needed (s) | |
531 | lang_input_statement_type *s; | |
532 | { | |
533 | if (global_found) | |
534 | return; | |
535 | ||
577a0623 | 536 | if (s->filename != NULL) |
252b5132 | 537 | { |
577a0623 AM |
538 | const char *f; |
539 | ||
540 | if (strcmp (s->filename, global_needed->name) == 0) | |
541 | { | |
542 | global_found = true; | |
543 | return; | |
544 | } | |
545 | ||
546 | if (s->search_dirs_flag) | |
547 | { | |
548 | f = strrchr (s->filename, '/'); | |
549 | if (f != NULL | |
550 | && strcmp (f + 1, global_needed->name) == 0) | |
551 | { | |
552 | global_found = true; | |
553 | return; | |
554 | } | |
555 | } | |
252b5132 RH |
556 | } |
557 | ||
558 | if (s->the_bfd != NULL) | |
559 | { | |
560 | const char *soname; | |
561 | ||
562 | soname = bfd_elf_get_dt_soname (s->the_bfd); | |
563 | if (soname != NULL | |
564 | && strcmp (soname, global_needed->name) == 0) | |
565 | { | |
566 | global_found = true; | |
567 | return; | |
568 | } | |
569 | } | |
252b5132 RH |
570 | } |
571 | ||
41392f03 AM |
572 | EOF |
573 | ||
574 | if test x"$LDEMUL_AFTER_OPEN" != xgld"$EMULATION_NAME"_after_open; then | |
575 | cat >>e${EMULATION_NAME}.c <<EOF | |
04925e1e AM |
576 | |
577 | /* This is called after all the input files have been opened. */ | |
252b5132 RH |
578 | |
579 | static void | |
04925e1e | 580 | gld${EMULATION_NAME}_after_open () |
252b5132 | 581 | { |
04925e1e | 582 | struct bfd_link_needed_list *needed, *l; |
252b5132 | 583 | |
04925e1e AM |
584 | /* We only need to worry about this when doing a final link. */ |
585 | if (link_info.relocateable || link_info.shared) | |
252b5132 RH |
586 | return; |
587 | ||
04925e1e AM |
588 | /* Get the list of files which appear in DT_NEEDED entries in |
589 | dynamic objects included in the link (often there will be none). | |
590 | For each such file, we want to track down the corresponding | |
591 | library, and include the symbol table in the link. This is what | |
592 | the runtime dynamic linker will do. Tracking the files down here | |
593 | permits one dynamic object to include another without requiring | |
594 | special action by the person doing the link. Note that the | |
595 | needed list can actually grow while we are stepping through this | |
596 | loop. */ | |
597 | needed = bfd_elf_get_needed_list (output_bfd, &link_info); | |
598 | for (l = needed; l != NULL; l = l->next) | |
252b5132 | 599 | { |
04925e1e AM |
600 | struct bfd_link_needed_list *ll; |
601 | int force; | |
252b5132 | 602 | |
04925e1e AM |
603 | /* If we've already seen this file, skip it. */ |
604 | for (ll = needed; ll != l; ll = ll->next) | |
605 | if (strcmp (ll->name, l->name) == 0) | |
606 | break; | |
607 | if (ll != l) | |
608 | continue; | |
252b5132 | 609 | |
04925e1e AM |
610 | /* See if this file was included in the link explicitly. */ |
611 | global_needed = l; | |
612 | global_found = false; | |
613 | lang_for_each_input_file (gld${EMULATION_NAME}_check_needed); | |
614 | if (global_found) | |
615 | continue; | |
252b5132 | 616 | |
ec4eb78a L |
617 | if (trace_file_tries) |
618 | info_msg (_("%s needed by %B\n"), l->name, l->by); | |
619 | ||
04925e1e AM |
620 | /* We need to find this file and include the symbol table. We |
621 | want to search for the file in the same way that the dynamic | |
622 | linker will search. That means that we want to use | |
623 | rpath_link, rpath, then the environment variable | |
ec4eb78a L |
624 | LD_LIBRARY_PATH (native only), then the DT_RPATH/DT_RUNPATH |
625 | entries (native only), then the linker script LIB_SEARCH_DIRS. | |
626 | We do not search using the -L arguments. | |
252b5132 | 627 | |
04925e1e AM |
628 | We search twice. The first time, we skip objects which may |
629 | introduce version mismatches. The second time, we force | |
630 | their use. See gld${EMULATION_NAME}_vercheck comment. */ | |
631 | for (force = 0; force < 2; force++) | |
632 | { | |
04925e1e AM |
633 | size_t len; |
634 | search_dirs_type *search; | |
6dd8c765 L |
635 | EOF |
636 | if [ "x${host}" = "x${target}" ] ; then | |
637 | case " ${EMULATION_LIBPATH} " in | |
638 | *" ${EMULATION_NAME} "*) | |
639 | cat >>e${EMULATION_NAME}.c <<EOF | |
dcb0bd0e | 640 | const char *lib_path; |
6dd8c765 L |
641 | struct bfd_link_needed_list *rp; |
642 | int found; | |
643 | EOF | |
644 | ;; | |
645 | esac | |
646 | fi | |
647 | cat >>e${EMULATION_NAME}.c <<EOF | |
252b5132 | 648 | |
04925e1e AM |
649 | if (gld${EMULATION_NAME}_search_needed (command_line.rpath_link, |
650 | l->name, force)) | |
651 | break; | |
dcb0bd0e L |
652 | EOF |
653 | if [ "x${host}" = "x${target}" ] ; then | |
654 | case " ${EMULATION_LIBPATH} " in | |
655 | *" ${EMULATION_NAME} "*) | |
656 | cat >>e${EMULATION_NAME}.c <<EOF | |
04925e1e AM |
657 | if (gld${EMULATION_NAME}_search_needed (command_line.rpath, |
658 | l->name, force)) | |
659 | break; | |
660 | if (command_line.rpath_link == NULL | |
661 | && command_line.rpath == NULL) | |
662 | { | |
663 | lib_path = (const char *) getenv ("LD_RUN_PATH"); | |
664 | if (gld${EMULATION_NAME}_search_needed (lib_path, l->name, | |
665 | force)) | |
666 | break; | |
667 | } | |
04925e1e AM |
668 | lib_path = (const char *) getenv ("LD_LIBRARY_PATH"); |
669 | if (gld${EMULATION_NAME}_search_needed (lib_path, l->name, force)) | |
670 | break; | |
ec4eb78a L |
671 | |
672 | found = 0; | |
6dd8c765 L |
673 | rp = bfd_elf_get_runpath_list (output_bfd, &link_info); |
674 | for (; !found && rp != NULL; rp = rp->next) | |
ec4eb78a L |
675 | { |
676 | found = (rp->by == l->by | |
677 | && gld${EMULATION_NAME}_search_needed (rp->name, | |
678 | l->name, | |
679 | force)); | |
680 | } | |
681 | if (found) | |
682 | break; | |
683 | ||
04925e1e AM |
684 | EOF |
685 | ;; | |
686 | esac | |
687 | fi | |
688 | cat >>e${EMULATION_NAME}.c <<EOF | |
689 | len = strlen (l->name); | |
690 | for (search = search_head; search != NULL; search = search->next) | |
691 | { | |
692 | char *filename; | |
252b5132 | 693 | |
04925e1e AM |
694 | if (search->cmdline) |
695 | continue; | |
696 | filename = (char *) xmalloc (strlen (search->name) + len + 2); | |
697 | sprintf (filename, "%s/%s", search->name, l->name); | |
698 | if (gld${EMULATION_NAME}_try_needed (filename, force)) | |
699 | break; | |
700 | free (filename); | |
701 | } | |
702 | if (search != NULL) | |
703 | break; | |
704 | EOF | |
705 | if [ "x${host}" = "x${target}" ] ; then | |
706 | case " ${EMULATION_LIBPATH} " in | |
707 | *" ${EMULATION_NAME} "*) | |
482e8b32 DB |
708 | case ${target} in |
709 | *-*-linux-gnu*) | |
710 | cat >>e${EMULATION_NAME}.c <<EOF | |
04925e1e AM |
711 | if (gld${EMULATION_NAME}_check_ld_so_conf (l->name, force)) |
712 | break; | |
713 | EOF | |
482e8b32 DB |
714 | # Linux |
715 | ;; | |
716 | esac | |
04925e1e AM |
717 | ;; |
718 | esac | |
719 | fi | |
720 | cat >>e${EMULATION_NAME}.c <<EOF | |
721 | } | |
252b5132 | 722 | |
04925e1e AM |
723 | if (force < 2) |
724 | continue; | |
252b5132 | 725 | |
e374f1d9 | 726 | einfo ("%P: warning: %s, needed by %B, not found (try using -rpath or -rpath-link)\n", |
04925e1e AM |
727 | l->name, l->by); |
728 | } | |
729 | } | |
252b5132 | 730 | |
41392f03 AM |
731 | EOF |
732 | fi | |
733 | ||
734 | cat >>e${EMULATION_NAME}.c <<EOF | |
252b5132 | 735 | |
04925e1e | 736 | /* Look through an expression for an assignment statement. */ |
252b5132 | 737 | |
04925e1e AM |
738 | static void |
739 | gld${EMULATION_NAME}_find_exp_assignment (exp) | |
740 | etree_type *exp; | |
741 | { | |
742 | struct bfd_link_hash_entry *h; | |
743 | ||
744 | switch (exp->type.node_class) | |
252b5132 | 745 | { |
04925e1e AM |
746 | case etree_provide: |
747 | h = bfd_link_hash_lookup (link_info.hash, exp->assign.dst, | |
748 | false, false, false); | |
749 | if (h == NULL) | |
750 | break; | |
252b5132 | 751 | |
04925e1e AM |
752 | /* We call record_link_assignment even if the symbol is defined. |
753 | This is because if it is defined by a dynamic object, we | |
754 | actually want to use the value defined by the linker script, | |
755 | not the value from the dynamic object (because we are setting | |
756 | symbols like etext). If the symbol is defined by a regular | |
757 | object, then, as it happens, calling record_link_assignment | |
758 | will do no harm. */ | |
759 | ||
760 | /* Fall through. */ | |
761 | case etree_assign: | |
762 | if (strcmp (exp->assign.dst, ".") != 0) | |
252b5132 | 763 | { |
04925e1e AM |
764 | if (! (bfd_elf${ELFSIZE}_record_link_assignment |
765 | (output_bfd, &link_info, exp->assign.dst, | |
766 | exp->type.node_class == etree_provide ? true : false))) | |
767 | einfo ("%P%F: failed to record assignment to %s: %E\n", | |
768 | exp->assign.dst); | |
252b5132 | 769 | } |
04925e1e AM |
770 | gld${EMULATION_NAME}_find_exp_assignment (exp->assign.src); |
771 | break; | |
252b5132 | 772 | |
04925e1e AM |
773 | case etree_binary: |
774 | gld${EMULATION_NAME}_find_exp_assignment (exp->binary.lhs); | |
775 | gld${EMULATION_NAME}_find_exp_assignment (exp->binary.rhs); | |
776 | break; | |
252b5132 | 777 | |
04925e1e AM |
778 | case etree_trinary: |
779 | gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.cond); | |
780 | gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.lhs); | |
781 | gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.rhs); | |
782 | break; | |
252b5132 | 783 | |
04925e1e AM |
784 | case etree_unary: |
785 | gld${EMULATION_NAME}_find_exp_assignment (exp->unary.child); | |
786 | break; | |
252b5132 | 787 | |
04925e1e AM |
788 | default: |
789 | break; | |
252b5132 RH |
790 | } |
791 | } | |
792 | ||
04925e1e AM |
793 | |
794 | /* This is called by the before_allocation routine via | |
795 | lang_for_each_statement. It locates any assignment statements, and | |
796 | tells the ELF backend about them, in case they are assignments to | |
797 | symbols which are referred to by dynamic objects. */ | |
798 | ||
799 | static void | |
800 | gld${EMULATION_NAME}_find_statement_assignment (s) | |
801 | lang_statement_union_type *s; | |
802 | { | |
803 | if (s->header.type == lang_assignment_statement_enum) | |
804 | gld${EMULATION_NAME}_find_exp_assignment (s->assignment_statement.exp); | |
805 | } | |
806 | ||
41392f03 AM |
807 | EOF |
808 | ||
809 | if test x"$LDEMUL_BEFORE_ALLOCATION" != xgld"$EMULATION_NAME"_before_allocation; then | |
57e6abd2 AO |
810 | if test x"${ELF_INTERPRETER_NAME+set}" = xset; then |
811 | ELF_INTERPRETER_SET_DEFAULT=" | |
812 | if (sinterp != NULL) | |
813 | { | |
814 | sinterp->contents = ${ELF_INTERPRETER_NAME}; | |
815 | sinterp->_raw_size = strlen (sinterp->contents) + 1; | |
816 | } | |
817 | ||
818 | " | |
819 | else | |
820 | ELF_INTERPRETER_SET_DEFAULT= | |
821 | fi | |
41392f03 | 822 | cat >>e${EMULATION_NAME}.c <<EOF |
04925e1e | 823 | |
252b5132 RH |
824 | /* This is called after the sections have been attached to output |
825 | sections, but before any sizes or addresses have been set. */ | |
826 | ||
827 | static void | |
828 | gld${EMULATION_NAME}_before_allocation () | |
829 | { | |
830 | const char *rpath; | |
831 | asection *sinterp; | |
832 | ||
833 | /* If we are going to make any variable assignments, we need to let | |
834 | the ELF backend know about them in case the variables are | |
835 | referred to by dynamic objects. */ | |
836 | lang_for_each_statement (gld${EMULATION_NAME}_find_statement_assignment); | |
837 | ||
838 | /* Let the ELF backend work out the sizes of any sections required | |
839 | by dynamic linking. */ | |
840 | rpath = command_line.rpath; | |
841 | if (rpath == NULL) | |
842 | rpath = (const char *) getenv ("LD_RUN_PATH"); | |
843 | if (! (bfd_elf${ELFSIZE}_size_dynamic_sections | |
844 | (output_bfd, command_line.soname, rpath, | |
605d9b3a | 845 | command_line.filter_shlib, |
252b5132 RH |
846 | (const char * const *) command_line.auxiliary_filters, |
847 | &link_info, &sinterp, lang_elf_version_info))) | |
848 | einfo ("%P%F: failed to set dynamic section sizes: %E\n"); | |
57e6abd2 | 849 | ${ELF_INTERPRETER_SET_DEFAULT} |
252b5132 RH |
850 | /* Let the user override the dynamic linker we are using. */ |
851 | if (command_line.interpreter != NULL | |
852 | && sinterp != NULL) | |
853 | { | |
854 | sinterp->contents = (bfd_byte *) command_line.interpreter; | |
855 | sinterp->_raw_size = strlen (command_line.interpreter) + 1; | |
856 | } | |
857 | ||
858 | /* Look for any sections named .gnu.warning. As a GNU extensions, | |
859 | we treat such sections as containing warning messages. We print | |
860 | out the warning message, and then zero out the section size so | |
861 | that it does not get copied into the output file. */ | |
862 | ||
863 | { | |
864 | LANG_FOR_EACH_INPUT_STATEMENT (is) | |
865 | { | |
866 | asection *s; | |
867 | bfd_size_type sz; | |
868 | char *msg; | |
869 | boolean ret; | |
870 | ||
871 | if (is->just_syms_flag) | |
872 | continue; | |
873 | ||
874 | s = bfd_get_section_by_name (is->the_bfd, ".gnu.warning"); | |
875 | if (s == NULL) | |
876 | continue; | |
877 | ||
878 | sz = bfd_section_size (is->the_bfd, s); | |
879 | msg = xmalloc ((size_t) sz + 1); | |
880 | if (! bfd_get_section_contents (is->the_bfd, s, msg, (file_ptr) 0, sz)) | |
881 | einfo ("%F%B: Can't read contents of section .gnu.warning: %E\n", | |
882 | is->the_bfd); | |
883 | msg[sz] = '\0'; | |
884 | ret = link_info.callbacks->warning (&link_info, msg, | |
885 | (const char *) NULL, | |
886 | is->the_bfd, (asection *) NULL, | |
887 | (bfd_vma) 0); | |
888 | ASSERT (ret); | |
889 | free (msg); | |
890 | ||
891 | /* Clobber the section size, so that we don't waste copying the | |
892 | warning into the output file. */ | |
893 | s->_raw_size = 0; | |
894 | } | |
895 | } | |
896 | } | |
897 | ||
41392f03 AM |
898 | EOF |
899 | fi | |
900 | ||
901 | if test x"$LDEMUL_OPEN_DYNAMIC_ARCHIVE" != xgld"$EMULATION_NAME"_open_dynamic_archive; then | |
902 | cat >>e${EMULATION_NAME}.c <<EOF | |
252b5132 | 903 | |
04925e1e AM |
904 | /* Try to open a dynamic archive. This is where we know that ELF |
905 | dynamic libraries have an extension of .so (or .sl on oddball systems | |
906 | like hpux). */ | |
907 | ||
908 | static boolean | |
909 | gld${EMULATION_NAME}_open_dynamic_archive (arch, search, entry) | |
910 | const char *arch; | |
911 | search_dirs_type *search; | |
912 | lang_input_statement_type *entry; | |
252b5132 | 913 | { |
04925e1e AM |
914 | const char *filename; |
915 | char *string; | |
252b5132 | 916 | |
04925e1e AM |
917 | if (! entry->is_archive) |
918 | return false; | |
252b5132 | 919 | |
04925e1e | 920 | filename = entry->filename; |
252b5132 | 921 | |
04925e1e AM |
922 | /* This allocates a few bytes too many when EXTRA_SHLIB_EXTENSION |
923 | is defined, but it does not seem worth the headache to optimize | |
924 | away those two bytes of space. */ | |
925 | string = (char *) xmalloc (strlen (search->name) | |
926 | + strlen (filename) | |
927 | + strlen (arch) | |
928 | #ifdef EXTRA_SHLIB_EXTENSION | |
929 | + strlen (EXTRA_SHLIB_EXTENSION) | |
930 | #endif | |
931 | + sizeof "/lib.so"); | |
932 | ||
933 | sprintf (string, "%s/lib%s%s.so", search->name, filename, arch); | |
934 | ||
935 | #ifdef EXTRA_SHLIB_EXTENSION | |
936 | /* Try the .so extension first. If that fails build a new filename | |
937 | using EXTRA_SHLIB_EXTENSION. */ | |
938 | if (! ldfile_try_open_bfd (string, entry)) | |
939 | sprintf (string, "%s/lib%s%s%s", search->name, | |
940 | filename, arch, EXTRA_SHLIB_EXTENSION); | |
941 | #endif | |
942 | ||
943 | if (! ldfile_try_open_bfd (string, entry)) | |
252b5132 | 944 | { |
04925e1e AM |
945 | free (string); |
946 | return false; | |
947 | } | |
252b5132 | 948 | |
04925e1e | 949 | entry->filename = string; |
252b5132 | 950 | |
04925e1e AM |
951 | /* We have found a dynamic object to include in the link. The ELF |
952 | backend linker will create a DT_NEEDED entry in the .dynamic | |
953 | section naming this file. If this file includes a DT_SONAME | |
954 | entry, it will be used. Otherwise, the ELF linker will just use | |
955 | the name of the file. For an archive found by searching, like | |
956 | this one, the DT_NEEDED entry should consist of just the name of | |
957 | the file, without the path information used to find it. Note | |
958 | that we only need to do this if we have a dynamic object; an | |
959 | archive will never be referenced by a DT_NEEDED entry. | |
252b5132 | 960 | |
04925e1e AM |
961 | FIXME: This approach--using bfd_elf_set_dt_needed_name--is not |
962 | very pretty. I haven't been able to think of anything that is | |
963 | pretty, though. */ | |
964 | if (bfd_check_format (entry->the_bfd, bfd_object) | |
965 | && (entry->the_bfd->flags & DYNAMIC) != 0) | |
966 | { | |
04925e1e | 967 | ASSERT (entry->is_archive && entry->search_dirs_flag); |
252b5132 | 968 | |
04925e1e | 969 | /* Rather than duplicating the logic above. Just use the |
1c9acd94 | 970 | filename we recorded earlier. */ |
04925e1e | 971 | |
1c9acd94 L |
972 | filename = xstrdup (basename (entry->filename)); |
973 | bfd_elf_set_dt_needed_name (entry->the_bfd, filename); | |
04925e1e AM |
974 | } |
975 | ||
976 | return true; | |
977 | } | |
978 | ||
41392f03 AM |
979 | EOF |
980 | fi | |
981 | cat >>e${EMULATION_NAME}.c <<EOF | |
982 | ||
983 | /* A variant of lang_output_section_find. Used by place_orphan. */ | |
04925e1e | 984 | |
04925e1e AM |
985 | static lang_output_section_statement_type * |
986 | output_rel_find () | |
987 | { | |
988 | lang_statement_union_type *u; | |
989 | lang_output_section_statement_type *lookup; | |
990 | ||
991 | for (u = lang_output_section_statement.head; | |
992 | u != (lang_statement_union_type *) NULL; | |
993 | u = lookup->next) | |
994 | { | |
995 | lookup = &u->output_section_statement; | |
996 | if (strncmp (".rel", lookup->name, 4) == 0 | |
997 | && lookup->bfd_section != NULL | |
998 | && (lookup->bfd_section->flags & SEC_ALLOC) != 0) | |
999 | { | |
1000 | return lookup; | |
1001 | } | |
252b5132 | 1002 | } |
04925e1e | 1003 | return (lang_output_section_statement_type *) NULL; |
252b5132 RH |
1004 | } |
1005 | ||
41392f03 AM |
1006 | EOF |
1007 | ||
1008 | if test x"$LDEMUL_PLACE_ORPHAN" != xgld"$EMULATION_NAME"_place_orphan; then | |
1009 | cat >>e${EMULATION_NAME}.c <<EOF | |
04925e1e | 1010 | |
95500e1c JJ |
1011 | /* Find the last output section before given output statement. |
1012 | Used by place_orphan. */ | |
1013 | ||
1014 | static asection * | |
1015 | output_prev_sec_find (os) | |
1016 | lang_output_section_statement_type *os; | |
1017 | { | |
1018 | asection *s = (asection *) NULL; | |
1019 | lang_statement_union_type *u; | |
1020 | lang_output_section_statement_type *lookup; | |
1021 | ||
1022 | for (u = lang_output_section_statement.head; | |
1023 | u != (lang_statement_union_type *) NULL; | |
1024 | u = lookup->next) | |
1025 | { | |
1026 | lookup = &u->output_section_statement; | |
1027 | if (lookup == os) | |
1028 | break; | |
5030876b L |
1029 | if (lookup->bfd_section != NULL |
1030 | && lookup->bfd_section != bfd_abs_section_ptr | |
1031 | && lookup->bfd_section != bfd_com_section_ptr | |
1032 | && lookup->bfd_section != bfd_und_section_ptr) | |
95500e1c JJ |
1033 | s = lookup->bfd_section; |
1034 | } | |
1035 | ||
1036 | if (u == NULL) | |
1037 | return NULL; | |
1038 | ||
1039 | return s; | |
1040 | } | |
1041 | ||
1042 | ||
252b5132 RH |
1043 | /* Place an orphan section. We use this to put random SHF_ALLOC |
1044 | sections in the right segment. */ | |
1045 | ||
41392f03 | 1046 | struct orphan_save { |
6a345e87 | 1047 | lang_output_section_statement_type *os; |
5ba47421 | 1048 | asection **section; |
6a345e87 AM |
1049 | lang_statement_union_type **stmt; |
1050 | }; | |
252b5132 | 1051 | |
252b5132 RH |
1052 | static boolean |
1053 | gld${EMULATION_NAME}_place_orphan (file, s) | |
1054 | lang_input_statement_type *file; | |
1055 | asection *s; | |
1056 | { | |
aea4bd9d AM |
1057 | static struct orphan_save hold_text; |
1058 | static struct orphan_save hold_rodata; | |
1059 | static struct orphan_save hold_data; | |
1060 | static struct orphan_save hold_bss; | |
1061 | static struct orphan_save hold_rel; | |
1062 | static struct orphan_save hold_interp; | |
c940e6fc | 1063 | static struct orphan_save hold_sdata; |
f9989030 | 1064 | static int count = 1; |
6a345e87 | 1065 | struct orphan_save *place; |
71bfc0ae | 1066 | lang_statement_list_type *old; |
252b5132 RH |
1067 | lang_statement_list_type add; |
1068 | etree_type *address; | |
a854a4a7 | 1069 | const char *secname; |
252b5132 | 1070 | const char *outsecname; |
a854a4a7 | 1071 | const char *ps = NULL; |
252b5132 RH |
1072 | lang_output_section_statement_type *os; |
1073 | ||
aea4bd9d AM |
1074 | secname = bfd_get_section_name (s->owner, s); |
1075 | ||
577a0623 | 1076 | if (! config.unique_orphan_sections && ! unique_section_p (secname)) |
252b5132 | 1077 | { |
6d02a667 | 1078 | /* Look through the script to see where to place this section. */ |
a854a4a7 AM |
1079 | os = lang_output_section_find (secname); |
1080 | ||
1081 | if (os != NULL | |
0f33d40b AM |
1082 | && (os->bfd_section == NULL |
1083 | || ((s->flags ^ os->bfd_section->flags) | |
1084 | & (SEC_LOAD | SEC_ALLOC)) == 0)) | |
a854a4a7 | 1085 | { |
0f33d40b AM |
1086 | /* We already have an output section statement with this |
1087 | name, and its bfd section has compatible flags. */ | |
a854a4a7 AM |
1088 | wild_doit (&os->children, s, os, file); |
1089 | return true; | |
1090 | } | |
252b5132 RH |
1091 | } |
1092 | ||
aea4bd9d AM |
1093 | if (hold_text.os == NULL) |
1094 | hold_text.os = lang_output_section_find (".text"); | |
252b5132 RH |
1095 | |
1096 | /* If this is a final link, then always put .gnu.warning.SYMBOL | |
1097 | sections into the .text section to get them out of the way. */ | |
1098 | if (! link_info.shared | |
1099 | && ! link_info.relocateable | |
1100 | && strncmp (secname, ".gnu.warning.", sizeof ".gnu.warning." - 1) == 0 | |
6a345e87 | 1101 | && hold_text.os != NULL) |
252b5132 | 1102 | { |
6a345e87 | 1103 | wild_doit (&hold_text.os->children, s, hold_text.os, file); |
252b5132 RH |
1104 | return true; |
1105 | } | |
1106 | ||
1107 | /* Decide which segment the section should go in based on the | |
1108 | section name and section flags. We put loadable .note sections | |
1109 | right after the .interp section, so that the PT_NOTE segment is | |
1110 | stored right after the program headers where the OS can read it | |
1111 | in the first page. */ | |
aea4bd9d AM |
1112 | #define HAVE_SECTION(hold, name) \ |
1113 | (hold.os != NULL || (hold.os = lang_output_section_find (name)) != NULL) | |
1114 | ||
252b5132 | 1115 | if (s->flags & SEC_EXCLUDE) |
0f33d40b | 1116 | return true; |
71bfc0ae AM |
1117 | |
1118 | place = NULL; | |
1119 | if ((s->flags & SEC_ALLOC) == 0) | |
1120 | ; | |
252b5132 | 1121 | else if ((s->flags & SEC_LOAD) != 0 |
577a0623 | 1122 | && strncmp (secname, ".note", 5) == 0 |
aea4bd9d | 1123 | && HAVE_SECTION (hold_interp, ".interp")) |
6a345e87 | 1124 | place = &hold_interp; |
252b5132 | 1125 | else if ((s->flags & SEC_HAS_CONTENTS) == 0 |
aea4bd9d | 1126 | && HAVE_SECTION (hold_bss, ".bss")) |
6a345e87 | 1127 | place = &hold_bss; |
c940e6fc JW |
1128 | else if ((s->flags & SEC_SMALL_DATA) != 0 |
1129 | && HAVE_SECTION (hold_sdata, ".sdata")) | |
1130 | place = &hold_sdata; | |
252b5132 | 1131 | else if ((s->flags & SEC_READONLY) == 0 |
aea4bd9d | 1132 | && HAVE_SECTION (hold_data, ".data")) |
6a345e87 | 1133 | place = &hold_data; |
252b5132 | 1134 | else if (strncmp (secname, ".rel", 4) == 0 |
aea4bd9d AM |
1135 | && (hold_rel.os != NULL |
1136 | || (hold_rel.os = output_rel_find ()) != NULL)) | |
6a345e87 | 1137 | place = &hold_rel; |
71bfc0ae | 1138 | else if ((s->flags & (SEC_CODE | SEC_READONLY)) == SEC_READONLY |
aea4bd9d | 1139 | && HAVE_SECTION (hold_rodata, ".rodata")) |
6a345e87 | 1140 | place = &hold_rodata; |
71bfc0ae | 1141 | else if ((s->flags & (SEC_CODE | SEC_READONLY)) == (SEC_CODE | SEC_READONLY) |
6a345e87 AM |
1142 | && hold_text.os != NULL) |
1143 | place = &hold_text; | |
252b5132 | 1144 | |
aea4bd9d AM |
1145 | #undef HAVE_SECTION |
1146 | ||
252b5132 RH |
1147 | /* Choose a unique name for the section. This will be needed if the |
1148 | same section name appears in the input file with different | |
f813923c | 1149 | loadable or allocatable characteristics. */ |
252b5132 RH |
1150 | outsecname = secname; |
1151 | if (bfd_get_section_by_name (output_bfd, outsecname) != NULL) | |
b3ea3584 AM |
1152 | { |
1153 | outsecname = bfd_get_unique_section_name (output_bfd, | |
1154 | outsecname, | |
1155 | &count); | |
1156 | if (outsecname == NULL) | |
1157 | einfo ("%F%P: place_orphan failed: %E\n"); | |
1158 | } | |
252b5132 | 1159 | |
71bfc0ae AM |
1160 | /* Start building a list of statements for this section. |
1161 | First save the current statement pointer. */ | |
1162 | old = stat_ptr; | |
1163 | ||
1164 | /* If we have found an appropriate place for the output section | |
1165 | statements for this orphan, add them to our own private list, | |
1166 | inserting them later into the global statement list. */ | |
5ba47421 | 1167 | if (place != NULL) |
252b5132 | 1168 | { |
5ba47421 AM |
1169 | stat_ptr = &add; |
1170 | lang_list_init (stat_ptr); | |
71bfc0ae | 1171 | } |
5ba47421 | 1172 | |
71bfc0ae AM |
1173 | if (config.build_constructors) |
1174 | { | |
5ba47421 AM |
1175 | /* If the name of the section is representable in C, then create |
1176 | symbols to mark the start and the end of the section. */ | |
1177 | for (ps = outsecname; *ps != '\0'; ps++) | |
1178 | if (! isalnum ((unsigned char) *ps) && *ps != '_') | |
1179 | break; | |
71bfc0ae | 1180 | if (*ps == '\0') |
5ba47421 AM |
1181 | { |
1182 | char *symname; | |
1183 | etree_type *e_align; | |
1184 | ||
1185 | symname = (char *) xmalloc (ps - outsecname + sizeof "__start_"); | |
1186 | sprintf (symname, "__start_%s", outsecname); | |
1187 | e_align = exp_unop (ALIGN_K, | |
1188 | exp_intop ((bfd_vma) 1 << s->alignment_power)); | |
1189 | lang_add_assignment (exp_assop ('=', symname, e_align)); | |
1190 | } | |
252b5132 RH |
1191 | } |
1192 | ||
01cc8ff8 | 1193 | if (link_info.relocateable || (s->flags & (SEC_LOAD | SEC_ALLOC)) == 0) |
252b5132 | 1194 | address = exp_intop ((bfd_vma) 0); |
01cc8ff8 AM |
1195 | else |
1196 | address = NULL; | |
252b5132 | 1197 | |
aea4bd9d AM |
1198 | os = lang_enter_output_section_statement (outsecname, address, 0, |
1199 | (bfd_vma) 0, | |
1200 | (etree_type *) NULL, | |
1201 | (etree_type *) NULL, | |
1202 | (etree_type *) NULL); | |
252b5132 | 1203 | |
252b5132 RH |
1204 | wild_doit (&os->children, s, os, file); |
1205 | ||
20d04697 L |
1206 | lang_leave_output_section_statement |
1207 | ((bfd_vma) 0, "*default*", | |
1208 | (struct lang_output_section_phdr_list *) NULL, "*default*"); | |
1209 | ||
71bfc0ae | 1210 | if (config.build_constructors && *ps == '\0') |
252b5132 | 1211 | { |
71bfc0ae | 1212 | char *symname; |
252b5132 | 1213 | |
71bfc0ae AM |
1214 | /* lang_leave_ouput_section_statement resets stat_ptr. Put |
1215 | stat_ptr back where we want it. */ | |
1216 | if (place != NULL) | |
1217 | stat_ptr = &add; | |
252b5132 | 1218 | |
71bfc0ae AM |
1219 | symname = (char *) xmalloc (ps - outsecname + sizeof "__stop_"); |
1220 | sprintf (symname, "__stop_%s", outsecname); | |
1221 | lang_add_assignment (exp_assop ('=', symname, | |
1222 | exp_nameop (NAME, "."))); | |
1223 | } | |
5ba47421 | 1224 | |
71bfc0ae AM |
1225 | /* Restore the global list pointer. */ |
1226 | stat_ptr = old; | |
1227 | ||
1228 | if (place != NULL) | |
1229 | { | |
95500e1c | 1230 | asection *snew, **pps, *bfd_section; |
5ba47421 AM |
1231 | |
1232 | snew = os->bfd_section; | |
95500e1c JJ |
1233 | bfd_section = place->os->bfd_section; |
1234 | if (place->section == NULL && bfd_section == NULL) | |
1235 | bfd_section = output_prev_sec_find (place->os); | |
1236 | ||
f9989030 | 1237 | if (place->section != NULL |
95500e1c JJ |
1238 | || (bfd_section != NULL |
1239 | && bfd_section != snew)) | |
5ba47421 | 1240 | { |
71bfc0ae AM |
1241 | /* Shuffle the section to make the output file look neater. |
1242 | This is really only cosmetic. */ | |
5ba47421 AM |
1243 | if (place->section == NULL) |
1244 | { | |
1245 | #if 0 | |
1246 | /* Finding the end of the list is a little tricky. We | |
1247 | make a wild stab at it by comparing section flags. */ | |
95500e1c JJ |
1248 | flagword first_flags = bfd_section->flags; |
1249 | for (pps = &bfd_section->next; | |
5ba47421 AM |
1250 | *pps != NULL && (*pps)->flags == first_flags; |
1251 | pps = &(*pps)->next) | |
1252 | ; | |
1253 | place->section = pps; | |
1254 | #else | |
1255 | /* Put orphans after the first section on the list. */ | |
95500e1c | 1256 | place->section = &bfd_section->next; |
5ba47421 AM |
1257 | #endif |
1258 | } | |
1259 | ||
1260 | /* Unlink the section. */ | |
1261 | for (pps = &output_bfd->sections; *pps != snew; pps = &(*pps)->next) | |
1262 | ; | |
1263 | *pps = snew->next; | |
1264 | ||
1265 | /* Now tack it on to the "place->os" section list. */ | |
1266 | snew->next = *place->section; | |
1267 | *place->section = snew; | |
1268 | } | |
1269 | place->section = &snew->next; /* Save the end of this list. */ | |
1270 | ||
ed15ac6a | 1271 | if (add.head != NULL) |
01cc8ff8 | 1272 | { |
ed15ac6a AM |
1273 | /* We try to put the output statements in some sort of |
1274 | reasonable order here, because they determine the final | |
1275 | load addresses of the orphan sections. */ | |
1276 | if (place->stmt == NULL) | |
1277 | { | |
1278 | /* Put the new statement list right at the head. */ | |
1279 | *add.tail = place->os->header.next; | |
1280 | place->os->header.next = add.head; | |
1281 | } | |
1282 | else | |
1283 | { | |
1284 | /* Put it after the last orphan statement we added. */ | |
1285 | *add.tail = *place->stmt; | |
1286 | *place->stmt = add.head; | |
1287 | } | |
71bfc0ae | 1288 | |
ed15ac6a AM |
1289 | /* Fix the global list pointer if we happened to tack our |
1290 | new list at the tail. */ | |
1291 | if (*old->tail == add.head) | |
1292 | old->tail = add.tail; | |
71bfc0ae | 1293 | |
ed15ac6a AM |
1294 | /* Save the end of this list. */ |
1295 | place->stmt = add.tail; | |
1296 | } | |
6a345e87 | 1297 | } |
252b5132 RH |
1298 | |
1299 | return true; | |
1300 | } | |
1301 | ||
41392f03 AM |
1302 | EOF |
1303 | fi | |
1304 | ||
1305 | if test x"$LDEMUL_GET_SCRIPT" != xgld"$EMULATION_NAME"_get_script; then | |
1306 | cat >>e${EMULATION_NAME}.c <<EOF | |
252b5132 RH |
1307 | |
1308 | static char * | |
41392f03 | 1309 | gld${EMULATION_NAME}_get_script (isfile) |
252b5132 RH |
1310 | int *isfile; |
1311 | EOF | |
1312 | ||
1313 | if test -n "$COMPILE_IN" | |
1314 | then | |
1315 | # Scripts compiled in. | |
1316 | ||
1317 | # sed commands to quote an ld script as a C string. | |
597e2591 | 1318 | sc="-f stringify.sed" |
252b5132 RH |
1319 | |
1320 | cat >>e${EMULATION_NAME}.c <<EOF | |
60bcf0fa | 1321 | { |
252b5132 RH |
1322 | *isfile = 0; |
1323 | ||
1324 | if (link_info.relocateable == true && config.build_constructors == true) | |
597e2591 | 1325 | return |
252b5132 | 1326 | EOF |
597e2591 ILT |
1327 | sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c |
1328 | echo ' ; else if (link_info.relocateable == true) return' >> e${EMULATION_NAME}.c | |
1329 | sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c | |
1330 | echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c | |
1331 | sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c | |
1332 | echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c | |
1333 | sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c | |
252b5132 RH |
1334 | |
1335 | if test -n "$GENERATE_SHLIB_SCRIPT" ; then | |
597e2591 ILT |
1336 | echo ' ; else if (link_info.shared) return' >> e${EMULATION_NAME}.c |
1337 | sed $sc ldscripts/${EMULATION_NAME}.xs >> e${EMULATION_NAME}.c | |
252b5132 RH |
1338 | fi |
1339 | ||
597e2591 ILT |
1340 | echo ' ; else return' >> e${EMULATION_NAME}.c |
1341 | sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c | |
1342 | echo '; }' >> e${EMULATION_NAME}.c | |
252b5132 RH |
1343 | |
1344 | else | |
1345 | # Scripts read from the filesystem. | |
1346 | ||
1347 | cat >>e${EMULATION_NAME}.c <<EOF | |
60bcf0fa | 1348 | { |
252b5132 RH |
1349 | *isfile = 1; |
1350 | ||
1351 | if (link_info.relocateable == true && config.build_constructors == true) | |
1352 | return "ldscripts/${EMULATION_NAME}.xu"; | |
1353 | else if (link_info.relocateable == true) | |
1354 | return "ldscripts/${EMULATION_NAME}.xr"; | |
1355 | else if (!config.text_read_only) | |
1356 | return "ldscripts/${EMULATION_NAME}.xbn"; | |
1357 | else if (!config.magic_demand_paged) | |
1358 | return "ldscripts/${EMULATION_NAME}.xn"; | |
1359 | else if (link_info.shared) | |
1360 | return "ldscripts/${EMULATION_NAME}.xs"; | |
1361 | else | |
1362 | return "ldscripts/${EMULATION_NAME}.x"; | |
1363 | } | |
252b5132 | 1364 | |
3b108066 | 1365 | EOF |
41392f03 AM |
1366 | fi |
1367 | fi | |
3b108066 | 1368 | |
41392f03 | 1369 | if test -n "$PARSE_AND_LIST_ARGS_CASES" -o x"$GENERATE_SHLIB_SCRIPT" = xyes; then |
3b108066 | 1370 | |
4b209b22 | 1371 | if test x"$LDEMUL_PARSE_ARGS" != xgld"$EMULATION_NAME"_parse_args; then |
3b108066 | 1372 | |
e0ee487b L |
1373 | if test -n "$PARSE_AND_LIST_PROLOGUE" ; then |
1374 | cat >>e${EMULATION_NAME}.c <<EOF | |
1375 | $PARSE_AND_LIST_PROLOGUE | |
1376 | EOF | |
1377 | fi | |
1378 | ||
e0ee487b L |
1379 | cat >>e${EMULATION_NAME}.c <<EOF |
1380 | ||
1381 | #include "getopt.h" | |
1382 | ||
6c1439be L |
1383 | #define OPTION_DISABLE_NEW_DTAGS (400) |
1384 | #define OPTION_ENABLE_NEW_DTAGS (OPTION_DISABLE_NEW_DTAGS + 1) | |
a1ab1d2a | 1385 | #define OPTION_GROUP (OPTION_ENABLE_NEW_DTAGS + 1) |
6c1439be | 1386 | |
e0ee487b L |
1387 | static struct option longopts[] = |
1388 | { | |
1389 | EOF | |
e0ee487b L |
1390 | |
1391 | if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then | |
1392 | cat >>e${EMULATION_NAME}.c <<EOF | |
699845ef L |
1393 | /* getopt allows abbreviations, so we do this to stop it from |
1394 | treating -d/-e as abbreviations for these options. */ | |
6c1439be | 1395 | {"disable-new-dtags", no_argument, NULL, OPTION_DISABLE_NEW_DTAGS}, |
699845ef L |
1396 | {"disable-new-dtags", no_argument, NULL, OPTION_DISABLE_NEW_DTAGS}, |
1397 | {"enable-new-dtags", no_argument, NULL, OPTION_ENABLE_NEW_DTAGS}, | |
6c1439be | 1398 | {"enable-new-dtags", no_argument, NULL, OPTION_ENABLE_NEW_DTAGS}, |
a1ab1d2a UD |
1399 | {"Bgroup", no_argument, NULL, OPTION_GROUP}, |
1400 | {"Bgroup", no_argument, NULL, OPTION_GROUP}, | |
e0ee487b L |
1401 | EOF |
1402 | fi | |
1403 | ||
1404 | if test -n "$PARSE_AND_LIST_LONGOPTS" ; then | |
1405 | cat >>e${EMULATION_NAME}.c <<EOF | |
1406 | $PARSE_AND_LIST_LONGOPTS | |
1407 | EOF | |
1408 | fi | |
1409 | ||
e0ee487b L |
1410 | cat >>e${EMULATION_NAME}.c <<EOF |
1411 | {NULL, no_argument, NULL, 0} | |
1412 | }; | |
1413 | ||
04925e1e | 1414 | |
4b209b22 | 1415 | static int gld${EMULATION_NAME}_parse_args PARAMS ((int, char **)); |
41392f03 | 1416 | |
e0ee487b | 1417 | static int |
4b209b22 | 1418 | gld${EMULATION_NAME}_parse_args (argc, argv) |
e0ee487b L |
1419 | int argc; |
1420 | char ** argv; | |
1421 | { | |
4b209b22 AM |
1422 | int longind; |
1423 | int optc; | |
1424 | static int prevoptind = -1; | |
e0ee487b L |
1425 | int prevopterr = opterr; |
1426 | int wanterror; | |
e0ee487b | 1427 | |
4b209b22 | 1428 | if (prevoptind != optind) |
e0ee487b L |
1429 | opterr = 0; |
1430 | ||
4b209b22 AM |
1431 | wanterror = opterr; |
1432 | prevoptind = optind; | |
1433 | ||
41392f03 AM |
1434 | optc = getopt_long_only (argc, argv, |
1435 | "-${PARSE_AND_LIST_SHORTOPTS}z:", longopts, | |
1436 | &longind); | |
e0ee487b L |
1437 | opterr = prevopterr; |
1438 | ||
1439 | switch (optc) | |
1440 | { | |
1441 | default: | |
1442 | if (wanterror) | |
1443 | xexit (1); | |
4b209b22 | 1444 | optind = prevoptind; |
e0ee487b | 1445 | return 0; |
6c1439be | 1446 | |
e0ee487b | 1447 | EOF |
e0ee487b L |
1448 | |
1449 | if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then | |
1450 | cat >>e${EMULATION_NAME}.c <<EOF | |
6c1439be L |
1451 | case OPTION_DISABLE_NEW_DTAGS: |
1452 | link_info.new_dtags = false; | |
1453 | break; | |
1454 | ||
1455 | case OPTION_ENABLE_NEW_DTAGS: | |
1456 | link_info.new_dtags = true; | |
1457 | break; | |
1458 | ||
a1ab1d2a UD |
1459 | case OPTION_GROUP: |
1460 | link_info.flags_1 |= (bfd_vma) DF_1_GROUP; | |
1461 | /* Groups must be self-contained. */ | |
1462 | link_info.no_undefined = true; | |
1463 | break; | |
1464 | ||
e0ee487b L |
1465 | case 'z': |
1466 | if (strcmp (optarg, "initfirst") == 0) | |
1467 | link_info.flags_1 |= (bfd_vma) DF_1_INITFIRST; | |
1468 | else if (strcmp (optarg, "interpose") == 0) | |
1469 | link_info.flags_1 |= (bfd_vma) DF_1_INTERPOSE; | |
1470 | else if (strcmp (optarg, "loadfltr") == 0) | |
1471 | link_info.flags_1 |= (bfd_vma) DF_1_LOADFLTR; | |
1472 | else if (strcmp (optarg, "nodefaultlib") == 0) | |
1473 | link_info.flags_1 |= (bfd_vma) DF_1_NODEFLIB; | |
1474 | else if (strcmp (optarg, "nodelete") == 0) | |
1475 | link_info.flags_1 |= (bfd_vma) DF_1_NODELETE; | |
1476 | else if (strcmp (optarg, "nodlopen") == 0) | |
1477 | link_info.flags_1 |= (bfd_vma) DF_1_NOOPEN; | |
1478 | else if (strcmp (optarg, "nodump") == 0) | |
1479 | link_info.flags_1 |= (bfd_vma) DF_1_NODUMP; | |
1480 | else if (strcmp (optarg, "now") == 0) | |
1481 | { | |
1482 | link_info.flags |= (bfd_vma) DF_BIND_NOW; | |
1483 | link_info.flags_1 |= (bfd_vma) DF_1_NOW; | |
1484 | } | |
1485 | else if (strcmp (optarg, "origin") == 0) | |
1486 | { | |
1487 | link_info.flags |= (bfd_vma) DF_ORIGIN; | |
1488 | link_info.flags_1 |= (bfd_vma) DF_1_ORIGIN; | |
1489 | } | |
a1ab1d2a UD |
1490 | else if (strcmp (optarg, "defs") == 0) |
1491 | link_info.no_undefined = true; | |
e0ee487b | 1492 | /* What about the other Solaris -z options? FIXME. */ |
6c1439be | 1493 | break; |
e0ee487b L |
1494 | EOF |
1495 | fi | |
1496 | ||
1497 | if test -n "$PARSE_AND_LIST_ARGS_CASES" ; then | |
1498 | cat >>e${EMULATION_NAME}.c <<EOF | |
1499 | $PARSE_AND_LIST_ARGS_CASES | |
1500 | EOF | |
1501 | fi | |
1502 | ||
e0ee487b L |
1503 | cat >>e${EMULATION_NAME}.c <<EOF |
1504 | } | |
1505 | ||
1506 | return 1; | |
1507 | } | |
1508 | ||
41392f03 AM |
1509 | EOF |
1510 | fi | |
1511 | ||
4b209b22 | 1512 | if test x"$LDEMUL_LIST_OPTIONS" != xgld"$EMULATION_NAME"_list_options; then |
41392f03 AM |
1513 | cat >>e${EMULATION_NAME}.c <<EOF |
1514 | ||
4b209b22 | 1515 | static void gld${EMULATION_NAME}_list_options PARAMS ((FILE * file)); |
04925e1e | 1516 | |
e0ee487b | 1517 | static void |
4b209b22 | 1518 | gld${EMULATION_NAME}_list_options (file) |
e0ee487b L |
1519 | FILE * file; |
1520 | { | |
1521 | EOF | |
e0ee487b L |
1522 | |
1523 | if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then | |
1524 | cat >>e${EMULATION_NAME}.c <<EOF | |
a1ab1d2a | 1525 | fprintf (file, _(" -Bgroup\t\tSelects group name lookup rules for DSO\n")); |
6c1439be L |
1526 | fprintf (file, _(" --disable-new-dtags\tDisable new dynamic tags\n")); |
1527 | fprintf (file, _(" --enable-new-dtags\tEnable new dynamic tags\n")); | |
a1ab1d2a | 1528 | fprintf (file, _(" -z defs\t\tDisallows undefined symbols\n")); |
f813923c HPN |
1529 | fprintf (file, _(" -z initfirst\t\tMark DSO to be initialized first at runtime\n")); |
1530 | fprintf (file, _(" -z interpose\t\tMark object to interpose all DSOs but executable\n")); | |
e0ee487b L |
1531 | fprintf (file, _(" -z loadfltr\t\tMark object requiring immediate process\n")); |
1532 | fprintf (file, _(" -z nodefaultlib\tMark object not to use default search paths\n")); | |
1533 | fprintf (file, _(" -z nodelete\t\tMark DSO non-deletable at runtime\n")); | |
f813923c HPN |
1534 | fprintf (file, _(" -z nodlopen\t\tMark DSO not available to dlopen\n")); |
1535 | fprintf (file, _(" -z nodump\t\tMark DSO not available to dldump\n")); | |
e0ee487b L |
1536 | fprintf (file, _(" -z now\t\tMark object non-lazy runtime binding\n")); |
1537 | fprintf (file, _(" -z origin\t\tMark object requiring immediate \$ORIGIN processing\n")); | |
1538 | fprintf (file, _("\t\t\t at runtime\n")); | |
19e3be22 | 1539 | fprintf (file, _(" -z KEYWORD\t\tIgnored for Solaris compatibility\n")); |
e0ee487b L |
1540 | EOF |
1541 | fi | |
1542 | ||
1543 | if test -n "$PARSE_AND_LIST_OPTIONS" ; then | |
1544 | cat >>e${EMULATION_NAME}.c <<EOF | |
1545 | $PARSE_AND_LIST_OPTIONS | |
1546 | EOF | |
1547 | fi | |
1548 | ||
e0ee487b L |
1549 | cat >>e${EMULATION_NAME}.c <<EOF |
1550 | } | |
1551 | EOF | |
e0ee487b L |
1552 | |
1553 | if test -n "$PARSE_AND_LIST_EPILOGUE" ; then | |
1554 | cat >>e${EMULATION_NAME}.c <<EOF | |
1555 | $PARSE_AND_LIST_EPILOGUE | |
1556 | EOF | |
1557 | fi | |
41392f03 AM |
1558 | fi |
1559 | else | |
4b209b22 | 1560 | if test x"$LDEMUL_PARSE_ARGS" != xgld"$EMULATION_NAME"_parse_args; then |
41392f03 | 1561 | cat >>e${EMULATION_NAME}.c <<EOF |
4b209b22 | 1562 | #define gld${EMULATION_NAME}_parse_args NULL |
41392f03 AM |
1563 | EOF |
1564 | fi | |
4b209b22 | 1565 | if test x"$LDEMUL_LIST_OPTIONS" != xgld"$EMULATION_NAME"_list_options; then |
41392f03 | 1566 | cat >>e${EMULATION_NAME}.c <<EOF |
4b209b22 | 1567 | #define gld${EMULATION_NAME}_list_options NULL |
41392f03 AM |
1568 | EOF |
1569 | fi | |
1570 | fi | |
e0ee487b | 1571 | |
252b5132 RH |
1572 | cat >>e${EMULATION_NAME}.c <<EOF |
1573 | ||
60bcf0fa | 1574 | struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation = |
252b5132 | 1575 | { |
41392f03 AM |
1576 | ${LDEMUL_BEFORE_PARSE-gld${EMULATION_NAME}_before_parse}, |
1577 | ${LDEMUL_SYSLIB-syslib_default}, | |
1578 | ${LDEMUL_HLL-hll_default}, | |
1579 | ${LDEMUL_AFTER_PARSE-after_parse_default}, | |
1580 | ${LDEMUL_AFTER_OPEN-gld${EMULATION_NAME}_after_open}, | |
1581 | ${LDEMUL_AFTER_ALLOCATION-after_allocation_default}, | |
1582 | ${LDEMUL_SET_OUTPUT_ARCH-set_output_arch_default}, | |
1583 | ${LDEMUL_CHOOSE_TARGET-ldemul_default_target}, | |
1584 | ${LDEMUL_BEFORE_ALLOCATION-gld${EMULATION_NAME}_before_allocation}, | |
1585 | ${LDEMUL_GET_SCRIPT-gld${EMULATION_NAME}_get_script}, | |
252b5132 RH |
1586 | "${EMULATION_NAME}", |
1587 | "${OUTPUT_FORMAT}", | |
41392f03 AM |
1588 | ${LDEMUL_FINISH-NULL}, |
1589 | ${LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS-NULL}, | |
1590 | ${LDEMUL_OPEN_DYNAMIC_ARCHIVE-gld${EMULATION_NAME}_open_dynamic_archive}, | |
1591 | ${LDEMUL_PLACE_ORPHAN-gld${EMULATION_NAME}_place_orphan}, | |
1592 | ${LDEMUL_SET_SYMBOLS-NULL}, | |
4b209b22 | 1593 | ${LDEMUL_PARSE_ARGS-gld${EMULATION_NAME}_parse_args}, |
41392f03 | 1594 | ${LDEMUL_UNRECOGNIZED_FILE-NULL}, |
4b209b22 | 1595 | ${LDEMUL_LIST_OPTIONS-gld${EMULATION_NAME}_list_options}, |
41392f03 AM |
1596 | ${LDEMUL_RECOGNIZED_FILE-NULL}, |
1597 | ${LDEMUL_FIND_POTENTIAL_LIBRARIES-NULL}, | |
252b5132 RH |
1598 | }; |
1599 | EOF |