]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - ld/emultempl/elf32.em
06f02c6d860e2137a433d9d692cbd083122bb10c
[thirdparty/binutils-gdb.git] / ld / emultempl / elf32.em
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
6 if [ -z "$MACHINE" ]; then
7 OUTPUT_ARCH=${ARCH}
8 else
9 OUTPUT_ARCH=${ARCH}:${MACHINE}
10 fi
11 fragment <<EOF
12 /* This file is is generated by a shell script. DO NOT EDIT! */
13
14 /* ${ELFSIZE} bit ELF emulation code for ${EMULATION_NAME}
15 Copyright (C) 1991-2016 Free Software Foundation, Inc.
16 Written by Steve Chamberlain <sac@cygnus.com>
17 ELF support by Ian Lance Taylor <ian@cygnus.com>
18
19 This file is part of the GNU Binutils.
20
21 This program is free software; you can redistribute it and/or modify
22 it under the terms of the GNU General Public License as published by
23 the Free Software Foundation; either version 3 of the License, or
24 (at your option) any later version.
25
26 This program is distributed in the hope that it will be useful,
27 but WITHOUT ANY WARRANTY; without even the implied warranty of
28 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 GNU General Public License for more details.
30
31 You should have received a copy of the GNU General Public License
32 along with this program; if not, write to the Free Software
33 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
34 MA 02110-1301, USA. */
35
36 #define TARGET_IS_${EMULATION_NAME}
37
38 #include "sysdep.h"
39 #include "bfd.h"
40 #include "libiberty.h"
41 #include "safe-ctype.h"
42 #include "filenames.h"
43 #include "getopt.h"
44 #include <fcntl.h>
45
46 #include "bfdlink.h"
47
48 #include "ld.h"
49 #include "ldmain.h"
50 #include "ldmisc.h"
51 #include "ldexp.h"
52 #include "ldlang.h"
53 #include "ldfile.h"
54 #include "ldemul.h"
55 #include "ldbuildid.h"
56 #include <ldgram.h>
57 #include "elf/common.h"
58 #include "elf-bfd.h"
59 #include "filenames.h"
60
61 /* Declare functions used by various EXTRA_EM_FILEs. */
62 static void gld${EMULATION_NAME}_before_parse (void);
63 static void gld${EMULATION_NAME}_after_parse (void);
64 static void gld${EMULATION_NAME}_after_open (void);
65 static void gld${EMULATION_NAME}_before_allocation (void);
66 static void gld${EMULATION_NAME}_after_allocation (void);
67 static lang_output_section_statement_type *gld${EMULATION_NAME}_place_orphan
68 (asection *, const char *, int);
69 EOF
70
71 if [ "x${USE_LIBPATH}" = xyes ] ; then
72 case ${target} in
73 *-*-linux-* | *-*-k*bsd*-* | *-*-gnu*)
74 fragment <<EOF
75 #ifdef HAVE_GLOB
76 #include <glob.h>
77 #endif
78 EOF
79 ;;
80 esac
81 fi
82
83 # Import any needed special functions and/or overrides.
84 #
85 source_em ${srcdir}/emultempl/elf-generic.em
86 if test -n "$EXTRA_EM_FILE" ; then
87 source_em ${srcdir}/emultempl/${EXTRA_EM_FILE}.em
88 fi
89
90 # Functions in this file can be overridden by setting the LDEMUL_* shell
91 # variables. If the name of the overriding function is the same as is
92 # defined in this file, then don't output this file's version.
93 # If a different overriding name is given then output the standard function
94 # as presumably it is called from the overriding function.
95 #
96 if test x"$LDEMUL_BEFORE_PARSE" != xgld"$EMULATION_NAME"_before_parse; then
97 fragment <<EOF
98
99 static void
100 gld${EMULATION_NAME}_before_parse (void)
101 {
102 ldfile_set_output_arch ("${OUTPUT_ARCH}", bfd_arch_`echo ${ARCH} | sed -e 's/:.*//'`);
103 input_flags.dynamic = ${DYNAMIC_LINK-TRUE};
104 config.has_shared = `if test -n "$GENERATE_SHLIB_SCRIPT" ; then echo TRUE ; else echo FALSE ; fi`;
105 config.separate_code = `if test "x${SEPARATE_CODE}" = xyes ; then echo TRUE ; else echo FALSE ; fi`;
106 `if test -n "$CALL_NOP_BYTE" ; then echo link_info.call_nop_byte = $CALL_NOP_BYTE; fi`;
107 link_info.check_relocs_after_open_input = `if test "x${CHECK_RELOCS_AFTER_OPEN_INPUT}" = xyes ; then echo TRUE ; else echo FALSE ; fi`;
108 link_info.relro = DEFAULT_LD_Z_RELRO;
109 }
110
111 EOF
112 fi
113
114 if test x"$LDEMUL_AFTER_PARSE" != xgld"$EMULATION_NAME"_after_parse; then
115 fragment <<EOF
116
117 static void
118 gld${EMULATION_NAME}_after_parse (void)
119 {
120 if (bfd_link_pie (&link_info))
121 link_info.flags_1 |= (bfd_vma) DF_1_PIE;
122
123 after_parse_default ();
124 }
125
126 EOF
127 fi
128
129 if test x"$LDEMUL_RECOGNIZED_FILE" != xgld"${EMULATION_NAME}"_load_symbols; then
130 fragment <<EOF
131 /* Handle the generation of DT_NEEDED tags. */
132
133 static bfd_boolean
134 gld${EMULATION_NAME}_load_symbols (lang_input_statement_type *entry)
135 {
136 int link_class = 0;
137
138 /* Tell the ELF linker that we don't want the output file to have a
139 DT_NEEDED entry for this file, unless it is used to resolve
140 references in a regular object. */
141 if (entry->flags.add_DT_NEEDED_for_regular)
142 link_class = DYN_AS_NEEDED;
143
144 /* Tell the ELF linker that we don't want the output file to have a
145 DT_NEEDED entry for any dynamic library in DT_NEEDED tags from
146 this file at all. */
147 if (!entry->flags.add_DT_NEEDED_for_dynamic)
148 link_class |= DYN_NO_ADD_NEEDED;
149
150 if (entry->flags.just_syms
151 && (bfd_get_file_flags (entry->the_bfd) & DYNAMIC) != 0)
152 einfo (_("%P%F: --just-symbols may not be used on DSO: %B\n"),
153 entry->the_bfd);
154
155 if (link_class == 0
156 || (bfd_get_file_flags (entry->the_bfd) & DYNAMIC) == 0)
157 return FALSE;
158
159 bfd_elf_set_dyn_lib_class (entry->the_bfd,
160 (enum dynamic_lib_link_class) link_class);
161
162 /* Continue on with normal load_symbols processing. */
163 return FALSE;
164 }
165 EOF
166 fi
167
168 fragment <<EOF
169
170 /* These variables are required to pass information back and forth
171 between after_open and check_needed and stat_needed and vercheck. */
172
173 static struct bfd_link_needed_list *global_needed;
174 static struct stat global_stat;
175 static lang_input_statement_type *global_found;
176 static struct bfd_link_needed_list *global_vercheck_needed;
177 static bfd_boolean global_vercheck_failed;
178
179 /* These variables are used to implement target options */
180
181 static char *audit; /* colon (typically) separated list of libs */
182 static char *depaudit; /* colon (typically) separated list of libs */
183
184 /* Style of .note.gnu.build-id section. */
185 static const char *emit_note_gnu_build_id;
186
187 /* On Linux, it's possible to have different versions of the same
188 shared library linked against different versions of libc. The
189 dynamic linker somehow tags which libc version to use in
190 /etc/ld.so.cache, and, based on the libc that it sees in the
191 executable, chooses which version of the shared library to use.
192
193 We try to do a similar check here by checking whether this shared
194 library needs any other shared libraries which may conflict with
195 libraries we have already included in the link. If it does, we
196 skip it, and try to find another shared library farther on down the
197 link path.
198
199 This is called via lang_for_each_input_file.
200 GLOBAL_VERCHECK_NEEDED is the list of objects needed by the object
201 which we are checking. This sets GLOBAL_VERCHECK_FAILED if we find
202 a conflicting version. */
203
204 static void
205 gld${EMULATION_NAME}_vercheck (lang_input_statement_type *s)
206 {
207 const char *soname;
208 struct bfd_link_needed_list *l;
209
210 if (global_vercheck_failed)
211 return;
212 if (s->the_bfd == NULL
213 || (bfd_get_file_flags (s->the_bfd) & DYNAMIC) == 0)
214 return;
215
216 soname = bfd_elf_get_dt_soname (s->the_bfd);
217 if (soname == NULL)
218 soname = lbasename (bfd_get_filename (s->the_bfd));
219
220 for (l = global_vercheck_needed; l != NULL; l = l->next)
221 {
222 const char *suffix;
223
224 if (filename_cmp (soname, l->name) == 0)
225 {
226 /* Probably can't happen, but it's an easy check. */
227 continue;
228 }
229
230 if (strchr (l->name, '/') != NULL)
231 continue;
232
233 suffix = strstr (l->name, ".so.");
234 if (suffix == NULL)
235 continue;
236
237 suffix += sizeof ".so." - 1;
238
239 if (filename_ncmp (soname, l->name, suffix - l->name) == 0)
240 {
241 /* Here we know that S is a dynamic object FOO.SO.VER1, and
242 the object we are considering needs a dynamic object
243 FOO.SO.VER2, and VER1 and VER2 are different. This
244 appears to be a version mismatch, so we tell the caller
245 to try a different version of this library. */
246 global_vercheck_failed = TRUE;
247 return;
248 }
249 }
250 }
251
252
253 /* See if an input file matches a DT_NEEDED entry by running stat on
254 the file. */
255
256 static void
257 gld${EMULATION_NAME}_stat_needed (lang_input_statement_type *s)
258 {
259 struct stat st;
260 const char *suffix;
261 const char *soname;
262
263 if (global_found != NULL)
264 return;
265 if (s->the_bfd == NULL)
266 return;
267
268 /* If this input file was an as-needed entry, and wasn't found to be
269 needed at the stage it was linked, then don't say we have loaded it. */
270 if ((bfd_elf_get_dyn_lib_class (s->the_bfd) & DYN_AS_NEEDED) != 0)
271 return;
272
273 if (bfd_stat (s->the_bfd, &st) != 0)
274 {
275 einfo ("%P:%B: bfd_stat failed: %E\n", s->the_bfd);
276 return;
277 }
278
279 /* Some operating systems, e.g. Windows, do not provide a meaningful
280 st_ino; they always set it to zero. (Windows does provide a
281 meaningful st_dev.) Do not indicate a duplicate library in that
282 case. While there is no guarantee that a system that provides
283 meaningful inode numbers will never set st_ino to zero, this is
284 merely an optimization, so we do not need to worry about false
285 negatives. */
286 if (st.st_dev == global_stat.st_dev
287 && st.st_ino == global_stat.st_ino
288 && st.st_ino != 0)
289 {
290 global_found = s;
291 return;
292 }
293
294 /* We issue a warning if it looks like we are including two
295 different versions of the same shared library. For example,
296 there may be a problem if -lc picks up libc.so.6 but some other
297 shared library has a DT_NEEDED entry of libc.so.5. This is a
298 heuristic test, and it will only work if the name looks like
299 NAME.so.VERSION. FIXME: Depending on file names is error-prone.
300 If we really want to issue warnings about mixing version numbers
301 of shared libraries, we need to find a better way. */
302
303 if (strchr (global_needed->name, '/') != NULL)
304 return;
305 suffix = strstr (global_needed->name, ".so.");
306 if (suffix == NULL)
307 return;
308 suffix += sizeof ".so." - 1;
309
310 soname = bfd_elf_get_dt_soname (s->the_bfd);
311 if (soname == NULL)
312 soname = lbasename (s->filename);
313
314 if (filename_ncmp (soname, global_needed->name, suffix - global_needed->name) == 0)
315 einfo ("%P: warning: %s, needed by %B, may conflict with %s\n",
316 global_needed->name, global_needed->by, soname);
317 }
318
319 struct dt_needed
320 {
321 bfd *by;
322 const char *name;
323 };
324
325 /* This function is called for each possible name for a dynamic object
326 named by a DT_NEEDED entry. The FORCE parameter indicates whether
327 to skip the check for a conflicting version. */
328
329 static bfd_boolean
330 gld${EMULATION_NAME}_try_needed (struct dt_needed *needed,
331 int force)
332 {
333 bfd *abfd;
334 const char *name = needed->name;
335 const char *soname;
336 int link_class;
337
338 abfd = bfd_openr (name, bfd_get_target (link_info.output_bfd));
339 if (abfd == NULL)
340 {
341 if (verbose)
342 info_msg (_("attempt to open %s failed\n"), name);
343 return FALSE;
344 }
345
346 /* Linker needs to decompress sections. */
347 abfd->flags |= BFD_DECOMPRESS;
348
349 if (! bfd_check_format (abfd, bfd_object))
350 {
351 bfd_close (abfd);
352 return FALSE;
353 }
354 if ((bfd_get_file_flags (abfd) & DYNAMIC) == 0)
355 {
356 bfd_close (abfd);
357 return FALSE;
358 }
359
360 /* For DT_NEEDED, they have to match. */
361 if (abfd->xvec != link_info.output_bfd->xvec)
362 {
363 bfd_close (abfd);
364 return FALSE;
365 }
366
367 /* Check whether this object would include any conflicting library
368 versions. If FORCE is set, then we skip this check; we use this
369 the second time around, if we couldn't find any compatible
370 instance of the shared library. */
371
372 if (! force)
373 {
374 struct bfd_link_needed_list *needs;
375
376 if (! bfd_elf_get_bfd_needed_list (abfd, &needs))
377 einfo ("%F%P:%B: bfd_elf_get_bfd_needed_list failed: %E\n", abfd);
378
379 if (needs != NULL)
380 {
381 global_vercheck_needed = needs;
382 global_vercheck_failed = FALSE;
383 lang_for_each_input_file (gld${EMULATION_NAME}_vercheck);
384 if (global_vercheck_failed)
385 {
386 bfd_close (abfd);
387 /* Return FALSE to force the caller to move on to try
388 another file on the search path. */
389 return FALSE;
390 }
391
392 /* But wait! It gets much worse. On Linux, if a shared
393 library does not use libc at all, we are supposed to skip
394 it the first time around in case we encounter a shared
395 library later on with the same name which does use the
396 version of libc that we want. This is much too horrible
397 to use on any system other than Linux. */
398
399 EOF
400 case ${target} in
401 *-*-linux-* | *-*-k*bsd*-* | *-*-gnu*)
402 fragment <<EOF
403 {
404 struct bfd_link_needed_list *l;
405
406 for (l = needs; l != NULL; l = l->next)
407 if (CONST_STRNEQ (l->name, "libc.so"))
408 break;
409 if (l == NULL)
410 {
411 bfd_close (abfd);
412 return FALSE;
413 }
414 }
415
416 EOF
417 ;;
418 esac
419 fragment <<EOF
420 }
421 }
422
423 /* We've found a dynamic object matching the DT_NEEDED entry. */
424
425 /* We have already checked that there is no other input file of the
426 same name. We must now check again that we are not including the
427 same file twice. We need to do this because on many systems
428 libc.so is a symlink to, e.g., libc.so.1. The SONAME entry will
429 reference libc.so.1. If we have already included libc.so, we
430 don't want to include libc.so.1 if they are the same file, and we
431 can only check that using stat. */
432
433 if (bfd_stat (abfd, &global_stat) != 0)
434 einfo ("%F%P:%B: bfd_stat failed: %E\n", abfd);
435
436 /* First strip off everything before the last '/'. */
437 soname = lbasename (abfd->filename);
438
439 if (verbose)
440 info_msg (_("found %s at %s\n"), soname, name);
441
442 global_found = NULL;
443 lang_for_each_input_file (gld${EMULATION_NAME}_stat_needed);
444 if (global_found != NULL)
445 {
446 /* Return TRUE to indicate that we found the file, even though
447 we aren't going to do anything with it. */
448 return TRUE;
449 }
450
451 /* Specify the soname to use. */
452 bfd_elf_set_dt_needed_name (abfd, soname);
453
454 /* Tell the ELF linker that we don't want the output file to have a
455 DT_NEEDED entry for this file, unless it is used to resolve
456 references in a regular object. */
457 link_class = DYN_DT_NEEDED;
458
459 /* Tell the ELF linker that we don't want the output file to have a
460 DT_NEEDED entry for this file at all if the entry is from a file
461 with DYN_NO_ADD_NEEDED. */
462 if (needed->by != NULL
463 && (bfd_elf_get_dyn_lib_class (needed->by) & DYN_NO_ADD_NEEDED) != 0)
464 link_class |= DYN_NO_NEEDED | DYN_NO_ADD_NEEDED;
465
466 bfd_elf_set_dyn_lib_class (abfd, (enum dynamic_lib_link_class) link_class);
467
468 /* Add this file into the symbol table. */
469 if (! bfd_link_add_symbols (abfd, &link_info))
470 einfo ("%F%B: error adding symbols: %E\n", abfd);
471
472 return TRUE;
473 }
474
475 EOF
476 if [ "x${NATIVE}" = xyes ] ; then
477 fragment <<EOF
478 #ifdef HAVE_GETAUXVAL
479 #include <sys/auxv.h>
480 #endif
481 EOF
482 fi
483 fragment <<EOF
484
485 /* Search for a needed file in a path. */
486
487 static bfd_boolean
488 gld${EMULATION_NAME}_search_needed (const char *path,
489 struct dt_needed *n, int force)
490 {
491 const char *s;
492 const char *name = n->name;
493 size_t len;
494 struct dt_needed needed;
495
496 if (name[0] == '/')
497 return gld${EMULATION_NAME}_try_needed (n, force);
498
499 if (path == NULL || *path == '\0')
500 return FALSE;
501
502 needed.by = n->by;
503 needed.name = n->name;
504
505 len = strlen (name);
506 while (1)
507 {
508 char * var;
509 char *filename, *sset;
510
511 s = strchr (path, config.rpath_separator);
512 if (s == NULL)
513 s = path + strlen (path);
514
515 #if HAVE_DOS_BASED_FILE_SYSTEM
516 /* Assume a match on the second char is part of drive specifier. */
517 else if (config.rpath_separator == ':'
518 && s == path + 1
519 && ISALPHA (*path))
520 {
521 s = strchr (s + 1, config.rpath_separator);
522 if (s == NULL)
523 s = path + strlen (path);
524 }
525 #endif
526 filename = (char *) xmalloc (s - path + len + 2);
527 if (s == path)
528 sset = filename;
529 else
530 {
531 memcpy (filename, path, s - path);
532 filename[s - path] = '/';
533 sset = filename + (s - path) + 1;
534 }
535 strcpy (sset, name);
536
537 /* PR 20535: Support the same pseudo-environment variables that
538 are supported by ld.so. Namely, $ORIGIN, $LIB and $PLATFORM.
539 Since there can be more than one occurrence of these tokens in
540 the path we loop until no more are found. */
541 while ((var = strchr (filename, '$')) != NULL)
542 {
543 /* The ld.so manual page does not say, but I am going to assume that
544 these tokens are terminated by a directory seperator character
545 (/) or the end of the string. There is also an implication that
546 $ORIGIN should only be used at the start of a path, but that is
547 not enforced here.
548
549 FIXME: The ld.so manual page also states that it allows ${ORIGIN}
550 ${LIB} and ${PLATFORM}. We should support these variants too.
551
552 FIXME: The code could be a lot cleverer about allocating space
553 for the processed string. */
554 char * end = strchr (var, '/');
555 char * replacement = NULL;
556 char * freeme = NULL;
557 unsigned flen = strlen (filename);
558
559 if (end != NULL)
560 /* Temporarily terminate the filename at the end of the token. */
561 * end = 0;
562
563 switch (var[1])
564 {
565 case 'O':
566 if (strcmp (var + 2, "RIGIN") == 0)
567 {
568 /* ORIGIN - replace with the full path to the directory
569 containing the program or shared object. */
570 if (needed.by == NULL)
571 break;
572 replacement = bfd_get_filename (needed.by);
573 if (replacement)
574 {
575 char * slash;
576
577 if (replacement[0] == '/')
578 freeme = xstrdup (replacement);
579 else
580 {
581 char * current_dir = getpwd ();
582
583 freeme = xmalloc (strlen (replacement) + strlen (current_dir));
584 sprintf (freeme, "%s/%s", current_dir, replacement);
585 }
586
587 replacement = freeme;
588 if ((slash = strrchr (replacement, '/')) != NULL)
589 * slash = 0;
590 }
591 }
592 break;
593
594 case 'L':
595 if (strcmp (var + 2, "IB") == 0)
596 {
597 /* LIB - replace with "lib" in 32-bit environments
598 and "lib64" in 64-bit environments. */
599
600 /* Note - we could replace this switch statement by
601 conditional fragments of shell script, but that is messy.
602 Any compiler worth its salt is going to optimize away
603 all but one of these case statements anyway. */
604 switch ($ELFSIZE)
605 {
606 case 32: replacement = "lib"; break;
607 case 64: replacement = "lib64"; break;
608 default:
609 /* $ELFSIZE is not 32 or 64 ... */
610 abort ();
611 }
612 }
613 break;
614
615 case 'P':
616 if (strcmp (var + 2, "LATFORM") == 0)
617 {
618 /* PLATFORM - replace with a string corresponding
619 to the processor type of the host system.
620
621 FIXME: Supporting this token might be a bad idea,
622 especially for non-native linkers. It has the potential
623 to find incorrect results. Maybe issuing a warning
624 message would be safer. Current policy: wait and see if
625 somebody complains. */
626 replacement = "$OUTPUT_ARCH";
627 EOF
628 # We use getauxval() if it is available, but only for natives.
629 if [ "x${NATIVE}" = xyes ] ; then
630 fragment <<EOF
631 #ifdef HAVE_GETAUXVAL
632 replacement = (char *) getauxval (AT_PLATFORM);
633 #endif
634 EOF
635 fi
636 fragment <<EOF
637 }
638 break;
639
640 default:
641 break;
642 }
643
644 if (replacement)
645 {
646 char * filename2 = xmalloc (flen + strlen (replacement));
647
648 if (end)
649 sprintf (filename2, "%.*s%s/%s",
650 (int)(var - filename), filename,
651 replacement, end + 1);
652 else
653 sprintf (filename2, "%.*s%s",
654 (int)(var - filename), filename,
655 replacement);
656
657 free (filename);
658 filename = filename2;
659 /* There is no need to restore the path separator (when
660 end != NULL) as we have replaced the entire string. */
661 }
662 else
663 {
664 if (verbose)
665 /* We only issue an "unrecognised" message in verbose mode
666 as the $<foo> token might be a legitimate component of
667 a path name in the target's file system. */
668 info_msg (_("unrecognised token '%s' in search path\n"), var);
669
670 if (end)
671 /* Restore the path separator. */
672 * end = '/';
673 }
674
675 free (freeme);
676 }
677
678 needed.name = filename;
679 if (gld${EMULATION_NAME}_try_needed (&needed, force))
680 return TRUE;
681
682 free (filename);
683
684 if (*s == '\0')
685 break;
686 path = s + 1;
687 }
688
689 return FALSE;
690 }
691
692 EOF
693 if [ "x${USE_LIBPATH}" = xyes ] ; then
694 fragment <<EOF
695
696 /* Add the sysroot to every entry in a path separated by
697 config.rpath_separator. */
698
699 static char *
700 gld${EMULATION_NAME}_add_sysroot (const char *path)
701 {
702 int len, colons, i;
703 char *ret, *p;
704
705 len = strlen (path);
706 colons = 0;
707 i = 0;
708 while (path[i])
709 if (path[i++] == config.rpath_separator)
710 colons++;
711
712 if (path[i])
713 colons++;
714
715 len = len + (colons + 1) * strlen (ld_sysroot);
716 ret = xmalloc (len + 1);
717 strcpy (ret, ld_sysroot);
718 p = ret + strlen (ret);
719 i = 0;
720 while (path[i])
721 if (path[i] == config.rpath_separator)
722 {
723 *p++ = path[i++];
724 strcpy (p, ld_sysroot);
725 p = p + strlen (p);
726 }
727 else
728 *p++ = path[i++];
729
730 *p = 0;
731 return ret;
732 }
733
734 EOF
735 case ${target} in
736 *-*-freebsd* | *-*-dragonfly*)
737 fragment <<EOF
738 /* Read the system search path the FreeBSD way rather than the Linux way. */
739 #ifdef HAVE_ELF_HINTS_H
740 #include <elf-hints.h>
741 #else
742 #include "elf-hints-local.h"
743 #endif
744
745 static bfd_boolean
746 gld${EMULATION_NAME}_check_ld_elf_hints (const struct bfd_link_needed_list *l,
747 int force)
748 {
749 static bfd_boolean initialized;
750 static char *ld_elf_hints;
751 struct dt_needed needed;
752
753 if (!initialized)
754 {
755 FILE *f;
756 char *tmppath;
757
758 tmppath = concat (ld_sysroot, _PATH_ELF_HINTS, (const char *) NULL);
759 f = fopen (tmppath, FOPEN_RB);
760 free (tmppath);
761 if (f != NULL)
762 {
763 struct elfhints_hdr hdr;
764
765 if (fread (&hdr, 1, sizeof (hdr), f) == sizeof (hdr)
766 && hdr.magic == ELFHINTS_MAGIC
767 && hdr.version == 1)
768 {
769 if (fseek (f, hdr.strtab + hdr.dirlist, SEEK_SET) != -1)
770 {
771 char *b;
772
773 b = xmalloc (hdr.dirlistlen + 1);
774 if (fread (b, 1, hdr.dirlistlen + 1, f) ==
775 hdr.dirlistlen + 1)
776 ld_elf_hints = gld${EMULATION_NAME}_add_sysroot (b);
777
778 free (b);
779 }
780 }
781 fclose (f);
782 }
783
784 initialized = TRUE;
785 }
786
787 if (ld_elf_hints == NULL)
788 return FALSE;
789
790 needed.by = l->by;
791 needed.name = l->name;
792 return gld${EMULATION_NAME}_search_needed (ld_elf_hints, &needed, force);
793 }
794 EOF
795 # FreeBSD
796 ;;
797
798 *-*-linux-* | *-*-k*bsd*-* | *-*-gnu*)
799 fragment <<EOF
800 /* For a native linker, check the file /etc/ld.so.conf for directories
801 in which we may find shared libraries. /etc/ld.so.conf is really
802 only meaningful on Linux. */
803
804 struct gld${EMULATION_NAME}_ld_so_conf
805 {
806 char *path;
807 size_t len, alloc;
808 };
809
810 static bfd_boolean
811 gld${EMULATION_NAME}_parse_ld_so_conf
812 (struct gld${EMULATION_NAME}_ld_so_conf *info, const char *filename);
813
814 static void
815 gld${EMULATION_NAME}_parse_ld_so_conf_include
816 (struct gld${EMULATION_NAME}_ld_so_conf *info, const char *filename,
817 const char *pattern)
818 {
819 char *newp = NULL;
820 #ifdef HAVE_GLOB
821 glob_t gl;
822 #endif
823
824 if (pattern[0] != '/')
825 {
826 char *p = strrchr (filename, '/');
827 size_t patlen = strlen (pattern) + 1;
828
829 newp = xmalloc (p - filename + 1 + patlen);
830 memcpy (newp, filename, p - filename + 1);
831 memcpy (newp + (p - filename + 1), pattern, patlen);
832 pattern = newp;
833 }
834
835 #ifdef HAVE_GLOB
836 if (glob (pattern, 0, NULL, &gl) == 0)
837 {
838 size_t i;
839
840 for (i = 0; i < gl.gl_pathc; ++i)
841 gld${EMULATION_NAME}_parse_ld_so_conf (info, gl.gl_pathv[i]);
842 globfree (&gl);
843 }
844 #else
845 /* If we do not have glob, treat the pattern as a literal filename. */
846 gld${EMULATION_NAME}_parse_ld_so_conf (info, pattern);
847 #endif
848
849 if (newp)
850 free (newp);
851 }
852
853 static bfd_boolean
854 gld${EMULATION_NAME}_parse_ld_so_conf
855 (struct gld${EMULATION_NAME}_ld_so_conf *info, const char *filename)
856 {
857 FILE *f = fopen (filename, FOPEN_RT);
858 char *line;
859 size_t linelen;
860
861 if (f == NULL)
862 return FALSE;
863
864 linelen = 256;
865 line = xmalloc (linelen);
866 do
867 {
868 char *p = line, *q;
869
870 /* Normally this would use getline(3), but we need to be portable. */
871 while ((q = fgets (p, linelen - (p - line), f)) != NULL
872 && strlen (q) == linelen - (p - line) - 1
873 && line[linelen - 2] != '\n')
874 {
875 line = xrealloc (line, 2 * linelen);
876 p = line + linelen - 1;
877 linelen += linelen;
878 }
879
880 if (q == NULL && p == line)
881 break;
882
883 p = strchr (line, '\n');
884 if (p)
885 *p = '\0';
886
887 /* Because the file format does not know any form of quoting we
888 can search forward for the next '#' character and if found
889 make it terminating the line. */
890 p = strchr (line, '#');
891 if (p)
892 *p = '\0';
893
894 /* Remove leading whitespace. NUL is no whitespace character. */
895 p = line;
896 while (*p == ' ' || *p == '\f' || *p == '\r' || *p == '\t' || *p == '\v')
897 ++p;
898
899 /* If the line is blank it is ignored. */
900 if (p[0] == '\0')
901 continue;
902
903 if (CONST_STRNEQ (p, "include") && (p[7] == ' ' || p[7] == '\t'))
904 {
905 char *dir, c;
906 p += 8;
907 do
908 {
909 while (*p == ' ' || *p == '\t')
910 ++p;
911
912 if (*p == '\0')
913 break;
914
915 dir = p;
916
917 while (*p != ' ' && *p != '\t' && *p)
918 ++p;
919
920 c = *p;
921 *p++ = '\0';
922 if (dir[0] != '\0')
923 gld${EMULATION_NAME}_parse_ld_so_conf_include (info, filename,
924 dir);
925 }
926 while (c != '\0');
927 }
928 else
929 {
930 char *dir = p;
931 while (*p && *p != '=' && *p != ' ' && *p != '\t' && *p != '\f'
932 && *p != '\r' && *p != '\v')
933 ++p;
934
935 while (p != dir && p[-1] == '/')
936 --p;
937 if (info->path == NULL)
938 {
939 info->alloc = p - dir + 1 + 256;
940 info->path = xmalloc (info->alloc);
941 info->len = 0;
942 }
943 else
944 {
945 if (info->len + 1 + (p - dir) >= info->alloc)
946 {
947 info->alloc += p - dir + 256;
948 info->path = xrealloc (info->path, info->alloc);
949 }
950 info->path[info->len++] = config.rpath_separator;
951 }
952 memcpy (info->path + info->len, dir, p - dir);
953 info->len += p - dir;
954 info->path[info->len] = '\0';
955 }
956 }
957 while (! feof (f));
958 free (line);
959 fclose (f);
960 return TRUE;
961 }
962
963 static bfd_boolean
964 gld${EMULATION_NAME}_check_ld_so_conf (const struct bfd_link_needed_list *l,
965 int force)
966 {
967 static bfd_boolean initialized;
968 static char *ld_so_conf;
969 struct dt_needed needed;
970
971 if (! initialized)
972 {
973 char *tmppath;
974 struct gld${EMULATION_NAME}_ld_so_conf info;
975
976 info.path = NULL;
977 info.len = info.alloc = 0;
978 tmppath = concat (ld_sysroot, "${prefix}/etc/ld.so.conf",
979 (const char *) NULL);
980 if (!gld${EMULATION_NAME}_parse_ld_so_conf (&info, tmppath))
981 {
982 free (tmppath);
983 tmppath = concat (ld_sysroot, "/etc/ld.so.conf",
984 (const char *) NULL);
985 gld${EMULATION_NAME}_parse_ld_so_conf (&info, tmppath);
986 }
987 free (tmppath);
988
989 if (info.path)
990 {
991 char *d = gld${EMULATION_NAME}_add_sysroot (info.path);
992 free (info.path);
993 ld_so_conf = d;
994 }
995 initialized = TRUE;
996 }
997
998 if (ld_so_conf == NULL)
999 return FALSE;
1000
1001
1002 needed.by = l->by;
1003 needed.name = l->name;
1004 return gld${EMULATION_NAME}_search_needed (ld_so_conf, &needed, force);
1005 }
1006
1007 EOF
1008 # Linux
1009 ;;
1010 esac
1011 fi
1012 fragment <<EOF
1013
1014 /* See if an input file matches a DT_NEEDED entry by name. */
1015
1016 static void
1017 gld${EMULATION_NAME}_check_needed (lang_input_statement_type *s)
1018 {
1019 const char *soname;
1020
1021 /* Stop looking if we've found a loaded lib. */
1022 if (global_found != NULL
1023 && (bfd_elf_get_dyn_lib_class (global_found->the_bfd)
1024 & DYN_AS_NEEDED) == 0)
1025 return;
1026
1027 if (s->filename == NULL || s->the_bfd == NULL)
1028 return;
1029
1030 /* Don't look for a second non-loaded as-needed lib. */
1031 if (global_found != NULL
1032 && (bfd_elf_get_dyn_lib_class (s->the_bfd) & DYN_AS_NEEDED) != 0)
1033 return;
1034
1035 if (filename_cmp (s->filename, global_needed->name) == 0)
1036 {
1037 global_found = s;
1038 return;
1039 }
1040
1041 if (s->flags.search_dirs)
1042 {
1043 const char *f = strrchr (s->filename, '/');
1044 if (f != NULL
1045 && filename_cmp (f + 1, global_needed->name) == 0)
1046 {
1047 global_found = s;
1048 return;
1049 }
1050 }
1051
1052 soname = bfd_elf_get_dt_soname (s->the_bfd);
1053 if (soname != NULL
1054 && filename_cmp (soname, global_needed->name) == 0)
1055 {
1056 global_found = s;
1057 return;
1058 }
1059 }
1060
1061 EOF
1062
1063 if test x"$LDEMUL_AFTER_OPEN" != xgld"$EMULATION_NAME"_after_open; then
1064 fragment <<EOF
1065
1066 static bfd_size_type
1067 id_note_section_size (bfd *abfd ATTRIBUTE_UNUSED)
1068 {
1069 const char *style = emit_note_gnu_build_id;
1070 bfd_size_type size;
1071 bfd_size_type build_id_size;
1072
1073 size = offsetof (Elf_External_Note, name[sizeof "GNU"]);
1074 size = (size + 3) & -(bfd_size_type) 4;
1075
1076 build_id_size = compute_build_id_size (style);
1077 if (build_id_size)
1078 size += build_id_size;
1079 else
1080 size = 0;
1081
1082 return size;
1083 }
1084
1085 static bfd_boolean
1086 write_build_id (bfd *abfd)
1087 {
1088 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
1089 struct elf_obj_tdata *t = elf_tdata (abfd);
1090 const char *style;
1091 asection *asec;
1092 Elf_Internal_Shdr *i_shdr;
1093 unsigned char *contents, *id_bits;
1094 bfd_size_type size;
1095 file_ptr position;
1096 Elf_External_Note *e_note;
1097
1098 style = t->o->build_id.style;
1099 asec = t->o->build_id.sec;
1100 if (bfd_is_abs_section (asec->output_section))
1101 {
1102 einfo (_("%P: warning: .note.gnu.build-id section discarded,"
1103 " --build-id ignored.\n"));
1104 return TRUE;
1105 }
1106 i_shdr = &elf_section_data (asec->output_section)->this_hdr;
1107
1108 if (i_shdr->contents == NULL)
1109 {
1110 if (asec->contents == NULL)
1111 asec->contents = (unsigned char *) xmalloc (asec->size);
1112 contents = asec->contents;
1113 }
1114 else
1115 contents = i_shdr->contents + asec->output_offset;
1116
1117 e_note = (Elf_External_Note *) contents;
1118 size = offsetof (Elf_External_Note, name[sizeof "GNU"]);
1119 size = (size + 3) & -(bfd_size_type) 4;
1120 id_bits = contents + size;
1121 size = asec->size - size;
1122
1123 bfd_h_put_32 (abfd, sizeof "GNU", &e_note->namesz);
1124 bfd_h_put_32 (abfd, size, &e_note->descsz);
1125 bfd_h_put_32 (abfd, NT_GNU_BUILD_ID, &e_note->type);
1126 memcpy (e_note->name, "GNU", sizeof "GNU");
1127
1128 generate_build_id (abfd, style, bed->s->checksum_contents, id_bits, size);
1129
1130 position = i_shdr->sh_offset + asec->output_offset;
1131 size = asec->size;
1132 return (bfd_seek (abfd, position, SEEK_SET) == 0
1133 && bfd_bwrite (contents, size, abfd) == size);
1134 }
1135
1136 /* Make .note.gnu.build-id section, and set up elf_tdata->build_id. */
1137
1138 static bfd_boolean
1139 setup_build_id (bfd *ibfd)
1140 {
1141 asection *s;
1142 bfd_size_type size;
1143 flagword flags;
1144
1145 size = id_note_section_size (ibfd);
1146 if (size == 0)
1147 {
1148 einfo ("%P: warning: unrecognized --build-id style ignored.\n");
1149 return FALSE;
1150 }
1151
1152 flags = (SEC_ALLOC | SEC_LOAD | SEC_IN_MEMORY
1153 | SEC_LINKER_CREATED | SEC_READONLY | SEC_DATA);
1154 s = bfd_make_section_with_flags (ibfd, ".note.gnu.build-id", flags);
1155 if (s != NULL && bfd_set_section_alignment (ibfd, s, 2))
1156 {
1157 struct elf_obj_tdata *t = elf_tdata (link_info.output_bfd);
1158 t->o->build_id.after_write_object_contents = &write_build_id;
1159 t->o->build_id.style = emit_note_gnu_build_id;
1160 t->o->build_id.sec = s;
1161 elf_section_type (s) = SHT_NOTE;
1162 s->size = size;
1163 return TRUE;
1164 }
1165
1166 einfo ("%P: warning: Cannot create .note.gnu.build-id section,"
1167 " --build-id ignored.\n");
1168 return FALSE;
1169 }
1170
1171 /* This is called after all the input files have been opened. */
1172
1173 static void
1174 gld${EMULATION_NAME}_after_open (void)
1175 {
1176 struct bfd_link_needed_list *needed, *l;
1177 struct elf_link_hash_table *htab;
1178
1179 after_open_default ();
1180
1181 htab = elf_hash_table (&link_info);
1182 if (!is_elf_hash_table (htab))
1183 return;
1184
1185 if (command_line.out_implib_filename)
1186 {
1187 unlink_if_ordinary (command_line.out_implib_filename);
1188 link_info.out_implib_bfd
1189 = bfd_openw (command_line.out_implib_filename,
1190 bfd_get_target (link_info.output_bfd));
1191
1192 if (link_info.out_implib_bfd == NULL)
1193 {
1194 einfo ("%F%s: Can't open for writing: %E\n",
1195 command_line.out_implib_filename);
1196 }
1197 }
1198
1199 if (emit_note_gnu_build_id != NULL)
1200 {
1201 bfd *abfd;
1202
1203 /* Find an ELF input. */
1204 for (abfd = link_info.input_bfds;
1205 abfd != (bfd *) NULL; abfd = abfd->link.next)
1206 if (bfd_get_flavour (abfd) == bfd_target_elf_flavour
1207 && bfd_count_sections (abfd) != 0)
1208 break;
1209
1210 /* PR 10555: If there are no ELF input files do not try to
1211 create a .note.gnu-build-id section. */
1212 if (abfd == NULL
1213 || !setup_build_id (abfd))
1214 {
1215 free ((char *) emit_note_gnu_build_id);
1216 emit_note_gnu_build_id = NULL;
1217 }
1218 }
1219
1220 if (bfd_link_relocatable (&link_info))
1221 {
1222 if (link_info.execstack == ! link_info.noexecstack)
1223 /* PR ld/16744: If "-z [no]execstack" has been specified on the
1224 command line and we are perfoming a relocatable link then no
1225 PT_GNU_STACK segment will be created and so the
1226 linkinfo.[no]execstack values set in _handle_option() will have no
1227 effect. Instead we create a .note.GNU-stack section in much the
1228 same way as the assembler does with its --[no]execstack option. */
1229 (void) bfd_make_section_with_flags (link_info.input_bfds,
1230 ".note.GNU-stack",
1231 SEC_READONLY | (link_info.execstack ? SEC_CODE : 0));
1232
1233 return;
1234 }
1235
1236 if (!link_info.traditional_format)
1237 {
1238 bfd *abfd, *elfbfd = NULL;
1239 bfd_boolean warn_eh_frame = FALSE;
1240 asection *s;
1241 int seen_type = 0;
1242
1243 for (abfd = link_info.input_bfds; abfd; abfd = abfd->link.next)
1244 {
1245 int type = 0;
1246 for (s = abfd->sections; s && type < COMPACT_EH_HDR; s = s->next)
1247 {
1248 const char *name = bfd_get_section_name (abfd, s);
1249
1250 if (bfd_is_abs_section (s->output_section))
1251 continue;
1252 if (CONST_STRNEQ (name, ".eh_frame_entry"))
1253 type = COMPACT_EH_HDR;
1254 else if (strcmp (name, ".eh_frame") == 0 && s->size > 8)
1255 type = DWARF2_EH_HDR;
1256 }
1257
1258 if (type != 0)
1259 {
1260 if (seen_type == 0)
1261 {
1262 seen_type = type;
1263 }
1264 else if (seen_type != type)
1265 {
1266 einfo (_("%P%F: compact frame descriptions incompatible with"
1267 " DWARF2 .eh_frame from %B\n"),
1268 type == DWARF2_EH_HDR ? abfd : elfbfd);
1269 break;
1270 }
1271
1272 if (!elfbfd
1273 && (type == COMPACT_EH_HDR || link_info.eh_frame_hdr_type != 0))
1274 {
1275 if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
1276 elfbfd = abfd;
1277
1278 warn_eh_frame = TRUE;
1279 }
1280 }
1281
1282 if (seen_type == COMPACT_EH_HDR)
1283 link_info.eh_frame_hdr_type = COMPACT_EH_HDR;
1284
1285 if (bfd_count_sections (abfd) == 0)
1286 continue;
1287 }
1288 if (elfbfd)
1289 {
1290 const struct elf_backend_data *bed;
1291
1292 bed = get_elf_backend_data (elfbfd);
1293 s = bfd_make_section_with_flags (elfbfd, ".eh_frame_hdr",
1294 bed->dynamic_sec_flags
1295 | SEC_READONLY);
1296 if (s != NULL
1297 && bfd_set_section_alignment (elfbfd, s, 2))
1298 {
1299 htab->eh_info.hdr_sec = s;
1300 warn_eh_frame = FALSE;
1301 }
1302 }
1303 if (warn_eh_frame)
1304 einfo ("%P: warning: Cannot create .eh_frame_hdr section,"
1305 " --eh-frame-hdr ignored.\n");
1306 }
1307
1308 /* Get the list of files which appear in DT_NEEDED entries in
1309 dynamic objects included in the link (often there will be none).
1310 For each such file, we want to track down the corresponding
1311 library, and include the symbol table in the link. This is what
1312 the runtime dynamic linker will do. Tracking the files down here
1313 permits one dynamic object to include another without requiring
1314 special action by the person doing the link. Note that the
1315 needed list can actually grow while we are stepping through this
1316 loop. */
1317 needed = bfd_elf_get_needed_list (link_info.output_bfd, &link_info);
1318 for (l = needed; l != NULL; l = l->next)
1319 {
1320 struct bfd_link_needed_list *ll;
1321 struct dt_needed n, nn;
1322 int force;
1323
1324 /* If the lib that needs this one was --as-needed and wasn't
1325 found to be needed, then this lib isn't needed either. */
1326 if (l->by != NULL
1327 && (bfd_elf_get_dyn_lib_class (l->by) & DYN_AS_NEEDED) != 0)
1328 continue;
1329
1330 /* Skip the lib if --no-copy-dt-needed-entries and
1331 --allow-shlib-undefined is in effect. */
1332 if (l->by != NULL
1333 && link_info.unresolved_syms_in_shared_libs == RM_IGNORE
1334 && (bfd_elf_get_dyn_lib_class (l->by) & DYN_NO_ADD_NEEDED) != 0)
1335 continue;
1336
1337 /* If we've already seen this file, skip it. */
1338 for (ll = needed; ll != l; ll = ll->next)
1339 if ((ll->by == NULL
1340 || (bfd_elf_get_dyn_lib_class (ll->by) & DYN_AS_NEEDED) == 0)
1341 && strcmp (ll->name, l->name) == 0)
1342 break;
1343 if (ll != l)
1344 continue;
1345
1346 /* See if this file was included in the link explicitly. */
1347 global_needed = l;
1348 global_found = NULL;
1349 lang_for_each_input_file (gld${EMULATION_NAME}_check_needed);
1350 if (global_found != NULL
1351 && (bfd_elf_get_dyn_lib_class (global_found->the_bfd)
1352 & DYN_AS_NEEDED) == 0)
1353 continue;
1354
1355 n.by = l->by;
1356 n.name = l->name;
1357 nn.by = l->by;
1358 if (verbose)
1359 info_msg (_("%s needed by %B\n"), l->name, l->by);
1360
1361 /* As-needed libs specified on the command line (or linker script)
1362 take priority over libs found in search dirs. */
1363 if (global_found != NULL)
1364 {
1365 nn.name = global_found->filename;
1366 if (gld${EMULATION_NAME}_try_needed (&nn, TRUE))
1367 continue;
1368 }
1369
1370 /* We need to find this file and include the symbol table. We
1371 want to search for the file in the same way that the dynamic
1372 linker will search. That means that we want to use
1373 rpath_link, rpath, then the environment variable
1374 LD_LIBRARY_PATH (native only), then the DT_RPATH/DT_RUNPATH
1375 entries (native only), then the linker script LIB_SEARCH_DIRS.
1376 We do not search using the -L arguments.
1377
1378 We search twice. The first time, we skip objects which may
1379 introduce version mismatches. The second time, we force
1380 their use. See gld${EMULATION_NAME}_vercheck comment. */
1381 for (force = 0; force < 2; force++)
1382 {
1383 size_t len;
1384 search_dirs_type *search;
1385 EOF
1386 if [ "x${NATIVE}" = xyes ] ; then
1387 fragment <<EOF
1388 const char *lib_path;
1389 EOF
1390 fi
1391 if [ "x${USE_LIBPATH}" = xyes ] ; then
1392 fragment <<EOF
1393 struct bfd_link_needed_list *rp;
1394 int found;
1395 EOF
1396 fi
1397 fragment <<EOF
1398
1399 if (gld${EMULATION_NAME}_search_needed (command_line.rpath_link,
1400 &n, force))
1401 break;
1402 EOF
1403 if [ "x${USE_LIBPATH}" = xyes ] ; then
1404 fragment <<EOF
1405 if (gld${EMULATION_NAME}_search_needed (command_line.rpath,
1406 &n, force))
1407 break;
1408 EOF
1409 fi
1410 if [ "x${NATIVE}" = xyes ] ; then
1411 fragment <<EOF
1412 if (command_line.rpath_link == NULL
1413 && command_line.rpath == NULL)
1414 {
1415 lib_path = (const char *) getenv ("LD_RUN_PATH");
1416 if (gld${EMULATION_NAME}_search_needed (lib_path, &n,
1417 force))
1418 break;
1419 }
1420 lib_path = (const char *) getenv ("LD_LIBRARY_PATH");
1421 if (gld${EMULATION_NAME}_search_needed (lib_path, &n, force))
1422 break;
1423 EOF
1424 fi
1425 if [ "x${USE_LIBPATH}" = xyes ] ; then
1426 fragment <<EOF
1427 found = 0;
1428 rp = bfd_elf_get_runpath_list (link_info.output_bfd, &link_info);
1429 for (; !found && rp != NULL; rp = rp->next)
1430 {
1431 const char *tmpname = rp->name;
1432
1433 if (IS_ABSOLUTE_PATH (tmpname))
1434 tmpname = gld${EMULATION_NAME}_add_sysroot (tmpname);
1435 found = (rp->by == l->by
1436 && gld${EMULATION_NAME}_search_needed (tmpname,
1437 &n,
1438 force));
1439 if (tmpname != rp->name)
1440 free ((char *) tmpname);
1441 }
1442 if (found)
1443 break;
1444
1445 EOF
1446 fi
1447 if [ "x${USE_LIBPATH}" = xyes ] ; then
1448 case ${target} in
1449 *-*-freebsd* | *-*-dragonfly*)
1450 fragment <<EOF
1451 if (gld${EMULATION_NAME}_check_ld_elf_hints (l, force))
1452 break;
1453 EOF
1454 # FreeBSD
1455 ;;
1456
1457 *-*-linux-* | *-*-k*bsd*-* | *-*-gnu*)
1458 fragment <<EOF
1459 if (gld${EMULATION_NAME}_check_ld_so_conf (l, force))
1460 break;
1461
1462 EOF
1463 # Linux
1464 ;;
1465 esac
1466 fi
1467 fragment <<EOF
1468 len = strlen (l->name);
1469 for (search = search_head; search != NULL; search = search->next)
1470 {
1471 char *filename;
1472
1473 if (search->cmdline)
1474 continue;
1475 filename = (char *) xmalloc (strlen (search->name) + len + 2);
1476 sprintf (filename, "%s/%s", search->name, l->name);
1477 nn.name = filename;
1478 if (gld${EMULATION_NAME}_try_needed (&nn, force))
1479 break;
1480 free (filename);
1481 }
1482 if (search != NULL)
1483 break;
1484 EOF
1485 fragment <<EOF
1486 }
1487
1488 if (force < 2)
1489 continue;
1490
1491 einfo ("%P: warning: %s, needed by %B, not found (try using -rpath or -rpath-link)\n",
1492 l->name, l->by);
1493 }
1494
1495 if (link_info.eh_frame_hdr_type == COMPACT_EH_HDR)
1496 if (bfd_elf_parse_eh_frame_entries (NULL, &link_info) == FALSE)
1497 einfo (_("%P%F: Failed to parse EH frame entries.\n"));
1498 }
1499
1500 EOF
1501 fi
1502
1503 fragment <<EOF
1504
1505 /* Look through an expression for an assignment statement. */
1506
1507 static void
1508 gld${EMULATION_NAME}_find_exp_assignment (etree_type *exp)
1509 {
1510 bfd_boolean provide = FALSE;
1511
1512 switch (exp->type.node_class)
1513 {
1514 case etree_provide:
1515 case etree_provided:
1516 provide = TRUE;
1517 /* Fall thru */
1518 case etree_assign:
1519 /* We call record_link_assignment even if the symbol is defined.
1520 This is because if it is defined by a dynamic object, we
1521 actually want to use the value defined by the linker script,
1522 not the value from the dynamic object (because we are setting
1523 symbols like etext). If the symbol is defined by a regular
1524 object, then, as it happens, calling record_link_assignment
1525 will do no harm. */
1526 if (strcmp (exp->assign.dst, ".") != 0)
1527 {
1528 if (!bfd_elf_record_link_assignment (link_info.output_bfd,
1529 &link_info,
1530 exp->assign.dst, provide,
1531 exp->assign.hidden))
1532 einfo ("%P%F: failed to record assignment to %s: %E\n",
1533 exp->assign.dst);
1534 }
1535 gld${EMULATION_NAME}_find_exp_assignment (exp->assign.src);
1536 break;
1537
1538 case etree_binary:
1539 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.lhs);
1540 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.rhs);
1541 break;
1542
1543 case etree_trinary:
1544 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.cond);
1545 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.lhs);
1546 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.rhs);
1547 break;
1548
1549 case etree_unary:
1550 gld${EMULATION_NAME}_find_exp_assignment (exp->unary.child);
1551 break;
1552
1553 default:
1554 break;
1555 }
1556 }
1557
1558
1559 /* This is called by the before_allocation routine via
1560 lang_for_each_statement. It locates any assignment statements, and
1561 tells the ELF backend about them, in case they are assignments to
1562 symbols which are referred to by dynamic objects. */
1563
1564 static void
1565 gld${EMULATION_NAME}_find_statement_assignment (lang_statement_union_type *s)
1566 {
1567 if (s->header.type == lang_assignment_statement_enum)
1568 gld${EMULATION_NAME}_find_exp_assignment (s->assignment_statement.exp);
1569 }
1570
1571 EOF
1572
1573 if test x"$LDEMUL_BEFORE_ALLOCATION" != xgld"$EMULATION_NAME"_before_allocation; then
1574 if test x"${ELF_INTERPRETER_NAME+set}" = xset; then
1575 ELF_INTERPRETER_SET_DEFAULT="
1576 if (sinterp != NULL)
1577 {
1578 sinterp->contents = (unsigned char *) ${ELF_INTERPRETER_NAME};
1579 sinterp->size = strlen ((char *) sinterp->contents) + 1;
1580 }
1581
1582 "
1583 else
1584 ELF_INTERPRETER_SET_DEFAULT=
1585 fi
1586 fragment <<EOF
1587
1588 /* used by before_allocation and handle_option. */
1589 static void
1590 gld${EMULATION_NAME}_append_to_separated_string (char **to, char *op_arg)
1591 {
1592 if (*to == NULL)
1593 *to = xstrdup (op_arg);
1594 else
1595 {
1596 size_t to_len = strlen (*to);
1597 size_t op_arg_len = strlen (op_arg);
1598 char *buf;
1599 char *cp = *to;
1600
1601 /* First see whether OPTARG is already in the path. */
1602 do
1603 {
1604 if (strncmp (op_arg, cp, op_arg_len) == 0
1605 && (cp[op_arg_len] == 0
1606 || cp[op_arg_len] == config.rpath_separator))
1607 /* We found it. */
1608 break;
1609
1610 /* Not yet found. */
1611 cp = strchr (cp, config.rpath_separator);
1612 if (cp != NULL)
1613 ++cp;
1614 }
1615 while (cp != NULL);
1616
1617 if (cp == NULL)
1618 {
1619 buf = xmalloc (to_len + op_arg_len + 2);
1620 sprintf (buf, "%s%c%s", *to,
1621 config.rpath_separator, op_arg);
1622 free (*to);
1623 *to = buf;
1624 }
1625 }
1626 }
1627
1628 #if defined(__GNUC__) && GCC_VERSION < 4006
1629 /* Work around a GCC uninitialized warning bug fixed in GCC 4.6. */
1630 static struct bfd_link_hash_entry ehdr_start_empty;
1631 #endif
1632
1633 /* This is called after the sections have been attached to output
1634 sections, but before any sizes or addresses have been set. */
1635
1636 static void
1637 gld${EMULATION_NAME}_before_allocation (void)
1638 {
1639 const char *rpath;
1640 asection *sinterp;
1641 bfd *abfd;
1642 struct elf_link_hash_entry *ehdr_start = NULL;
1643 #if defined(__GNUC__) && GCC_VERSION < 4006
1644 /* Work around a GCC uninitialized warning bug fixed in GCC 4.6. */
1645 struct bfd_link_hash_entry ehdr_start_save = ehdr_start_empty;
1646 #else
1647 struct bfd_link_hash_entry ehdr_start_save;
1648 #endif
1649
1650 if (is_elf_hash_table (link_info.hash))
1651 {
1652 _bfd_elf_tls_setup (link_info.output_bfd, &link_info);
1653
1654 /* Make __ehdr_start hidden if it has been referenced, to
1655 prevent the symbol from being dynamic. */
1656 if (!bfd_link_relocatable (&link_info))
1657 {
1658 struct elf_link_hash_entry *h
1659 = elf_link_hash_lookup (elf_hash_table (&link_info), "__ehdr_start",
1660 FALSE, FALSE, TRUE);
1661
1662 /* Only adjust the export class if the symbol was referenced
1663 and not defined, otherwise leave it alone. */
1664 if (h != NULL
1665 && (h->root.type == bfd_link_hash_new
1666 || h->root.type == bfd_link_hash_undefined
1667 || h->root.type == bfd_link_hash_undefweak
1668 || h->root.type == bfd_link_hash_common))
1669 {
1670 _bfd_elf_link_hash_hide_symbol (&link_info, h, TRUE);
1671 if (ELF_ST_VISIBILITY (h->other) != STV_INTERNAL)
1672 h->other = (h->other & ~ELF_ST_VISIBILITY (-1)) | STV_HIDDEN;
1673 /* Don't leave the symbol undefined. Undefined hidden
1674 symbols typically won't have dynamic relocations, but
1675 we most likely will need dynamic relocations for
1676 __ehdr_start if we are building a PIE or shared
1677 library. */
1678 ehdr_start = h;
1679 ehdr_start_save = h->root;
1680 h->root.type = bfd_link_hash_defined;
1681 h->root.u.def.section = bfd_abs_section_ptr;
1682 h->root.u.def.value = 0;
1683 }
1684 }
1685
1686 /* If we are going to make any variable assignments, we need to
1687 let the ELF backend know about them in case the variables are
1688 referred to by dynamic objects. */
1689 lang_for_each_statement (gld${EMULATION_NAME}_find_statement_assignment);
1690 }
1691
1692 /* Let the ELF backend work out the sizes of any sections required
1693 by dynamic linking. */
1694 rpath = command_line.rpath;
1695 if (rpath == NULL)
1696 rpath = (const char *) getenv ("LD_RUN_PATH");
1697
1698 for (abfd = link_info.input_bfds; abfd; abfd = abfd->link.next)
1699 if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
1700 {
1701 const char *audit_libs = elf_dt_audit (abfd);
1702
1703 /* If the input bfd contains an audit entry, we need to add it as
1704 a dep audit entry. */
1705 if (audit_libs && *audit_libs != '\0')
1706 {
1707 char *cp = xstrdup (audit_libs);
1708 do
1709 {
1710 int more = 0;
1711 char *cp2 = strchr (cp, config.rpath_separator);
1712
1713 if (cp2)
1714 {
1715 *cp2 = '\0';
1716 more = 1;
1717 }
1718
1719 if (cp != NULL && *cp != '\0')
1720 gld${EMULATION_NAME}_append_to_separated_string (&depaudit, cp);
1721
1722 cp = more ? ++cp2 : NULL;
1723 }
1724 while (cp != NULL);
1725 }
1726 }
1727
1728 if (! (bfd_elf_size_dynamic_sections
1729 (link_info.output_bfd, command_line.soname, rpath,
1730 command_line.filter_shlib, audit, depaudit,
1731 (const char * const *) command_line.auxiliary_filters,
1732 &link_info, &sinterp)))
1733 einfo ("%P%F: failed to set dynamic section sizes: %E\n");
1734
1735 ${ELF_INTERPRETER_SET_DEFAULT}
1736 /* Let the user override the dynamic linker we are using. */
1737 if (command_line.interpreter != NULL
1738 && sinterp != NULL)
1739 {
1740 sinterp->contents = (bfd_byte *) command_line.interpreter;
1741 sinterp->size = strlen (command_line.interpreter) + 1;
1742 }
1743
1744 /* Look for any sections named .gnu.warning. As a GNU extensions,
1745 we treat such sections as containing warning messages. We print
1746 out the warning message, and then zero out the section size so
1747 that it does not get copied into the output file. */
1748
1749 {
1750 LANG_FOR_EACH_INPUT_STATEMENT (is)
1751 {
1752 asection *s;
1753 bfd_size_type sz;
1754 char *msg;
1755
1756 if (is->flags.just_syms)
1757 continue;
1758
1759 s = bfd_get_section_by_name (is->the_bfd, ".gnu.warning");
1760 if (s == NULL)
1761 continue;
1762
1763 sz = s->size;
1764 msg = (char *) xmalloc ((size_t) (sz + 1));
1765 if (! bfd_get_section_contents (is->the_bfd, s, msg,
1766 (file_ptr) 0, sz))
1767 einfo ("%F%B: Can't read contents of section .gnu.warning: %E\n",
1768 is->the_bfd);
1769 msg[sz] = '\0';
1770 (*link_info.callbacks->warning) (&link_info, msg,
1771 (const char *) NULL, is->the_bfd,
1772 (asection *) NULL, (bfd_vma) 0);
1773 free (msg);
1774
1775 /* Clobber the section size, so that we don't waste space
1776 copying the warning into the output file. If we've already
1777 sized the output section, adjust its size. The adjustment
1778 is on rawsize because targets that size sections early will
1779 have called lang_reset_memory_regions after sizing. */
1780 if (s->output_section != NULL
1781 && s->output_section->rawsize >= s->size)
1782 s->output_section->rawsize -= s->size;
1783
1784 s->size = 0;
1785
1786 /* Also set SEC_EXCLUDE, so that local symbols defined in the
1787 warning section don't get copied to the output. */
1788 s->flags |= SEC_EXCLUDE | SEC_KEEP;
1789 }
1790 }
1791
1792 before_allocation_default ();
1793
1794 if (!bfd_elf_size_dynsym_hash_dynstr (link_info.output_bfd, &link_info))
1795 einfo ("%P%F: failed to set dynamic section sizes: %E\n");
1796
1797 if (ehdr_start != NULL)
1798 {
1799 /* If we twiddled __ehdr_start to defined earlier, put it back
1800 as it was. */
1801 ehdr_start->root.type = ehdr_start_save.type;
1802 ehdr_start->root.u = ehdr_start_save.u;
1803 }
1804 }
1805
1806 EOF
1807 fi
1808
1809 if test x"$LDEMUL_OPEN_DYNAMIC_ARCHIVE" != xgld"$EMULATION_NAME"_open_dynamic_archive; then
1810 fragment <<EOF
1811
1812 /* Try to open a dynamic archive. This is where we know that ELF
1813 dynamic libraries have an extension of .so (or .sl on oddball systems
1814 like hpux). */
1815
1816 static bfd_boolean
1817 gld${EMULATION_NAME}_open_dynamic_archive
1818 (const char *arch, search_dirs_type *search, lang_input_statement_type *entry)
1819 {
1820 const char *filename;
1821 char *string;
1822 size_t len;
1823 bfd_boolean opened = FALSE;
1824
1825 if (! entry->flags.maybe_archive)
1826 return FALSE;
1827
1828 filename = entry->filename;
1829 len = strlen (search->name) + strlen (filename);
1830 if (entry->flags.full_name_provided)
1831 {
1832 len += sizeof "/";
1833 string = (char *) xmalloc (len);
1834 sprintf (string, "%s/%s", search->name, filename);
1835 }
1836 else
1837 {
1838 size_t xlen = 0;
1839
1840 len += strlen (arch) + sizeof "/lib.so";
1841 #ifdef EXTRA_SHLIB_EXTENSION
1842 xlen = (strlen (EXTRA_SHLIB_EXTENSION) > 3
1843 ? strlen (EXTRA_SHLIB_EXTENSION) - 3
1844 : 0);
1845 #endif
1846 string = (char *) xmalloc (len + xlen);
1847 sprintf (string, "%s/lib%s%s.so", search->name, filename, arch);
1848 #ifdef EXTRA_SHLIB_EXTENSION
1849 /* Try the .so extension first. If that fails build a new filename
1850 using EXTRA_SHLIB_EXTENSION. */
1851 opened = ldfile_try_open_bfd (string, entry);
1852 if (!opened)
1853 strcpy (string + len - 4, EXTRA_SHLIB_EXTENSION);
1854 #endif
1855 }
1856
1857 if (!opened && !ldfile_try_open_bfd (string, entry))
1858 {
1859 free (string);
1860 return FALSE;
1861 }
1862
1863 entry->filename = string;
1864
1865 /* We have found a dynamic object to include in the link. The ELF
1866 backend linker will create a DT_NEEDED entry in the .dynamic
1867 section naming this file. If this file includes a DT_SONAME
1868 entry, it will be used. Otherwise, the ELF linker will just use
1869 the name of the file. For an archive found by searching, like
1870 this one, the DT_NEEDED entry should consist of just the name of
1871 the file, without the path information used to find it. Note
1872 that we only need to do this if we have a dynamic object; an
1873 archive will never be referenced by a DT_NEEDED entry.
1874
1875 FIXME: This approach--using bfd_elf_set_dt_needed_name--is not
1876 very pretty. I haven't been able to think of anything that is
1877 pretty, though. */
1878 if (bfd_check_format (entry->the_bfd, bfd_object)
1879 && (entry->the_bfd->flags & DYNAMIC) != 0)
1880 {
1881 ASSERT (entry->flags.maybe_archive && entry->flags.search_dirs);
1882
1883 /* Rather than duplicating the logic above. Just use the
1884 filename we recorded earlier. */
1885
1886 if (!entry->flags.full_name_provided)
1887 filename = lbasename (entry->filename);
1888 bfd_elf_set_dt_needed_name (entry->the_bfd, filename);
1889 }
1890
1891 return TRUE;
1892 }
1893
1894 EOF
1895 fi
1896
1897 if test x"$LDEMUL_PLACE_ORPHAN" != xgld"$EMULATION_NAME"_place_orphan; then
1898 fragment <<EOF
1899
1900 /* A variant of lang_output_section_find used by place_orphan. */
1901
1902 static lang_output_section_statement_type *
1903 output_rel_find (asection *sec, int isdyn)
1904 {
1905 lang_output_section_statement_type *lookup;
1906 lang_output_section_statement_type *last = NULL;
1907 lang_output_section_statement_type *last_alloc = NULL;
1908 lang_output_section_statement_type *last_ro_alloc = NULL;
1909 lang_output_section_statement_type *last_rel = NULL;
1910 lang_output_section_statement_type *last_rel_alloc = NULL;
1911 int rela = sec->name[4] == 'a';
1912
1913 for (lookup = &lang_output_section_statement.head->output_section_statement;
1914 lookup != NULL;
1915 lookup = lookup->next)
1916 {
1917 if (lookup->constraint >= 0
1918 && CONST_STRNEQ (lookup->name, ".rel"))
1919 {
1920 int lookrela = lookup->name[4] == 'a';
1921
1922 /* .rel.dyn must come before all other reloc sections, to suit
1923 GNU ld.so. */
1924 if (isdyn)
1925 break;
1926
1927 /* Don't place after .rel.plt as doing so results in wrong
1928 dynamic tags. */
1929 if (strcmp (".plt", lookup->name + 4 + lookrela) == 0)
1930 break;
1931
1932 if (rela == lookrela || last_rel == NULL)
1933 last_rel = lookup;
1934 if ((rela == lookrela || last_rel_alloc == NULL)
1935 && lookup->bfd_section != NULL
1936 && (lookup->bfd_section->flags & SEC_ALLOC) != 0)
1937 last_rel_alloc = lookup;
1938 }
1939
1940 last = lookup;
1941 if (lookup->bfd_section != NULL
1942 && (lookup->bfd_section->flags & SEC_ALLOC) != 0)
1943 {
1944 last_alloc = lookup;
1945 if ((lookup->bfd_section->flags & SEC_READONLY) != 0)
1946 last_ro_alloc = lookup;
1947 }
1948 }
1949
1950 if (last_rel_alloc)
1951 return last_rel_alloc;
1952
1953 if (last_rel)
1954 return last_rel;
1955
1956 if (last_ro_alloc)
1957 return last_ro_alloc;
1958
1959 if (last_alloc)
1960 return last_alloc;
1961
1962 return last;
1963 }
1964
1965 /* Place an orphan section. We use this to put random SHF_ALLOC
1966 sections in the right segment. */
1967
1968 static lang_output_section_statement_type *
1969 gld${EMULATION_NAME}_place_orphan (asection *s,
1970 const char *secname,
1971 int constraint)
1972 {
1973 static struct orphan_save hold[] =
1974 {
1975 { ".text",
1976 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE,
1977 0, 0, 0, 0 },
1978 { ".rodata",
1979 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
1980 0, 0, 0, 0 },
1981 { ".tdata",
1982 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_THREAD_LOCAL,
1983 0, 0, 0, 0 },
1984 { ".data",
1985 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_DATA,
1986 0, 0, 0, 0 },
1987 { ".bss",
1988 SEC_ALLOC,
1989 0, 0, 0, 0 },
1990 { 0,
1991 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
1992 0, 0, 0, 0 },
1993 { ".interp",
1994 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
1995 0, 0, 0, 0 },
1996 { ".sdata",
1997 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_SMALL_DATA,
1998 0, 0, 0, 0 },
1999 { ".comment",
2000 SEC_HAS_CONTENTS,
2001 0, 0, 0, 0 },
2002 };
2003 enum orphan_save_index
2004 {
2005 orphan_text = 0,
2006 orphan_rodata,
2007 orphan_tdata,
2008 orphan_data,
2009 orphan_bss,
2010 orphan_rel,
2011 orphan_interp,
2012 orphan_sdata,
2013 orphan_nonalloc
2014 };
2015 static int orphan_init_done = 0;
2016 struct orphan_save *place;
2017 lang_output_section_statement_type *after;
2018 lang_output_section_statement_type *os;
2019 lang_output_section_statement_type *match_by_name = NULL;
2020 int isdyn = 0;
2021 int iself = s->owner->xvec->flavour == bfd_target_elf_flavour;
2022 unsigned int sh_type = iself ? elf_section_type (s) : SHT_NULL;
2023 flagword flags;
2024 asection *nexts;
2025
2026 if (!bfd_link_relocatable (&link_info)
2027 && link_info.combreloc
2028 && (s->flags & SEC_ALLOC))
2029 {
2030 if (iself)
2031 switch (sh_type)
2032 {
2033 case SHT_RELA:
2034 secname = ".rela.dyn";
2035 isdyn = 1;
2036 break;
2037 case SHT_REL:
2038 secname = ".rel.dyn";
2039 isdyn = 1;
2040 break;
2041 default:
2042 break;
2043 }
2044 else if (CONST_STRNEQ (secname, ".rel"))
2045 {
2046 secname = secname[4] == 'a' ? ".rela.dyn" : ".rel.dyn";
2047 isdyn = 1;
2048 }
2049 }
2050
2051 /* Look through the script to see where to place this section. */
2052 if (constraint == 0)
2053 for (os = lang_output_section_find (secname);
2054 os != NULL;
2055 os = next_matching_output_section_statement (os, 0))
2056 {
2057 /* If we don't match an existing output section, tell
2058 lang_insert_orphan to create a new output section. */
2059 constraint = SPECIAL;
2060
2061 /* SEC_EXCLUDE is cleared when doing a relocatable link. But
2062 we can't merge 2 input sections with the same name when only
2063 one of them has SHF_EXCLUDE. */
2064 if (os->bfd_section != NULL
2065 && (os->bfd_section->flags == 0
2066 || ((!bfd_link_relocatable (&link_info)
2067 || (((elf_section_flags (s)
2068 ^ elf_section_flags (os->bfd_section))
2069 & SHF_EXCLUDE) == 0))
2070 && ((s->flags ^ os->bfd_section->flags)
2071 & (SEC_LOAD | SEC_ALLOC)) == 0
2072 && _bfd_elf_match_sections_by_type (link_info.output_bfd,
2073 os->bfd_section,
2074 s->owner, s))))
2075 {
2076 /* We already have an output section statement with this
2077 name, and its bfd section has compatible flags.
2078 If the section already exists but does not have any flags
2079 set, then it has been created by the linker, probably as a
2080 result of a --section-start command line switch. */
2081 lang_add_section (&os->children, s, NULL, os);
2082 return os;
2083 }
2084
2085 /* Save unused output sections in case we can match them
2086 against orphans later. */
2087 if (os->bfd_section == NULL)
2088 match_by_name = os;
2089 }
2090
2091 /* If we didn't match an active output section, see if we matched an
2092 unused one and use that. */
2093 if (match_by_name)
2094 {
2095 lang_add_section (&match_by_name->children, s, NULL, match_by_name);
2096 return match_by_name;
2097 }
2098
2099 if (!orphan_init_done)
2100 {
2101 struct orphan_save *ho;
2102
2103 for (ho = hold; ho < hold + sizeof (hold) / sizeof (hold[0]); ++ho)
2104 if (ho->name != NULL)
2105 {
2106 ho->os = lang_output_section_find (ho->name);
2107 if (ho->os != NULL && ho->os->flags == 0)
2108 ho->os->flags = ho->flags;
2109 }
2110 orphan_init_done = 1;
2111 }
2112
2113 /* If this is a final link, then always put .gnu.warning.SYMBOL
2114 sections into the .text section to get them out of the way. */
2115 if (bfd_link_executable (&link_info)
2116 && CONST_STRNEQ (s->name, ".gnu.warning.")
2117 && hold[orphan_text].os != NULL)
2118 {
2119 os = hold[orphan_text].os;
2120 lang_add_section (&os->children, s, NULL, os);
2121 return os;
2122 }
2123
2124 flags = s->flags;
2125 if (!bfd_link_relocatable (&link_info))
2126 {
2127 nexts = s;
2128 while ((nexts = bfd_get_next_section_by_name (nexts->owner, nexts))
2129 != NULL)
2130 if (nexts->output_section == NULL
2131 && (nexts->flags & SEC_EXCLUDE) == 0
2132 && ((nexts->flags ^ flags) & (SEC_LOAD | SEC_ALLOC)) == 0
2133 && (nexts->owner->flags & DYNAMIC) == 0
2134 && nexts->owner->usrdata != NULL
2135 && !(((lang_input_statement_type *) nexts->owner->usrdata)
2136 ->flags.just_syms)
2137 && _bfd_elf_match_sections_by_type (nexts->owner, nexts,
2138 s->owner, s))
2139 flags = (((flags ^ SEC_READONLY)
2140 | (nexts->flags ^ SEC_READONLY))
2141 ^ SEC_READONLY);
2142 }
2143
2144 /* Decide which segment the section should go in based on the
2145 section name and section flags. We put loadable .note sections
2146 right after the .interp section, so that the PT_NOTE segment is
2147 stored right after the program headers where the OS can read it
2148 in the first page. */
2149
2150 place = NULL;
2151 if ((flags & (SEC_ALLOC | SEC_DEBUGGING)) == 0)
2152 place = &hold[orphan_nonalloc];
2153 else if ((flags & SEC_ALLOC) == 0)
2154 ;
2155 else if ((flags & SEC_LOAD) != 0
2156 && ((iself && sh_type == SHT_NOTE)
2157 || (!iself && CONST_STRNEQ (secname, ".note"))))
2158 place = &hold[orphan_interp];
2159 else if ((flags & (SEC_LOAD | SEC_HAS_CONTENTS | SEC_THREAD_LOCAL)) == 0)
2160 place = &hold[orphan_bss];
2161 else if ((flags & SEC_SMALL_DATA) != 0)
2162 place = &hold[orphan_sdata];
2163 else if ((flags & SEC_THREAD_LOCAL) != 0)
2164 place = &hold[orphan_tdata];
2165 else if ((flags & SEC_READONLY) == 0)
2166 place = &hold[orphan_data];
2167 else if (((iself && (sh_type == SHT_RELA || sh_type == SHT_REL))
2168 || (!iself && CONST_STRNEQ (secname, ".rel")))
2169 && (flags & SEC_LOAD) != 0)
2170 place = &hold[orphan_rel];
2171 else if ((flags & SEC_CODE) == 0)
2172 place = &hold[orphan_rodata];
2173 else
2174 place = &hold[orphan_text];
2175
2176 after = NULL;
2177 if (place != NULL)
2178 {
2179 if (place->os == NULL)
2180 {
2181 if (place->name != NULL)
2182 place->os = lang_output_section_find (place->name);
2183 else
2184 place->os = output_rel_find (s, isdyn);
2185 }
2186 after = place->os;
2187 if (after == NULL)
2188 after
2189 = lang_output_section_find_by_flags (s, flags, &place->os,
2190 _bfd_elf_match_sections_by_type);
2191 if (after == NULL)
2192 /* *ABS* is always the first output section statement. */
2193 after = &lang_output_section_statement.head->output_section_statement;
2194 }
2195
2196 return lang_insert_orphan (s, secname, constraint, after, place, NULL, NULL);
2197 }
2198 EOF
2199 fi
2200
2201 if test x"$LDEMUL_AFTER_ALLOCATION" != xgld"$EMULATION_NAME"_after_allocation; then
2202 fragment <<EOF
2203
2204 static void
2205 gld${EMULATION_NAME}_after_allocation (void)
2206 {
2207 int need_layout = bfd_elf_discard_info (link_info.output_bfd, &link_info);
2208
2209 if (need_layout < 0)
2210 einfo ("%X%P: .eh_frame/.stab edit: %E\n");
2211 else
2212 gld${EMULATION_NAME}_map_segments (need_layout);
2213 }
2214 EOF
2215 fi
2216
2217 if test x"$LDEMUL_GET_SCRIPT" != xgld"$EMULATION_NAME"_get_script; then
2218 fragment <<EOF
2219
2220 static char *
2221 gld${EMULATION_NAME}_get_script (int *isfile)
2222 EOF
2223
2224 if test x"$COMPILE_IN" = xyes
2225 then
2226 # Scripts compiled in.
2227
2228 # sed commands to quote an ld script as a C string.
2229 sc="-f stringify.sed"
2230
2231 fragment <<EOF
2232 {
2233 *isfile = 0;
2234
2235 if (bfd_link_relocatable (&link_info) && config.build_constructors)
2236 return
2237 EOF
2238 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
2239 echo ' ; else if (bfd_link_relocatable (&link_info)) return' >> e${EMULATION_NAME}.c
2240 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
2241 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
2242 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
2243 if cmp -s ldscripts/${EMULATION_NAME}.x ldscripts/${EMULATION_NAME}.xn; then : ; else
2244 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
2245 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
2246 fi
2247 if test -n "$GENERATE_PIE_SCRIPT" ; then
2248 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
2249 echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c
2250 echo ' && link_info.combreloc' >> e${EMULATION_NAME}.c
2251 echo ' && link_info.relro' >> e${EMULATION_NAME}.c
2252 echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
2253 sed $sc ldscripts/${EMULATION_NAME}.xdw >> e${EMULATION_NAME}.c
2254 echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c
2255 echo ' && link_info.combreloc) return' >> e${EMULATION_NAME}.c
2256 sed $sc ldscripts/${EMULATION_NAME}.xdc >> e${EMULATION_NAME}.c
2257 fi
2258 echo ' ; else if (bfd_link_pie (&link_info)) return' >> e${EMULATION_NAME}.c
2259 sed $sc ldscripts/${EMULATION_NAME}.xd >> e${EMULATION_NAME}.c
2260 fi
2261 if test -n "$GENERATE_SHLIB_SCRIPT" ; then
2262 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
2263 echo ' ; else if (bfd_link_dll (&link_info) && link_info.combreloc' >> e${EMULATION_NAME}.c
2264 echo ' && link_info.relro' >> e${EMULATION_NAME}.c
2265 echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
2266 sed $sc ldscripts/${EMULATION_NAME}.xsw >> e${EMULATION_NAME}.c
2267 echo ' ; else if (bfd_link_dll (&link_info) && link_info.combreloc) return' >> e${EMULATION_NAME}.c
2268 sed $sc ldscripts/${EMULATION_NAME}.xsc >> e${EMULATION_NAME}.c
2269 fi
2270 echo ' ; else if (bfd_link_dll (&link_info)) return' >> e${EMULATION_NAME}.c
2271 sed $sc ldscripts/${EMULATION_NAME}.xs >> e${EMULATION_NAME}.c
2272 fi
2273 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
2274 echo ' ; else if (link_info.combreloc && link_info.relro' >> e${EMULATION_NAME}.c
2275 echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
2276 sed $sc ldscripts/${EMULATION_NAME}.xw >> e${EMULATION_NAME}.c
2277 echo ' ; else if (link_info.combreloc) return' >> e${EMULATION_NAME}.c
2278 sed $sc ldscripts/${EMULATION_NAME}.xc >> e${EMULATION_NAME}.c
2279 fi
2280 echo ' ; else return' >> e${EMULATION_NAME}.c
2281 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
2282 echo '; }' >> e${EMULATION_NAME}.c
2283
2284 else
2285 # Scripts read from the filesystem.
2286
2287 fragment <<EOF
2288 {
2289 *isfile = 1;
2290
2291 if (bfd_link_relocatable (&link_info) && config.build_constructors)
2292 return "ldscripts/${EMULATION_NAME}.xu";
2293 else if (bfd_link_relocatable (&link_info))
2294 return "ldscripts/${EMULATION_NAME}.xr";
2295 else if (!config.text_read_only)
2296 return "ldscripts/${EMULATION_NAME}.xbn";
2297 EOF
2298 if cmp -s ldscripts/${EMULATION_NAME}.x ldscripts/${EMULATION_NAME}.xn; then :
2299 else
2300 fragment <<EOF
2301 else if (!config.magic_demand_paged)
2302 return "ldscripts/${EMULATION_NAME}.xn";
2303 EOF
2304 fi
2305 if test -n "$GENERATE_PIE_SCRIPT" ; then
2306 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
2307 fragment <<EOF
2308 else if (bfd_link_pie (&link_info)
2309 && link_info.combreloc
2310 && link_info.relro
2311 && (link_info.flags & DF_BIND_NOW))
2312 return "ldscripts/${EMULATION_NAME}.xdw";
2313 else if (bfd_link_pie (&link_info)
2314 && link_info.combreloc)
2315 return "ldscripts/${EMULATION_NAME}.xdc";
2316 EOF
2317 fi
2318 fragment <<EOF
2319 else if (bfd_link_pie (&link_info))
2320 return "ldscripts/${EMULATION_NAME}.xd";
2321 EOF
2322 fi
2323 if test -n "$GENERATE_SHLIB_SCRIPT" ; then
2324 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
2325 fragment <<EOF
2326 else if (bfd_link_dll (&link_info) && link_info.combreloc
2327 && link_info.relro && (link_info.flags & DF_BIND_NOW))
2328 return "ldscripts/${EMULATION_NAME}.xsw";
2329 else if (bfd_link_dll (&link_info) && link_info.combreloc)
2330 return "ldscripts/${EMULATION_NAME}.xsc";
2331 EOF
2332 fi
2333 fragment <<EOF
2334 else if (bfd_link_dll (&link_info))
2335 return "ldscripts/${EMULATION_NAME}.xs";
2336 EOF
2337 fi
2338 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
2339 fragment <<EOF
2340 else if (link_info.combreloc && link_info.relro
2341 && (link_info.flags & DF_BIND_NOW))
2342 return "ldscripts/${EMULATION_NAME}.xw";
2343 else if (link_info.combreloc)
2344 return "ldscripts/${EMULATION_NAME}.xc";
2345 EOF
2346 fi
2347 fragment <<EOF
2348 else
2349 return "ldscripts/${EMULATION_NAME}.x";
2350 }
2351
2352 EOF
2353 fi
2354 fi
2355
2356 if test -n "$PARSE_AND_LIST_PROLOGUE" ; then
2357 fragment <<EOF
2358 $PARSE_AND_LIST_PROLOGUE
2359 EOF
2360 fi
2361
2362 fragment <<EOF
2363
2364 enum elf_options
2365 {
2366 OPTION_DISABLE_NEW_DTAGS = 400,
2367 OPTION_ENABLE_NEW_DTAGS,
2368 OPTION_GROUP,
2369 OPTION_EH_FRAME_HDR,
2370 OPTION_NO_EH_FRAME_HDR,
2371 OPTION_EXCLUDE_LIBS,
2372 OPTION_HASH_STYLE,
2373 OPTION_BUILD_ID,
2374 OPTION_AUDIT,
2375 OPTION_COMPRESS_DEBUG
2376 };
2377
2378 static void
2379 gld${EMULATION_NAME}_add_options
2380 (int ns, char **shortopts, int nl, struct option **longopts,
2381 int nrl ATTRIBUTE_UNUSED, struct option **really_longopts ATTRIBUTE_UNUSED)
2382 {
2383 EOF
2384 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
2385 fragment <<EOF
2386 static const char xtra_short[] = "${PARSE_AND_LIST_SHORTOPTS}z:P:";
2387 EOF
2388 else
2389 fragment <<EOF
2390 static const char xtra_short[] = "${PARSE_AND_LIST_SHORTOPTS}z:";
2391 EOF
2392 fi
2393 fragment <<EOF
2394 static const struct option xtra_long[] = {
2395 EOF
2396 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
2397 fragment <<EOF
2398 {"audit", required_argument, NULL, OPTION_AUDIT},
2399 {"Bgroup", no_argument, NULL, OPTION_GROUP},
2400 EOF
2401 fi
2402 fragment <<EOF
2403 {"build-id", optional_argument, NULL, OPTION_BUILD_ID},
2404 {"compress-debug-sections", required_argument, NULL, OPTION_COMPRESS_DEBUG},
2405 EOF
2406 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
2407 fragment <<EOF
2408 {"depaudit", required_argument, NULL, 'P'},
2409 {"disable-new-dtags", no_argument, NULL, OPTION_DISABLE_NEW_DTAGS},
2410 {"enable-new-dtags", no_argument, NULL, OPTION_ENABLE_NEW_DTAGS},
2411 {"eh-frame-hdr", no_argument, NULL, OPTION_EH_FRAME_HDR},
2412 {"no-eh-frame-hdr", no_argument, NULL, OPTION_NO_EH_FRAME_HDR},
2413 {"exclude-libs", required_argument, NULL, OPTION_EXCLUDE_LIBS},
2414 {"hash-style", required_argument, NULL, OPTION_HASH_STYLE},
2415 EOF
2416 fi
2417 if test -n "$PARSE_AND_LIST_LONGOPTS" ; then
2418 fragment <<EOF
2419 $PARSE_AND_LIST_LONGOPTS
2420 EOF
2421 fi
2422 fragment <<EOF
2423 {NULL, no_argument, NULL, 0}
2424 };
2425
2426 *shortopts = (char *) xrealloc (*shortopts, ns + sizeof (xtra_short));
2427 memcpy (*shortopts + ns, &xtra_short, sizeof (xtra_short));
2428 *longopts = (struct option *)
2429 xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long));
2430 memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
2431 }
2432
2433 #define DEFAULT_BUILD_ID_STYLE "sha1"
2434
2435 static bfd_boolean
2436 gld${EMULATION_NAME}_handle_option (int optc)
2437 {
2438 switch (optc)
2439 {
2440 default:
2441 return FALSE;
2442
2443 case OPTION_BUILD_ID:
2444 if (emit_note_gnu_build_id != NULL)
2445 {
2446 free ((char *) emit_note_gnu_build_id);
2447 emit_note_gnu_build_id = NULL;
2448 }
2449 if (optarg == NULL)
2450 optarg = DEFAULT_BUILD_ID_STYLE;
2451 if (strcmp (optarg, "none"))
2452 emit_note_gnu_build_id = xstrdup (optarg);
2453 break;
2454
2455 case OPTION_COMPRESS_DEBUG:
2456 if (strcasecmp (optarg, "none") == 0)
2457 link_info.compress_debug = COMPRESS_DEBUG_NONE;
2458 else if (strcasecmp (optarg, "zlib") == 0)
2459 link_info.compress_debug = COMPRESS_DEBUG_GABI_ZLIB;
2460 else if (strcasecmp (optarg, "zlib-gnu") == 0)
2461 link_info.compress_debug = COMPRESS_DEBUG_GNU_ZLIB;
2462 else if (strcasecmp (optarg, "zlib-gabi") == 0)
2463 link_info.compress_debug = COMPRESS_DEBUG_GABI_ZLIB;
2464 else
2465 einfo (_("%P%F: invalid --compress-debug-sections option: \`%s'\n"),
2466 optarg);
2467 break;
2468 EOF
2469
2470 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
2471 fragment <<EOF
2472 case OPTION_AUDIT:
2473 gld${EMULATION_NAME}_append_to_separated_string (&audit, optarg);
2474 break;
2475
2476 case 'P':
2477 gld${EMULATION_NAME}_append_to_separated_string (&depaudit, optarg);
2478 break;
2479
2480 case OPTION_DISABLE_NEW_DTAGS:
2481 link_info.new_dtags = FALSE;
2482 break;
2483
2484 case OPTION_ENABLE_NEW_DTAGS:
2485 link_info.new_dtags = TRUE;
2486 break;
2487
2488 case OPTION_EH_FRAME_HDR:
2489 link_info.eh_frame_hdr_type = DWARF2_EH_HDR;
2490 break;
2491
2492 case OPTION_NO_EH_FRAME_HDR:
2493 link_info.eh_frame_hdr_type = 0;
2494 break;
2495
2496 case OPTION_GROUP:
2497 link_info.flags_1 |= (bfd_vma) DF_1_GROUP;
2498 /* Groups must be self-contained. */
2499 link_info.unresolved_syms_in_objects = RM_GENERATE_ERROR;
2500 link_info.unresolved_syms_in_shared_libs = RM_GENERATE_ERROR;
2501 break;
2502
2503 case OPTION_EXCLUDE_LIBS:
2504 add_excluded_libs (optarg);
2505 break;
2506
2507 case OPTION_HASH_STYLE:
2508 link_info.emit_hash = FALSE;
2509 link_info.emit_gnu_hash = FALSE;
2510 if (strcmp (optarg, "sysv") == 0)
2511 link_info.emit_hash = TRUE;
2512 else if (strcmp (optarg, "gnu") == 0)
2513 link_info.emit_gnu_hash = TRUE;
2514 else if (strcmp (optarg, "both") == 0)
2515 {
2516 link_info.emit_hash = TRUE;
2517 link_info.emit_gnu_hash = TRUE;
2518 }
2519 else
2520 einfo (_("%P%F: invalid hash style \`%s'\n"), optarg);
2521 break;
2522
2523 EOF
2524 fi
2525 fragment <<EOF
2526 case 'z':
2527 if (strcmp (optarg, "defs") == 0)
2528 link_info.unresolved_syms_in_objects = RM_GENERATE_ERROR;
2529 else if (strcmp (optarg, "muldefs") == 0)
2530 link_info.allow_multiple_definition = TRUE;
2531 else if (CONST_STRNEQ (optarg, "max-page-size="))
2532 {
2533 char *end;
2534
2535 config.maxpagesize = strtoul (optarg + 14, &end, 0);
2536 if (*end || (config.maxpagesize & (config.maxpagesize - 1)) != 0)
2537 einfo (_("%P%F: invalid maxium page size \`%s'\n"),
2538 optarg + 14);
2539 }
2540 else if (CONST_STRNEQ (optarg, "common-page-size="))
2541 {
2542 char *end;
2543 config.commonpagesize = strtoul (optarg + 17, &end, 0);
2544 if (*end
2545 || (config.commonpagesize & (config.commonpagesize - 1)) != 0)
2546 einfo (_("%P%F: invalid common page size \`%s'\n"),
2547 optarg + 17);
2548 }
2549 else if (CONST_STRNEQ (optarg, "stack-size="))
2550 {
2551 char *end;
2552 link_info.stacksize = strtoul (optarg + 11, &end, 0);
2553 if (*end || link_info.stacksize < 0)
2554 einfo (_("%P%F: invalid stack size \`%s'\n"), optarg + 11);
2555 if (!link_info.stacksize)
2556 /* Use -1 for explicit no-stack, because zero means
2557 'default'. */
2558 link_info.stacksize = -1;
2559 }
2560 else if (strcmp (optarg, "execstack") == 0)
2561 {
2562 link_info.execstack = TRUE;
2563 link_info.noexecstack = FALSE;
2564 }
2565 else if (strcmp (optarg, "noexecstack") == 0)
2566 {
2567 link_info.noexecstack = TRUE;
2568 link_info.execstack = FALSE;
2569 }
2570 EOF
2571
2572 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
2573 fragment <<EOF
2574 else if (strcmp (optarg, "global") == 0)
2575 link_info.flags_1 |= (bfd_vma) DF_1_GLOBAL;
2576 else if (strcmp (optarg, "initfirst") == 0)
2577 link_info.flags_1 |= (bfd_vma) DF_1_INITFIRST;
2578 else if (strcmp (optarg, "interpose") == 0)
2579 link_info.flags_1 |= (bfd_vma) DF_1_INTERPOSE;
2580 else if (strcmp (optarg, "loadfltr") == 0)
2581 link_info.flags_1 |= (bfd_vma) DF_1_LOADFLTR;
2582 else if (strcmp (optarg, "nodefaultlib") == 0)
2583 link_info.flags_1 |= (bfd_vma) DF_1_NODEFLIB;
2584 else if (strcmp (optarg, "nodelete") == 0)
2585 link_info.flags_1 |= (bfd_vma) DF_1_NODELETE;
2586 else if (strcmp (optarg, "nodlopen") == 0)
2587 link_info.flags_1 |= (bfd_vma) DF_1_NOOPEN;
2588 else if (strcmp (optarg, "nodump") == 0)
2589 link_info.flags_1 |= (bfd_vma) DF_1_NODUMP;
2590 else if (strcmp (optarg, "now") == 0)
2591 {
2592 link_info.flags |= (bfd_vma) DF_BIND_NOW;
2593 link_info.flags_1 |= (bfd_vma) DF_1_NOW;
2594 }
2595 else if (strcmp (optarg, "lazy") == 0)
2596 {
2597 link_info.flags &= ~(bfd_vma) DF_BIND_NOW;
2598 link_info.flags_1 &= ~(bfd_vma) DF_1_NOW;
2599 }
2600 else if (strcmp (optarg, "origin") == 0)
2601 {
2602 link_info.flags |= (bfd_vma) DF_ORIGIN;
2603 link_info.flags_1 |= (bfd_vma) DF_1_ORIGIN;
2604 }
2605 else if (strcmp (optarg, "combreloc") == 0)
2606 link_info.combreloc = TRUE;
2607 else if (strcmp (optarg, "nocombreloc") == 0)
2608 link_info.combreloc = FALSE;
2609 else if (strcmp (optarg, "nocopyreloc") == 0)
2610 link_info.nocopyreloc = TRUE;
2611 else if (strcmp (optarg, "relro") == 0)
2612 link_info.relro = TRUE;
2613 else if (strcmp (optarg, "norelro") == 0)
2614 link_info.relro = FALSE;
2615 else if (strcmp (optarg, "common") == 0)
2616 link_info.elf_stt_common = elf_stt_common;
2617 else if (strcmp (optarg, "nocommon") == 0)
2618 link_info.elf_stt_common = no_elf_stt_common;
2619 else if (strcmp (optarg, "text") == 0)
2620 link_info.error_textrel = TRUE;
2621 else if (strcmp (optarg, "notext") == 0)
2622 link_info.error_textrel = FALSE;
2623 else if (strcmp (optarg, "textoff") == 0)
2624 link_info.error_textrel = FALSE;
2625 EOF
2626 fi
2627
2628 if test -n "$PARSE_AND_LIST_ARGS_CASE_Z" ; then
2629 fragment <<EOF
2630 $PARSE_AND_LIST_ARGS_CASE_Z
2631 EOF
2632 fi
2633
2634 fragment <<EOF
2635 else
2636 einfo (_("%P: warning: -z %s ignored.\n"), optarg);
2637 break;
2638 EOF
2639
2640 if test -n "$PARSE_AND_LIST_ARGS_CASES" ; then
2641 fragment <<EOF
2642 $PARSE_AND_LIST_ARGS_CASES
2643 EOF
2644 fi
2645
2646 fragment <<EOF
2647 }
2648
2649 return TRUE;
2650 }
2651
2652 EOF
2653
2654 if test x"$LDEMUL_LIST_OPTIONS" != xgld"$EMULATION_NAME"_list_options; then
2655 gld_list_options="gld${EMULATION_NAME}_list_options"
2656 if test -n "$PARSE_AND_LIST_OPTIONS"; then
2657 fragment <<EOF
2658
2659 static void
2660 gld${EMULATION_NAME}_list_options (FILE * file)
2661 {
2662 EOF
2663
2664 if test -n "$PARSE_AND_LIST_OPTIONS" ; then
2665 fragment <<EOF
2666 $PARSE_AND_LIST_OPTIONS
2667 EOF
2668 fi
2669
2670 fragment <<EOF
2671 }
2672 EOF
2673 else
2674 gld_list_options="NULL"
2675 fi
2676
2677 if test -n "$PARSE_AND_LIST_EPILOGUE" ; then
2678 fragment <<EOF
2679 $PARSE_AND_LIST_EPILOGUE
2680 EOF
2681 fi
2682 fi
2683
2684 fragment <<EOF
2685
2686 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
2687 {
2688 ${LDEMUL_BEFORE_PARSE-gld${EMULATION_NAME}_before_parse},
2689 ${LDEMUL_SYSLIB-syslib_default},
2690 ${LDEMUL_HLL-hll_default},
2691 ${LDEMUL_AFTER_PARSE-gld${EMULATION_NAME}_after_parse},
2692 ${LDEMUL_AFTER_OPEN-gld${EMULATION_NAME}_after_open},
2693 ${LDEMUL_AFTER_ALLOCATION-gld${EMULATION_NAME}_after_allocation},
2694 ${LDEMUL_SET_OUTPUT_ARCH-set_output_arch_default},
2695 ${LDEMUL_CHOOSE_TARGET-ldemul_default_target},
2696 ${LDEMUL_BEFORE_ALLOCATION-gld${EMULATION_NAME}_before_allocation},
2697 ${LDEMUL_GET_SCRIPT-gld${EMULATION_NAME}_get_script},
2698 "${EMULATION_NAME}",
2699 "${OUTPUT_FORMAT}",
2700 ${LDEMUL_FINISH-finish_default},
2701 ${LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS-NULL},
2702 ${LDEMUL_OPEN_DYNAMIC_ARCHIVE-gld${EMULATION_NAME}_open_dynamic_archive},
2703 ${LDEMUL_PLACE_ORPHAN-gld${EMULATION_NAME}_place_orphan},
2704 ${LDEMUL_SET_SYMBOLS-NULL},
2705 ${LDEMUL_PARSE_ARGS-NULL},
2706 gld${EMULATION_NAME}_add_options,
2707 gld${EMULATION_NAME}_handle_option,
2708 ${LDEMUL_UNRECOGNIZED_FILE-NULL},
2709 ${LDEMUL_LIST_OPTIONS-${gld_list_options}},
2710 ${LDEMUL_RECOGNIZED_FILE-gld${EMULATION_NAME}_load_symbols},
2711 ${LDEMUL_FIND_POTENTIAL_LIBRARIES-NULL},
2712 ${LDEMUL_NEW_VERS_PATTERN-NULL},
2713 ${LDEMUL_EXTRA_MAP_FILE_TEXT-NULL}
2714 };
2715 EOF