9ac184031698d76372b6c662f3f24d4bdad37989
[deliverable/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-2017 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 /* Search for a needed file in a path. */
476
477 static bfd_boolean
478 gld${EMULATION_NAME}_search_needed (const char *path,
479 struct dt_needed *n, int force)
480 {
481 const char *s;
482 const char *name = n->name;
483 size_t len;
484 struct dt_needed needed;
485
486 if (name[0] == '/')
487 return gld${EMULATION_NAME}_try_needed (n, force);
488
489 if (path == NULL || *path == '\0')
490 return FALSE;
491
492 needed.by = n->by;
493 needed.name = n->name;
494
495 len = strlen (name);
496 while (1)
497 {
498 unsigned offset = 0;
499 char * var;
500 char *filename, *sset;
501
502 s = strchr (path, config.rpath_separator);
503 if (s == NULL)
504 s = path + strlen (path);
505
506 #if HAVE_DOS_BASED_FILE_SYSTEM
507 /* Assume a match on the second char is part of drive specifier. */
508 else if (config.rpath_separator == ':'
509 && s == path + 1
510 && ISALPHA (*path))
511 {
512 s = strchr (s + 1, config.rpath_separator);
513 if (s == NULL)
514 s = path + strlen (path);
515 }
516 #endif
517 filename = (char *) xmalloc (s - path + len + 2);
518 if (s == path)
519 sset = filename;
520 else
521 {
522 memcpy (filename, path, s - path);
523 filename[s - path] = '/';
524 sset = filename + (s - path) + 1;
525 }
526 strcpy (sset, name);
527
528 /* PR 20535: Support the same pseudo-environment variables that
529 are supported by ld.so. Namely, $ORIGIN, $LIB and $PLATFORM.
530 Since there can be more than one occurrence of these tokens in
531 the path we loop until no more are found. Since we might not
532 be able to substitute some of the tokens we maintain an offset
533 into the filename for where we should begin our scan. */
534 while ((var = strchr (filename + offset, '$')) != NULL)
535 {
536 /* The ld.so manual page does not say, but I am going to assume that
537 these tokens are terminated by a directory separator character
538 (/) or the end of the string. There is also an implication that
539 $ORIGIN should only be used at the start of a path, but that is
540 not enforced here.
541
542 The ld.so manual page also states that it allows ${ORIGIN},
543 ${LIB} and ${PLATFORM}, so these are supported as well.
544
545 FIXME: The code could be a lot cleverer about allocating space
546 for the processed string. */
547 char * end = strchr (var, '/');
548 char * replacement = NULL;
549 char * v = var + 1;
550 char * freeme = NULL;
551 unsigned flen = strlen (filename);
552
553 if (end != NULL)
554 /* Temporarily terminate the filename at the end of the token. */
555 * end = 0;
556
557 if (*v == '{')
558 ++ v;
559 switch (*v++)
560 {
561 case 'O':
562 if (strcmp (v, "RIGIN") == 0 || strcmp (v, "RIGIN}") == 0)
563 {
564 /* ORIGIN - replace with the full path to the directory
565 containing the program or shared object. */
566 if (needed.by == NULL)
567 {
568 if (link_info.output_bfd == NULL)
569 {
570 break;
571 }
572 else
573 replacement = bfd_get_filename (link_info.output_bfd);
574 }
575 else
576 replacement = bfd_get_filename (needed.by);
577
578 if (replacement)
579 {
580 char * slash;
581
582 if (replacement[0] == '/')
583 freeme = xstrdup (replacement);
584 else
585 {
586 char * current_dir = getpwd ();
587
588 freeme = xmalloc (strlen (replacement) + strlen (current_dir) + 2);
589 sprintf (freeme, "%s/%s", current_dir, replacement);
590 }
591
592 replacement = freeme;
593 if ((slash = strrchr (replacement, '/')) != NULL)
594 * slash = 0;
595 }
596 }
597 break;
598
599 case 'L':
600 if (strcmp (v, "IB") == 0 || strcmp (v, "IB}") == 0)
601 {
602 /* LIB - replace with "lib" in 32-bit environments
603 and "lib64" in 64-bit environments. */
604
605 /* Note - we could replace this switch statement by
606 conditional fragments of shell script, but that is messy.
607 Any compiler worth its salt is going to optimize away
608 all but one of these case statements anyway. */
609 switch ($ELFSIZE)
610 {
611 case 32: replacement = "lib"; break;
612 case 64: replacement = "lib64"; break;
613 default:
614 /* $ELFSIZE is not 32 or 64 ... */
615 abort ();
616 }
617 }
618 break;
619
620 case 'P':
621 /* Supporting $PLATFORM in a cross-hosted environment is not
622 possible. Supporting it in a native environment involves
623 loading the <sys/auxv.h> header file which loads the
624 system <elf.h> header file, which conflicts with the
625 "include/elf/mips.h" header file. */
626 /* Fall through. */
627 default:
628 break;
629 }
630
631 if (replacement)
632 {
633 char * filename2 = xmalloc (flen + strlen (replacement));
634
635 if (end)
636 {
637 sprintf (filename2, "%.*s%s/%s",
638 (int)(var - filename), filename,
639 replacement, end + 1);
640 offset = (var - filename) + 1 + strlen (replacement);
641 }
642 else
643 {
644 sprintf (filename2, "%.*s%s",
645 (int)(var - filename), filename,
646 replacement);
647 offset = var - filename + strlen (replacement);
648 }
649
650 free (filename);
651 filename = filename2;
652 /* There is no need to restore the path separator (when
653 end != NULL) as we have replaced the entire string. */
654 }
655 else
656 {
657 if (verbose)
658 /* We only issue an "unrecognised" message in verbose mode
659 as the $<foo> token might be a legitimate component of
660 a path name in the target's file system. */
661 info_msg (_("unrecognised or unsupported token '%s' in search path\n"), var);
662
663 if (end)
664 /* Restore the path separator. */
665 * end = '/';
666
667 /* PR 20784: Make sure that we resume the scan
668 *after* the token that we could not replace. */
669 offset = (var + 1) - filename;
670 }
671
672 free (freeme);
673 }
674
675 needed.name = filename;
676
677 if (gld${EMULATION_NAME}_try_needed (&needed, force))
678 return TRUE;
679
680 free (filename);
681
682 if (*s == '\0')
683 break;
684 path = s + 1;
685 }
686
687 return FALSE;
688 }
689
690 EOF
691 if [ "x${USE_LIBPATH}" = xyes ] ; then
692 fragment <<EOF
693
694 /* Prefix the sysroot to absolute paths in PATH, a string containing
695 paths separated by config.rpath_separator. If running on a DOS
696 file system, paths containing a drive spec won't have the sysroot
697 prefix added, unless the sysroot also specifies the same drive. */
698
699 static const char *
700 gld${EMULATION_NAME}_add_sysroot (const char *path)
701 {
702 size_t len, extra;
703 const char *p;
704 char *ret, *q;
705 int dos_drive_sysroot = HAS_DRIVE_SPEC (ld_sysroot);
706
707 len = strlen (ld_sysroot);
708 for (extra = 0, p = path; ; )
709 {
710 int dos_drive = HAS_DRIVE_SPEC (p);
711
712 if (dos_drive)
713 p += 2;
714 if (IS_DIR_SEPARATOR (*p)
715 && (!dos_drive
716 || (dos_drive_sysroot
717 && ld_sysroot[0] == p[-2])))
718 {
719 if (dos_drive && dos_drive_sysroot)
720 extra += len - 2;
721 else
722 extra += len;
723 }
724 p = strchr (p, config.rpath_separator);
725 if (!p)
726 break;
727 ++p;
728 }
729
730 ret = xmalloc (strlen (path) + extra + 1);
731
732 for (q = ret, p = path; ; )
733 {
734 const char *end;
735 int dos_drive = HAS_DRIVE_SPEC (p);
736
737 if (dos_drive)
738 {
739 *q++ = *p++;
740 *q++ = *p++;
741 }
742 if (IS_DIR_SEPARATOR (*p)
743 && (!dos_drive
744 || (dos_drive_sysroot
745 && ld_sysroot[0] == p[-2])))
746 {
747 if (dos_drive && dos_drive_sysroot)
748 {
749 strcpy (q, ld_sysroot + 2);
750 q += len - 2;
751 }
752 else
753 {
754 strcpy (q, ld_sysroot);
755 q += len;
756 }
757 }
758 end = strchr (p, config.rpath_separator);
759 if (end)
760 {
761 size_t n = end - p + 1;
762 strncpy (q, p, n);
763 q += n;
764 p += n;
765 }
766 else
767 {
768 strcpy (q, p);
769 break;
770 }
771 }
772
773 return ret;
774 }
775
776 EOF
777 case ${target} in
778 *-*-freebsd* | *-*-dragonfly*)
779 fragment <<EOF
780 /* Read the system search path the FreeBSD way rather than the Linux way. */
781 #ifdef HAVE_ELF_HINTS_H
782 #include <elf-hints.h>
783 #else
784 #include "elf-hints-local.h"
785 #endif
786
787 static bfd_boolean
788 gld${EMULATION_NAME}_check_ld_elf_hints (const struct bfd_link_needed_list *l,
789 int force)
790 {
791 static bfd_boolean initialized;
792 static const char *ld_elf_hints;
793 struct dt_needed needed;
794
795 if (!initialized)
796 {
797 FILE *f;
798 char *tmppath;
799
800 tmppath = concat (ld_sysroot, _PATH_ELF_HINTS, (const char *) NULL);
801 f = fopen (tmppath, FOPEN_RB);
802 free (tmppath);
803 if (f != NULL)
804 {
805 struct elfhints_hdr hdr;
806
807 if (fread (&hdr, 1, sizeof (hdr), f) == sizeof (hdr)
808 && hdr.magic == ELFHINTS_MAGIC
809 && hdr.version == 1)
810 {
811 if (fseek (f, hdr.strtab + hdr.dirlist, SEEK_SET) != -1)
812 {
813 char *b;
814
815 b = xmalloc (hdr.dirlistlen + 1);
816 if (fread (b, 1, hdr.dirlistlen + 1, f) ==
817 hdr.dirlistlen + 1)
818 ld_elf_hints = gld${EMULATION_NAME}_add_sysroot (b);
819
820 free (b);
821 }
822 }
823 fclose (f);
824 }
825
826 initialized = TRUE;
827 }
828
829 if (ld_elf_hints == NULL)
830 return FALSE;
831
832 needed.by = l->by;
833 needed.name = l->name;
834 return gld${EMULATION_NAME}_search_needed (ld_elf_hints, &needed, force);
835 }
836 EOF
837 # FreeBSD
838 ;;
839
840 *-*-linux-* | *-*-k*bsd*-* | *-*-gnu*)
841 fragment <<EOF
842 /* For a native linker, check the file /etc/ld.so.conf for directories
843 in which we may find shared libraries. /etc/ld.so.conf is really
844 only meaningful on Linux. */
845
846 struct gld${EMULATION_NAME}_ld_so_conf
847 {
848 char *path;
849 size_t len, alloc;
850 };
851
852 static bfd_boolean
853 gld${EMULATION_NAME}_parse_ld_so_conf
854 (struct gld${EMULATION_NAME}_ld_so_conf *info, const char *filename);
855
856 static void
857 gld${EMULATION_NAME}_parse_ld_so_conf_include
858 (struct gld${EMULATION_NAME}_ld_so_conf *info, const char *filename,
859 const char *pattern)
860 {
861 char *newp = NULL;
862 #ifdef HAVE_GLOB
863 glob_t gl;
864 #endif
865
866 if (pattern[0] != '/')
867 {
868 char *p = strrchr (filename, '/');
869 size_t patlen = strlen (pattern) + 1;
870
871 newp = xmalloc (p - filename + 1 + patlen);
872 memcpy (newp, filename, p - filename + 1);
873 memcpy (newp + (p - filename + 1), pattern, patlen);
874 pattern = newp;
875 }
876
877 #ifdef HAVE_GLOB
878 if (glob (pattern, 0, NULL, &gl) == 0)
879 {
880 size_t i;
881
882 for (i = 0; i < gl.gl_pathc; ++i)
883 gld${EMULATION_NAME}_parse_ld_so_conf (info, gl.gl_pathv[i]);
884 globfree (&gl);
885 }
886 #else
887 /* If we do not have glob, treat the pattern as a literal filename. */
888 gld${EMULATION_NAME}_parse_ld_so_conf (info, pattern);
889 #endif
890
891 if (newp)
892 free (newp);
893 }
894
895 static bfd_boolean
896 gld${EMULATION_NAME}_parse_ld_so_conf
897 (struct gld${EMULATION_NAME}_ld_so_conf *info, const char *filename)
898 {
899 FILE *f = fopen (filename, FOPEN_RT);
900 char *line;
901 size_t linelen;
902
903 if (f == NULL)
904 return FALSE;
905
906 linelen = 256;
907 line = xmalloc (linelen);
908 do
909 {
910 char *p = line, *q;
911
912 /* Normally this would use getline(3), but we need to be portable. */
913 while ((q = fgets (p, linelen - (p - line), f)) != NULL
914 && strlen (q) == linelen - (p - line) - 1
915 && line[linelen - 2] != '\n')
916 {
917 line = xrealloc (line, 2 * linelen);
918 p = line + linelen - 1;
919 linelen += linelen;
920 }
921
922 if (q == NULL && p == line)
923 break;
924
925 p = strchr (line, '\n');
926 if (p)
927 *p = '\0';
928
929 /* Because the file format does not know any form of quoting we
930 can search forward for the next '#' character and if found
931 make it terminating the line. */
932 p = strchr (line, '#');
933 if (p)
934 *p = '\0';
935
936 /* Remove leading whitespace. NUL is no whitespace character. */
937 p = line;
938 while (*p == ' ' || *p == '\f' || *p == '\r' || *p == '\t' || *p == '\v')
939 ++p;
940
941 /* If the line is blank it is ignored. */
942 if (p[0] == '\0')
943 continue;
944
945 if (CONST_STRNEQ (p, "include") && (p[7] == ' ' || p[7] == '\t'))
946 {
947 char *dir, c;
948 p += 8;
949 do
950 {
951 while (*p == ' ' || *p == '\t')
952 ++p;
953
954 if (*p == '\0')
955 break;
956
957 dir = p;
958
959 while (*p != ' ' && *p != '\t' && *p)
960 ++p;
961
962 c = *p;
963 *p++ = '\0';
964 if (dir[0] != '\0')
965 gld${EMULATION_NAME}_parse_ld_so_conf_include (info, filename,
966 dir);
967 }
968 while (c != '\0');
969 }
970 else
971 {
972 char *dir = p;
973 while (*p && *p != '=' && *p != ' ' && *p != '\t' && *p != '\f'
974 && *p != '\r' && *p != '\v')
975 ++p;
976
977 while (p != dir && p[-1] == '/')
978 --p;
979 if (info->path == NULL)
980 {
981 info->alloc = p - dir + 1 + 256;
982 info->path = xmalloc (info->alloc);
983 info->len = 0;
984 }
985 else
986 {
987 if (info->len + 1 + (p - dir) >= info->alloc)
988 {
989 info->alloc += p - dir + 256;
990 info->path = xrealloc (info->path, info->alloc);
991 }
992 info->path[info->len++] = config.rpath_separator;
993 }
994 memcpy (info->path + info->len, dir, p - dir);
995 info->len += p - dir;
996 info->path[info->len] = '\0';
997 }
998 }
999 while (! feof (f));
1000 free (line);
1001 fclose (f);
1002 return TRUE;
1003 }
1004
1005 static bfd_boolean
1006 gld${EMULATION_NAME}_check_ld_so_conf (const struct bfd_link_needed_list *l,
1007 int force)
1008 {
1009 static bfd_boolean initialized;
1010 static const char *ld_so_conf;
1011 struct dt_needed needed;
1012
1013 if (! initialized)
1014 {
1015 char *tmppath;
1016 struct gld${EMULATION_NAME}_ld_so_conf info;
1017
1018 info.path = NULL;
1019 info.len = info.alloc = 0;
1020 tmppath = concat (ld_sysroot, "${prefix}/etc/ld.so.conf",
1021 (const char *) NULL);
1022 if (!gld${EMULATION_NAME}_parse_ld_so_conf (&info, tmppath))
1023 {
1024 free (tmppath);
1025 tmppath = concat (ld_sysroot, "/etc/ld.so.conf",
1026 (const char *) NULL);
1027 gld${EMULATION_NAME}_parse_ld_so_conf (&info, tmppath);
1028 }
1029 free (tmppath);
1030
1031 if (info.path)
1032 {
1033 ld_so_conf = gld${EMULATION_NAME}_add_sysroot (info.path);
1034 free (info.path);
1035 }
1036 initialized = TRUE;
1037 }
1038
1039 if (ld_so_conf == NULL)
1040 return FALSE;
1041
1042
1043 needed.by = l->by;
1044 needed.name = l->name;
1045 return gld${EMULATION_NAME}_search_needed (ld_so_conf, &needed, force);
1046 }
1047
1048 EOF
1049 # Linux
1050 ;;
1051 esac
1052 fi
1053 fragment <<EOF
1054
1055 /* See if an input file matches a DT_NEEDED entry by name. */
1056
1057 static void
1058 gld${EMULATION_NAME}_check_needed (lang_input_statement_type *s)
1059 {
1060 const char *soname;
1061
1062 /* Stop looking if we've found a loaded lib. */
1063 if (global_found != NULL
1064 && (bfd_elf_get_dyn_lib_class (global_found->the_bfd)
1065 & DYN_AS_NEEDED) == 0)
1066 return;
1067
1068 if (s->filename == NULL || s->the_bfd == NULL)
1069 return;
1070
1071 /* Don't look for a second non-loaded as-needed lib. */
1072 if (global_found != NULL
1073 && (bfd_elf_get_dyn_lib_class (s->the_bfd) & DYN_AS_NEEDED) != 0)
1074 return;
1075
1076 if (filename_cmp (s->filename, global_needed->name) == 0)
1077 {
1078 global_found = s;
1079 return;
1080 }
1081
1082 if (s->flags.search_dirs)
1083 {
1084 const char *f = strrchr (s->filename, '/');
1085 if (f != NULL
1086 && filename_cmp (f + 1, global_needed->name) == 0)
1087 {
1088 global_found = s;
1089 return;
1090 }
1091 }
1092
1093 soname = bfd_elf_get_dt_soname (s->the_bfd);
1094 if (soname != NULL
1095 && filename_cmp (soname, global_needed->name) == 0)
1096 {
1097 global_found = s;
1098 return;
1099 }
1100 }
1101
1102 EOF
1103
1104 if test x"$LDEMUL_AFTER_OPEN" != xgld"$EMULATION_NAME"_after_open; then
1105 fragment <<EOF
1106
1107 static bfd_size_type
1108 id_note_section_size (bfd *abfd ATTRIBUTE_UNUSED)
1109 {
1110 const char *style = emit_note_gnu_build_id;
1111 bfd_size_type size;
1112 bfd_size_type build_id_size;
1113
1114 size = offsetof (Elf_External_Note, name[sizeof "GNU"]);
1115 size = (size + 3) & -(bfd_size_type) 4;
1116
1117 build_id_size = compute_build_id_size (style);
1118 if (build_id_size)
1119 size += build_id_size;
1120 else
1121 size = 0;
1122
1123 return size;
1124 }
1125
1126 static bfd_boolean
1127 write_build_id (bfd *abfd)
1128 {
1129 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
1130 struct elf_obj_tdata *t = elf_tdata (abfd);
1131 const char *style;
1132 asection *asec;
1133 Elf_Internal_Shdr *i_shdr;
1134 unsigned char *contents, *id_bits;
1135 bfd_size_type size;
1136 file_ptr position;
1137 Elf_External_Note *e_note;
1138
1139 style = t->o->build_id.style;
1140 asec = t->o->build_id.sec;
1141 if (bfd_is_abs_section (asec->output_section))
1142 {
1143 einfo (_("%P: warning: .note.gnu.build-id section discarded,"
1144 " --build-id ignored.\n"));
1145 return TRUE;
1146 }
1147 i_shdr = &elf_section_data (asec->output_section)->this_hdr;
1148
1149 if (i_shdr->contents == NULL)
1150 {
1151 if (asec->contents == NULL)
1152 asec->contents = (unsigned char *) xmalloc (asec->size);
1153 contents = asec->contents;
1154 }
1155 else
1156 contents = i_shdr->contents + asec->output_offset;
1157
1158 e_note = (Elf_External_Note *) contents;
1159 size = offsetof (Elf_External_Note, name[sizeof "GNU"]);
1160 size = (size + 3) & -(bfd_size_type) 4;
1161 id_bits = contents + size;
1162 size = asec->size - size;
1163
1164 bfd_h_put_32 (abfd, sizeof "GNU", &e_note->namesz);
1165 bfd_h_put_32 (abfd, size, &e_note->descsz);
1166 bfd_h_put_32 (abfd, NT_GNU_BUILD_ID, &e_note->type);
1167 memcpy (e_note->name, "GNU", sizeof "GNU");
1168
1169 generate_build_id (abfd, style, bed->s->checksum_contents, id_bits, size);
1170
1171 position = i_shdr->sh_offset + asec->output_offset;
1172 size = asec->size;
1173 return (bfd_seek (abfd, position, SEEK_SET) == 0
1174 && bfd_bwrite (contents, size, abfd) == size);
1175 }
1176
1177 /* Make .note.gnu.build-id section, and set up elf_tdata->build_id. */
1178
1179 static bfd_boolean
1180 setup_build_id (bfd *ibfd)
1181 {
1182 asection *s;
1183 bfd_size_type size;
1184 flagword flags;
1185
1186 size = id_note_section_size (ibfd);
1187 if (size == 0)
1188 {
1189 einfo ("%P: warning: unrecognized --build-id style ignored.\n");
1190 return FALSE;
1191 }
1192
1193 flags = (SEC_ALLOC | SEC_LOAD | SEC_IN_MEMORY
1194 | SEC_LINKER_CREATED | SEC_READONLY | SEC_DATA);
1195 s = bfd_make_section_with_flags (ibfd, ".note.gnu.build-id", flags);
1196 if (s != NULL && bfd_set_section_alignment (ibfd, s, 2))
1197 {
1198 struct elf_obj_tdata *t = elf_tdata (link_info.output_bfd);
1199 t->o->build_id.after_write_object_contents = &write_build_id;
1200 t->o->build_id.style = emit_note_gnu_build_id;
1201 t->o->build_id.sec = s;
1202 elf_section_type (s) = SHT_NOTE;
1203 s->size = size;
1204 return TRUE;
1205 }
1206
1207 einfo ("%P: warning: Cannot create .note.gnu.build-id section,"
1208 " --build-id ignored.\n");
1209 return FALSE;
1210 }
1211
1212 /* This is called after all the input files have been opened. */
1213
1214 static void
1215 gld${EMULATION_NAME}_after_open (void)
1216 {
1217 struct bfd_link_needed_list *needed, *l;
1218 struct elf_link_hash_table *htab;
1219 asection *s;
1220 bfd *abfd;
1221
1222 after_open_default ();
1223
1224 htab = elf_hash_table (&link_info);
1225 if (!is_elf_hash_table (htab))
1226 return;
1227
1228 if (command_line.out_implib_filename)
1229 {
1230 unlink_if_ordinary (command_line.out_implib_filename);
1231 link_info.out_implib_bfd
1232 = bfd_openw (command_line.out_implib_filename,
1233 bfd_get_target (link_info.output_bfd));
1234
1235 if (link_info.out_implib_bfd == NULL)
1236 {
1237 einfo ("%F%s: Can't open for writing: %E\n",
1238 command_line.out_implib_filename);
1239 }
1240 }
1241
1242 if (emit_note_gnu_build_id != NULL)
1243 {
1244 /* Find an ELF input. */
1245 for (abfd = link_info.input_bfds;
1246 abfd != (bfd *) NULL; abfd = abfd->link.next)
1247 if (bfd_get_flavour (abfd) == bfd_target_elf_flavour
1248 && bfd_count_sections (abfd) != 0
1249 && !((lang_input_statement_type *) abfd->usrdata)->flags.just_syms)
1250 break;
1251
1252 /* PR 10555: If there are no ELF input files do not try to
1253 create a .note.gnu-build-id section. */
1254 if (abfd == NULL
1255 || !setup_build_id (abfd))
1256 {
1257 free ((char *) emit_note_gnu_build_id);
1258 emit_note_gnu_build_id = NULL;
1259 }
1260 }
1261
1262 get_elf_backend_data (link_info.output_bfd)->setup_gnu_properties (&link_info);
1263
1264 if (bfd_link_relocatable (&link_info))
1265 {
1266 if (link_info.execstack == ! link_info.noexecstack)
1267 /* PR ld/16744: If "-z [no]execstack" has been specified on the
1268 command line and we are perfoming a relocatable link then no
1269 PT_GNU_STACK segment will be created and so the
1270 linkinfo.[no]execstack values set in _handle_option() will have no
1271 effect. Instead we create a .note.GNU-stack section in much the
1272 same way as the assembler does with its --[no]execstack option. */
1273 (void) bfd_make_section_with_flags (link_info.input_bfds,
1274 ".note.GNU-stack",
1275 SEC_READONLY | (link_info.execstack ? SEC_CODE : 0));
1276
1277 return;
1278 }
1279
1280 if (!link_info.traditional_format)
1281 {
1282 bfd *elfbfd = NULL;
1283 bfd_boolean warn_eh_frame = FALSE;
1284 int seen_type = 0;
1285
1286 for (abfd = link_info.input_bfds; abfd; abfd = abfd->link.next)
1287 {
1288 int type = 0;
1289
1290 if (((lang_input_statement_type *) abfd->usrdata)->flags.just_syms)
1291 continue;
1292
1293 for (s = abfd->sections; s && type < COMPACT_EH_HDR; s = s->next)
1294 {
1295 const char *name = bfd_get_section_name (abfd, s);
1296
1297 if (bfd_is_abs_section (s->output_section))
1298 continue;
1299 if (CONST_STRNEQ (name, ".eh_frame_entry"))
1300 type = COMPACT_EH_HDR;
1301 else if (strcmp (name, ".eh_frame") == 0 && s->size > 8)
1302 type = DWARF2_EH_HDR;
1303 }
1304
1305 if (type != 0)
1306 {
1307 if (seen_type == 0)
1308 {
1309 seen_type = type;
1310 }
1311 else if (seen_type != type)
1312 {
1313 einfo (_("%P%F: compact frame descriptions incompatible with"
1314 " DWARF2 .eh_frame from %B\n"),
1315 type == DWARF2_EH_HDR ? abfd : elfbfd);
1316 break;
1317 }
1318
1319 if (!elfbfd
1320 && (type == COMPACT_EH_HDR || link_info.eh_frame_hdr_type != 0))
1321 {
1322 if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
1323 elfbfd = abfd;
1324
1325 warn_eh_frame = TRUE;
1326 }
1327 }
1328
1329 if (seen_type == COMPACT_EH_HDR)
1330 link_info.eh_frame_hdr_type = COMPACT_EH_HDR;
1331 }
1332 if (elfbfd)
1333 {
1334 const struct elf_backend_data *bed;
1335
1336 bed = get_elf_backend_data (elfbfd);
1337 s = bfd_make_section_with_flags (elfbfd, ".eh_frame_hdr",
1338 bed->dynamic_sec_flags
1339 | SEC_READONLY);
1340 if (s != NULL
1341 && bfd_set_section_alignment (elfbfd, s, 2))
1342 {
1343 htab->eh_info.hdr_sec = s;
1344 warn_eh_frame = FALSE;
1345 }
1346 }
1347 if (warn_eh_frame)
1348 einfo ("%P: warning: Cannot create .eh_frame_hdr section,"
1349 " --eh-frame-hdr ignored.\n");
1350 }
1351
1352 /* Get the list of files which appear in DT_NEEDED entries in
1353 dynamic objects included in the link (often there will be none).
1354 For each such file, we want to track down the corresponding
1355 library, and include the symbol table in the link. This is what
1356 the runtime dynamic linker will do. Tracking the files down here
1357 permits one dynamic object to include another without requiring
1358 special action by the person doing the link. Note that the
1359 needed list can actually grow while we are stepping through this
1360 loop. */
1361 needed = bfd_elf_get_needed_list (link_info.output_bfd, &link_info);
1362 for (l = needed; l != NULL; l = l->next)
1363 {
1364 struct bfd_link_needed_list *ll;
1365 struct dt_needed n, nn;
1366 int force;
1367
1368 /* If the lib that needs this one was --as-needed and wasn't
1369 found to be needed, then this lib isn't needed either. */
1370 if (l->by != NULL
1371 && (bfd_elf_get_dyn_lib_class (l->by) & DYN_AS_NEEDED) != 0)
1372 continue;
1373
1374 /* Skip the lib if --no-copy-dt-needed-entries and
1375 --allow-shlib-undefined is in effect. */
1376 if (l->by != NULL
1377 && link_info.unresolved_syms_in_shared_libs == RM_IGNORE
1378 && (bfd_elf_get_dyn_lib_class (l->by) & DYN_NO_ADD_NEEDED) != 0)
1379 continue;
1380
1381 /* If we've already seen this file, skip it. */
1382 for (ll = needed; ll != l; ll = ll->next)
1383 if ((ll->by == NULL
1384 || (bfd_elf_get_dyn_lib_class (ll->by) & DYN_AS_NEEDED) == 0)
1385 && strcmp (ll->name, l->name) == 0)
1386 break;
1387 if (ll != l)
1388 continue;
1389
1390 /* See if this file was included in the link explicitly. */
1391 global_needed = l;
1392 global_found = NULL;
1393 lang_for_each_input_file (gld${EMULATION_NAME}_check_needed);
1394 if (global_found != NULL
1395 && (bfd_elf_get_dyn_lib_class (global_found->the_bfd)
1396 & DYN_AS_NEEDED) == 0)
1397 continue;
1398
1399 n.by = l->by;
1400 n.name = l->name;
1401 nn.by = l->by;
1402 if (verbose)
1403 info_msg (_("%s needed by %B\n"), l->name, l->by);
1404
1405 /* As-needed libs specified on the command line (or linker script)
1406 take priority over libs found in search dirs. */
1407 if (global_found != NULL)
1408 {
1409 nn.name = global_found->filename;
1410 if (gld${EMULATION_NAME}_try_needed (&nn, TRUE))
1411 continue;
1412 }
1413
1414 /* We need to find this file and include the symbol table. We
1415 want to search for the file in the same way that the dynamic
1416 linker will search. That means that we want to use
1417 rpath_link, rpath, then the environment variable
1418 LD_LIBRARY_PATH (native only), then the DT_RPATH/DT_RUNPATH
1419 entries (native only), then the linker script LIB_SEARCH_DIRS.
1420 We do not search using the -L arguments.
1421
1422 We search twice. The first time, we skip objects which may
1423 introduce version mismatches. The second time, we force
1424 their use. See gld${EMULATION_NAME}_vercheck comment. */
1425 for (force = 0; force < 2; force++)
1426 {
1427 size_t len;
1428 search_dirs_type *search;
1429 EOF
1430 if [ "x${NATIVE}" = xyes ] || [ "x${USE_LIBPATH}" = xyes ] ; then
1431 fragment <<EOF
1432 const char *path;
1433 EOF
1434 fi
1435 if [ "x${USE_LIBPATH}" = xyes ] ; then
1436 fragment <<EOF
1437 struct bfd_link_needed_list *rp;
1438 int found;
1439 EOF
1440 fi
1441 fragment <<EOF
1442
1443 if (gld${EMULATION_NAME}_search_needed (command_line.rpath_link,
1444 &n, force))
1445 break;
1446 EOF
1447 if [ "x${USE_LIBPATH}" = xyes ] ; then
1448 fragment <<EOF
1449 path = command_line.rpath;
1450 if (path)
1451 {
1452 path = gld${EMULATION_NAME}_add_sysroot (path);
1453 found = gld${EMULATION_NAME}_search_needed (path, &n, force);
1454 free ((char *) path);
1455 if (found)
1456 break;
1457 }
1458 EOF
1459 fi
1460 if [ "x${NATIVE}" = xyes ] ; then
1461 fragment <<EOF
1462 if (command_line.rpath_link == NULL
1463 && command_line.rpath == NULL)
1464 {
1465 path = (const char *) getenv ("LD_RUN_PATH");
1466 if (path
1467 && gld${EMULATION_NAME}_search_needed (path, &n, force))
1468 break;
1469 }
1470 path = (const char *) getenv ("LD_LIBRARY_PATH");
1471 if (path
1472 && gld${EMULATION_NAME}_search_needed (path, &n, force))
1473 break;
1474 EOF
1475 fi
1476 if [ "x${USE_LIBPATH}" = xyes ] ; then
1477 fragment <<EOF
1478 found = 0;
1479 rp = bfd_elf_get_runpath_list (link_info.output_bfd, &link_info);
1480 for (; !found && rp != NULL; rp = rp->next)
1481 {
1482 path = gld${EMULATION_NAME}_add_sysroot (rp->name);
1483 found = (rp->by == l->by
1484 && gld${EMULATION_NAME}_search_needed (path, &n,
1485 force));
1486 free ((char *) path);
1487 }
1488 if (found)
1489 break;
1490
1491 EOF
1492 fi
1493 if [ "x${USE_LIBPATH}" = xyes ] ; then
1494 case ${target} in
1495 *-*-freebsd* | *-*-dragonfly*)
1496 fragment <<EOF
1497 if (gld${EMULATION_NAME}_check_ld_elf_hints (l, force))
1498 break;
1499 EOF
1500 # FreeBSD
1501 ;;
1502
1503 *-*-linux-* | *-*-k*bsd*-* | *-*-gnu*)
1504 fragment <<EOF
1505 if (gld${EMULATION_NAME}_check_ld_so_conf (l, force))
1506 break;
1507
1508 EOF
1509 # Linux
1510 ;;
1511 esac
1512 fi
1513 fragment <<EOF
1514 len = strlen (l->name);
1515 for (search = search_head; search != NULL; search = search->next)
1516 {
1517 char *filename;
1518
1519 if (search->cmdline)
1520 continue;
1521 filename = (char *) xmalloc (strlen (search->name) + len + 2);
1522 sprintf (filename, "%s/%s", search->name, l->name);
1523 nn.name = filename;
1524 if (gld${EMULATION_NAME}_try_needed (&nn, force))
1525 break;
1526 free (filename);
1527 }
1528 if (search != NULL)
1529 break;
1530 EOF
1531 fragment <<EOF
1532 }
1533
1534 if (force < 2)
1535 continue;
1536
1537 einfo ("%P: warning: %s, needed by %B, not found (try using -rpath or -rpath-link)\n",
1538 l->name, l->by);
1539 }
1540
1541 if (link_info.eh_frame_hdr_type == COMPACT_EH_HDR)
1542 if (!bfd_elf_parse_eh_frame_entries (NULL, &link_info))
1543 einfo (_("%P%F: Failed to parse EH frame entries.\n"));
1544 }
1545
1546 EOF
1547 fi
1548
1549 fragment <<EOF
1550
1551 /* Look through an expression for an assignment statement. */
1552
1553 static void
1554 gld${EMULATION_NAME}_find_exp_assignment (etree_type *exp)
1555 {
1556 bfd_boolean provide = FALSE;
1557
1558 switch (exp->type.node_class)
1559 {
1560 case etree_provide:
1561 case etree_provided:
1562 provide = TRUE;
1563 /* Fallthru */
1564 case etree_assign:
1565 /* We call record_link_assignment even if the symbol is defined.
1566 This is because if it is defined by a dynamic object, we
1567 actually want to use the value defined by the linker script,
1568 not the value from the dynamic object (because we are setting
1569 symbols like etext). If the symbol is defined by a regular
1570 object, then, as it happens, calling record_link_assignment
1571 will do no harm. */
1572 if (strcmp (exp->assign.dst, ".") != 0)
1573 {
1574 if (!bfd_elf_record_link_assignment (link_info.output_bfd,
1575 &link_info,
1576 exp->assign.dst, provide,
1577 exp->assign.hidden))
1578 einfo ("%P%F: failed to record assignment to %s: %E\n",
1579 exp->assign.dst);
1580 }
1581 gld${EMULATION_NAME}_find_exp_assignment (exp->assign.src);
1582 break;
1583
1584 case etree_binary:
1585 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.lhs);
1586 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.rhs);
1587 break;
1588
1589 case etree_trinary:
1590 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.cond);
1591 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.lhs);
1592 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.rhs);
1593 break;
1594
1595 case etree_unary:
1596 gld${EMULATION_NAME}_find_exp_assignment (exp->unary.child);
1597 break;
1598
1599 default:
1600 break;
1601 }
1602 }
1603
1604
1605 /* This is called by the before_allocation routine via
1606 lang_for_each_statement. It locates any assignment statements, and
1607 tells the ELF backend about them, in case they are assignments to
1608 symbols which are referred to by dynamic objects. */
1609
1610 static void
1611 gld${EMULATION_NAME}_find_statement_assignment (lang_statement_union_type *s)
1612 {
1613 if (s->header.type == lang_assignment_statement_enum)
1614 gld${EMULATION_NAME}_find_exp_assignment (s->assignment_statement.exp);
1615 }
1616
1617 EOF
1618
1619 if test x"$LDEMUL_BEFORE_ALLOCATION" != xgld"$EMULATION_NAME"_before_allocation; then
1620 if test x"${ELF_INTERPRETER_NAME+set}" = xset; then
1621 ELF_INTERPRETER_SET_DEFAULT="
1622 if (sinterp != NULL)
1623 {
1624 sinterp->contents = (unsigned char *) ${ELF_INTERPRETER_NAME};
1625 sinterp->size = strlen ((char *) sinterp->contents) + 1;
1626 }
1627
1628 "
1629 else
1630 ELF_INTERPRETER_SET_DEFAULT=
1631 fi
1632 fragment <<EOF
1633
1634 /* used by before_allocation and handle_option. */
1635 static void
1636 gld${EMULATION_NAME}_append_to_separated_string (char **to, char *op_arg)
1637 {
1638 if (*to == NULL)
1639 *to = xstrdup (op_arg);
1640 else
1641 {
1642 size_t to_len = strlen (*to);
1643 size_t op_arg_len = strlen (op_arg);
1644 char *buf;
1645 char *cp = *to;
1646
1647 /* First see whether OPTARG is already in the path. */
1648 do
1649 {
1650 if (strncmp (op_arg, cp, op_arg_len) == 0
1651 && (cp[op_arg_len] == 0
1652 || cp[op_arg_len] == config.rpath_separator))
1653 /* We found it. */
1654 break;
1655
1656 /* Not yet found. */
1657 cp = strchr (cp, config.rpath_separator);
1658 if (cp != NULL)
1659 ++cp;
1660 }
1661 while (cp != NULL);
1662
1663 if (cp == NULL)
1664 {
1665 buf = xmalloc (to_len + op_arg_len + 2);
1666 sprintf (buf, "%s%c%s", *to,
1667 config.rpath_separator, op_arg);
1668 free (*to);
1669 *to = buf;
1670 }
1671 }
1672 }
1673
1674 #if defined(__GNUC__) && GCC_VERSION < 4006
1675 /* Work around a GCC uninitialized warning bug fixed in GCC 4.6. */
1676 static struct bfd_link_hash_entry ehdr_start_empty;
1677 #endif
1678
1679 /* This is called after the sections have been attached to output
1680 sections, but before any sizes or addresses have been set. */
1681
1682 static void
1683 gld${EMULATION_NAME}_before_allocation (void)
1684 {
1685 const char *rpath;
1686 asection *sinterp;
1687 bfd *abfd;
1688 struct elf_link_hash_entry *ehdr_start = NULL;
1689 #if defined(__GNUC__) && GCC_VERSION < 4006
1690 /* Work around a GCC uninitialized warning bug fixed in GCC 4.6. */
1691 struct bfd_link_hash_entry ehdr_start_save = ehdr_start_empty;
1692 #else
1693 struct bfd_link_hash_entry ehdr_start_save;
1694 #endif
1695
1696 if (is_elf_hash_table (link_info.hash))
1697 {
1698 _bfd_elf_tls_setup (link_info.output_bfd, &link_info);
1699
1700 /* Make __ehdr_start hidden if it has been referenced, to
1701 prevent the symbol from being dynamic. */
1702 if (!bfd_link_relocatable (&link_info))
1703 {
1704 struct elf_link_hash_entry *h
1705 = elf_link_hash_lookup (elf_hash_table (&link_info), "__ehdr_start",
1706 FALSE, FALSE, TRUE);
1707
1708 /* Only adjust the export class if the symbol was referenced
1709 and not defined, otherwise leave it alone. */
1710 if (h != NULL
1711 && (h->root.type == bfd_link_hash_new
1712 || h->root.type == bfd_link_hash_undefined
1713 || h->root.type == bfd_link_hash_undefweak
1714 || h->root.type == bfd_link_hash_common))
1715 {
1716 _bfd_elf_link_hash_hide_symbol (&link_info, h, TRUE);
1717 if (ELF_ST_VISIBILITY (h->other) != STV_INTERNAL)
1718 h->other = (h->other & ~ELF_ST_VISIBILITY (-1)) | STV_HIDDEN;
1719 /* Don't leave the symbol undefined. Undefined hidden
1720 symbols typically won't have dynamic relocations, but
1721 we most likely will need dynamic relocations for
1722 __ehdr_start if we are building a PIE or shared
1723 library. */
1724 ehdr_start = h;
1725 ehdr_start_save = h->root;
1726 h->root.type = bfd_link_hash_defined;
1727 h->root.u.def.section = bfd_abs_section_ptr;
1728 h->root.u.def.value = 0;
1729 }
1730 }
1731
1732 /* If we are going to make any variable assignments, we need to
1733 let the ELF backend know about them in case the variables are
1734 referred to by dynamic objects. */
1735 lang_for_each_statement (gld${EMULATION_NAME}_find_statement_assignment);
1736 }
1737
1738 /* Let the ELF backend work out the sizes of any sections required
1739 by dynamic linking. */
1740 rpath = command_line.rpath;
1741 if (rpath == NULL)
1742 rpath = (const char *) getenv ("LD_RUN_PATH");
1743
1744 for (abfd = link_info.input_bfds; abfd; abfd = abfd->link.next)
1745 if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
1746 {
1747 const char *audit_libs = elf_dt_audit (abfd);
1748
1749 /* If the input bfd contains an audit entry, we need to add it as
1750 a dep audit entry. */
1751 if (audit_libs && *audit_libs != '\0')
1752 {
1753 char *cp = xstrdup (audit_libs);
1754 do
1755 {
1756 int more = 0;
1757 char *cp2 = strchr (cp, config.rpath_separator);
1758
1759 if (cp2)
1760 {
1761 *cp2 = '\0';
1762 more = 1;
1763 }
1764
1765 if (cp != NULL && *cp != '\0')
1766 gld${EMULATION_NAME}_append_to_separated_string (&depaudit, cp);
1767
1768 cp = more ? ++cp2 : NULL;
1769 }
1770 while (cp != NULL);
1771 }
1772 }
1773
1774 if (! (bfd_elf_size_dynamic_sections
1775 (link_info.output_bfd, command_line.soname, rpath,
1776 command_line.filter_shlib, audit, depaudit,
1777 (const char * const *) command_line.auxiliary_filters,
1778 &link_info, &sinterp)))
1779 einfo ("%P%F: failed to set dynamic section sizes: %E\n");
1780
1781 ${ELF_INTERPRETER_SET_DEFAULT}
1782 /* Let the user override the dynamic linker we are using. */
1783 if (command_line.interpreter != NULL
1784 && sinterp != NULL)
1785 {
1786 sinterp->contents = (bfd_byte *) command_line.interpreter;
1787 sinterp->size = strlen (command_line.interpreter) + 1;
1788 }
1789
1790 /* Look for any sections named .gnu.warning. As a GNU extensions,
1791 we treat such sections as containing warning messages. We print
1792 out the warning message, and then zero out the section size so
1793 that it does not get copied into the output file. */
1794
1795 {
1796 LANG_FOR_EACH_INPUT_STATEMENT (is)
1797 {
1798 asection *s;
1799 bfd_size_type sz;
1800 char *msg;
1801
1802 if (is->flags.just_syms)
1803 continue;
1804
1805 s = bfd_get_section_by_name (is->the_bfd, ".gnu.warning");
1806 if (s == NULL)
1807 continue;
1808
1809 sz = s->size;
1810 msg = (char *) xmalloc ((size_t) (sz + 1));
1811 if (! bfd_get_section_contents (is->the_bfd, s, msg,
1812 (file_ptr) 0, sz))
1813 einfo ("%F%B: Can't read contents of section .gnu.warning: %E\n",
1814 is->the_bfd);
1815 msg[sz] = '\0';
1816 (*link_info.callbacks->warning) (&link_info, msg,
1817 (const char *) NULL, is->the_bfd,
1818 (asection *) NULL, (bfd_vma) 0);
1819 free (msg);
1820
1821 /* Clobber the section size, so that we don't waste space
1822 copying the warning into the output file. If we've already
1823 sized the output section, adjust its size. The adjustment
1824 is on rawsize because targets that size sections early will
1825 have called lang_reset_memory_regions after sizing. */
1826 if (s->output_section != NULL
1827 && s->output_section->rawsize >= s->size)
1828 s->output_section->rawsize -= s->size;
1829
1830 s->size = 0;
1831
1832 /* Also set SEC_EXCLUDE, so that local symbols defined in the
1833 warning section don't get copied to the output. */
1834 s->flags |= SEC_EXCLUDE | SEC_KEEP;
1835 }
1836 }
1837
1838 before_allocation_default ();
1839
1840 if (!bfd_elf_size_dynsym_hash_dynstr (link_info.output_bfd, &link_info))
1841 einfo ("%P%F: failed to set dynamic section sizes: %E\n");
1842
1843 if (ehdr_start != NULL)
1844 {
1845 /* If we twiddled __ehdr_start to defined earlier, put it back
1846 as it was. */
1847 ehdr_start->root.type = ehdr_start_save.type;
1848 ehdr_start->root.u = ehdr_start_save.u;
1849 }
1850 }
1851
1852 EOF
1853 fi
1854
1855 if test x"$LDEMUL_OPEN_DYNAMIC_ARCHIVE" != xgld"$EMULATION_NAME"_open_dynamic_archive; then
1856 fragment <<EOF
1857
1858 /* Try to open a dynamic archive. This is where we know that ELF
1859 dynamic libraries have an extension of .so (or .sl on oddball systems
1860 like hpux). */
1861
1862 static bfd_boolean
1863 gld${EMULATION_NAME}_open_dynamic_archive
1864 (const char *arch, search_dirs_type *search, lang_input_statement_type *entry)
1865 {
1866 const char *filename;
1867 char *string;
1868 size_t len;
1869 bfd_boolean opened = FALSE;
1870
1871 if (! entry->flags.maybe_archive)
1872 return FALSE;
1873
1874 filename = entry->filename;
1875 len = strlen (search->name) + strlen (filename);
1876 if (entry->flags.full_name_provided)
1877 {
1878 len += sizeof "/";
1879 string = (char *) xmalloc (len);
1880 sprintf (string, "%s/%s", search->name, filename);
1881 }
1882 else
1883 {
1884 size_t xlen = 0;
1885
1886 len += strlen (arch) + sizeof "/lib.so";
1887 #ifdef EXTRA_SHLIB_EXTENSION
1888 xlen = (strlen (EXTRA_SHLIB_EXTENSION) > 3
1889 ? strlen (EXTRA_SHLIB_EXTENSION) - 3
1890 : 0);
1891 #endif
1892 string = (char *) xmalloc (len + xlen);
1893 sprintf (string, "%s/lib%s%s.so", search->name, filename, arch);
1894 #ifdef EXTRA_SHLIB_EXTENSION
1895 /* Try the .so extension first. If that fails build a new filename
1896 using EXTRA_SHLIB_EXTENSION. */
1897 opened = ldfile_try_open_bfd (string, entry);
1898 if (!opened)
1899 strcpy (string + len - 4, EXTRA_SHLIB_EXTENSION);
1900 #endif
1901 }
1902
1903 if (!opened && !ldfile_try_open_bfd (string, entry))
1904 {
1905 free (string);
1906 return FALSE;
1907 }
1908
1909 entry->filename = string;
1910
1911 /* We have found a dynamic object to include in the link. The ELF
1912 backend linker will create a DT_NEEDED entry in the .dynamic
1913 section naming this file. If this file includes a DT_SONAME
1914 entry, it will be used. Otherwise, the ELF linker will just use
1915 the name of the file. For an archive found by searching, like
1916 this one, the DT_NEEDED entry should consist of just the name of
1917 the file, without the path information used to find it. Note
1918 that we only need to do this if we have a dynamic object; an
1919 archive will never be referenced by a DT_NEEDED entry.
1920
1921 FIXME: This approach--using bfd_elf_set_dt_needed_name--is not
1922 very pretty. I haven't been able to think of anything that is
1923 pretty, though. */
1924 if (bfd_check_format (entry->the_bfd, bfd_object)
1925 && (entry->the_bfd->flags & DYNAMIC) != 0)
1926 {
1927 ASSERT (entry->flags.maybe_archive && entry->flags.search_dirs);
1928
1929 /* Rather than duplicating the logic above. Just use the
1930 filename we recorded earlier. */
1931
1932 if (!entry->flags.full_name_provided)
1933 filename = lbasename (entry->filename);
1934 bfd_elf_set_dt_needed_name (entry->the_bfd, filename);
1935 }
1936
1937 return TRUE;
1938 }
1939
1940 EOF
1941 fi
1942
1943 if test x"$LDEMUL_PLACE_ORPHAN" != xgld"$EMULATION_NAME"_place_orphan; then
1944 fragment <<EOF
1945
1946 /* A variant of lang_output_section_find used by place_orphan. */
1947
1948 static lang_output_section_statement_type *
1949 output_rel_find (asection *sec, int isdyn)
1950 {
1951 lang_output_section_statement_type *lookup;
1952 lang_output_section_statement_type *last = NULL;
1953 lang_output_section_statement_type *last_alloc = NULL;
1954 lang_output_section_statement_type *last_ro_alloc = NULL;
1955 lang_output_section_statement_type *last_rel = NULL;
1956 lang_output_section_statement_type *last_rel_alloc = NULL;
1957 int rela = sec->name[4] == 'a';
1958
1959 for (lookup = &lang_output_section_statement.head->output_section_statement;
1960 lookup != NULL;
1961 lookup = lookup->next)
1962 {
1963 if (lookup->constraint >= 0
1964 && CONST_STRNEQ (lookup->name, ".rel"))
1965 {
1966 int lookrela = lookup->name[4] == 'a';
1967
1968 /* .rel.dyn must come before all other reloc sections, to suit
1969 GNU ld.so. */
1970 if (isdyn)
1971 break;
1972
1973 /* Don't place after .rel.plt as doing so results in wrong
1974 dynamic tags. */
1975 if (strcmp (".plt", lookup->name + 4 + lookrela) == 0)
1976 break;
1977
1978 if (rela == lookrela || last_rel == NULL)
1979 last_rel = lookup;
1980 if ((rela == lookrela || last_rel_alloc == NULL)
1981 && lookup->bfd_section != NULL
1982 && (lookup->bfd_section->flags & SEC_ALLOC) != 0)
1983 last_rel_alloc = lookup;
1984 }
1985
1986 last = lookup;
1987 if (lookup->bfd_section != NULL
1988 && (lookup->bfd_section->flags & SEC_ALLOC) != 0)
1989 {
1990 last_alloc = lookup;
1991 if ((lookup->bfd_section->flags & SEC_READONLY) != 0)
1992 last_ro_alloc = lookup;
1993 }
1994 }
1995
1996 if (last_rel_alloc)
1997 return last_rel_alloc;
1998
1999 if (last_rel)
2000 return last_rel;
2001
2002 if (last_ro_alloc)
2003 return last_ro_alloc;
2004
2005 if (last_alloc)
2006 return last_alloc;
2007
2008 return last;
2009 }
2010
2011 /* Return whether IN is suitable to be part of OUT. */
2012
2013 static bfd_boolean
2014 elf_orphan_compatible (asection *in, asection *out)
2015 {
2016 /* Non-zero sh_info implies a section with SHF_INFO_LINK with
2017 unknown semantics for the generic linker, or a SHT_REL/SHT_RELA
2018 section where sh_info specifies a symbol table. (We won't see
2019 SHT_GROUP, SHT_SYMTAB or SHT_DYNSYM sections here.) We clearly
2020 can't merge SHT_REL/SHT_RELA using differing symbol tables, and
2021 shouldn't merge sections with differing unknown semantics. */
2022 if (elf_section_data (out)->this_hdr.sh_info
2023 != elf_section_data (in)->this_hdr.sh_info)
2024 return FALSE;
2025 /* We can't merge two sections with differing SHF_EXCLUDE when doing
2026 a relocatable link. */
2027 if (bfd_link_relocatable (&link_info)
2028 && ((elf_section_flags (out) ^ elf_section_flags (in)) & SHF_EXCLUDE) != 0)
2029 return FALSE;
2030 return _bfd_elf_match_sections_by_type (link_info.output_bfd, out,
2031 in->owner, in);
2032 }
2033
2034 /* Place an orphan section. We use this to put random SHF_ALLOC
2035 sections in the right segment. */
2036
2037 static lang_output_section_statement_type *
2038 gld${EMULATION_NAME}_place_orphan (asection *s,
2039 const char *secname,
2040 int constraint)
2041 {
2042 static struct orphan_save hold[] =
2043 {
2044 { ".text",
2045 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE,
2046 0, 0, 0, 0 },
2047 { ".rodata",
2048 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
2049 0, 0, 0, 0 },
2050 { ".tdata",
2051 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_THREAD_LOCAL,
2052 0, 0, 0, 0 },
2053 { ".data",
2054 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_DATA,
2055 0, 0, 0, 0 },
2056 { ".bss",
2057 SEC_ALLOC,
2058 0, 0, 0, 0 },
2059 { 0,
2060 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
2061 0, 0, 0, 0 },
2062 { ".interp",
2063 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
2064 0, 0, 0, 0 },
2065 { ".sdata",
2066 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_SMALL_DATA,
2067 0, 0, 0, 0 },
2068 { ".comment",
2069 SEC_HAS_CONTENTS,
2070 0, 0, 0, 0 },
2071 };
2072 enum orphan_save_index
2073 {
2074 orphan_text = 0,
2075 orphan_rodata,
2076 orphan_tdata,
2077 orphan_data,
2078 orphan_bss,
2079 orphan_rel,
2080 orphan_interp,
2081 orphan_sdata,
2082 orphan_nonalloc
2083 };
2084 static int orphan_init_done = 0;
2085 struct orphan_save *place;
2086 lang_output_section_statement_type *after;
2087 lang_output_section_statement_type *os;
2088 lang_output_section_statement_type *match_by_name = NULL;
2089 int isdyn = 0;
2090 int elfinput = s->owner->xvec->flavour == bfd_target_elf_flavour;
2091 int elfoutput = link_info.output_bfd->xvec->flavour == bfd_target_elf_flavour;
2092 unsigned int sh_type = elfinput ? elf_section_type (s) : SHT_NULL;
2093 flagword flags;
2094 asection *nexts;
2095
2096 if (!bfd_link_relocatable (&link_info)
2097 && link_info.combreloc
2098 && (s->flags & SEC_ALLOC))
2099 {
2100 if (elfinput)
2101 switch (sh_type)
2102 {
2103 case SHT_RELA:
2104 secname = ".rela.dyn";
2105 isdyn = 1;
2106 break;
2107 case SHT_REL:
2108 secname = ".rel.dyn";
2109 isdyn = 1;
2110 break;
2111 default:
2112 break;
2113 }
2114 else if (CONST_STRNEQ (secname, ".rel"))
2115 {
2116 secname = secname[4] == 'a' ? ".rela.dyn" : ".rel.dyn";
2117 isdyn = 1;
2118 }
2119 }
2120
2121 if (!bfd_link_relocatable (&link_info)
2122 && elfinput
2123 && elfoutput
2124 && (s->flags & SEC_ALLOC) != 0
2125 && (elf_section_flags (s) & SHF_GNU_MBIND) != 0)
2126 {
2127 /* Find the output mbind section with the same type, attributes
2128 and sh_info field. */
2129 for (os = &lang_output_section_statement.head->output_section_statement;
2130 os != NULL;
2131 os = os->next)
2132 if (os->bfd_section != NULL
2133 && !bfd_is_abs_section (os->bfd_section)
2134 && (elf_section_flags (os->bfd_section) & SHF_GNU_MBIND) != 0
2135 && ((s->flags & (SEC_ALLOC
2136 | SEC_LOAD
2137 | SEC_HAS_CONTENTS
2138 | SEC_READONLY
2139 | SEC_CODE))
2140 == (os->bfd_section->flags & (SEC_ALLOC
2141 | SEC_LOAD
2142 | SEC_HAS_CONTENTS
2143 | SEC_READONLY
2144 | SEC_CODE)))
2145 && (elf_section_data (os->bfd_section)->this_hdr.sh_info
2146 == elf_section_data (s)->this_hdr.sh_info))
2147 {
2148 lang_add_section (&os->children, s, NULL, os);
2149 return os;
2150 }
2151
2152 /* Create the output mbind section with the ".mbind." prefix
2153 in section name. */
2154 if ((s->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
2155 secname = ".mbind.bss";
2156 else if ((s->flags & SEC_READONLY) == 0)
2157 secname = ".mbind.data";
2158 else if ((s->flags & SEC_CODE) == 0)
2159 secname = ".mbind.rodata";
2160 else
2161 secname = ".mbind.text";
2162 }
2163
2164 /* Look through the script to see where to place this section. The
2165 script includes entries added by previous lang_insert_orphan
2166 calls, so this loop puts multiple compatible orphans of the same
2167 name into a single output section. */
2168 if (constraint == 0)
2169 for (os = lang_output_section_find (secname);
2170 os != NULL;
2171 os = next_matching_output_section_statement (os, 0))
2172 {
2173 /* If we don't match an existing output section, tell
2174 lang_insert_orphan to create a new output section. */
2175 constraint = SPECIAL;
2176
2177 /* Check to see if we already have an output section statement
2178 with this name, and its bfd section has compatible flags.
2179 If the section already exists but does not have any flags
2180 set, then it has been created by the linker, possibly as a
2181 result of a --section-start command line switch. */
2182 if (os->bfd_section != NULL
2183 && (os->bfd_section->flags == 0
2184 || (((s->flags ^ os->bfd_section->flags)
2185 & (SEC_LOAD | SEC_ALLOC)) == 0
2186 && (!elfinput
2187 || !elfoutput
2188 || elf_orphan_compatible (s, os->bfd_section)))))
2189 {
2190 lang_add_section (&os->children, s, NULL, os);
2191 return os;
2192 }
2193
2194 /* Save unused output sections in case we can match them
2195 against orphans later. */
2196 if (os->bfd_section == NULL)
2197 match_by_name = os;
2198 }
2199
2200 /* If we didn't match an active output section, see if we matched an
2201 unused one and use that. */
2202 if (match_by_name)
2203 {
2204 lang_add_section (&match_by_name->children, s, NULL, match_by_name);
2205 return match_by_name;
2206 }
2207
2208 if (!orphan_init_done)
2209 {
2210 struct orphan_save *ho;
2211
2212 for (ho = hold; ho < hold + sizeof (hold) / sizeof (hold[0]); ++ho)
2213 if (ho->name != NULL)
2214 {
2215 ho->os = lang_output_section_find (ho->name);
2216 if (ho->os != NULL && ho->os->flags == 0)
2217 ho->os->flags = ho->flags;
2218 }
2219 orphan_init_done = 1;
2220 }
2221
2222 /* If this is a final link, then always put .gnu.warning.SYMBOL
2223 sections into the .text section to get them out of the way. */
2224 if (bfd_link_executable (&link_info)
2225 && CONST_STRNEQ (s->name, ".gnu.warning.")
2226 && hold[orphan_text].os != NULL)
2227 {
2228 os = hold[orphan_text].os;
2229 lang_add_section (&os->children, s, NULL, os);
2230 return os;
2231 }
2232
2233 flags = s->flags;
2234 if (!bfd_link_relocatable (&link_info))
2235 {
2236 nexts = s;
2237 while ((nexts = bfd_get_next_section_by_name (nexts->owner, nexts))
2238 != NULL)
2239 if (nexts->output_section == NULL
2240 && (nexts->flags & SEC_EXCLUDE) == 0
2241 && ((nexts->flags ^ flags) & (SEC_LOAD | SEC_ALLOC)) == 0
2242 && (nexts->owner->flags & DYNAMIC) == 0
2243 && nexts->owner->usrdata != NULL
2244 && !(((lang_input_statement_type *) nexts->owner->usrdata)
2245 ->flags.just_syms)
2246 && _bfd_elf_match_sections_by_type (nexts->owner, nexts,
2247 s->owner, s))
2248 flags = (((flags ^ SEC_READONLY)
2249 | (nexts->flags ^ SEC_READONLY))
2250 ^ SEC_READONLY);
2251 }
2252
2253 /* Decide which segment the section should go in based on the
2254 section name and section flags. We put loadable .note sections
2255 right after the .interp section, so that the PT_NOTE segment is
2256 stored right after the program headers where the OS can read it
2257 in the first page. */
2258
2259 place = NULL;
2260 if ((flags & (SEC_ALLOC | SEC_DEBUGGING)) == 0)
2261 place = &hold[orphan_nonalloc];
2262 else if ((flags & SEC_ALLOC) == 0)
2263 ;
2264 else if ((flags & SEC_LOAD) != 0
2265 && ((elfinput && sh_type == SHT_NOTE)
2266 || (!elfinput && CONST_STRNEQ (secname, ".note"))))
2267 place = &hold[orphan_interp];
2268 else if ((flags & (SEC_LOAD | SEC_HAS_CONTENTS | SEC_THREAD_LOCAL)) == 0)
2269 place = &hold[orphan_bss];
2270 else if ((flags & SEC_SMALL_DATA) != 0)
2271 place = &hold[orphan_sdata];
2272 else if ((flags & SEC_THREAD_LOCAL) != 0)
2273 place = &hold[orphan_tdata];
2274 else if ((flags & SEC_READONLY) == 0)
2275 place = &hold[orphan_data];
2276 else if (((elfinput && (sh_type == SHT_RELA || sh_type == SHT_REL))
2277 || (!elfinput && CONST_STRNEQ (secname, ".rel")))
2278 && (flags & SEC_LOAD) != 0)
2279 place = &hold[orphan_rel];
2280 else if ((flags & SEC_CODE) == 0)
2281 place = &hold[orphan_rodata];
2282 else
2283 place = &hold[orphan_text];
2284
2285 after = NULL;
2286 if (place != NULL)
2287 {
2288 if (place->os == NULL)
2289 {
2290 if (place->name != NULL)
2291 place->os = lang_output_section_find (place->name);
2292 else
2293 place->os = output_rel_find (s, isdyn);
2294 }
2295 after = place->os;
2296 if (after == NULL)
2297 after
2298 = lang_output_section_find_by_flags (s, flags, &place->os,
2299 _bfd_elf_match_sections_by_type);
2300 if (after == NULL)
2301 /* *ABS* is always the first output section statement. */
2302 after = &lang_output_section_statement.head->output_section_statement;
2303 }
2304
2305 return lang_insert_orphan (s, secname, constraint, after, place, NULL, NULL);
2306 }
2307 EOF
2308 fi
2309
2310 if test x"$LDEMUL_AFTER_ALLOCATION" != xgld"$EMULATION_NAME"_after_allocation; then
2311 fragment <<EOF
2312
2313 static void
2314 gld${EMULATION_NAME}_after_allocation (void)
2315 {
2316 int need_layout = bfd_elf_discard_info (link_info.output_bfd, &link_info);
2317
2318 if (need_layout < 0)
2319 einfo ("%X%P: .eh_frame/.stab edit: %E\n");
2320 else
2321 gld${EMULATION_NAME}_map_segments (need_layout);
2322 }
2323 EOF
2324 fi
2325
2326 if test x"$LDEMUL_GET_SCRIPT" != xgld"$EMULATION_NAME"_get_script; then
2327 fragment <<EOF
2328
2329 static char *
2330 gld${EMULATION_NAME}_get_script (int *isfile)
2331 EOF
2332
2333 if test x"$COMPILE_IN" = xyes
2334 then
2335 # Scripts compiled in.
2336
2337 # sed commands to quote an ld script as a C string.
2338 sc="-f stringify.sed"
2339
2340 fragment <<EOF
2341 {
2342 *isfile = 0;
2343
2344 if (bfd_link_relocatable (&link_info) && config.build_constructors)
2345 return
2346 EOF
2347 sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
2348 echo ' ; else if (bfd_link_relocatable (&link_info)) return' >> e${EMULATION_NAME}.c
2349 sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
2350 echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
2351 sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
2352 if cmp -s ldscripts/${EMULATION_NAME}.x ldscripts/${EMULATION_NAME}.xn; then : ; else
2353 echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
2354 sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
2355 fi
2356 if test -n "$GENERATE_PIE_SCRIPT" ; then
2357 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
2358 echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c
2359 echo ' && link_info.combreloc' >> e${EMULATION_NAME}.c
2360 echo ' && link_info.relro' >> e${EMULATION_NAME}.c
2361 echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
2362 sed $sc ldscripts/${EMULATION_NAME}.xdw >> e${EMULATION_NAME}.c
2363 echo ' ; else if (bfd_link_pie (&link_info)' >> e${EMULATION_NAME}.c
2364 echo ' && link_info.combreloc) return' >> e${EMULATION_NAME}.c
2365 sed $sc ldscripts/${EMULATION_NAME}.xdc >> e${EMULATION_NAME}.c
2366 fi
2367 echo ' ; else if (bfd_link_pie (&link_info)) return' >> e${EMULATION_NAME}.c
2368 sed $sc ldscripts/${EMULATION_NAME}.xd >> e${EMULATION_NAME}.c
2369 fi
2370 if test -n "$GENERATE_SHLIB_SCRIPT" ; then
2371 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
2372 echo ' ; else if (bfd_link_dll (&link_info) && link_info.combreloc' >> e${EMULATION_NAME}.c
2373 echo ' && link_info.relro' >> e${EMULATION_NAME}.c
2374 echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
2375 sed $sc ldscripts/${EMULATION_NAME}.xsw >> e${EMULATION_NAME}.c
2376 echo ' ; else if (bfd_link_dll (&link_info) && link_info.combreloc) return' >> e${EMULATION_NAME}.c
2377 sed $sc ldscripts/${EMULATION_NAME}.xsc >> e${EMULATION_NAME}.c
2378 fi
2379 echo ' ; else if (bfd_link_dll (&link_info)) return' >> e${EMULATION_NAME}.c
2380 sed $sc ldscripts/${EMULATION_NAME}.xs >> e${EMULATION_NAME}.c
2381 fi
2382 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
2383 echo ' ; else if (link_info.combreloc && link_info.relro' >> e${EMULATION_NAME}.c
2384 echo ' && (link_info.flags & DF_BIND_NOW)) return' >> e${EMULATION_NAME}.c
2385 sed $sc ldscripts/${EMULATION_NAME}.xw >> e${EMULATION_NAME}.c
2386 echo ' ; else if (link_info.combreloc) return' >> e${EMULATION_NAME}.c
2387 sed $sc ldscripts/${EMULATION_NAME}.xc >> e${EMULATION_NAME}.c
2388 fi
2389 echo ' ; else return' >> e${EMULATION_NAME}.c
2390 sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
2391 echo '; }' >> e${EMULATION_NAME}.c
2392
2393 else
2394 # Scripts read from the filesystem.
2395
2396 fragment <<EOF
2397 {
2398 *isfile = 1;
2399
2400 if (bfd_link_relocatable (&link_info) && config.build_constructors)
2401 return "ldscripts/${EMULATION_NAME}.xu";
2402 else if (bfd_link_relocatable (&link_info))
2403 return "ldscripts/${EMULATION_NAME}.xr";
2404 else if (!config.text_read_only)
2405 return "ldscripts/${EMULATION_NAME}.xbn";
2406 EOF
2407 if cmp -s ldscripts/${EMULATION_NAME}.x ldscripts/${EMULATION_NAME}.xn; then :
2408 else
2409 fragment <<EOF
2410 else if (!config.magic_demand_paged)
2411 return "ldscripts/${EMULATION_NAME}.xn";
2412 EOF
2413 fi
2414 if test -n "$GENERATE_PIE_SCRIPT" ; then
2415 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
2416 fragment <<EOF
2417 else if (bfd_link_pie (&link_info)
2418 && link_info.combreloc
2419 && link_info.relro
2420 && (link_info.flags & DF_BIND_NOW))
2421 return "ldscripts/${EMULATION_NAME}.xdw";
2422 else if (bfd_link_pie (&link_info)
2423 && link_info.combreloc)
2424 return "ldscripts/${EMULATION_NAME}.xdc";
2425 EOF
2426 fi
2427 fragment <<EOF
2428 else if (bfd_link_pie (&link_info))
2429 return "ldscripts/${EMULATION_NAME}.xd";
2430 EOF
2431 fi
2432 if test -n "$GENERATE_SHLIB_SCRIPT" ; then
2433 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
2434 fragment <<EOF
2435 else if (bfd_link_dll (&link_info) && link_info.combreloc
2436 && link_info.relro && (link_info.flags & DF_BIND_NOW))
2437 return "ldscripts/${EMULATION_NAME}.xsw";
2438 else if (bfd_link_dll (&link_info) && link_info.combreloc)
2439 return "ldscripts/${EMULATION_NAME}.xsc";
2440 EOF
2441 fi
2442 fragment <<EOF
2443 else if (bfd_link_dll (&link_info))
2444 return "ldscripts/${EMULATION_NAME}.xs";
2445 EOF
2446 fi
2447 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
2448 fragment <<EOF
2449 else if (link_info.combreloc && link_info.relro
2450 && (link_info.flags & DF_BIND_NOW))
2451 return "ldscripts/${EMULATION_NAME}.xw";
2452 else if (link_info.combreloc)
2453 return "ldscripts/${EMULATION_NAME}.xc";
2454 EOF
2455 fi
2456 fragment <<EOF
2457 else
2458 return "ldscripts/${EMULATION_NAME}.x";
2459 }
2460
2461 EOF
2462 fi
2463 fi
2464
2465 if test -n "$PARSE_AND_LIST_PROLOGUE" ; then
2466 fragment <<EOF
2467 $PARSE_AND_LIST_PROLOGUE
2468 EOF
2469 fi
2470
2471 fragment <<EOF
2472
2473 enum elf_options
2474 {
2475 OPTION_DISABLE_NEW_DTAGS = 400,
2476 OPTION_ENABLE_NEW_DTAGS,
2477 OPTION_GROUP,
2478 OPTION_EH_FRAME_HDR,
2479 OPTION_NO_EH_FRAME_HDR,
2480 OPTION_EXCLUDE_LIBS,
2481 OPTION_HASH_STYLE,
2482 OPTION_BUILD_ID,
2483 OPTION_AUDIT,
2484 OPTION_COMPRESS_DEBUG
2485 };
2486
2487 static void
2488 gld${EMULATION_NAME}_add_options
2489 (int ns, char **shortopts, int nl, struct option **longopts,
2490 int nrl ATTRIBUTE_UNUSED, struct option **really_longopts ATTRIBUTE_UNUSED)
2491 {
2492 EOF
2493 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
2494 fragment <<EOF
2495 static const char xtra_short[] = "${PARSE_AND_LIST_SHORTOPTS}z:P:";
2496 EOF
2497 else
2498 fragment <<EOF
2499 static const char xtra_short[] = "${PARSE_AND_LIST_SHORTOPTS}z:";
2500 EOF
2501 fi
2502 fragment <<EOF
2503 static const struct option xtra_long[] = {
2504 EOF
2505 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
2506 fragment <<EOF
2507 {"audit", required_argument, NULL, OPTION_AUDIT},
2508 {"Bgroup", no_argument, NULL, OPTION_GROUP},
2509 EOF
2510 fi
2511 fragment <<EOF
2512 {"build-id", optional_argument, NULL, OPTION_BUILD_ID},
2513 {"compress-debug-sections", required_argument, NULL, OPTION_COMPRESS_DEBUG},
2514 EOF
2515 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
2516 fragment <<EOF
2517 {"depaudit", required_argument, NULL, 'P'},
2518 {"disable-new-dtags", no_argument, NULL, OPTION_DISABLE_NEW_DTAGS},
2519 {"enable-new-dtags", no_argument, NULL, OPTION_ENABLE_NEW_DTAGS},
2520 {"eh-frame-hdr", no_argument, NULL, OPTION_EH_FRAME_HDR},
2521 {"no-eh-frame-hdr", no_argument, NULL, OPTION_NO_EH_FRAME_HDR},
2522 {"exclude-libs", required_argument, NULL, OPTION_EXCLUDE_LIBS},
2523 {"hash-style", required_argument, NULL, OPTION_HASH_STYLE},
2524 EOF
2525 fi
2526 if test -n "$PARSE_AND_LIST_LONGOPTS" ; then
2527 fragment <<EOF
2528 $PARSE_AND_LIST_LONGOPTS
2529 EOF
2530 fi
2531 fragment <<EOF
2532 {NULL, no_argument, NULL, 0}
2533 };
2534
2535 *shortopts = (char *) xrealloc (*shortopts, ns + sizeof (xtra_short));
2536 memcpy (*shortopts + ns, &xtra_short, sizeof (xtra_short));
2537 *longopts = (struct option *)
2538 xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long));
2539 memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
2540 }
2541
2542 #define DEFAULT_BUILD_ID_STYLE "sha1"
2543
2544 static bfd_boolean
2545 gld${EMULATION_NAME}_handle_option (int optc)
2546 {
2547 switch (optc)
2548 {
2549 default:
2550 return FALSE;
2551
2552 case OPTION_BUILD_ID:
2553 if (emit_note_gnu_build_id != NULL)
2554 {
2555 free ((char *) emit_note_gnu_build_id);
2556 emit_note_gnu_build_id = NULL;
2557 }
2558 if (optarg == NULL)
2559 optarg = DEFAULT_BUILD_ID_STYLE;
2560 if (strcmp (optarg, "none"))
2561 emit_note_gnu_build_id = xstrdup (optarg);
2562 break;
2563
2564 case OPTION_COMPRESS_DEBUG:
2565 if (strcasecmp (optarg, "none") == 0)
2566 link_info.compress_debug = COMPRESS_DEBUG_NONE;
2567 else if (strcasecmp (optarg, "zlib") == 0)
2568 link_info.compress_debug = COMPRESS_DEBUG_GABI_ZLIB;
2569 else if (strcasecmp (optarg, "zlib-gnu") == 0)
2570 link_info.compress_debug = COMPRESS_DEBUG_GNU_ZLIB;
2571 else if (strcasecmp (optarg, "zlib-gabi") == 0)
2572 link_info.compress_debug = COMPRESS_DEBUG_GABI_ZLIB;
2573 else
2574 einfo (_("%P%F: invalid --compress-debug-sections option: \`%s'\n"),
2575 optarg);
2576 break;
2577 EOF
2578
2579 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
2580 fragment <<EOF
2581 case OPTION_AUDIT:
2582 gld${EMULATION_NAME}_append_to_separated_string (&audit, optarg);
2583 break;
2584
2585 case 'P':
2586 gld${EMULATION_NAME}_append_to_separated_string (&depaudit, optarg);
2587 break;
2588
2589 case OPTION_DISABLE_NEW_DTAGS:
2590 link_info.new_dtags = FALSE;
2591 break;
2592
2593 case OPTION_ENABLE_NEW_DTAGS:
2594 link_info.new_dtags = TRUE;
2595 break;
2596
2597 case OPTION_EH_FRAME_HDR:
2598 link_info.eh_frame_hdr_type = DWARF2_EH_HDR;
2599 break;
2600
2601 case OPTION_NO_EH_FRAME_HDR:
2602 link_info.eh_frame_hdr_type = 0;
2603 break;
2604
2605 case OPTION_GROUP:
2606 link_info.flags_1 |= (bfd_vma) DF_1_GROUP;
2607 /* Groups must be self-contained. */
2608 link_info.unresolved_syms_in_objects = RM_GENERATE_ERROR;
2609 link_info.unresolved_syms_in_shared_libs = RM_GENERATE_ERROR;
2610 break;
2611
2612 case OPTION_EXCLUDE_LIBS:
2613 add_excluded_libs (optarg);
2614 break;
2615
2616 case OPTION_HASH_STYLE:
2617 link_info.emit_hash = FALSE;
2618 link_info.emit_gnu_hash = FALSE;
2619 if (strcmp (optarg, "sysv") == 0)
2620 link_info.emit_hash = TRUE;
2621 else if (strcmp (optarg, "gnu") == 0)
2622 link_info.emit_gnu_hash = TRUE;
2623 else if (strcmp (optarg, "both") == 0)
2624 {
2625 link_info.emit_hash = TRUE;
2626 link_info.emit_gnu_hash = TRUE;
2627 }
2628 else
2629 einfo (_("%P%F: invalid hash style \`%s'\n"), optarg);
2630 break;
2631
2632 EOF
2633 fi
2634 fragment <<EOF
2635 case 'z':
2636 if (strcmp (optarg, "defs") == 0)
2637 link_info.unresolved_syms_in_objects = RM_GENERATE_ERROR;
2638 else if (strcmp (optarg, "muldefs") == 0)
2639 link_info.allow_multiple_definition = TRUE;
2640 else if (CONST_STRNEQ (optarg, "max-page-size="))
2641 {
2642 char *end;
2643
2644 config.maxpagesize = strtoul (optarg + 14, &end, 0);
2645 if (*end || (config.maxpagesize & (config.maxpagesize - 1)) != 0)
2646 einfo (_("%P%F: invalid maxium page size \`%s'\n"),
2647 optarg + 14);
2648 }
2649 else if (CONST_STRNEQ (optarg, "common-page-size="))
2650 {
2651 char *end;
2652 config.commonpagesize = strtoul (optarg + 17, &end, 0);
2653 if (*end
2654 || (config.commonpagesize & (config.commonpagesize - 1)) != 0)
2655 einfo (_("%P%F: invalid common page size \`%s'\n"),
2656 optarg + 17);
2657 }
2658 else if (CONST_STRNEQ (optarg, "stack-size="))
2659 {
2660 char *end;
2661 link_info.stacksize = strtoul (optarg + 11, &end, 0);
2662 if (*end || link_info.stacksize < 0)
2663 einfo (_("%P%F: invalid stack size \`%s'\n"), optarg + 11);
2664 if (!link_info.stacksize)
2665 /* Use -1 for explicit no-stack, because zero means
2666 'default'. */
2667 link_info.stacksize = -1;
2668 }
2669 else if (strcmp (optarg, "execstack") == 0)
2670 {
2671 link_info.execstack = TRUE;
2672 link_info.noexecstack = FALSE;
2673 }
2674 else if (strcmp (optarg, "noexecstack") == 0)
2675 {
2676 link_info.noexecstack = TRUE;
2677 link_info.execstack = FALSE;
2678 }
2679 EOF
2680
2681 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
2682 fragment <<EOF
2683 else if (strcmp (optarg, "global") == 0)
2684 link_info.flags_1 |= (bfd_vma) DF_1_GLOBAL;
2685 else if (strcmp (optarg, "initfirst") == 0)
2686 link_info.flags_1 |= (bfd_vma) DF_1_INITFIRST;
2687 else if (strcmp (optarg, "interpose") == 0)
2688 link_info.flags_1 |= (bfd_vma) DF_1_INTERPOSE;
2689 else if (strcmp (optarg, "loadfltr") == 0)
2690 link_info.flags_1 |= (bfd_vma) DF_1_LOADFLTR;
2691 else if (strcmp (optarg, "nodefaultlib") == 0)
2692 link_info.flags_1 |= (bfd_vma) DF_1_NODEFLIB;
2693 else if (strcmp (optarg, "nodelete") == 0)
2694 link_info.flags_1 |= (bfd_vma) DF_1_NODELETE;
2695 else if (strcmp (optarg, "nodlopen") == 0)
2696 link_info.flags_1 |= (bfd_vma) DF_1_NOOPEN;
2697 else if (strcmp (optarg, "nodump") == 0)
2698 link_info.flags_1 |= (bfd_vma) DF_1_NODUMP;
2699 else if (strcmp (optarg, "now") == 0)
2700 {
2701 link_info.flags |= (bfd_vma) DF_BIND_NOW;
2702 link_info.flags_1 |= (bfd_vma) DF_1_NOW;
2703 }
2704 else if (strcmp (optarg, "lazy") == 0)
2705 {
2706 link_info.flags &= ~(bfd_vma) DF_BIND_NOW;
2707 link_info.flags_1 &= ~(bfd_vma) DF_1_NOW;
2708 }
2709 else if (strcmp (optarg, "origin") == 0)
2710 {
2711 link_info.flags |= (bfd_vma) DF_ORIGIN;
2712 link_info.flags_1 |= (bfd_vma) DF_1_ORIGIN;
2713 }
2714 else if (strcmp (optarg, "combreloc") == 0)
2715 link_info.combreloc = TRUE;
2716 else if (strcmp (optarg, "nocombreloc") == 0)
2717 link_info.combreloc = FALSE;
2718 else if (strcmp (optarg, "nocopyreloc") == 0)
2719 link_info.nocopyreloc = TRUE;
2720 else if (strcmp (optarg, "relro") == 0)
2721 link_info.relro = TRUE;
2722 else if (strcmp (optarg, "norelro") == 0)
2723 link_info.relro = FALSE;
2724 else if (strcmp (optarg, "common") == 0)
2725 link_info.elf_stt_common = elf_stt_common;
2726 else if (strcmp (optarg, "nocommon") == 0)
2727 link_info.elf_stt_common = no_elf_stt_common;
2728 else if (strcmp (optarg, "text") == 0)
2729 link_info.error_textrel = TRUE;
2730 else if (strcmp (optarg, "notext") == 0)
2731 link_info.error_textrel = FALSE;
2732 else if (strcmp (optarg, "textoff") == 0)
2733 link_info.error_textrel = FALSE;
2734 EOF
2735 fi
2736
2737 if test -n "$PARSE_AND_LIST_ARGS_CASE_Z" ; then
2738 fragment <<EOF
2739 $PARSE_AND_LIST_ARGS_CASE_Z
2740 EOF
2741 fi
2742
2743 fragment <<EOF
2744 else
2745 einfo (_("%P: warning: -z %s ignored.\n"), optarg);
2746 break;
2747 EOF
2748
2749 if test -n "$PARSE_AND_LIST_ARGS_CASES" ; then
2750 fragment <<EOF
2751 $PARSE_AND_LIST_ARGS_CASES
2752 EOF
2753 fi
2754
2755 fragment <<EOF
2756 }
2757
2758 return TRUE;
2759 }
2760
2761 EOF
2762
2763 if test x"$LDEMUL_LIST_OPTIONS" != xgld"$EMULATION_NAME"_list_options; then
2764 gld_list_options="gld${EMULATION_NAME}_list_options"
2765 if test -n "$PARSE_AND_LIST_OPTIONS"; then
2766 fragment <<EOF
2767
2768 static void
2769 gld${EMULATION_NAME}_list_options (FILE * file)
2770 {
2771 EOF
2772
2773 if test -n "$PARSE_AND_LIST_OPTIONS" ; then
2774 fragment <<EOF
2775 $PARSE_AND_LIST_OPTIONS
2776 EOF
2777 fi
2778
2779 fragment <<EOF
2780 }
2781 EOF
2782 else
2783 gld_list_options="NULL"
2784 fi
2785
2786 if test -n "$PARSE_AND_LIST_EPILOGUE" ; then
2787 fragment <<EOF
2788 $PARSE_AND_LIST_EPILOGUE
2789 EOF
2790 fi
2791 fi
2792
2793 fragment <<EOF
2794
2795 struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
2796 {
2797 ${LDEMUL_BEFORE_PARSE-gld${EMULATION_NAME}_before_parse},
2798 ${LDEMUL_SYSLIB-syslib_default},
2799 ${LDEMUL_HLL-hll_default},
2800 ${LDEMUL_AFTER_PARSE-gld${EMULATION_NAME}_after_parse},
2801 ${LDEMUL_AFTER_OPEN-gld${EMULATION_NAME}_after_open},
2802 ${LDEMUL_AFTER_ALLOCATION-gld${EMULATION_NAME}_after_allocation},
2803 ${LDEMUL_SET_OUTPUT_ARCH-set_output_arch_default},
2804 ${LDEMUL_CHOOSE_TARGET-ldemul_default_target},
2805 ${LDEMUL_BEFORE_ALLOCATION-gld${EMULATION_NAME}_before_allocation},
2806 ${LDEMUL_GET_SCRIPT-gld${EMULATION_NAME}_get_script},
2807 "${EMULATION_NAME}",
2808 "${OUTPUT_FORMAT}",
2809 ${LDEMUL_FINISH-finish_default},
2810 ${LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS-NULL},
2811 ${LDEMUL_OPEN_DYNAMIC_ARCHIVE-gld${EMULATION_NAME}_open_dynamic_archive},
2812 ${LDEMUL_PLACE_ORPHAN-gld${EMULATION_NAME}_place_orphan},
2813 ${LDEMUL_SET_SYMBOLS-NULL},
2814 ${LDEMUL_PARSE_ARGS-NULL},
2815 gld${EMULATION_NAME}_add_options,
2816 gld${EMULATION_NAME}_handle_option,
2817 ${LDEMUL_UNRECOGNIZED_FILE-NULL},
2818 ${LDEMUL_LIST_OPTIONS-${gld_list_options}},
2819 ${LDEMUL_RECOGNIZED_FILE-gld${EMULATION_NAME}_load_symbols},
2820 ${LDEMUL_FIND_POTENTIAL_LIBRARIES-NULL},
2821 ${LDEMUL_NEW_VERS_PATTERN-NULL},
2822 ${LDEMUL_EXTRA_MAP_FILE_TEXT-NULL}
2823 };
2824 EOF
This page took 0.104816 seconds and 4 git commands to generate.