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