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