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