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