1# This shell script emits a C file. -*- C -*- 2# It does some substitutions. 3# This file is now misnamed, because it supports both 32 bit and 64 bit 4# ELF emulations. 5test -z "${ELFSIZE}" && ELFSIZE=32 6if [ -z "$MACHINE" ]; then 7 OUTPUT_ARCH=${ARCH} 8else 9 OUTPUT_ARCH=${ARCH}:${MACHINE} 10fi 11cat >e${EMULATION_NAME}.c <<EOF 12/* This file is is generated by a shell script. DO NOT EDIT! */ 13 14/* ${ELFSIZE} bit ELF emulation code for ${EMULATION_NAME} 15 Copyright 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 16 2002, 2003, 2004 Free Software Foundation, Inc. 17 Written by Steve Chamberlain <sac@cygnus.com> 18 ELF support by Ian Lance Taylor <ian@cygnus.com> 19 20This file is part of GLD, the Gnu Linker. 21 22This program is free software; you can redistribute it and/or modify 23it under the terms of the GNU General Public License as published by 24the Free Software Foundation; either version 2 of the License, or 25(at your option) any later version. 26 27This program is distributed in the hope that it will be useful, 28but WITHOUT ANY WARRANTY; without even the implied warranty of 29MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 30GNU General Public License for more details. 31 32You should have received a copy of the GNU General Public License 33along with this program; if not, write to the Free Software 34Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 35 36#define TARGET_IS_${EMULATION_NAME} 37 38#include "bfd.h" 39#include "sysdep.h" 40#include "libiberty.h" 41#include "safe-ctype.h" 42#include "getopt.h" 43 44#include "bfdlink.h" 45 46#include "ld.h" 47#include "ldmain.h" 48#include "ldmisc.h" 49#include "ldexp.h" 50#include "ldlang.h" 51#include "ldfile.h" 52#include "ldemul.h" 53#include <ldgram.h> 54#include "elf/common.h" 55 56/* Declare functions used by various EXTRA_EM_FILEs. */ 57static void gld${EMULATION_NAME}_before_parse (void); 58static void gld${EMULATION_NAME}_after_open (void); 59static void gld${EMULATION_NAME}_before_allocation (void); 60static bfd_boolean gld${EMULATION_NAME}_place_orphan 61 (lang_input_statement_type *file, asection *s); 62static void gld${EMULATION_NAME}_finish (void); 63 64EOF 65case ${target} in 66 *-*-openbsd*) 67 cat >>e${EMULATION_NAME}.c <<EOF 68#include <sys/types.h> 69#include <dirent.h> 70 71/* Search a directory for a .so file. */ 72 73static char * gld${EMULATION_NAME}_search_dir_needed (const char *dirlist, const char *filename); 74 75static char * gld${EMULATION_NAME}_search_dir (const char *dirname, 76 const char *filename, int req_maj, int req_min); 77 78static char * gld${EMULATION_NAME}_split_lib_name (char *name, int *pmaj, 79 int *pmin); 80 81/* THIS FUNCTION MODIFIES THE name ARGUMENT string */ 82static char * 83gld${EMULATION_NAME}_split_lib_name (name, pmaj, pmin) 84 char *name; 85 int *pmaj, *pmin; 86{ 87 char*eptr, *lib = name; 88 char *s; 89 int found_so = 0; 90 91 *pmaj = -1; 92 *pmin = -1; 93 94 if (strncmp(lib, "lib", 3) == 0) 95 lib += 3; 96 97 s = lib; 98 while (found_so == 0) 99 { 100 s = strstr(s, ".so"); 101 102 /* if .so not found, return not found, invalid lib name */ 103 if (s == NULL) 104 { 105 return NULL; 106 } 107 108 /* if .so is at end of string, fine return with pmaj/pmin -1 */ 109 if (s[3] == '\0') 110 { 111 *s = '\0'; 112 return lib; 113 } 114 115 if (s[3] == '.') 116 { 117 *s = '\0'; 118 found_so = 1; 119 } 120 /* skip over the ".so" */ 121 s += 3; 122 } 123 124 125 /* lib[name].so.[M].[N] */ 126 /* s ^ */ 127 s += 1; 128 129 /* lib[name].so.[M].[N] */ 130 /* s ^ */ 131 *pmaj = strtoul (s, &eptr, 10); 132 133 /* lib[name].so.[M]X... */ 134 /* eptr ^ */ 135 if (*eptr != '.' || s == eptr) 136 return NULL; /* invalid, must have minor */ 137 138 s = eptr+1; 139 140 /* lib[name].so.[M].[N] */ 141 /* s ^ */ 142 *pmin = strtoul (s, &eptr, 10); 143 144 /* lib[name].so.[M].[N] */ 145 /* eptr ^ */ 146 if (*eptr != '\0' || s == eptr) 147 return NULL; /* minor must be last field of library */ 148 149 return lib; 150} 151 152static char * 153gld${EMULATION_NAME}_search_dir_needed (dirlist, filename) 154 const char *dirlist; 155 const char *filename; 156{ 157 char *dlist, *dlist_alloc, *dir; 158 char *fnam, *fnam_alloc, *lib; 159 char *found = NULL; 160 int maj = -1, min = -1; 161 162 dlist_alloc = dlist = xstrdup(dirlist); 163 fnam_alloc = fnam = xstrdup(filename); 164 165 lib = gld${EMULATION_NAME}_split_lib_name(fnam, &maj, &min); 166 167 while (lib != NULL && found == NULL) 168 { 169 dir = strsep(&dlist, ":"); 170 if (dir == NULL) 171 break; 172 if (*dir == '\0') 173 continue; /* skip dirlist of ...::... */ 174 found = gld${EMULATION_NAME}_search_dir(dir, lib, maj, min); 175 } 176 177 free(dlist_alloc); 178 free(fnam_alloc); 179 return found; 180} 181 182 183static char * 184gld${EMULATION_NAME}_search_dir (dirname, filename, req_maj, req_min) 185 const char *dirname; 186 const char *filename; 187 int req_maj, req_min; 188{ 189 const char *dot; 190 unsigned int len; 191 char *found; 192 int max_maj, max_min; 193 DIR *dir; 194 struct dirent *entry; 195 unsigned int dirnamelen; 196 char *full_path; 197 int statval; 198 struct stat st; 199 200 dot = strchr (filename, '.'); 201 len = strlen (filename); 202 found = NULL; 203 max_maj = max_min = 0; 204 205 dir = opendir (dirname); 206 if (dir == NULL) 207 return NULL; 208 dirnamelen = strlen (dirname); 209 210 while ((entry = readdir (dir)) != NULL) 211 { 212 const char *s; 213 char *eptr, *eptr1; 214 int found_maj, found_min; 215 216 if (strncmp (entry->d_name, "lib", 3) != 0 217 || strncmp (entry->d_name + 3, filename, len) != 0) 218 continue; 219 220 /* We accept libfoo.so without a version number, even though the 221 native linker does not. This is more convenient for packages 222 which just generate .so files for shared libraries, as on ELF 223 systems. */ 224 if (strncmp (entry->d_name + 3 + len, ".so", 3) != 0) 225 continue; 226 227 if (entry->d_name[6 + len] == '\0') 228 ; 229 else if (entry->d_name[6 + len] == '.' 230 && ISDIGIT ((unsigned char) entry->d_name[7 + len])) 231 ; 232 else 233 continue; 234 235 for (s = entry->d_name + 6 + len; *s != '\0'; s++) 236 if (*s != '.' && ! ISDIGIT ((unsigned char) *s)) 237 break; 238 if (*s != '\0') 239 continue; 240 241 /* We've found a .so file. Work out the major and minor 242 version numbers. */ 243 found_maj = -1; 244 found_min = -1; 245 246 /* do allow libN.so */ 247 if (entry->d_name[6 + len] == '.') { 248 found_maj = strtoul (entry->d_name + 7 + len, &eptr, 10); 249 250 /* do not support libN.so. or libN.so.X */ 251 if (*eptr != '.' || ((entry->d_name + 3 + len) == eptr)) 252 continue; 253 254 found_min = strtoul (eptr+1, &eptr1, 10); 255 256 /* do not support libN.so.X. or libN.so.X.Y.[anything] */ 257 if (*eptr1 != '\0' || (eptr+1 == eptr1)) 258 continue; 259 } 260 261 /* Make sure the file really exists (ignore broken symlinks). */ 262 full_path = xmalloc (dirnamelen + 1 + strlen (entry->d_name) + 1); 263 sprintf (full_path, "%s/%s", dirname, entry->d_name); 264 statval = stat (full_path, &st); 265 free (full_path); 266 if (statval != 0) 267 continue; 268 269 /* We've found a match for the name we are searching for. See 270 if this is the version we should use. */ 271 if (((req_maj == -1) && (found == NULL 272 || (found_maj > max_maj) 273 || (found_maj == max_maj && (found_min > max_min)))) 274 || ((found_maj == req_maj) && (found_min >= req_min) 275 && (found_min > max_min))) 276 { 277 if (found != NULL) 278 free (found); 279 found = (char *) xmalloc (dirnamelen + strlen (entry->d_name) + 2); 280 sprintf (found, "%s/%s", dirname, entry->d_name); 281 max_maj = found_maj; 282 max_min = found_min; 283 } 284 } 285 286 closedir (dir); 287 288 return found; 289} 290 291EOF 292 ;; 293esac 294cat >>e${EMULATION_NAME}.c <<EOF 295EOF 296 297# Import any needed special functions and/or overrides. 298# 299if test -n "$EXTRA_EM_FILE" ; then 300. ${srcdir}/emultempl/${EXTRA_EM_FILE}.em 301fi 302 303# Functions in this file can be overridden by setting the LDEMUL_* shell 304# variables. If the name of the overriding function is the same as is 305# defined in this file, then don't output this file's version. 306# If a different overriding name is given then output the standard function 307# as presumably it is called from the overriding function. 308# 309if test x"$LDEMUL_BEFORE_PARSE" != xgld"$EMULATION_NAME"_before_parse; then 310cat >>e${EMULATION_NAME}.c <<EOF 311 312static void 313gld${EMULATION_NAME}_before_parse (void) 314{ 315 ldfile_set_output_arch ("${OUTPUT_ARCH}", bfd_arch_`echo ${ARCH} | sed -e 's/:.*//'`); 316 config.dynamic_link = ${DYNAMIC_LINK-TRUE}; 317 config.has_shared = `if test -n "$GENERATE_SHLIB_SCRIPT" ; then echo TRUE ; else echo FALSE ; fi`; 318} 319 320EOF 321fi 322 323if test x"$LDEMUL_RECOGNIZED_FILE" != xgld"${EMULATION_NAME}"_load_symbols; then 324cat >>e${EMULATION_NAME}.c <<EOF 325/* Handle as_needed DT_NEEDED. */ 326 327static bfd_boolean 328gld${EMULATION_NAME}_load_symbols (lang_input_statement_type *entry) 329{ 330 if (!entry->as_needed 331 || (bfd_get_file_flags (entry->the_bfd) & DYNAMIC) == 0) 332 return FALSE; 333 334 /* Tell the ELF linker that we don't want the output file to have a 335 DT_NEEDED entry for this file, unless it is used to resolve 336 references in a regular object. */ 337 bfd_elf_set_dyn_lib_class (entry->the_bfd, DYN_AS_NEEDED); 338 339 /* Continue on with normal load_symbols processing. */ 340 return FALSE; 341} 342EOF 343fi 344 345cat >>e${EMULATION_NAME}.c <<EOF 346 347/* These variables are required to pass information back and forth 348 between after_open and check_needed and stat_needed and vercheck. */ 349 350static struct bfd_link_needed_list *global_needed; 351static struct stat global_stat; 352static bfd_boolean global_found; 353static struct bfd_link_needed_list *global_vercheck_needed; 354static bfd_boolean global_vercheck_failed; 355 356 357/* On Linux, it's possible to have different versions of the same 358 shared library linked against different versions of libc. The 359 dynamic linker somehow tags which libc version to use in 360 /etc/ld.so.cache, and, based on the libc that it sees in the 361 executable, chooses which version of the shared library to use. 362 363 We try to do a similar check here by checking whether this shared 364 library needs any other shared libraries which may conflict with 365 libraries we have already included in the link. If it does, we 366 skip it, and try to find another shared library farther on down the 367 link path. 368 369 This is called via lang_for_each_input_file. 370 GLOBAL_VERCHECK_NEEDED is the list of objects needed by the object 371 which we are checking. This sets GLOBAL_VERCHECK_FAILED if we find 372 a conflicting version. */ 373 374static void 375gld${EMULATION_NAME}_vercheck (lang_input_statement_type *s) 376{ 377 const char *soname; 378 struct bfd_link_needed_list *l; 379 380 if (global_vercheck_failed) 381 return; 382 if (s->the_bfd == NULL 383 || (bfd_get_file_flags (s->the_bfd) & DYNAMIC) == 0) 384 return; 385 386 soname = bfd_elf_get_dt_soname (s->the_bfd); 387 if (soname == NULL) 388 soname = lbasename (bfd_get_filename (s->the_bfd)); 389 390 for (l = global_vercheck_needed; l != NULL; l = l->next) 391 { 392 const char *suffix; 393 394 if (strcmp (soname, l->name) == 0) 395 { 396 /* Probably can't happen, but it's an easy check. */ 397 continue; 398 } 399 400 if (strchr (l->name, '/') != NULL) 401 continue; 402 403 suffix = strstr (l->name, ".so."); 404 if (suffix == NULL) 405 continue; 406 407 suffix += sizeof ".so." - 1; 408 409 if (strncmp (soname, l->name, suffix - l->name) == 0) 410 { 411 /* Here we know that S is a dynamic object FOO.SO.VER1, and 412 the object we are considering needs a dynamic object 413 FOO.SO.VER2, and VER1 and VER2 are different. This 414 appears to be a version mismatch, so we tell the caller 415 to try a different version of this library. */ 416 global_vercheck_failed = TRUE; 417 return; 418 } 419 } 420} 421 422 423/* See if an input file matches a DT_NEEDED entry by running stat on 424 the file. */ 425 426static void 427gld${EMULATION_NAME}_stat_needed (lang_input_statement_type *s) 428{ 429 struct stat st; 430 const char *suffix; 431 const char *soname; 432 433 if (global_found) 434 return; 435 if (s->the_bfd == NULL) 436 return; 437 438 if (bfd_stat (s->the_bfd, &st) != 0) 439 { 440 einfo ("%P:%B: bfd_stat failed: %E\n", s->the_bfd); 441 return; 442 } 443 444 if (st.st_dev == global_stat.st_dev 445 && st.st_ino == global_stat.st_ino) 446 { 447 global_found = TRUE; 448 return; 449 } 450 451 /* We issue a warning if it looks like we are including two 452 different versions of the same shared library. For example, 453 there may be a problem if -lc picks up libc.so.6 but some other 454 shared library has a DT_NEEDED entry of libc.so.5. This is a 455 heuristic test, and it will only work if the name looks like 456 NAME.so.VERSION. FIXME: Depending on file names is error-prone. 457 If we really want to issue warnings about mixing version numbers 458 of shared libraries, we need to find a better way. */ 459 460 if (strchr (global_needed->name, '/') != NULL) 461 return; 462 suffix = strstr (global_needed->name, ".so."); 463 if (suffix == NULL) 464 return; 465 suffix += sizeof ".so." - 1; 466 467 soname = bfd_elf_get_dt_soname (s->the_bfd); 468 if (soname == NULL) 469 soname = lbasename (s->filename); 470 471 if (strncmp (soname, global_needed->name, suffix - global_needed->name) == 0) 472 einfo ("%P: warning: %s, needed by %B, may conflict with %s\n", 473 global_needed->name, global_needed->by, soname); 474} 475 476 477/* This function is called for each possible name for a dynamic object 478 named by a DT_NEEDED entry. The FORCE parameter indicates whether 479 to skip the check for a conflicting version. */ 480 481static bfd_boolean 482gld${EMULATION_NAME}_try_needed (const char *name, int force) 483{ 484 bfd *abfd; 485 char *soname; 486 487 abfd = bfd_openr (name, bfd_get_target (output_bfd)); 488 if (abfd == NULL) 489 return FALSE; 490 if (! bfd_check_format (abfd, bfd_object)) 491 { 492 bfd_close (abfd); 493 return FALSE; 494 } 495 if ((bfd_get_file_flags (abfd) & DYNAMIC) == 0) 496 { 497 bfd_close (abfd); 498 return FALSE; 499 } 500 501 /* For DT_NEEDED, they have to match. */ 502 if (abfd->xvec != output_bfd->xvec) 503 { 504 bfd_close (abfd); 505 return FALSE; 506 } 507 508 /* Check whether this object would include any conflicting library 509 versions. If FORCE is set, then we skip this check; we use this 510 the second time around, if we couldn't find any compatible 511 instance of the shared library. */ 512 513 if (! force) 514 { 515 struct bfd_link_needed_list *needed; 516 517 if (! bfd_elf_get_bfd_needed_list (abfd, &needed)) 518 einfo ("%F%P:%B: bfd_elf_get_bfd_needed_list failed: %E\n", abfd); 519 520 if (needed != NULL) 521 { 522 global_vercheck_needed = needed; 523 global_vercheck_failed = FALSE; 524 lang_for_each_input_file (gld${EMULATION_NAME}_vercheck); 525 if (global_vercheck_failed) 526 { 527 bfd_close (abfd); 528 /* Return FALSE to force the caller to move on to try 529 another file on the search path. */ 530 return FALSE; 531 } 532 533 /* But wait! It gets much worse. On Linux, if a shared 534 library does not use libc at all, we are supposed to skip 535 it the first time around in case we encounter a shared 536 library later on with the same name which does use the 537 version of libc that we want. This is much too horrible 538 to use on any system other than Linux. */ 539 540EOF 541case ${target} in 542 *-*-linux-gnu*) 543 cat >>e${EMULATION_NAME}.c <<EOF 544 { 545 struct bfd_link_needed_list *l; 546 547 for (l = needed; l != NULL; l = l->next) 548 if (strncmp (l->name, "libc.so", 7) == 0) 549 break; 550 if (l == NULL) 551 { 552 bfd_close (abfd); 553 return FALSE; 554 } 555 } 556 557EOF 558 ;; 559esac 560cat >>e${EMULATION_NAME}.c <<EOF 561 } 562 } 563 564 /* We've found a dynamic object matching the DT_NEEDED entry. */ 565 566 /* We have already checked that there is no other input file of the 567 same name. We must now check again that we are not including the 568 same file twice. We need to do this because on many systems 569 libc.so is a symlink to, e.g., libc.so.1. The SONAME entry will 570 reference libc.so.1. If we have already included libc.so, we 571 don't want to include libc.so.1 if they are the same file, and we 572 can only check that using stat. */ 573 574 if (bfd_stat (abfd, &global_stat) != 0) 575 einfo ("%F%P:%B: bfd_stat failed: %E\n", abfd); 576 577 /* First strip off everything before the last '/'. */ 578 soname = xstrdup (lbasename (abfd->filename)); 579 580 if (trace_file_tries) 581 info_msg (_("found %s at %s\n"), soname, name); 582 583 global_found = FALSE; 584 lang_for_each_input_file (gld${EMULATION_NAME}_stat_needed); 585 if (global_found) 586 { 587 /* Return TRUE to indicate that we found the file, even though 588 we aren't going to do anything with it. */ 589 free (soname); 590 return TRUE; 591 } 592 593 /* Specify the soname to use. */ 594 bfd_elf_set_dt_needed_name (abfd, soname); 595 596 /* Tell the ELF linker that we don't want the output file to have a 597 DT_NEEDED entry for this file, unless it is used to resolve 598 references in a regular object. */ 599 bfd_elf_set_dyn_lib_class (abfd, DYN_DT_NEEDED); 600 601 /* Add this file into the symbol table. */ 602 if (! bfd_link_add_symbols (abfd, &link_info)) 603 einfo ("%F%B: could not read symbols: %E\n", abfd); 604 605 return TRUE; 606} 607 608 609/* Search for a needed file in a path. */ 610 611static bfd_boolean 612gld${EMULATION_NAME}_search_needed (const char *path, const char *name, int force) 613{ 614 const char *s; 615 size_t len; 616 617 if (name[0] == '/') 618 return gld${EMULATION_NAME}_try_needed (name, force); 619 620 if (path == NULL || *path == '\0') 621 return FALSE; 622 623EOF 624case ${target} in 625 *-*-openbsd*) 626 cat >>e${EMULATION_NAME}.c <<EOF 627 { 628 char *found; 629 if ((found = gld${EMULATION_NAME}_search_dir_needed(path, name)) != NULL) { 630 if (gld${EMULATION_NAME}_try_needed (found, force)) { 631 return TRUE; 632 } 633 free(found); 634 } 635 } 636 637EOF 638esac 639cat >>e${EMULATION_NAME}.c <<EOF 640 len = strlen (name); 641 while (1) 642 { 643 char *filename, *sset; 644 645 s = strchr (path, ':'); 646 if (s == NULL) 647 s = path + strlen (path); 648 649 filename = (char *) xmalloc (s - path + len + 2); 650 if (s == path) 651 sset = filename; 652 else 653 { 654 memcpy (filename, path, s - path); 655 filename[s - path] = '/'; 656 sset = filename + (s - path) + 1; 657 } 658 strcpy (sset, name); 659 660 if (gld${EMULATION_NAME}_try_needed (filename, force)) 661 return TRUE; 662 663 free (filename); 664 665 if (*s == '\0') 666 break; 667 path = s + 1; 668 } 669 670 return FALSE; 671} 672 673EOF 674if [ "x${USE_LIBPATH}" = xyes ] ; then 675 cat >>e${EMULATION_NAME}.c <<EOF 676 677/* Add the sysroot to every entry in a colon-separated path. */ 678 679static char * 680gld${EMULATION_NAME}_add_sysroot (const char *path) 681{ 682 int len, colons, i; 683 char *ret, *p; 684 685 len = strlen (path); 686 colons = 0; 687 i = 0; 688 while (path[i]) 689 if (path[i++] == ':') 690 colons++; 691 692 if (path[i]) 693 colons++; 694 695 len = len + (colons + 1) * strlen (ld_sysroot); 696 ret = xmalloc (len + 1); 697 strcpy (ret, ld_sysroot); 698 p = ret + strlen (ret); 699 i = 0; 700 while (path[i]) 701 if (path[i] == ':') 702 { 703 *p++ = path[i++]; 704 strcpy (p, ld_sysroot); 705 p = p + strlen (p); 706 } 707 else 708 *p++ = path[i++]; 709 710 *p = 0; 711 return ret; 712} 713 714EOF 715 case ${target} in 716 *-*-linux-gnu*) 717 cat >>e${EMULATION_NAME}.c <<EOF 718/* For a native linker, check the file /etc/ld.so.conf for directories 719 in which we may find shared libraries. /etc/ld.so.conf is really 720 only meaningful on Linux. */ 721 722static bfd_boolean 723gld${EMULATION_NAME}_check_ld_so_conf (const char *name, int force) 724{ 725 static bfd_boolean initialized; 726 static char *ld_so_conf; 727 728 if (! initialized) 729 { 730 FILE *f; 731 char *tmppath; 732 733 tmppath = concat (ld_sysroot, "/etc/ld.so.conf", NULL); 734 f = fopen (tmppath, FOPEN_RT); 735 free (tmppath); 736 if (f != NULL) 737 { 738 char *b; 739 size_t len, alloc; 740 int c; 741 742 len = 0; 743 alloc = 100; 744 b = (char *) xmalloc (alloc); 745 746 while ((c = getc (f)) != EOF) 747 { 748 if (len + 1 >= alloc) 749 { 750 alloc *= 2; 751 b = (char *) xrealloc (b, alloc); 752 } 753 if (c != ':' 754 && c != ' ' 755 && c != '\t' 756 && c != '\n' 757 && c != ',') 758 { 759 b[len] = c; 760 ++len; 761 } 762 else 763 { 764 if (len > 0 && b[len - 1] != ':') 765 { 766 b[len] = ':'; 767 ++len; 768 } 769 } 770 } 771 772 if (len > 0 && b[len - 1] == ':') 773 --len; 774 775 if (len > 0) 776 b[len] = '\0'; 777 else 778 { 779 free (b); 780 b = NULL; 781 } 782 783 fclose (f); 784 785 if (b) 786 { 787 char *d = gld${EMULATION_NAME}_add_sysroot (b); 788 free (b); 789 b = d; 790 } 791 792 ld_so_conf = b; 793 } 794 795 initialized = TRUE; 796 } 797 798 if (ld_so_conf == NULL) 799 return FALSE; 800 801 return gld${EMULATION_NAME}_search_needed (ld_so_conf, name, force); 802} 803 804EOF 805 # Linux 806 ;; 807 esac 808fi 809cat >>e${EMULATION_NAME}.c <<EOF 810 811/* See if an input file matches a DT_NEEDED entry by name. */ 812 813static void 814gld${EMULATION_NAME}_check_needed (lang_input_statement_type *s) 815{ 816 if (global_found) 817 return; 818 819 if (s->filename != NULL) 820 { 821 const char *f; 822 823 if (strcmp (s->filename, global_needed->name) == 0) 824 { 825 global_found = TRUE; 826 return; 827 } 828 829 if (s->search_dirs_flag) 830 { 831 f = strrchr (s->filename, '/'); 832 if (f != NULL 833 && strcmp (f + 1, global_needed->name) == 0) 834 { 835 global_found = TRUE; 836 return; 837 } 838 } 839 } 840 841 if (s->the_bfd != NULL) 842 { 843 const char *soname; 844 845 soname = bfd_elf_get_dt_soname (s->the_bfd); 846 if (soname != NULL 847 && strcmp (soname, global_needed->name) == 0) 848 { 849 global_found = TRUE; 850 return; 851 } 852 } 853} 854 855EOF 856 857if test x"$LDEMUL_AFTER_OPEN" != xgld"$EMULATION_NAME"_after_open; then 858cat >>e${EMULATION_NAME}.c <<EOF 859 860/* This is called after all the input files have been opened. */ 861 862static void 863gld${EMULATION_NAME}_after_open (void) 864{ 865 struct bfd_link_needed_list *needed, *l; 866 867 /* We only need to worry about this when doing a final link. */ 868 if (link_info.relocatable || !link_info.executable) 869 return; 870 871 /* Get the list of files which appear in DT_NEEDED entries in 872 dynamic objects included in the link (often there will be none). 873 For each such file, we want to track down the corresponding 874 library, and include the symbol table in the link. This is what 875 the runtime dynamic linker will do. Tracking the files down here 876 permits one dynamic object to include another without requiring 877 special action by the person doing the link. Note that the 878 needed list can actually grow while we are stepping through this 879 loop. */ 880 needed = bfd_elf_get_needed_list (output_bfd, &link_info); 881 for (l = needed; l != NULL; l = l->next) 882 { 883 struct bfd_link_needed_list *ll; 884 int force; 885 886 /* If we've already seen this file, skip it. */ 887 for (ll = needed; ll != l; ll = ll->next) 888 if (strcmp (ll->name, l->name) == 0) 889 break; 890 if (ll != l) 891 continue; 892 893 /* See if this file was included in the link explicitly. */ 894 global_needed = l; 895 global_found = FALSE; 896 lang_for_each_input_file (gld${EMULATION_NAME}_check_needed); 897 if (global_found) 898 continue; 899 900 if (trace_file_tries) 901 info_msg (_("%s needed by %B\n"), l->name, l->by); 902 903 /* We need to find this file and include the symbol table. We 904 want to search for the file in the same way that the dynamic 905 linker will search. That means that we want to use 906 rpath_link, rpath, then the environment variable 907 LD_LIBRARY_PATH (native only), then the DT_RPATH/DT_RUNPATH 908 entries (native only), then the linker script LIB_SEARCH_DIRS. 909 We look at the -L arguments to build the search path. 910 911 We search twice. The first time, we skip objects which may 912 introduce version mismatches. The second time, we force 913 their use. See gld${EMULATION_NAME}_vercheck comment. */ 914 for (force = 0; force < 2; force++) 915 { 916 size_t len; 917 search_dirs_type *search; 918EOF 919if [ "x${USE_LIBPATH}" = xyes ] ; then 920cat >>e${EMULATION_NAME}.c <<EOF 921 char *lib_path; 922 struct bfd_link_needed_list *rp; 923 int found; 924EOF 925fi 926cat >>e${EMULATION_NAME}.c <<EOF 927 928 if (gld${EMULATION_NAME}_search_needed (command_line.rpath_link, 929 l->name, force)) 930 break; 931EOF 932if [ "x${USE_LIBPATH}" = xyes ] ; then 933cat >>e${EMULATION_NAME}.c <<EOF 934 if (gld${EMULATION_NAME}_search_needed (command_line.rpath, 935 l->name, force)) 936 break; 937EOF 938fi 939if [ "x${NATIVE}" = xyes ] ; then 940cat >>e${EMULATION_NAME}.c <<EOF 941 if (getenv ("LD_RUN_PATH") != NULL 942 && command_line.rpath_link == NULL 943 && command_line.rpath == NULL) 944 { 945 lib_path = getenv ("LD_RUN_PATH"); 946 if (gld${EMULATION_NAME}_search_needed (lib_path, l->name, 947 force)) 948 break; 949 } 950 951 len = strlen(search_head->name); 952 lib_path = xstrdup(search_head->name); 953 for (search = search_head->next; search != NULL; 954 search = search->next) 955 { 956 size_t nlen; 957 958 nlen = strlen(search->name); 959 lib_path = xrealloc(lib_path, len + nlen + 2); 960 lib_path[len] = ':'; 961 strcpy(lib_path + len + 1, search->name); 962 len += nlen + 1; 963 } 964 965 if (gld${EMULATION_NAME}_search_needed (lib_path, l->name, force)) 966 { 967 free(lib_path); 968 break; 969 } 970 free(lib_path); 971 972 lib_path = getenv ("LD_LIBRARY_PATH"); 973 if (gld${EMULATION_NAME}_search_needed (lib_path, l->name, force)) 974 break; 975EOF 976fi 977if [ "x${USE_LIBPATH}" = xyes ] ; then 978cat >>e${EMULATION_NAME}.c <<EOF 979 found = 0; 980 rp = bfd_elf_get_runpath_list (output_bfd, &link_info); 981 for (; !found && rp != NULL; rp = rp->next) 982 { 983 char *tmpname = gld${EMULATION_NAME}_add_sysroot (rp->name); 984 found = (rp->by == l->by 985 && gld${EMULATION_NAME}_search_needed (tmpname, 986 l->name, 987 force)); 988 free (tmpname); 989 } 990 if (found) 991 break; 992 993EOF 994fi 995cat >>e${EMULATION_NAME}.c <<EOF 996 len = strlen (l->name); 997 for (search = search_head; search != NULL; search = search->next) 998 { 999 char *filename; 1000 1001 if (search->cmdline) 1002 continue; 1003 filename = (char *) xmalloc (strlen (search->name) + len + 2); 1004 sprintf (filename, "%s/%s", search->name, l->name); 1005 if (gld${EMULATION_NAME}_try_needed (filename, force)) 1006 break; 1007 free (filename); 1008 } 1009 if (search != NULL) 1010 break; 1011EOF 1012if [ "x${USE_LIBPATH}" = xyes ] ; then 1013 case ${target} in 1014 *-*-linux-gnu*) 1015 cat >>e${EMULATION_NAME}.c <<EOF 1016 if (gld${EMULATION_NAME}_check_ld_so_conf (l->name, force)) 1017 break; 1018EOF 1019 # Linux 1020 ;; 1021 esac 1022fi 1023cat >>e${EMULATION_NAME}.c <<EOF 1024 } 1025 1026 if (force < 2) 1027 continue; 1028 1029 einfo ("%P: warning: %s, needed by %B, not found (try using -rpath or -rpath-link)\n", 1030 l->name, l->by); 1031 } 1032} 1033 1034EOF 1035fi 1036 1037cat >>e${EMULATION_NAME}.c <<EOF 1038 1039/* Look through an expression for an assignment statement. */ 1040 1041static void 1042gld${EMULATION_NAME}_find_exp_assignment (etree_type *exp) 1043{ 1044 struct bfd_link_hash_entry *h; 1045 1046 switch (exp->type.node_class) 1047 { 1048 case etree_provide: 1049 h = bfd_link_hash_lookup (link_info.hash, exp->assign.dst, 1050 FALSE, FALSE, FALSE); 1051 if (h == NULL) 1052 break; 1053 1054 /* We call record_link_assignment even if the symbol is defined. 1055 This is because if it is defined by a dynamic object, we 1056 actually want to use the value defined by the linker script, 1057 not the value from the dynamic object (because we are setting 1058 symbols like etext). If the symbol is defined by a regular 1059 object, then, as it happens, calling record_link_assignment 1060 will do no harm. */ 1061 1062 /* Fall through. */ 1063 case etree_assign: 1064 if (strcmp (exp->assign.dst, ".") != 0) 1065 { 1066 if (! (bfd_elf_record_link_assignment 1067 (output_bfd, &link_info, exp->assign.dst, 1068 exp->type.node_class == etree_provide ? TRUE : FALSE))) 1069 einfo ("%P%F: failed to record assignment to %s: %E\n", 1070 exp->assign.dst); 1071 } 1072 gld${EMULATION_NAME}_find_exp_assignment (exp->assign.src); 1073 break; 1074 1075 case etree_binary: 1076 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.lhs); 1077 gld${EMULATION_NAME}_find_exp_assignment (exp->binary.rhs); 1078 break; 1079 1080 case etree_trinary: 1081 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.cond); 1082 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.lhs); 1083 gld${EMULATION_NAME}_find_exp_assignment (exp->trinary.rhs); 1084 break; 1085 1086 case etree_unary: 1087 gld${EMULATION_NAME}_find_exp_assignment (exp->unary.child); 1088 break; 1089 1090 default: 1091 break; 1092 } 1093} 1094 1095 1096/* This is called by the before_allocation routine via 1097 lang_for_each_statement. It locates any assignment statements, and 1098 tells the ELF backend about them, in case they are assignments to 1099 symbols which are referred to by dynamic objects. */ 1100 1101static void 1102gld${EMULATION_NAME}_find_statement_assignment (lang_statement_union_type *s) 1103{ 1104 if (s->header.type == lang_assignment_statement_enum) 1105 gld${EMULATION_NAME}_find_exp_assignment (s->assignment_statement.exp); 1106} 1107 1108EOF 1109 1110if test x"$LDEMUL_BEFORE_ALLOCATION" != xgld"$EMULATION_NAME"_before_allocation; then 1111 if test x"${ELF_INTERPRETER_NAME+set}" = xset; then 1112 ELF_INTERPRETER_SET_DEFAULT=" 1113 if (sinterp != NULL) 1114 { 1115 sinterp->contents = ${ELF_INTERPRETER_NAME}; 1116 sinterp->_raw_size = strlen (sinterp->contents) + 1; 1117 } 1118 1119" 1120 else 1121 ELF_INTERPRETER_SET_DEFAULT= 1122 fi 1123cat >>e${EMULATION_NAME}.c <<EOF 1124 1125/* This is called after the sections have been attached to output 1126 sections, but before any sizes or addresses have been set. */ 1127 1128static void 1129gld${EMULATION_NAME}_before_allocation (void) 1130{ 1131 const char *rpath; 1132 asection *sinterp; 1133 1134 if (link_info.hash->type == bfd_link_elf_hash_table) 1135 _bfd_elf_tls_setup (output_bfd, &link_info); 1136 1137 /* If we are going to make any variable assignments, we need to let 1138 the ELF backend know about them in case the variables are 1139 referred to by dynamic objects. */ 1140 lang_for_each_statement (gld${EMULATION_NAME}_find_statement_assignment); 1141 1142 /* Let the ELF backend work out the sizes of any sections required 1143 by dynamic linking. */ 1144 rpath = command_line.rpath; 1145 if (rpath == NULL) 1146 rpath = (const char *) getenv ("LD_RUN_PATH"); 1147 if (! (bfd_elf_size_dynamic_sections 1148 (output_bfd, command_line.soname, rpath, 1149 command_line.filter_shlib, 1150 (const char * const *) command_line.auxiliary_filters, 1151 &link_info, &sinterp, lang_elf_version_info))) 1152 einfo ("%P%F: failed to set dynamic section sizes: %E\n"); 1153${ELF_INTERPRETER_SET_DEFAULT} 1154 /* Let the user override the dynamic linker we are using. */ 1155 if (command_line.interpreter != NULL 1156 && sinterp != NULL) 1157 { 1158 sinterp->contents = (bfd_byte *) command_line.interpreter; 1159 sinterp->_raw_size = strlen (command_line.interpreter) + 1; 1160 } 1161 1162 /* Look for any sections named .gnu.warning. As a GNU extensions, 1163 we treat such sections as containing warning messages. We print 1164 out the warning message, and then zero out the section size so 1165 that it does not get copied into the output file. */ 1166 1167 { 1168 LANG_FOR_EACH_INPUT_STATEMENT (is) 1169 { 1170 asection *s; 1171 bfd_size_type sz; 1172 char *msg; 1173 bfd_boolean ret; 1174 1175 if (is->just_syms_flag) 1176 continue; 1177 1178 s = bfd_get_section_by_name (is->the_bfd, ".gnu.warning"); 1179 if (s == NULL) 1180 continue; 1181 1182 sz = bfd_section_size (is->the_bfd, s); 1183 msg = xmalloc ((size_t) (sz + 1)); 1184 if (! bfd_get_section_contents (is->the_bfd, s, msg, (file_ptr) 0, sz)) 1185 einfo ("%F%B: Can't read contents of section .gnu.warning: %E\n", 1186 is->the_bfd); 1187 msg[sz] = '\0'; 1188 ret = link_info.callbacks->warning (&link_info, msg, 1189 (const char *) NULL, 1190 is->the_bfd, (asection *) NULL, 1191 (bfd_vma) 0); 1192 ASSERT (ret); 1193 free (msg); 1194 1195 /* Clobber the section size, so that we don't waste copying the 1196 warning into the output file. */ 1197 s->_raw_size = 0; 1198 } 1199 } 1200} 1201 1202EOF 1203fi 1204 1205if test x"$LDEMUL_OPEN_DYNAMIC_ARCHIVE" != xgld"$EMULATION_NAME"_open_dynamic_archive; then 1206cat >>e${EMULATION_NAME}.c <<EOF 1207 1208/* Try to open a dynamic archive. This is where we know that ELF 1209 dynamic libraries have an extension of .so (or .sl on oddball systems 1210 like hpux). */ 1211 1212static bfd_boolean 1213gld${EMULATION_NAME}_open_dynamic_archive 1214 (const char *arch, search_dirs_type *search, lang_input_statement_type *entry) 1215{ 1216 const char *filename; 1217 char *string; 1218 1219 if (! entry->is_archive) 1220 return FALSE; 1221 1222 filename = entry->filename; 1223EOF 1224case ${target} in 1225 *-*-openbsd*) 1226 cat >>e${EMULATION_NAME}.c <<EOF 1227 string = gld${EMULATION_NAME}_search_dir(search->name, filename, -1, -1); 1228 if (string == NULL) 1229 return FALSE; 1230EOF 1231 ;; 1232 *) 1233 cat >>e${EMULATION_NAME}.c <<EOF 1234 /* This allocates a few bytes too many when EXTRA_SHLIB_EXTENSION 1235 is defined, but it does not seem worth the headache to optimize 1236 away those two bytes of space. */ 1237 string = (char *) xmalloc (strlen (search->name) 1238 + strlen (filename) 1239 + strlen (arch) 1240#ifdef EXTRA_SHLIB_EXTENSION 1241 + strlen (EXTRA_SHLIB_EXTENSION) 1242#endif 1243 + sizeof "/lib.so"); 1244 1245 sprintf (string, "%s/lib%s%s.so", search->name, filename, arch); 1246 1247EOF 1248 ;; 1249esac 1250cat >>e${EMULATION_NAME}.c <<EOF 1251#ifdef EXTRA_SHLIB_EXTENSION 1252 /* Try the .so extension first. If that fails build a new filename 1253 using EXTRA_SHLIB_EXTENSION. */ 1254 if (! ldfile_try_open_bfd (string, entry)) 1255 sprintf (string, "%s/lib%s%s%s", search->name, 1256 filename, arch, EXTRA_SHLIB_EXTENSION); 1257#endif 1258 1259 if (! ldfile_try_open_bfd (string, entry)) 1260 { 1261 free (string); 1262 return FALSE; 1263 } 1264 1265 entry->filename = string; 1266 1267 /* We have found a dynamic object to include in the link. The ELF 1268 backend linker will create a DT_NEEDED entry in the .dynamic 1269 section naming this file. If this file includes a DT_SONAME 1270 entry, it will be used. Otherwise, the ELF linker will just use 1271 the name of the file. For an archive found by searching, like 1272 this one, the DT_NEEDED entry should consist of just the name of 1273 the file, without the path information used to find it. Note 1274 that we only need to do this if we have a dynamic object; an 1275 archive will never be referenced by a DT_NEEDED entry. 1276 1277 FIXME: This approach--using bfd_elf_set_dt_needed_name--is not 1278 very pretty. I haven't been able to think of anything that is 1279 pretty, though. */ 1280 if (bfd_check_format (entry->the_bfd, bfd_object) 1281 && (entry->the_bfd->flags & DYNAMIC) != 0) 1282 { 1283 ASSERT (entry->is_archive && entry->search_dirs_flag); 1284 1285 /* Rather than duplicating the logic above. Just use the 1286 filename we recorded earlier. */ 1287 1288 filename = lbasename (entry->filename); 1289 bfd_elf_set_dt_needed_name (entry->the_bfd, filename); 1290 } 1291 1292 return TRUE; 1293} 1294 1295EOF 1296fi 1297 1298if test x"$LDEMUL_PLACE_ORPHAN" != xgld"$EMULATION_NAME"_place_orphan; then 1299cat >>e${EMULATION_NAME}.c <<EOF 1300 1301/* A variant of lang_output_section_find. Used by place_orphan. */ 1302 1303static lang_output_section_statement_type * 1304output_rel_find (asection *sec, int isdyn) 1305{ 1306 lang_statement_union_type *u; 1307 lang_output_section_statement_type *lookup; 1308 lang_output_section_statement_type *last = NULL; 1309 lang_output_section_statement_type *last_alloc = NULL; 1310 lang_output_section_statement_type *last_rel = NULL; 1311 lang_output_section_statement_type *last_rel_alloc = NULL; 1312 int rela = sec->name[4] == 'a'; 1313 1314 for (u = lang_output_section_statement.head; u; u = lookup->next) 1315 { 1316 lookup = &u->output_section_statement; 1317 if (strncmp (".rel", lookup->name, 4) == 0) 1318 { 1319 int lookrela = lookup->name[4] == 'a'; 1320 1321 /* .rel.dyn must come before all other reloc sections, to suit 1322 GNU ld.so. */ 1323 if (isdyn) 1324 break; 1325 1326 /* Don't place after .rel.plt as doing so results in wrong 1327 dynamic tags. */ 1328 if (strcmp (".plt", lookup->name + 4 + lookrela) == 0) 1329 break; 1330 1331 if (rela == lookrela || last_rel == NULL) 1332 last_rel = lookup; 1333 if ((rela == lookrela || last_rel_alloc == NULL) 1334 && lookup->bfd_section != NULL 1335 && (lookup->bfd_section->flags & SEC_ALLOC) != 0) 1336 last_rel_alloc = lookup; 1337 } 1338 1339 last = lookup; 1340 if (lookup->bfd_section != NULL 1341 && (lookup->bfd_section->flags & SEC_ALLOC) != 0) 1342 last_alloc = lookup; 1343 } 1344 1345 if (last_rel_alloc) 1346 return last_rel_alloc; 1347 1348 if (last_rel) 1349 return last_rel; 1350 1351 if (last_alloc) 1352 return last_alloc; 1353 1354 return last; 1355} 1356 1357/* Find the last output section before given output statement. 1358 Used by place_orphan. */ 1359 1360static asection * 1361output_prev_sec_find (lang_output_section_statement_type *os) 1362{ 1363 asection *s = (asection *) NULL; 1364 lang_statement_union_type *u; 1365 lang_output_section_statement_type *lookup; 1366 1367 for (u = lang_output_section_statement.head; 1368 u != (lang_statement_union_type *) NULL; 1369 u = lookup->next) 1370 { 1371 lookup = &u->output_section_statement; 1372 if (lookup == os) 1373 return s; 1374 1375 if (lookup->bfd_section != NULL && lookup->bfd_section->owner != NULL) 1376 s = lookup->bfd_section; 1377 } 1378 1379 return NULL; 1380} 1381 1382/* Place an orphan section. We use this to put random SHF_ALLOC 1383 sections in the right segment. */ 1384 1385struct orphan_save { 1386 lang_output_section_statement_type *os; 1387 asection **section; 1388 lang_statement_union_type **stmt; 1389 lang_statement_union_type **os_tail; 1390}; 1391 1392static bfd_boolean 1393gld${EMULATION_NAME}_place_orphan (lang_input_statement_type *file, asection *s) 1394{ 1395 static struct orphan_save hold_text; 1396 static struct orphan_save hold_rodata; 1397 static struct orphan_save hold_data; 1398 static struct orphan_save hold_bss; 1399 static struct orphan_save hold_rel; 1400 static struct orphan_save hold_interp; 1401 static struct orphan_save hold_sdata; 1402 static int count = 1; 1403 struct orphan_save *place; 1404 lang_statement_list_type *old; 1405 lang_statement_list_type add; 1406 etree_type *address; 1407 const char *secname; 1408 const char *ps = NULL; 1409 lang_output_section_statement_type *os; 1410 lang_statement_union_type **os_tail; 1411 etree_type *load_base; 1412 int isdyn = 0; 1413 1414 secname = bfd_get_section_name (s->owner, s); 1415 if (! link_info.relocatable 1416 && link_info.combreloc 1417 && (s->flags & SEC_ALLOC) 1418 && strncmp (secname, ".rel", 4) == 0) 1419 { 1420 if (secname[4] == 'a') 1421 secname = ".rela.dyn"; 1422 else 1423 secname = ".rel.dyn"; 1424 isdyn = 1; 1425 } 1426 1427 if (isdyn || (!config.unique_orphan_sections && !unique_section_p (secname))) 1428 { 1429 /* Look through the script to see where to place this section. */ 1430 os = lang_output_section_find (secname); 1431 1432 if (os != NULL 1433 && (os->bfd_section == NULL 1434 || ((s->flags ^ os->bfd_section->flags) 1435 & (SEC_LOAD | SEC_ALLOC)) == 0)) 1436 { 1437 /* We already have an output section statement with this 1438 name, and its bfd section, if any, has compatible flags. */ 1439 lang_add_section (&os->children, s, os, file); 1440 return TRUE; 1441 } 1442 } 1443 1444 if (hold_text.os == NULL) 1445 hold_text.os = lang_output_section_find (".text"); 1446 1447 /* If this is a final link, then always put .gnu.warning.SYMBOL 1448 sections into the .text section to get them out of the way. */ 1449 if (link_info.executable 1450 && ! link_info.relocatable 1451 && strncmp (secname, ".gnu.warning.", sizeof ".gnu.warning." - 1) == 0 1452 && hold_text.os != NULL) 1453 { 1454 lang_add_section (&hold_text.os->children, s, hold_text.os, file); 1455 return TRUE; 1456 } 1457 1458 /* Decide which segment the section should go in based on the 1459 section name and section flags. We put loadable .note sections 1460 right after the .interp section, so that the PT_NOTE segment is 1461 stored right after the program headers where the OS can read it 1462 in the first page. */ 1463#define HAVE_SECTION(hold, name) \ 1464(hold.os != NULL || (hold.os = lang_output_section_find (name)) != NULL) 1465 1466 if ((s->flags & SEC_EXCLUDE) != 0 && !link_info.relocatable) 1467 { 1468 if (s->output_section == NULL) 1469 s->output_section = bfd_abs_section_ptr; 1470 return TRUE; 1471 } 1472 1473 place = NULL; 1474 if ((s->flags & SEC_ALLOC) == 0) 1475 ; 1476 else if ((s->flags & SEC_LOAD) != 0 1477 && strncmp (secname, ".note", 5) == 0 1478 && HAVE_SECTION (hold_interp, ".interp")) 1479 place = &hold_interp; 1480 else if ((s->flags & SEC_HAS_CONTENTS) == 0 1481 && HAVE_SECTION (hold_bss, ".bss")) 1482 place = &hold_bss; 1483 else if ((s->flags & SEC_SMALL_DATA) != 0 1484 && HAVE_SECTION (hold_sdata, ".sdata")) 1485 place = &hold_sdata; 1486 else if ((s->flags & SEC_READONLY) == 0 1487 && HAVE_SECTION (hold_data, ".data")) 1488 place = &hold_data; 1489 else if (strncmp (secname, ".rel", 4) == 0 1490 && (s->flags & SEC_LOAD) != 0 1491 && (hold_rel.os != NULL 1492 || (hold_rel.os = output_rel_find (s, isdyn)) != NULL)) 1493 place = &hold_rel; 1494 else if ((s->flags & (SEC_CODE | SEC_READONLY)) == SEC_READONLY 1495 && HAVE_SECTION (hold_rodata, ".rodata")) 1496 place = &hold_rodata; 1497 else if ((s->flags & (SEC_CODE | SEC_READONLY)) == (SEC_CODE | SEC_READONLY) 1498 && hold_text.os != NULL) 1499 place = &hold_text; 1500 1501#undef HAVE_SECTION 1502 1503 /* Choose a unique name for the section. This will be needed if the 1504 same section name appears in the input file with different 1505 loadable or allocatable characteristics. */ 1506 if (bfd_get_section_by_name (output_bfd, secname) != NULL) 1507 { 1508 secname = bfd_get_unique_section_name (output_bfd, secname, &count); 1509 if (secname == NULL) 1510 einfo ("%F%P: place_orphan failed: %E\n"); 1511 } 1512 1513 /* Start building a list of statements for this section. 1514 First save the current statement pointer. */ 1515 old = stat_ptr; 1516 1517 /* If we have found an appropriate place for the output section 1518 statements for this orphan, add them to our own private list, 1519 inserting them later into the global statement list. */ 1520 if (place != NULL) 1521 { 1522 stat_ptr = &add; 1523 lang_list_init (stat_ptr); 1524 } 1525 1526 if (config.build_constructors) 1527 { 1528 /* If the name of the section is representable in C, then create 1529 symbols to mark the start and the end of the section. */ 1530 for (ps = secname; *ps != '\0'; ps++) 1531 if (! ISALNUM (*ps) && *ps != '_') 1532 break; 1533 if (*ps == '\0') 1534 { 1535 char *symname; 1536 etree_type *e_align; 1537 1538 symname = (char *) xmalloc (ps - secname + sizeof "__start_"); 1539 sprintf (symname, "__start_%s", secname); 1540 e_align = exp_unop (ALIGN_K, 1541 exp_intop ((bfd_vma) 1 << s->alignment_power)); 1542 lang_add_assignment (exp_assop ('=', symname, e_align)); 1543 } 1544 } 1545 1546 address = NULL; 1547 if (link_info.relocatable || (s->flags & (SEC_LOAD | SEC_ALLOC)) == 0) 1548 address = exp_intop ((bfd_vma) 0); 1549 1550 load_base = NULL; 1551 if (place != NULL && place->os->load_base != NULL) 1552 { 1553 etree_type *lma_from_vma; 1554 lma_from_vma = exp_binop ('-', place->os->load_base, 1555 exp_nameop (ADDR, place->os->name)); 1556 load_base = exp_binop ('+', lma_from_vma, 1557 exp_nameop (ADDR, secname)); 1558 } 1559 1560 os_tail = lang_output_section_statement.tail; 1561 os = lang_enter_output_section_statement (secname, address, 0, 1562 (etree_type *) NULL, 1563 (etree_type *) NULL, 1564 load_base); 1565 1566 lang_add_section (&os->children, s, os, file); 1567 1568 lang_leave_output_section_statement 1569 ((bfd_vma) 0, "*default*", 1570 (struct lang_output_section_phdr_list *) NULL, NULL); 1571 1572 if (config.build_constructors && *ps == '\0') 1573 { 1574 char *symname; 1575 1576 /* lang_leave_ouput_section_statement resets stat_ptr. Put 1577 stat_ptr back where we want it. */ 1578 if (place != NULL) 1579 stat_ptr = &add; 1580 1581 symname = (char *) xmalloc (ps - secname + sizeof "__stop_"); 1582 sprintf (symname, "__stop_%s", secname); 1583 lang_add_assignment (exp_assop ('=', symname, 1584 exp_nameop (NAME, "."))); 1585 } 1586 1587 /* Restore the global list pointer. */ 1588 stat_ptr = old; 1589 1590 if (place != NULL && os->bfd_section != NULL) 1591 { 1592 asection *snew, **pps; 1593 1594 snew = os->bfd_section; 1595 1596 /* Shuffle the bfd section list to make the output file look 1597 neater. This is really only cosmetic. */ 1598 if (place->section == NULL) 1599 { 1600 asection *bfd_section = place->os->bfd_section; 1601 1602 /* If the output statement hasn't been used to place 1603 any input sections (and thus doesn't have an output 1604 bfd_section), look for the closest prior output statement 1605 having an output section. */ 1606 if (bfd_section == NULL) 1607 bfd_section = output_prev_sec_find (place->os); 1608 1609 if (bfd_section != NULL && bfd_section != snew) 1610 place->section = &bfd_section->next; 1611 } 1612 1613 if (place->section != NULL) 1614 { 1615 /* Unlink the section. */ 1616 for (pps = &output_bfd->sections; *pps != snew; pps = &(*pps)->next) 1617 ; 1618 bfd_section_list_remove (output_bfd, pps); 1619 1620 /* Now tack it on to the "place->os" section list. */ 1621 bfd_section_list_insert (output_bfd, place->section, snew); 1622 } 1623 1624 /* Save the end of this list. Further ophans of this type will 1625 follow the one we've just added. */ 1626 place->section = &snew->next; 1627 1628 /* The following is non-cosmetic. We try to put the output 1629 statements in some sort of reasonable order here, because 1630 they determine the final load addresses of the orphan 1631 sections. In addition, placing output statements in the 1632 wrong order may require extra segments. For instance, 1633 given a typical situation of all read-only sections placed 1634 in one segment and following that a segment containing all 1635 the read-write sections, we wouldn't want to place an orphan 1636 read/write section before or amongst the read-only ones. */ 1637 if (add.head != NULL) 1638 { 1639 lang_statement_union_type *newly_added_os; 1640 1641 if (place->stmt == NULL) 1642 { 1643 /* Put the new statement list right at the head. */ 1644 *add.tail = place->os->header.next; 1645 place->os->header.next = add.head; 1646 1647 place->os_tail = &place->os->next; 1648 } 1649 else 1650 { 1651 /* Put it after the last orphan statement we added. */ 1652 *add.tail = *place->stmt; 1653 *place->stmt = add.head; 1654 } 1655 1656 /* Fix the global list pointer if we happened to tack our 1657 new list at the tail. */ 1658 if (*old->tail == add.head) 1659 old->tail = add.tail; 1660 1661 /* Save the end of this list. */ 1662 place->stmt = add.tail; 1663 1664 /* Do the same for the list of output section statements. */ 1665 newly_added_os = *os_tail; 1666 *os_tail = NULL; 1667 newly_added_os->output_section_statement.next = *place->os_tail; 1668 *place->os_tail = newly_added_os; 1669 place->os_tail = &newly_added_os->output_section_statement.next; 1670 1671 /* Fixing the global list pointer here is a little different. 1672 We added to the list in lang_enter_output_section_statement, 1673 trimmed off the new output_section_statment above when 1674 assigning *os_tail = NULL, but possibly added it back in 1675 the same place when assigning *place->os_tail. */ 1676 if (*os_tail == NULL) 1677 lang_output_section_statement.tail = os_tail; 1678 } 1679 } 1680 1681 return TRUE; 1682} 1683EOF 1684fi 1685 1686if test x"$LDEMUL_FINISH" != xgld"$EMULATION_NAME"_finish; then 1687cat >>e${EMULATION_NAME}.c <<EOF 1688 1689static void 1690gld${EMULATION_NAME}_finish (void) 1691{ 1692 if (bfd_elf_discard_info (output_bfd, &link_info)) 1693 { 1694 lang_reset_memory_regions (); 1695 1696 /* Resize the sections. */ 1697 lang_size_sections (stat_ptr->head, abs_output_section, 1698 &stat_ptr->head, 0, (bfd_vma) 0, NULL, TRUE); 1699 1700 /* Redo special stuff. */ 1701 ldemul_after_allocation (); 1702 1703 /* Do the assignments again. */ 1704 lang_do_assignments (stat_ptr->head, abs_output_section, 1705 (fill_type *) 0, (bfd_vma) 0); 1706 } 1707} 1708EOF 1709fi 1710 1711if test x"$LDEMUL_GET_SCRIPT" != xgld"$EMULATION_NAME"_get_script; then 1712cat >>e${EMULATION_NAME}.c <<EOF 1713 1714static char * 1715gld${EMULATION_NAME}_get_script (int *isfile) 1716EOF 1717 1718if test -n "$COMPILE_IN" 1719then 1720# Scripts compiled in. 1721 1722# sed commands to quote an ld script as a C string. 1723sc="-f stringify.sed" 1724 1725cat >>e${EMULATION_NAME}.c <<EOF 1726{ 1727 *isfile = 0; 1728 1729 if (link_info.relocatable && config.build_constructors) 1730 return 1731EOF 1732sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c 1733echo ' ; else if (link_info.relocatable) return' >> e${EMULATION_NAME}.c 1734sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c 1735echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c 1736sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c 1737if cmp -s ldscripts/${EMULATION_NAME}.x ldscripts/${EMULATION_NAME}.xn; then : ; else 1738echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c 1739sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c 1740fi 1741if test -n "$GENERATE_PIE_SCRIPT" ; then 1742if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then 1743echo ' ; else if (link_info.pie && link_info.combreloc && config.data_bss_contig == TRUE) return' >> e${EMULATION_NAME}.c 1744sed $sc ldscripts/${EMULATION_NAME}.xdcz >> e${EMULATION_NAME}.c 1745echo ' ; else if (link_info.pie && link_info.combreloc) return' >> e${EMULATION_NAME}.c 1746sed $sc ldscripts/${EMULATION_NAME}.xdc >> e${EMULATION_NAME}.c 1747fi 1748echo ' ; else if (link_info.pie && config.data_bss_contig == TRUE) return' >> e${EMULATION_NAME}.c 1749sed $sc ldscripts/${EMULATION_NAME}.xdz >> e${EMULATION_NAME}.c 1750echo ' ; else if (link_info.pie) return' >> e${EMULATION_NAME}.c 1751sed $sc ldscripts/${EMULATION_NAME}.xd >> e${EMULATION_NAME}.c 1752fi 1753if test -n "$GENERATE_SHLIB_SCRIPT" ; then 1754if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then 1755echo ' ; else if (link_info.shared && link_info.combreloc) return' >> e${EMULATION_NAME}.c 1756sed $sc ldscripts/${EMULATION_NAME}.xsc >> e${EMULATION_NAME}.c 1757fi 1758echo ' ; else if (link_info.shared) return' >> e${EMULATION_NAME}.c 1759sed $sc ldscripts/${EMULATION_NAME}.xs >> e${EMULATION_NAME}.c 1760fi 1761echo ' ; else if (config.data_bss_contig == TRUE) return' >> e${EMULATION_NAME}.c 1762sed $sc ldscripts/${EMULATION_NAME}.xz >> e${EMULATION_NAME}.c 1763if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then 1764echo ' ; else if (link_info.combreloc) return' >> e${EMULATION_NAME}.c 1765sed $sc ldscripts/${EMULATION_NAME}.xc >> e${EMULATION_NAME}.c 1766fi 1767echo ' ; else return' >> e${EMULATION_NAME}.c 1768sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c 1769echo '; }' >> e${EMULATION_NAME}.c 1770 1771else 1772# Scripts read from the filesystem. 1773 1774cat >>e${EMULATION_NAME}.c <<EOF 1775{ 1776 *isfile = 1; 1777 1778 if (link_info.relocatable && config.build_constructors) 1779 return "ldscripts/${EMULATION_NAME}.xu"; 1780 else if (link_info.relocatable) 1781 return "ldscripts/${EMULATION_NAME}.xr"; 1782 else if (!config.text_read_only) 1783 return "ldscripts/${EMULATION_NAME}.xbn"; 1784EOF 1785if cmp -s ldscripts/${EMULATION_NAME}.x ldscripts/${EMULATION_NAME}.xn; then : 1786else 1787cat >>e${EMULATION_NAME}.c <<EOF 1788 else if (!config.magic_demand_paged) 1789 return "ldscripts/${EMULATION_NAME}.xn"; 1790EOF 1791fi 1792if test -n "$GENERATE_PIE_SCRIPT" ; then 1793if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then 1794cat >>e${EMULATION_NAME}.c <<EOF 1795 else if (link_info.pie && link_info.combreloc && config.data_bss_contig == TRUE) 1796 return "ldscripts/${EMULATION_NAME}.xdcz"; 1797 else if (link_info.pie && link_info.combreloc) 1798 return "ldscripts/${EMULATION_NAME}.xdc"; 1799EOF 1800fi 1801cat >>e${EMULATION_NAME}.c <<EOF 1802 else if (link_info.pie && config.data_bss_contig == TRUE) 1803 return "ldscripts/${EMULATION_NAME}.xdz"; 1804 else if (link_info.pie) 1805 return "ldscripts/${EMULATION_NAME}.xd"; 1806EOF 1807fi 1808if test -n "$GENERATE_SHLIB_SCRIPT" ; then 1809if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then 1810cat >>e${EMULATION_NAME}.c <<EOF 1811 else if (link_info.shared && link_info.combreloc) 1812 return "ldscripts/${EMULATION_NAME}.xsc"; 1813EOF 1814fi 1815cat >>e${EMULATION_NAME}.c <<EOF 1816 else if (link_info.shared) 1817 return "ldscripts/${EMULATION_NAME}.xs"; 1818EOF 1819fi 1820cat >>e${EMULATION_NAME}.c <<EOF 1821 else if (config.data_bss_contig == TRUE) 1822 return "ldscripts/${EMULATION_NAME}.xz"; 1823EOF 1824if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then 1825cat >>e${EMULATION_NAME}.c <<EOF 1826 else if (link_info.combreloc) 1827 return "ldscripts/${EMULATION_NAME}.xc"; 1828EOF 1829fi 1830cat >>e${EMULATION_NAME}.c <<EOF 1831 else 1832 return "ldscripts/${EMULATION_NAME}.x"; 1833} 1834 1835EOF 1836fi 1837fi 1838 1839if test -n "$PARSE_AND_LIST_ARGS_CASES" -o x"$GENERATE_SHLIB_SCRIPT" = xyes; then 1840 1841if test -n "$PARSE_AND_LIST_PROLOGUE" ; then 1842cat >>e${EMULATION_NAME}.c <<EOF 1843 $PARSE_AND_LIST_PROLOGUE 1844EOF 1845fi 1846 1847cat >>e${EMULATION_NAME}.c <<EOF 1848 1849#define OPTION_DISABLE_NEW_DTAGS (400) 1850#define OPTION_ENABLE_NEW_DTAGS (OPTION_DISABLE_NEW_DTAGS + 1) 1851#define OPTION_GROUP (OPTION_ENABLE_NEW_DTAGS + 1) 1852#define OPTION_EH_FRAME_HDR (OPTION_GROUP + 1) 1853 1854static void 1855gld${EMULATION_NAME}_add_options 1856 (int ns, char **shortopts, int nl, struct option **longopts, 1857 int nrl ATTRIBUTE_UNUSED, struct option **really_longopts ATTRIBUTE_UNUSED) 1858{ 1859 static const char xtra_short[] = "${PARSE_AND_LIST_SHORTOPTS}z:"; 1860 static const struct option xtra_long[] = { 1861EOF 1862 1863if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then 1864cat >>e${EMULATION_NAME}.c <<EOF 1865 {"disable-new-dtags", no_argument, NULL, OPTION_DISABLE_NEW_DTAGS}, 1866 {"enable-new-dtags", no_argument, NULL, OPTION_ENABLE_NEW_DTAGS}, 1867 {"eh-frame-hdr", no_argument, NULL, OPTION_EH_FRAME_HDR}, 1868 {"Bgroup", no_argument, NULL, OPTION_GROUP}, 1869EOF 1870fi 1871 1872if test -n "$PARSE_AND_LIST_LONGOPTS" ; then 1873cat >>e${EMULATION_NAME}.c <<EOF 1874 $PARSE_AND_LIST_LONGOPTS 1875EOF 1876fi 1877 1878cat >>e${EMULATION_NAME}.c <<EOF 1879 {NULL, no_argument, NULL, 0} 1880 }; 1881 1882 *shortopts = (char *) xrealloc (*shortopts, ns + sizeof (xtra_short)); 1883 memcpy (*shortopts + ns, &xtra_short, sizeof (xtra_short)); 1884 *longopts = (struct option *) 1885 xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long)); 1886 memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long)); 1887} 1888 1889static bfd_boolean 1890gld${EMULATION_NAME}_handle_option (int optc) 1891{ 1892 switch (optc) 1893 { 1894 default: 1895 return FALSE; 1896 1897EOF 1898 1899if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then 1900cat >>e${EMULATION_NAME}.c <<EOF 1901 case OPTION_DISABLE_NEW_DTAGS: 1902 link_info.new_dtags = FALSE; 1903 break; 1904 1905 case OPTION_ENABLE_NEW_DTAGS: 1906 link_info.new_dtags = TRUE; 1907 break; 1908 1909 case OPTION_EH_FRAME_HDR: 1910 link_info.eh_frame_hdr = TRUE; 1911 break; 1912 1913 case OPTION_GROUP: 1914 link_info.flags_1 |= (bfd_vma) DF_1_GROUP; 1915 /* Groups must be self-contained. */ 1916 link_info.unresolved_syms_in_objects = RM_GENERATE_ERROR; 1917 link_info.unresolved_syms_in_shared_libs = RM_GENERATE_ERROR; 1918 break; 1919 1920 case 'z': 1921 if (strcmp (optarg, "initfirst") == 0) 1922 link_info.flags_1 |= (bfd_vma) DF_1_INITFIRST; 1923 else if (strcmp (optarg, "interpose") == 0) 1924 link_info.flags_1 |= (bfd_vma) DF_1_INTERPOSE; 1925 else if (strcmp (optarg, "loadfltr") == 0) 1926 link_info.flags_1 |= (bfd_vma) DF_1_LOADFLTR; 1927 else if (strcmp (optarg, "nodefaultlib") == 0) 1928 link_info.flags_1 |= (bfd_vma) DF_1_NODEFLIB; 1929 else if (strcmp (optarg, "nodelete") == 0) 1930 link_info.flags_1 |= (bfd_vma) DF_1_NODELETE; 1931 else if (strcmp (optarg, "nodlopen") == 0) 1932 link_info.flags_1 |= (bfd_vma) DF_1_NOOPEN; 1933 else if (strcmp (optarg, "nodump") == 0) 1934 link_info.flags_1 |= (bfd_vma) DF_1_NODUMP; 1935 else if (strcmp (optarg, "now") == 0) 1936 { 1937 link_info.flags |= (bfd_vma) DF_BIND_NOW; 1938 link_info.flags_1 |= (bfd_vma) DF_1_NOW; 1939 } 1940 else if (strcmp (optarg, "origin") == 0) 1941 { 1942 link_info.flags |= (bfd_vma) DF_ORIGIN; 1943 link_info.flags_1 |= (bfd_vma) DF_1_ORIGIN; 1944 } 1945 else if (strcmp (optarg, "defs") == 0) 1946 link_info.unresolved_syms_in_objects = RM_GENERATE_ERROR; 1947 else if (strcmp (optarg, "muldefs") == 0) 1948 link_info.allow_multiple_definition = TRUE; 1949 else if (strcmp (optarg, "combreloc") == 0) 1950 link_info.combreloc = TRUE; 1951 else if (strcmp (optarg, "nocombreloc") == 0) 1952 link_info.combreloc = FALSE; 1953 else if (strcmp (optarg, "nocopyreloc") == 0) 1954 link_info.nocopyreloc = TRUE; 1955 else if (strcmp (optarg, "execstack") == 0) 1956 { 1957 link_info.execstack = TRUE; 1958 link_info.noexecstack = FALSE; 1959 } 1960 else if (strcmp (optarg, "noexecstack") == 0) 1961 { 1962 link_info.noexecstack = TRUE; 1963 link_info.execstack = FALSE; 1964 } 1965 /* What about the other Solaris -z options? FIXME. */ 1966 break; 1967EOF 1968fi 1969 1970if test -n "$PARSE_AND_LIST_ARGS_CASES" ; then 1971cat >>e${EMULATION_NAME}.c <<EOF 1972 $PARSE_AND_LIST_ARGS_CASES 1973EOF 1974fi 1975 1976cat >>e${EMULATION_NAME}.c <<EOF 1977 } 1978 1979 return TRUE; 1980} 1981 1982EOF 1983 1984if test x"$LDEMUL_LIST_OPTIONS" != xgld"$EMULATION_NAME"_list_options; then 1985cat >>e${EMULATION_NAME}.c <<EOF 1986 1987static void 1988gld${EMULATION_NAME}_list_options (FILE * file) 1989{ 1990EOF 1991 1992if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then 1993cat >>e${EMULATION_NAME}.c <<EOF 1994 fprintf (file, _(" -Bgroup\t\tSelects group name lookup rules for DSO\n")); 1995 fprintf (file, _(" --disable-new-dtags\tDisable new dynamic tags\n")); 1996 fprintf (file, _(" --enable-new-dtags\tEnable new dynamic tags\n")); 1997 fprintf (file, _(" --eh-frame-hdr\tCreate .eh_frame_hdr section\n")); 1998 fprintf (file, _(" -z combreloc\t\tMerge dynamic relocs into one section and sort\n")); 1999 fprintf (file, _(" -z defs\t\tReport unresolved symbols in object files.\n")); 2000 fprintf (file, _(" -z execstack\t\tMark executable as requiring executable stack\n")); 2001 fprintf (file, _(" -z initfirst\t\tMark DSO to be initialized first at runtime\n")); 2002 fprintf (file, _(" -z interpose\t\tMark object to interpose all DSOs but executable\n")); 2003 fprintf (file, _(" -z loadfltr\t\tMark object requiring immediate process\n")); 2004 fprintf (file, _(" -z muldefs\t\tAllow multiple definitions\n")); 2005 fprintf (file, _(" -z nocombreloc\tDon't merge dynamic relocs into one section\n")); 2006 fprintf (file, _(" -z nocopyreloc\tDon't create copy relocs\n")); 2007 fprintf (file, _(" -z nodefaultlib\tMark object not to use default search paths\n")); 2008 fprintf (file, _(" -z nodelete\t\tMark DSO non-deletable at runtime\n")); 2009 fprintf (file, _(" -z nodlopen\t\tMark DSO not available to dlopen\n")); 2010 fprintf (file, _(" -z nodump\t\tMark DSO not available to dldump\n")); 2011 fprintf (file, _(" -z noexecstack\tMark executable as not requiring executable stack\n")); 2012 fprintf (file, _(" -z now\t\tMark object non-lazy runtime binding\n")); 2013 fprintf (file, _(" -z origin\t\tMark object requiring immediate \$ORIGIN processing\n\t\t\t at runtime\n")); 2014 fprintf (file, _(" -z KEYWORD\t\tIgnored for Solaris compatibility\n")); 2015EOF 2016fi 2017 2018if test -n "$PARSE_AND_LIST_OPTIONS" ; then 2019cat >>e${EMULATION_NAME}.c <<EOF 2020 $PARSE_AND_LIST_OPTIONS 2021EOF 2022fi 2023 2024cat >>e${EMULATION_NAME}.c <<EOF 2025} 2026EOF 2027 2028if test -n "$PARSE_AND_LIST_EPILOGUE" ; then 2029cat >>e${EMULATION_NAME}.c <<EOF 2030 $PARSE_AND_LIST_EPILOGUE 2031EOF 2032fi 2033fi 2034else 2035cat >>e${EMULATION_NAME}.c <<EOF 2036#define gld${EMULATION_NAME}_add_options NULL 2037#define gld${EMULATION_NAME}_handle_option NULL 2038EOF 2039if test x"$LDEMUL_LIST_OPTIONS" != xgld"$EMULATION_NAME"_list_options; then 2040cat >>e${EMULATION_NAME}.c <<EOF 2041#define gld${EMULATION_NAME}_list_options NULL 2042EOF 2043fi 2044fi 2045 2046cat >>e${EMULATION_NAME}.c <<EOF 2047 2048struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation = 2049{ 2050 ${LDEMUL_BEFORE_PARSE-gld${EMULATION_NAME}_before_parse}, 2051 ${LDEMUL_SYSLIB-syslib_default}, 2052 ${LDEMUL_HLL-hll_default}, 2053 ${LDEMUL_AFTER_PARSE-after_parse_default}, 2054 ${LDEMUL_AFTER_OPEN-gld${EMULATION_NAME}_after_open}, 2055 ${LDEMUL_AFTER_ALLOCATION-after_allocation_default}, 2056 ${LDEMUL_SET_OUTPUT_ARCH-set_output_arch_default}, 2057 ${LDEMUL_CHOOSE_TARGET-ldemul_default_target}, 2058 ${LDEMUL_BEFORE_ALLOCATION-gld${EMULATION_NAME}_before_allocation}, 2059 ${LDEMUL_GET_SCRIPT-gld${EMULATION_NAME}_get_script}, 2060 "${EMULATION_NAME}", 2061 "${OUTPUT_FORMAT}", 2062 ${LDEMUL_FINISH-gld${EMULATION_NAME}_finish}, 2063 ${LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS-NULL}, 2064 ${LDEMUL_OPEN_DYNAMIC_ARCHIVE-gld${EMULATION_NAME}_open_dynamic_archive}, 2065 ${LDEMUL_PLACE_ORPHAN-gld${EMULATION_NAME}_place_orphan}, 2066 ${LDEMUL_SET_SYMBOLS-NULL}, 2067 ${LDEMUL_PARSE_ARGS-NULL}, 2068 gld${EMULATION_NAME}_add_options, 2069 gld${EMULATION_NAME}_handle_option, 2070 ${LDEMUL_UNRECOGNIZED_FILE-NULL}, 2071 ${LDEMUL_LIST_OPTIONS-gld${EMULATION_NAME}_list_options}, 2072 ${LDEMUL_RECOGNIZED_FILE-gld${EMULATION_NAME}_load_symbols}, 2073 ${LDEMUL_FIND_POTENTIAL_LIBRARIES-NULL}, 2074 ${LDEMUL_NEW_VERS_PATTERN-NULL} 2075}; 2076EOF 2077