ld.c revision 87cf5834841d0d85277234138b53aba032015ca8
144173edad1dfd24c4d98fcf032308f7df28db652Ulrich Drepper/* Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009 Red Hat, Inc. 2361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper This file is part of Red Hat elfutils. 3b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper Written by Ulrich Drepper <drepper@redhat.com>, 2001. 4b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 5361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper Red Hat elfutils is free software; you can redistribute it and/or modify 6361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper it under the terms of the GNU General Public License as published by the 7361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper Free Software Foundation; version 2 of the License. 8361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper 9361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper Red Hat elfutils is distributed in the hope that it will be useful, but 10361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper WITHOUT ANY WARRANTY; without even the implied warranty of 11361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper General Public License for more details. 13361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper 14361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper You should have received a copy of the GNU General Public License along 15361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper with Red Hat elfutils; if not, write to the Free Software Foundation, 161e9ef50681e20ef14c2ba38aef37a71ff148be08Ulrich Drepper Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA. 17361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper 18361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper Red Hat elfutils is an included package of the Open Invention Network. 19361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper An included package of the Open Invention Network is a package for which 20361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper Open Invention Network licensees cross-license their patents. No patent 21361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper license is granted, either expressly or impliedly, by designation as an 22361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper included package. Should you wish to participate in the Open Invention 23361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper Network licensing program, please visit www.openinventionnetwork.com 24361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper <http://www.openinventionnetwork.com>. */ 25b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 26b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#ifdef HAVE_CONFIG_H 27b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper# include <config.h> 28b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#endif 29b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 30b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#include <argp.h> 31b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#include <assert.h> 32b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#include <error.h> 33b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#include <fcntl.h> 34b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#include <libelf.h> 35b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#include <libintl.h> 36b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#include <locale.h> 37b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#include <mcheck.h> 38b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#include <stdio.h> 39b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#include <stdio_ext.h> 40b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#include <stdlib.h> 41b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#include <string.h> 42b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#include <unistd.h> 43b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 44b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#include <system.h> 45b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#include "ld.h" 46b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#include "list.h" 47b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 48b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 49b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Name and version of program. */ 50b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic void print_version (FILE *stream, struct argp_state *state); 51b08d5a8fb42f4586d756068065186b5af7e48daUlrich Dreppervoid (*argp_program_version_hook) (FILE *, struct argp_state *) = print_version; 52b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 53b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Bug report address. */ 54b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperconst char *argp_program_bug_address = PACKAGE_BUGREPORT; 55b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 56b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 57b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Values for the various options. */ 58b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperenum 59b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 60b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ARGP_whole_archive = 300, 61b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ARGP_no_whole_archive, 62b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ARGP_static, 63b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ARGP_dynamic, 64b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ARGP_pagesize, 65b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ARGP_rpath_link, 66b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ARGP_runpath, 67b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ARGP_runpath_link, 68b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ARGP_version_script, 69b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ARGP_gc_sections, 70b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ARGP_no_gc_sections, 71b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ARGP_no_undefined, 72b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ARGP_conserve, 738c56fe3b2c753234beb6f58a81c8b96f008226efUlrich Drepper ARGP_as_needed, 748c56fe3b2c753234beb6f58a81c8b96f008226efUlrich Drepper ARGP_no_as_needed, 7554f33a779527d6764b4fc4068267715a718c422cUlrich Drepper ARGP_eh_frame_hdr, 760e864dd86871c809668c557985ca19344dfff787Ulrich Drepper ARGP_hash_style, 7789759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper ARGP_build_id, 78b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#if YYDEBUG 79b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ARGP_yydebug, 80b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#endif 81b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper }; 82b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 83b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 84b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Definitions of arguments for argp functions. */ 85b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic const struct argp_option options[] = 86b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 87cbb51e5253e05d98af8bdaf2217fed00b2e489b9Ulrich Drepper { NULL, 0, NULL, 0, N_("Input File Control:"), 0 }, 88b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { "whole-archive", ARGP_whole_archive, NULL, 0, 89b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper N_("Include whole archives in the output from now on."), 0 }, 90b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { "no-whole-archive", ARGP_no_whole_archive, NULL, 0, 91b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper N_("Stop including the whole arhives in the output."), 0 }, 92cbb51e5253e05d98af8bdaf2217fed00b2e489b9Ulrich Drepper { NULL, 'l', N_("FILE"), OPTION_HIDDEN, NULL, 0 }, 93d9488292be8c78615163eb4733e105143cb7b7baUlrich Drepper { "start-group", '(', NULL, 0, N_("Start a group."), 0 }, 94d9488292be8c78615163eb4733e105143cb7b7baUlrich Drepper { "end-group", ')', NULL, 0, N_("End a group."), 0 }, 95cbb51e5253e05d98af8bdaf2217fed00b2e489b9Ulrich Drepper { NULL, 'L', N_("PATH"), 0, 96cbb51e5253e05d98af8bdaf2217fed00b2e489b9Ulrich Drepper N_("Add PATH to list of directories files are searched in."), 0 }, 97cbb51e5253e05d98af8bdaf2217fed00b2e489b9Ulrich Drepper { "as-needed", ARGP_as_needed, NULL, 0, 98cbb51e5253e05d98af8bdaf2217fed00b2e489b9Ulrich Drepper N_("Only set DT_NEEDED for following dynamic libs if actually used"), 0 }, 99cbb51e5253e05d98af8bdaf2217fed00b2e489b9Ulrich Drepper { "no-as-needed", ARGP_no_as_needed, NULL, 0, 100cbb51e5253e05d98af8bdaf2217fed00b2e489b9Ulrich Drepper N_("Always set DT_NEEDED for following dynamic libs"), 0 }, 101cbb51e5253e05d98af8bdaf2217fed00b2e489b9Ulrich Drepper { "rpath-link", ARGP_rpath_link, "PATH", OPTION_HIDDEN, NULL, 0 }, 102cbb51e5253e05d98af8bdaf2217fed00b2e489b9Ulrich Drepper { NULL, 'i', NULL, 0, N_("Ignore LD_LIBRARY_PATH environment variable."), 103cbb51e5253e05d98af8bdaf2217fed00b2e489b9Ulrich Drepper 0 }, 104b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 105cbb51e5253e05d98af8bdaf2217fed00b2e489b9Ulrich Drepper { NULL, 0, NULL, 0, N_("Output File Control:"), 0 }, 106b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { "output", 'o', N_("FILE"), 0, N_("Place output in FILE."), 0 }, 107b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { NULL, 'z', "KEYWORD", OPTION_HIDDEN, NULL, 0 }, 108b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { "-z nodefaultlib", '\0', NULL, OPTION_DOC, 109b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper N_("Object is marked to not use default search path at runtime."), 0 }, 110b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { "-z allextract", '\0', NULL, OPTION_DOC, 111b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper N_("Same as --whole-archive."), 0 }, 112b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { "-z defaultextract", '\0', NULL, OPTION_DOC, N_("\ 113b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperDefault rules of extracting from archive; weak references are not enough."), 114b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 0 }, 115b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { "-z weakextract", '\0', NULL, OPTION_DOC, 116b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper N_("Weak references cause extraction from archive."), 0 }, 117b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { "-z muldefs", '\0', NULL, OPTION_DOC, 118b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper N_("Allow multiple definitions; first is used."), 0 }, 119b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { "-z defs | nodefs", '\0', NULL, OPTION_DOC, 120b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper N_("Disallow/allow undefined symbols in DSOs."), 0 }, 121b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { "no-undefined", ARGP_no_undefined, NULL, OPTION_HIDDEN, NULL, 0 }, 122b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { "-z origin", '\0', NULL, OPTION_DOC, 123b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper N_("Object requires immediate handling of $ORIGIN."), 0 }, 124b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { "-z now", '\0', NULL, OPTION_DOC, 125b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper N_("Relocation will not be processed lazily."), 0 }, 126b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { "-z nodelete", '\0', NULL, OPTION_DOC, 127b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper N_("Object cannot be unloaded at runtime."), 0 }, 128b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { "-z initfirst", '\0', NULL, OPTION_DOC, 129b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper N_("Mark object to be initialized first."), 0 }, 130b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { "-z lazyload | nolazyload", '\0', NULL, OPTION_DOC, 131b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper N_("Enable/disable lazy-loading flag for following dependencies."), 0 }, 132b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { "-z nodlopen", '\0', NULL, OPTION_DOC, 133b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper N_("Mark object as not loadable with 'dlopen'."), 0 }, 134b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { "-z ignore | record", '\0', NULL, OPTION_DOC, 135b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper N_("Ignore/record dependencies on unused DSOs."), 0 }, 136b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { "-z systemlibrary", '\0', NULL, OPTION_DOC, 137b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper N_("Generated DSO will be a system library."), 0 }, 138b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { "entry", 'e', N_("ADDRESS"), 0, N_("Set entry point address."), 0 }, 139b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { "static", ARGP_static, NULL, OPTION_HIDDEN, NULL, 0 }, 140b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { "-B static", ARGP_static, NULL, OPTION_DOC, 141b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper N_("Do not link against shared libraries."), 0 }, 142b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { "dynamic", ARGP_dynamic, NULL, OPTION_HIDDEN, NULL, 0 }, 143b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { "-B dynamic", ARGP_dynamic, NULL, OPTION_DOC, 144b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper N_("Prefer linking against shared libraries."), 0 }, 145b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { "export-dynamic", 'E', NULL, 0, N_("Export all dynamic symbols."), 0 }, 146b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { "strip-all", 's', NULL, 0, N_("Strip all symbols."), 0 }, 147b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { "strip-debug", 'S', NULL, 0, N_("Strip debugging symbols."), 0 }, 148b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { "pagesize", ARGP_pagesize, "SIZE", 0, 149b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper N_("Assume pagesize for the target system to be SIZE."), 0 }, 150cbb51e5253e05d98af8bdaf2217fed00b2e489b9Ulrich Drepper { "rpath", 'R', "PATH", OPTION_HIDDEN, NULL, 0 }, 151b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { "runpath", ARGP_runpath, "PATH", 0, N_("Set runtime DSO search path."), 152b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 0 }, 153b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { "runpath-link", ARGP_runpath_link, "PATH", 0, 154b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper N_("Set link time DSO search path."), 0 }, 155b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { "shared", 'G', NULL, 0, N_("Generate dynamic shared object."), 0 }, 156b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { NULL, 'r', NULL, 0L, N_("Generate relocatable object."), 0 }, 157b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { NULL, 'B', "KEYWORD", OPTION_HIDDEN, "", 0 }, 158b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { "-B local", 'B', NULL, OPTION_DOC, 159b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper N_("Causes symbol not assigned to a version be reduced to local."), 0 }, 160b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { "gc-sections", ARGP_gc_sections, NULL, 0, N_("Remove unused sections."), 161b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 0 }, 162b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { "no-gc-sections", ARGP_no_gc_sections, NULL, 0, 163b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper N_("Don't remove unused sections."), 0 }, 164b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { "soname", 'h', "NAME", 0, N_("Set soname of shared object."), 0 }, 165b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { "dynamic-linker", 'I', "NAME", 0, N_("Set the dynamic linker name."), 0 }, 166b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { NULL, 'Q', "YN", OPTION_HIDDEN, NULL, 0 }, 167b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { "-Q y | n", 'Q', NULL, OPTION_DOC, 16889759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper N_("Add/suppress addition indentifying link-editor to .comment section."), 169b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 0 }, 17054f33a779527d6764b4fc4068267715a718c422cUlrich Drepper { "eh-frame-hdr", ARGP_eh_frame_hdr, NULL, 0, 17154f33a779527d6764b4fc4068267715a718c422cUlrich Drepper N_("Create .eh_frame_hdr section"), 0 }, 1720e864dd86871c809668c557985ca19344dfff787Ulrich Drepper { "hash-style", ARGP_hash_style, "STYLE", 0, 1730e864dd86871c809668c557985ca19344dfff787Ulrich Drepper N_("Set hash style to sysv, gnu or both."), 0 }, 17489759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper { "build-id", ARGP_build_id, "STYLE", OPTION_ARG_OPTIONAL, 175c54785af87adcac067f90b1dbc238c29062cf683Ulrich Drepper N_("Generate build ID note (md5, sha1 (default), uuid)."), 0 }, 17654f33a779527d6764b4fc4068267715a718c422cUlrich Drepper 177cbb51e5253e05d98af8bdaf2217fed00b2e489b9Ulrich Drepper { NULL, 0, NULL, 0, N_("Linker Operation Control:"), 0 }, 178cbb51e5253e05d98af8bdaf2217fed00b2e489b9Ulrich Drepper { "verbose", 'v', NULL, 0, N_("Verbose messages."), 0 }, 179cbb51e5253e05d98af8bdaf2217fed00b2e489b9Ulrich Drepper { "trace", 't', NULL, 0, N_("Trace file opens."), 0 }, 180cbb51e5253e05d98af8bdaf2217fed00b2e489b9Ulrich Drepper { "conserve-memory", ARGP_conserve, NULL, 0, 181cbb51e5253e05d98af8bdaf2217fed00b2e489b9Ulrich Drepper N_("Trade speed for less memory usage"), 0 }, 182cbb51e5253e05d98af8bdaf2217fed00b2e489b9Ulrich Drepper { NULL, 'O', N_("LEVEL"), OPTION_ARG_OPTIONAL, 183cbb51e5253e05d98af8bdaf2217fed00b2e489b9Ulrich Drepper N_("Set optimization level to LEVEL."), 0 }, 184cbb51e5253e05d98af8bdaf2217fed00b2e489b9Ulrich Drepper { NULL, 'c', N_("FILE"), 0, N_("Use linker script in FILE."), 0 }, 185b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#if YYDEBUG 186b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { "yydebug", ARGP_yydebug, NULL, 0, 187b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper N_("Select to get parser debug information"), 0 }, 188b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#endif 189cbb51e5253e05d98af8bdaf2217fed00b2e489b9Ulrich Drepper { "version-script", ARGP_version_script, "FILE", 0, 190cbb51e5253e05d98af8bdaf2217fed00b2e489b9Ulrich Drepper N_("Read version information from FILE."), 0 }, 191cbb51e5253e05d98af8bdaf2217fed00b2e489b9Ulrich Drepper { "emulation", 'm', "NAME", 0, N_("Set emulation to NAME."), 0 }, 192b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 193b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { NULL, 0, NULL, 0, NULL, 0 } 194b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper}; 195b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 196b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Short description of program. */ 197b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic const char doc[] = N_("Combine object and archive files."); 198b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 199b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Strings for arguments in help texts. */ 200b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic const char args_doc[] = N_("[FILE]..."); 201b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 202b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Prototype for option handler. */ 203b61c4cc4ab5d61d5d7c1a31e700bff8ad39fa079Ulrich Drepperstatic void replace_args (int argc, char *argv[]); 204b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic error_t parse_opt_1st (int key, char *arg, struct argp_state *state); 205b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic error_t parse_opt_2nd (int key, char *arg, struct argp_state *state); 206b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 207b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Data structure to communicate with argp functions. */ 208b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic struct argp argp_1st = 209b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 210b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper options, parse_opt_1st, args_doc, doc, NULL, NULL, NULL 211b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper}; 212b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic struct argp argp_2nd = 213b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 214b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper options, parse_opt_2nd, args_doc, doc, NULL, NULL, NULL 215b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper}; 216b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 217b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 218b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Linker state. This contains all global information. */ 219b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstruct ld_state ld_state; 220b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 221b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* List of the input files. */ 222b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic struct file_list 223b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 224b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper const char *name; 225b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct file_list *next; 226b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper} *input_file_list; 227b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 228b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* If nonzero be verbose. */ 229b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperint verbose; 230b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 231b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* If nonzero, trade speed for less memory/address space usage. */ 232b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperint conserve_memory; 233b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 234b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* The emulation name to use. */ 235b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic const char *emulation; 236b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 237b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Keep track of the nesting level. Even though we don't handle nested 238b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper groups we still keep track to improve the error messages. */ 239b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic int group_level; 240b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 241b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* The last file we processed. */ 242b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic struct usedfiles *last_file; 243b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 244b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* The default linker script. */ 245b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* XXX We'll do this a bit different in the real solution. */ 246b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic const char *linker_script = SRCDIR "/elf32-i386.script"; 247b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 248b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Nonzero if an error occurred while loading the input files. */ 249b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic int error_loading; 250b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 251b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 252b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Intermediate storage for the LD_LIBRARY_PATH information from the 253b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper environment. */ 254b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic char *ld_library_path1; 255b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 256b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Flag used to communicate with the scanner. */ 257b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperint ld_scan_version_script; 258b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 259b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Name of the input file. */ 260b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperconst char *ldin_fname; 261b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 262b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Define by parser if required. */ 263b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern int lddebug; 264b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 265b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 266b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Prototypes for local functions. */ 267b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic void parse_z_option (const char *arg); 268b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic void parse_z_option_2 (const char *arg); 269b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic void parse_B_option (const char *arg); 270b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic void parse_B_option_2 (const char *arg); 271b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic void determine_output_format (void); 272b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic void load_needed (void); 273b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic void collect_sections (void); 274b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic void add_rxxpath (struct pathelement **pathp, const char *str); 275b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic void gen_rxxpath_data (void); 276b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic void read_version_script (const char *fname); 277b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic void create_lscript_symbols (void); 278b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic void create_special_section_symbol (struct symbol **symp, 279b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper const char *name); 280b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 281b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 282b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperint 283b08d5a8fb42f4586d756068065186b5af7e48daUlrich Dreppermain (int argc, char *argv[]) 284b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 285b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper int remaining; 286b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper int err; 287b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 288b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#ifndef NDEBUG 289b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Enable memory debugging. */ 290b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper mtrace (); 291b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#endif 292b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 293b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Sanity check. We always want to use the LFS functionality. */ 294b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (sizeof (off_t) != sizeof (off64_t)) 295b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper abort (); 296b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 297b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* We use no threads here which can interfere with handling a stream. */ 298b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper __fsetlocking (stdin, FSETLOCKING_BYCALLER); 299b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper __fsetlocking (stdout, FSETLOCKING_BYCALLER); 300b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper __fsetlocking (stderr, FSETLOCKING_BYCALLER); 301b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 302b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Set locale. */ 303b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper setlocale (LC_ALL, ""); 304b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 305b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Make sure the message catalog can be found. */ 306b0243863149acde9e42b25688c7c2959830e69a9Ulrich Drepper bindtextdomain (PACKAGE_TARNAME, LOCALEDIR); 307b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 308b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Initialize the message catalog. */ 309b0243863149acde9e42b25688c7c2959830e69a9Ulrich Drepper textdomain (PACKAGE_TARNAME); 310b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 311b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Before we start tell the ELF library which version we are using. */ 312b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper elf_version (EV_CURRENT); 313b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 314b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* The user can use the LD_LIBRARY_PATH environment variable to add 315b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper additional lookup directories. */ 316b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_library_path1 = getenv ("LD_LIBRARY_PATH"); 317b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 318b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Initialize the memory handling. */ 319b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#define obstack_chunk_alloc xmalloc 320b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#define obstack_chunk_free free 321b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper obstack_init (&ld_state.smem); 322b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 323b61c4cc4ab5d61d5d7c1a31e700bff8ad39fa079Ulrich Drepper /* Recognize old-style parameters for compatibility. */ 324b61c4cc4ab5d61d5d7c1a31e700bff8ad39fa079Ulrich Drepper replace_args (argc, argv); 325b61c4cc4ab5d61d5d7c1a31e700bff8ad39fa079Ulrich Drepper 326b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* One quick pass over the parameters which allows us to scan for options 327b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper with global effect which influence the rest of the processing. */ 328b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper argp_parse (&argp_1st, argc, argv, ARGP_IN_ORDER, &remaining, NULL); 329b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 330b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* We need at least one input file. */ 331b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (input_file_list == NULL) 332b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 333b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper error (0, 0, gettext ("At least one input file needed")); 334b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper argp_help (&argp_1st, stderr, ARGP_HELP_SEE, "ld"); 335b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper exit (EXIT_FAILURE); 336b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 337b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 338b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Determine which ELF backend to use. */ 339b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper determine_output_format (); 340b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 3410e864dd86871c809668c557985ca19344dfff787Ulrich Drepper /* If no hash style was specific default to the oldand slow SysV 3420e864dd86871c809668c557985ca19344dfff787Ulrich Drepper method. */ 3430e864dd86871c809668c557985ca19344dfff787Ulrich Drepper if (unlikely (ld_state.hash_style == hash_style_none)) 3440e864dd86871c809668c557985ca19344dfff787Ulrich Drepper ld_state.hash_style = hash_style_sysv; 3450e864dd86871c809668c557985ca19344dfff787Ulrich Drepper 346b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Prepare state. */ 347b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper err = ld_prepare_state (emulation); 348b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (err != 0) 349b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper error (EXIT_FAILURE, 0, gettext ("error while preparing linking")); 350b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 351b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* XXX Read the linker script now. Since we later will have the linker 352b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper script built in we don't go into trouble to make sure we handle GROUP 353b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper statements in the script. This simply must not happen. */ 354b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ldin = fopen (linker_script, "r"); 355b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (ldin == NULL) 356e3f9b7db6c7361579ec5cc5eb5e414f7e93baeb6Ulrich Drepper error (EXIT_FAILURE, errno, gettext ("cannot open linker script '%s'"), 357b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper linker_script); 358b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* No need for locking. */ 359b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper __fsetlocking (ldin, FSETLOCKING_BYCALLER); 360b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 361b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.srcfiles = NULL; 362b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ldlineno = 1; 363b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_scan_version_script = 0; 364b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ldin_fname = linker_script; 365b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (ldparse () != 0) 366b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Something went wrong during parsing. */ 367b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper exit (EXIT_FAILURE); 368b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper fclose (ldin); 369b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 370b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* We now might have a list of directories to look for libraries in 371b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper named by the linker script. Put them in a different list so that 372b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper they are searched after all paths given by the user on the 373b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper command line. */ 374b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.default_paths = ld_state.paths; 375b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.paths = ld_state.tailpaths = NULL; 376b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 377b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Get runpath/rpath information in usable form. */ 378b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper gen_rxxpath_data (); 379b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 380b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Parse and process arguments for real. */ 381b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper argp_parse (&argp_2nd, argc, argv, ARGP_IN_ORDER, &remaining, NULL); 382b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* All options should have been processed by the argp parser. */ 383b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper assert (remaining == argc); 384b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 385b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Process the last file. */ 386b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper while (last_file != NULL) 387b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Try to open the file. */ 388b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper error_loading |= FILE_PROCESS (-1, last_file, &ld_state, &last_file); 389b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 390b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Stop if there has been a problem while reading the input files. */ 391b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (error_loading) 392b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper exit (error_loading); 393b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 394b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* See whether all opened -( were closed. */ 395b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (group_level > 0) 396b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 397b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper error (0, 0, gettext ("-( without matching -)")); 398b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper argp_help (&argp_1st, stderr, ARGP_HELP_SEE, "ld"); 399b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper exit (EXIT_FAILURE); 400b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 401b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 402b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* When we create a relocatable file we don't have to look for the 403b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DT_NEEDED DSOs and we also don't test for undefined symbols. */ 404b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (ld_state.file_type != relocatable_file_type) 405b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 406b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* At this point we have loaded all the direct dependencies. What 407b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper remains to be done is find the indirect dependencies. These are 408b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper DSOs which are referenced by the DT_NEEDED entries in the DSOs 409b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper which are direct dependencies. We have to transitively find and 410b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper load all these dependencies. */ 411b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper load_needed (); 412b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 413b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* At this point all object files and DSOs are read. If there 414b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper are still undefined symbols left they might have to be 415b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper synthesized from the linker script. */ 416b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper create_lscript_symbols (); 417b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 418b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Now that we have loaded all the object files we can determine 419b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper whether we have any non-weak unresolved references left. If 420b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper there are any we stop. If the user used the '-z nodefs' option 421b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper and we are creating a DSO don't perform the tests. */ 422b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (FLAG_UNRESOLVED (&ld_state) != 0) 423b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper exit (1); 424b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 425b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 426b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Collect information about the relocations which will be carried 427b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper forward into the output. We have to do this here and now since 428b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper we need to know which sections have to be created. */ 429b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (ld_state.file_type != relocatable_file_type) 430b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 431b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper void *p ; 432b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct scnhead *h; 433b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 434b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper p = NULL; 435b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper while ((h = ld_section_tab_iterate (&ld_state.section_tab, &p)) != NULL) 436b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (h->type == SHT_REL || h->type == SHT_RELA) 437b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 438b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct scninfo *runp = h->last; 439b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper do 440b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 441b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* If we are processing the relocations determine how 442b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper many will be in the output file. Also determine 443b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper how many GOT entries are needed. */ 444b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper COUNT_RELOCATIONS (&ld_state, runp); 445b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 446b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.relsize_total += runp->relsize; 447b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 448b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper while ((runp = runp->next) != h->last); 449b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 450b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 451b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 452b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Not part of the gABI, but part of every psABI: the symbols for the 453b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper GOT section. Add the symbol if necessary. */ 454b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (ld_state.need_got) 455b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper create_special_section_symbol (&ld_state.got_symbol, 456b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper "_GLOBAL_OFFSET_TABLE_"); 457b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Similarly for the _DYNAMIC symbol which points to the dynamic 458b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper section. */ 459b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (dynamically_linked_p ()) 460b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper create_special_section_symbol (&ld_state.dyn_symbol, "_DYNAMIC"); 461b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 462b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* We are ready to start working on the output file. Not all 463b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper information has been gather or created yet. This will be done as 464b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper we go. Open the file now. */ 465b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (OPEN_OUTFILE (&ld_state, EM_NONE, ELFCLASSNONE, ELFDATANONE) != 0) 466b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper exit (1); 467b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 468b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Create the sections which are generated by the linker and are not 469b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper present in the input file. The output file must already have 470b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper been opened since we need the ELF descriptor to deduce type 471b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper sizes. */ 472b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper GENERATE_SECTIONS (&ld_state); 473b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 474b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* At this point we have read all the files and know all the 475b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper sections which have to be linked into the application. We do now 476b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper create an array listing all the sections. We will than pass this 477b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper array to a system specific function which can reorder it at will. 478b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper The functions can also merge sections if this is what is 479b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper wanted. */ 480b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper collect_sections (); 481b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 482b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Create the output sections now. This may requires sorting them 483b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper first. */ 484b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper CREATE_SECTIONS (&ld_state); 485b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 486b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Create the output file data. Appropriate code for the selected 487b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper output file type is called. */ 488b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (CREATE_OUTFILE (&ld_state) != 0) 489b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper exit (1); 490b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 491b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Finalize the output file, write the data out. */ 492b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper err |= FINALIZE (&ld_state); 493b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 494b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Return with an non-zero exit status also if any error message has 495b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper been printed. */ 496b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper return err | (error_message_count != 0); 497b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper} 498b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 499b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 500b61c4cc4ab5d61d5d7c1a31e700bff8ad39fa079Ulrich Drepperstatic void 501b61c4cc4ab5d61d5d7c1a31e700bff8ad39fa079Ulrich Drepperreplace_args (int argc, char *argv[]) 502b61c4cc4ab5d61d5d7c1a31e700bff8ad39fa079Ulrich Drepper{ 503b61c4cc4ab5d61d5d7c1a31e700bff8ad39fa079Ulrich Drepper static const struct 504b61c4cc4ab5d61d5d7c1a31e700bff8ad39fa079Ulrich Drepper { 505b61c4cc4ab5d61d5d7c1a31e700bff8ad39fa079Ulrich Drepper const char *from; 506b61c4cc4ab5d61d5d7c1a31e700bff8ad39fa079Ulrich Drepper const char *to; 507b61c4cc4ab5d61d5d7c1a31e700bff8ad39fa079Ulrich Drepper } args[] = 508b61c4cc4ab5d61d5d7c1a31e700bff8ad39fa079Ulrich Drepper { 509b61c4cc4ab5d61d5d7c1a31e700bff8ad39fa079Ulrich Drepper { "-export-dynamic", "--export-dynamic" }, 510834de6f38901b6add14b6f5f7dda8550638d98ecUlrich Drepper { "-dynamic-linker", "--dynamic-linker" }, 511834de6f38901b6add14b6f5f7dda8550638d98ecUlrich Drepper { "-static", "--static" }, 512b61c4cc4ab5d61d5d7c1a31e700bff8ad39fa079Ulrich Drepper }; 513b61c4cc4ab5d61d5d7c1a31e700bff8ad39fa079Ulrich Drepper const size_t nargs = sizeof (args) / sizeof (args[0]); 514b61c4cc4ab5d61d5d7c1a31e700bff8ad39fa079Ulrich Drepper 515b61c4cc4ab5d61d5d7c1a31e700bff8ad39fa079Ulrich Drepper for (int i = 1; i < argc; ++i) 5167cd1bf7b762f0b7d3b1158e52c800d299ed5333fUlrich Drepper if (argv[i][0] == '-' && islower (argv[i][1]) && argv[i][2] != '\0') 517b61c4cc4ab5d61d5d7c1a31e700bff8ad39fa079Ulrich Drepper for (size_t j = 0; j < nargs; ++j) 518b61c4cc4ab5d61d5d7c1a31e700bff8ad39fa079Ulrich Drepper if (strcmp (argv[i], args[j].from) == 0) 519b61c4cc4ab5d61d5d7c1a31e700bff8ad39fa079Ulrich Drepper { 520b61c4cc4ab5d61d5d7c1a31e700bff8ad39fa079Ulrich Drepper argv[i] = (char *) args[j].to; 521b61c4cc4ab5d61d5d7c1a31e700bff8ad39fa079Ulrich Drepper break; 522b61c4cc4ab5d61d5d7c1a31e700bff8ad39fa079Ulrich Drepper } 523b61c4cc4ab5d61d5d7c1a31e700bff8ad39fa079Ulrich Drepper} 524b61c4cc4ab5d61d5d7c1a31e700bff8ad39fa079Ulrich Drepper 525b61c4cc4ab5d61d5d7c1a31e700bff8ad39fa079Ulrich Drepper 52689759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepperstatic int 52789759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Dreppervalid_hexarg (const char *arg) 52889759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper{ 52989759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper if (strncasecmp (arg, "0x", 2) != 0) 53089759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper return 0; 53189759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper 53289759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper arg += 2; 53389759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper do 53489759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper { 53589759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper if (isxdigit (arg[0]) && isxdigit (arg[1])) 53689759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper { 53789759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper arg += 2; 53889759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper if (arg[0] == '-' || arg[0] == ':') 53989759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper ++arg; 54089759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper } 54189759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper else 54289759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper return 0; 54389759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper } 54489759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper while (*arg != '\0'); 54589759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper 54689759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper return 1; 54789759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper} 54889759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper 54989759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper 550b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Quick scan of the parameter list for options with global effect. */ 551b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic error_t 552b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperparse_opt_1st (int key, char *arg, 553b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct argp_state *state __attribute__ ((unused))) 554b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 555b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper switch (key) 556b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 557b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case 'B': 558b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper parse_B_option (arg); 559b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 560b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 561b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case 'c': 562b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper linker_script = arg; 563b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 564b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 565b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case 'E': 566b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.export_all_dynamic = true; 567b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 568b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 569b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case 'G': 570b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (ld_state.file_type != no_file_type) 571b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper error (EXIT_FAILURE, 0, 572b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper gettext ("only one option of -G and -r is allowed")); 573b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.file_type = dso_file_type; 574b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 575b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* If we generate a DSO we have to export all symbols. */ 576b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.export_all_dynamic = true; 577b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 578b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 579b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case 'h': 580b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.soname = arg; 581b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 582b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 583b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case 'i': 584b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Discard the LD_LIBRARY_PATH value we found. */ 585b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_library_path1 = NULL; 586b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 587b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 588b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case 'I': 589b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.interp = arg; 590b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 591b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 592b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case 'm': 593b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (emulation != NULL) 594b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper error (EXIT_FAILURE, 0, gettext ("more than one '-m' parameter")); 595b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper emulation = arg; 596b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 597b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 598b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case 'Q': 599b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (arg[1] == '\0' && (arg[0] == 'y' || arg[0] == 'Y')) 600b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.add_ld_comment = true; 601b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else if (arg[1] == '\0' && (arg[0] == 'n' || arg[0] == 'N')) 602b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.add_ld_comment = true; 603b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else 604b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper error (EXIT_FAILURE, 0, gettext ("unknown option `-%c %s'"), 'Q', arg); 605b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 606b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 607b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case 'r': 608b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (ld_state.file_type != no_file_type) 609b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper error (EXIT_FAILURE, 0, 610b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper gettext ("only one option of -G and -r is allowed")); 611b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.file_type = relocatable_file_type; 612b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 613b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 614b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case 'S': 615b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.strip = strip_debug; 616b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 617b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 618b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case 't': 619b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.trace_files = true; 620b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 621b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 622b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case 'v': 623b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper verbose = 1; 624b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 625b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 626b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case 'z': 627b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* The SysV linker used 'z' to pass various flags to the linker. 628b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper We follow this. See 'parse_z_option' for the options we 629b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper recognize. */ 630b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper parse_z_option (arg); 631b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 632b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 633b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case ARGP_pagesize: 634b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 635b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper char *endp; 636b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.pagesize = strtoul (arg, &endp, 0); 637b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (*endp != '\0') 638b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 639b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (endp[1] == '\0' && tolower (*endp) == 'k') 640b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.pagesize *= 1024; 641b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else if (endp[1] == '\0' && tolower (*endp) == 'm') 642b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.pagesize *= 1024 * 1024; 643b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else 644b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 645b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper error (0, 0, 646e3f9b7db6c7361579ec5cc5eb5e414f7e93baeb6Ulrich Drepper gettext ("invalid page size value '%s': ignored"), 647b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper arg); 648b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.pagesize = 0; 649b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 650b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 651b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 652b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 653b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 654cbb51e5253e05d98af8bdaf2217fed00b2e489b9Ulrich Drepper case 'R': 655b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper add_rxxpath (&ld_state.rpath, arg); 656b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 657b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 658b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case ARGP_rpath_link: 659b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper add_rxxpath (&ld_state.rpath_link, arg); 660b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 661b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 662b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case ARGP_runpath: 663b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper add_rxxpath (&ld_state.runpath, arg); 664b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 665b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 666b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case ARGP_runpath_link: 667b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper add_rxxpath (&ld_state.runpath_link, arg); 668b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 669b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 670b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case ARGP_gc_sections: 671b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case ARGP_no_gc_sections: 672b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.gc_sections = key == ARGP_gc_sections; 673b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 674b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 67554f33a779527d6764b4fc4068267715a718c422cUlrich Drepper case ARGP_eh_frame_hdr: 67654f33a779527d6764b4fc4068267715a718c422cUlrich Drepper ld_state.eh_frame_hdr = true; 67754f33a779527d6764b4fc4068267715a718c422cUlrich Drepper break; 67854f33a779527d6764b4fc4068267715a718c422cUlrich Drepper 6790e864dd86871c809668c557985ca19344dfff787Ulrich Drepper case ARGP_hash_style: 6800e864dd86871c809668c557985ca19344dfff787Ulrich Drepper if (strcmp (arg, "gnu") == 0) 6810e864dd86871c809668c557985ca19344dfff787Ulrich Drepper ld_state.hash_style = hash_style_gnu; 6820e864dd86871c809668c557985ca19344dfff787Ulrich Drepper else if (strcmp (arg, "both") == 0) 6830e864dd86871c809668c557985ca19344dfff787Ulrich Drepper ld_state.hash_style = hash_style_gnu | hash_style_sysv; 6840e864dd86871c809668c557985ca19344dfff787Ulrich Drepper else if (strcmp (arg, "sysv") == 0) 6850e864dd86871c809668c557985ca19344dfff787Ulrich Drepper ld_state.hash_style = hash_style_sysv; 6860e864dd86871c809668c557985ca19344dfff787Ulrich Drepper else 6870e864dd86871c809668c557985ca19344dfff787Ulrich Drepper error (EXIT_FAILURE, 0, gettext ("invalid hash style '%s'"), arg); 6880e864dd86871c809668c557985ca19344dfff787Ulrich Drepper break; 6890e864dd86871c809668c557985ca19344dfff787Ulrich Drepper 69089759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper case ARGP_build_id: 69189759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper if (arg == NULL) 692c54785af87adcac067f90b1dbc238c29062cf683Ulrich Drepper ld_state.build_id = "sha1"; 69389759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper else if (strcmp (arg, "uuid") != 0 69489759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper && strcmp (arg, "md5") != 0 695c54785af87adcac067f90b1dbc238c29062cf683Ulrich Drepper && strcmp (arg, "sha1") != 0 69689759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper && !valid_hexarg (arg)) 69789759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper error (EXIT_FAILURE, 0, gettext ("invalid build-ID style '%s'"), arg); 69889759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper else 69989759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper ld_state.build_id = arg; 70089759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper break; 70189759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper 702b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case 's': 703b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (arg == NULL) 704b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 705b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (ld_state.strip == strip_all) 706b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.strip = strip_everything; 707b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else 708b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.strip = strip_all; 709b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 710b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 711b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* FALLTHROUGH */ 712b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 713b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case 'e': 714b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case 'o': 715b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case 'O': 716b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case ARGP_whole_archive: 717b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case ARGP_no_whole_archive: 7188c56fe3b2c753234beb6f58a81c8b96f008226efUlrich Drepper case ARGP_as_needed: 7198c56fe3b2c753234beb6f58a81c8b96f008226efUlrich Drepper case ARGP_no_as_needed: 720b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case 'L': 721b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case '(': 722b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case ')': 723b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case 'l': 724b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case ARGP_static: 725b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case ARGP_dynamic: 726b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case ARGP_version_script: 727b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* We'll handle these in the second pass. */ 728b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 729b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 730b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case ARGP_KEY_ARG: 731b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 732b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct file_list *newp; 733b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 734b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper newp = (struct file_list *) xmalloc (sizeof (struct file_list)); 735b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper newp->name = arg; 736b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#ifndef NDEBUG 737b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper newp->next = NULL; 738b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#endif 739b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper CSNGL_LIST_ADD_REAR (input_file_list, newp); 740b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 741b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 742b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 743b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#if YYDEBUG 744b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case ARGP_yydebug: 745b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper lddebug = 1; 746b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 747b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#endif 748b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 749b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case ARGP_no_undefined: 750b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.nodefs = false; 751b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 752b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 753b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case ARGP_conserve: 754b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper conserve_memory = 1; 755b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 756b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 757b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper default: 758b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper return ARGP_ERR_UNKNOWN; 759b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 760b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper return 0; 761b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper} 762b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 763b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 764b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Handle program arguments for real. */ 765b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic error_t 766b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperparse_opt_2nd (int key, char *arg, 767b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct argp_state *state __attribute__ ((unused))) 768b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 769b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper static bool group_start_requested; 770b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper static bool group_end_requested; 771b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 772b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper switch (key) 773b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 774b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case 'B': 775b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper parse_B_option_2 (arg); 776b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 777b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 778b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case 'e': 779b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.entry = arg; 780b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 781b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 782b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case 'o': 783b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (ld_state.outfname != NULL) 784b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 785b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper error (0, 0, gettext ("More than one output file name given.")); 786b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper see_help: 787b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper argp_help (&argp_2nd, stderr, ARGP_HELP_SEE, "ld"); 788b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper exit (EXIT_FAILURE); 789b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 790b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.outfname = arg; 791b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 792b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 793b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case 'O': 794b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (arg == NULL) 795b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.optlevel = 1; 796b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else 797b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 798b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper char *endp; 799b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper unsigned long int level = strtoul (arg, &endp, 10); 800b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (*endp != '\0') 801b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 802b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper error (0, 0, gettext ("Invalid optimization level `%s'"), arg); 803b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper goto see_help; 804b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 805b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.optlevel = level; 806b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 807b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 808b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 809b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case ARGP_whole_archive: 810b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.extract_rule = allextract; 811b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 812b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case ARGP_no_whole_archive: 813b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.extract_rule = defaultextract; 814b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 815b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 8168c56fe3b2c753234beb6f58a81c8b96f008226efUlrich Drepper case ARGP_as_needed: 8178c56fe3b2c753234beb6f58a81c8b96f008226efUlrich Drepper ld_state.as_needed = true; 8188c56fe3b2c753234beb6f58a81c8b96f008226efUlrich Drepper break; 8198c56fe3b2c753234beb6f58a81c8b96f008226efUlrich Drepper case ARGP_no_as_needed: 8208c56fe3b2c753234beb6f58a81c8b96f008226efUlrich Drepper ld_state.as_needed = false; 8218c56fe3b2c753234beb6f58a81c8b96f008226efUlrich Drepper break; 8228c56fe3b2c753234beb6f58a81c8b96f008226efUlrich Drepper 823b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case ARGP_static: 824b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case ARGP_dynamic: 825b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Enable/disable use for DSOs. */ 826b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.statically = key == ARGP_static; 827b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 828b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 829b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case 'z': 830b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* The SysV linker used 'z' to pass various flags to the linker. 831b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper We follow this. See 'parse_z_option' for the options we 832b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper recognize. */ 833b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper parse_z_option_2 (arg); 834b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 835b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 836b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case ARGP_version_script: 837b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper read_version_script (arg); 838b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 839b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 840b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case 'L': 841b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Add a new search directory. */ 842b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_new_searchdir (arg); 843b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 844b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 845b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case '(': 846b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Start a link group. We have to be able to determine the object 847b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper file which is named next. Do this by remembering a pointer to 848b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper the pointer which will point to the next object. */ 849b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (verbose && (group_start_requested || !group_end_requested)) 850b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper error (0, 0, gettext ("nested -( -) groups are not allowed")); 851b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 852b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Increment the nesting level. */ 853b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ++group_level; 854b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 855b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Record group start. */ 856b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper group_start_requested = true; 857b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper group_end_requested = false; 858b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 859b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 860b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case ')': 861b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* End a link group. If there is no group open this is clearly 862b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper a bug. If there is a group open insert a back reference 863b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper pointer in the record for the last object of the group. If 864b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper there is no new object or just one don't do anything. */ 865b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (!group_end_requested) 866b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 867b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (group_level == 0) 868b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 869b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper error (0, 0, gettext ("-) without matching -(")); 870b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper goto see_help; 871b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 872b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 873b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else 874b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper last_file->group_end = true; 875b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 876b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (group_level > 0) 877b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper --group_level; 878b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 879b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 880b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case 'l': 881b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case ARGP_KEY_ARG: 882b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 883b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper while (last_file != NULL) 884b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Try to open the file. */ 885b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper error_loading |= FILE_PROCESS (-1, last_file, &ld_state, &last_file); 886b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 887b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper last_file = ld_new_inputfile (arg, 888b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper key == 'l' 889b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ? archive_file_type 890b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper : relocatable_file_type); 891b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (group_start_requested) 892b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 893b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper last_file->group_start = true; 894b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 895b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper group_start_requested = false; 896b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper group_end_requested = true; 897b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 898b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 899b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 900b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 901b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper default: 902b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* We can catch all other options here. They either have 903b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper already been handled or, if the parameter was not correct, 904b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper the error has been reported. */ 905b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 906b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 907b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper return 0; 908b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper} 909b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 910b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 911b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Load all the DSOs named as dependencies in other DSOs we already 912b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper loaded. */ 913b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic void 914b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperload_needed (void) 915b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 916b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct usedfiles *first; 917b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct usedfiles *runp; 918b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 919b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* XXX There is one problem here: do we allow references from 920b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper regular object files to be satisfied by these implicit 921b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper dependencies? The old linker allows this and several libraries 922b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper depend on this. Solaris' linker does not allow this; it provides 923b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper the user with a comprehensive error message explaining the 924b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper situation. 925b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 926b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper XXX IMO the old ld behavior is correct since this is also how the 927b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper dynamic linker will work. It will look for unresolved references 928b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper in all loaded DSOs. 929b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 930b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper XXX Should we add an option to get Solaris compatibility? */ 931b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (ld_state.needed == NULL) 932b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper return; 933b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 934b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper runp = first = ld_state.needed->next; 935b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper do 936b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 937b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct usedfiles *ignore; 938b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct usedfiles *next = runp->next; 939b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper int err; 940b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 941b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper err = FILE_PROCESS (-1, runp, &ld_state, &ignore); 942b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (err != 0) 943b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Something went wrong. */ 944b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper exit (err); 945b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 946b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper runp = next; 947b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 948b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper while (runp != first); 949b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper} 950b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 951b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 952b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Print the version information. */ 953b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic void 954b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperprint_version (FILE *stream, struct argp_state *state __attribute__ ((unused))) 955b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 956b0243863149acde9e42b25688c7c2959830e69a9Ulrich Drepper fprintf (stream, "ld (%s) %s\n", PACKAGE_NAME, PACKAGE_VERSION); 957b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper fprintf (stream, gettext ("\ 958b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperCopyright (C) %s Red Hat, Inc.\n\ 959b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperThis is free software; see the source for copying conditions. There is NO\n\ 960b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\ 96144173edad1dfd24c4d98fcf032308f7df28db652Ulrich Drepper"), "2009"); 962b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper fprintf (stream, gettext ("Written by %s.\n"), "Ulrich Drepper"); 963b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper} 964b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 965b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 966b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* There are a lot of -z options, parse them here. Some of them have 967b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper to be parsed in the first pass, others must be handled in the 968b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper second pass. */ 969b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic void 970b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperparse_z_option (const char *arg) 971b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 972b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (strcmp (arg, "nodefaultlib") == 0 973b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* This is only meaningful if we create a DSO. */ 974b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper && ld_state.file_type == dso_file_type) 975b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.dt_flags_1 |= DF_1_NODEFLIB; 976b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else if (strcmp (arg, "muldefs") == 0) 977b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.muldefs = true; 978b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else if (strcmp (arg, "nodefs") == 0) 979b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.nodefs = true; 980b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else if (strcmp (arg, "defs") == 0) 981b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.nodefs = false; 982b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else if (strcmp (arg, "now") == 0) 983b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* We could also set the DF_1_NOW flag in DT_FLAGS_1 but this isn't 984b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper necessary. */ 985b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.dt_flags |= DF_BIND_NOW; 986b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else if (strcmp (arg, "origin") == 0) 987b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* We could also set the DF_1_ORIGIN flag in DT_FLAGS_1 but this isn't 988b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper necessary. */ 989b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.dt_flags |= DF_ORIGIN; 990b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else if (strcmp (arg, "nodelete") == 0 991b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* This is only meaningful if we create a DSO. */ 992b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper && ld_state.file_type == dso_file_type) 993b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.dt_flags_1 |= DF_1_NODELETE; 994b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else if (strcmp (arg, "initfirst") == 0) 995b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.dt_flags_1 |= DF_1_INITFIRST; 996b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else if (strcmp (arg, "nodlopen") == 0 997b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* This is only meaningful if we create a DSO. */ 998b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper && ld_state.file_type == dso_file_type) 999b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.dt_flags_1 |= DF_1_NOOPEN; 1000b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else if (strcmp (arg, "systemlibrary") == 0) 1001b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.is_system_library = true; 10022d88028a7b30d9e9be8e5af089cd6dcc22f80ce1Ulrich Drepper else if (strcmp (arg, "execstack") == 0) 10032d88028a7b30d9e9be8e5af089cd6dcc22f80ce1Ulrich Drepper ld_state.execstack = execstack_true; 10042d88028a7b30d9e9be8e5af089cd6dcc22f80ce1Ulrich Drepper else if (strcmp (arg, "noexecstack") == 0) 10052d88028a7b30d9e9be8e5af089cd6dcc22f80ce1Ulrich Drepper ld_state.execstack = execstack_false_force; 1006b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else if (strcmp (arg, "allextract") != 0 1007b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper && strcmp (arg, "defaultextract") != 0 1008b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper && strcmp (arg, "weakextract") != 0 1009b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper && strcmp (arg, "lazyload") != 0 10104f0a7a89be199fa86d9c5c7a56f4be9c5cfb2a4eUlrich Drepper && strcmp (arg, "nolazyload") != 0 10114f0a7a89be199fa86d9c5c7a56f4be9c5cfb2a4eUlrich Drepper && strcmp (arg, "ignore") != 0 10124f0a7a89be199fa86d9c5c7a56f4be9c5cfb2a4eUlrich Drepper && strcmp (arg, "record") != 0) 1013b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper error (0, 0, gettext ("unknown option `-%c %s'"), 'z', arg); 1014b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper} 1015b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1016b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1017b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic void 1018b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperparse_z_option_2 (const char *arg) 1019b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 1020b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (strcmp (arg, "allextract") == 0) 1021b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.extract_rule = allextract; 1022b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else if (strcmp (arg, "defaultextract") == 0) 1023b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.extract_rule = defaultextract; 1024b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else if (strcmp (arg, "weakextract") == 0) 1025b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.extract_rule = weakextract; 1026b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else if (strcmp (arg, "lazyload") == 0) 1027b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.lazyload = true; 1028b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else if (strcmp (arg, "nolazyload") == 0) 1029b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.lazyload = false; 10304f0a7a89be199fa86d9c5c7a56f4be9c5cfb2a4eUlrich Drepper else if (strcmp (arg, "ignore") == 0) 10314f0a7a89be199fa86d9c5c7a56f4be9c5cfb2a4eUlrich Drepper ld_state.as_needed = true; 10324f0a7a89be199fa86d9c5c7a56f4be9c5cfb2a4eUlrich Drepper else if (strcmp (arg, "record") == 0) 10334f0a7a89be199fa86d9c5c7a56f4be9c5cfb2a4eUlrich Drepper ld_state.as_needed = false; 1034b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper} 1035b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1036b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1037b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* There are a lot of -B options, parse them here. */ 1038b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic void 1039b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperparse_B_option (const char *arg) 1040b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 1041b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (strcmp (arg, "local") == 0) 1042b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.default_bind_local = true; 1043b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else if (strcmp (arg, "symbolic") != 0 1044b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper && strcmp (arg, "static") != 0 1045b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper && strcmp (arg, "dynamic") != 0) 1046b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper error (0, 0, gettext ("unknown option '-%c %s'"), 'B', arg); 1047b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper} 1048b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1049b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1050b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* The same functionality, but called in the second pass over the 1051b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper parameters. */ 1052b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic void 1053b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperparse_B_option_2 (const char *arg) 1054b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 1055b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (strcmp (arg, "static") == 0) 1056b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.statically = true; 1057b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else if (strcmp (arg, "dynamic") == 0) 1058b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.statically = false; 1059b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else if (strcmp (arg, "symbolic") == 0 1060b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* This is only meaningful if we create a DSO. */ 1061b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper && ld_state.file_type == dso_file_type) 1062b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.dt_flags |= DF_SYMBOLIC; 1063b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper} 1064b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1065b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1066b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic void 1067b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperdetermine_output_format (void) 1068b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 1069b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* First change the 'input_file_list' variable in a simple 1070b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper single-linked list. */ 1071b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct file_list *last = input_file_list; 1072b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper input_file_list = input_file_list->next; 1073b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper last->next = NULL; 1074b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1075b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Determine the target configuration which we are supposed to use. 1076b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper The user can use the '-m' option to select one. If this is 1077b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper missing we are trying to load one file and determine the 1078b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper architecture from that. */ 1079b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (emulation != NULL) 1080b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1081b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.ebl = ebl_openbackend_emulation (emulation); 1082b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1083b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper assert (ld_state.ebl != NULL); 1084b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1085b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else 1086b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1087b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Find an ELF input file and let it determine the ELf backend. */ 1088b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct file_list *runp = input_file_list; 1089b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1090b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper while (runp != NULL) 1091b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1092b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper int fd = open (runp->name, O_RDONLY); 1093b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (fd != -1) 1094b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1095b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper int try (Elf *elf) 1096b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1097b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper int result = 0; 1098b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1099b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (elf == NULL) 1100b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper return 0; 1101b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1102b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (elf_kind (elf) == ELF_K_ELF) 1103b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1104b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* We have an ELF file. We now can find out 1105b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper what the output format should be. */ 1106b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper XElf_Ehdr_vardef(ehdr); 1107b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1108b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Get the ELF header of the object. */ 1109b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper xelf_getehdr (elf, ehdr); 1110b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (ehdr != NULL) 1111b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.ebl = 1112b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ebl_openbackend_machine (ehdr->e_machine); 1113b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1114b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper result = 1; 1115b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1116b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else if (elf_kind (elf) == ELF_K_AR) 1117b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1118b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Try the archive members. This could 1119b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper potentially lead to wrong results if the 1120b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper archive contains files for more than one 1121b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper architecture. But this is the user's 1122b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper problem. */ 1123b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper Elf *subelf; 1124b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper Elf_Cmd cmd = ELF_C_READ_MMAP; 1125b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1126b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper while ((subelf = elf_begin (fd, cmd, elf)) != NULL) 1127b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1128b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper cmd = elf_next (subelf); 1129b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1130b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (try (subelf) != 0) 1131b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 1132b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1133b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1134b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1135b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper elf_end (elf); 1136b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1137b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper return result; 1138b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1139b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1140b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (try (elf_begin (fd, ELF_C_READ_MMAP, NULL)) != 0) 1141b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Found a file. */ 1142b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 1143b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1144b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1145b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper runp = runp->next; 1146b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1147b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1148b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (ld_state.ebl == NULL) 1149b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1150b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper error (0, 0, gettext ("\ 1151b08d5a8fb42f4586d756068065186b5af7e48daUlrich Dreppercould not find input file to determine output file format")); 1152b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper error (EXIT_FAILURE, 0, gettext ("\ 1153b08d5a8fb42f4586d756068065186b5af7e48daUlrich Dreppertry again with an appropriate '-m' parameter")); 1154b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1155b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1156b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1157b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* We don't need the list of input files anymore. The second run over 1158b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper the parameters will handle them. */ 1159b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper while (input_file_list != NULL) 1160b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1161b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct file_list *oldp = input_file_list; 1162b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper input_file_list = input_file_list->next; 1163b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper free (oldp); 1164b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1165b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1166b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* We also know now what kind of file we are supposed to create. If 1167b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper the user hasn't selected anythign we create and executable. */ 1168b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (ld_state.file_type == no_file_type) 1169b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.file_type = executable_file_type; 1170b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper} 1171b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1172b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Add DIR to the list of directories searched for object files and 1173b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper libraries. */ 1174b08d5a8fb42f4586d756068065186b5af7e48daUlrich Dreppervoid 1175b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperld_new_searchdir (const char *dir) 1176b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 1177b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct pathelement *newpath; 1178b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1179b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper newpath = (struct pathelement *) 1180b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper obstack_calloc (&ld_state.smem, sizeof (struct pathelement)); 1181b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1182b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper newpath->pname = dir; 1183b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1184b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Enqueue the file. */ 1185b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (ld_state.tailpaths == NULL) 118687cf5834841d0d85277234138b53aba032015ca8Ulrich Drepper ld_state.paths = ld_state.tailpaths = newpath->next = newpath; 1187b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else 1188b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1189b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.tailpaths->next = newpath; 1190b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.tailpaths = newpath; 119187cf5834841d0d85277234138b53aba032015ca8Ulrich Drepper newpath->next = ld_state.paths; 1192b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1193b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper} 1194b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1195b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1196b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstruct usedfiles * 1197b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperld_new_inputfile (const char *fname, enum file_type type) 1198b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 1199b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct usedfiles *newfile = (struct usedfiles *) 1200b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper obstack_calloc (&ld_state.smem, sizeof (struct usedfiles)); 1201b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1202b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper newfile->soname = newfile->fname = newfile->rfname = fname; 1203b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper newfile->file_type = type; 1204b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper newfile->extract_rule = ld_state.extract_rule; 12058c56fe3b2c753234beb6f58a81c8b96f008226efUlrich Drepper newfile->as_needed = ld_state.as_needed; 1206b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper newfile->lazyload = ld_state.lazyload; 1207b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper newfile->status = not_opened; 1208b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1209b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper return newfile; 1210b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper} 1211b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1212b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1213b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Create an array listing all the sections. We will than pass this 1214b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper array to a system specific function which can reorder it at will. 1215b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper The functions can also merge sections if this is what is 1216b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper wanted. */ 1217b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic void 1218b08d5a8fb42f4586d756068065186b5af7e48daUlrich Dreppercollect_sections (void) 1219b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 1220b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper void *p ; 1221b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct scnhead *h; 1222b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper size_t cnt; 1223b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1224b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* We have that many sections. At least for now. */ 1225b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.nallsections = ld_state.section_tab.filled; 1226b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1227b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Allocate the array. We allocate one more entry than computed so 1228b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper far since we might need a new section for the copy relocations. */ 1229b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.allsections = 1230b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper (struct scnhead **) obstack_alloc (&ld_state.smem, 1231b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper (ld_state.nallsections + 1) 1232b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper * sizeof (struct scnhead *)); 1233b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1234b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Fill the array. We rely here on the hash table iterator to 1235b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper return the entries in the order they were added. */ 1236b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper cnt = 0; 1237b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper p = NULL; 1238b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper while ((h = ld_section_tab_iterate (&ld_state.section_tab, &p)) != NULL) 1239b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1240b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct scninfo *runp; 1241b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper bool used = false; 1242b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1243b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (h->kind == scn_normal) 1244b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1245b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper runp = h->last; 1246b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper do 1247b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1248b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (h->type == SHT_REL || h->type == SHT_RELA) 1249b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1250b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (runp->used) 1251b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* This is a relocation section. If the section 1252b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper it is relocating is used in the result so must 1253b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper the relocation section. */ 1254b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper runp->used 1255b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper = runp->fileinfo->scninfo[SCNINFO_SHDR (runp->shdr).sh_info].used; 1256b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1257b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1258b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Accumulate the result. */ 1259b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper used |= runp->used; 1260b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1261b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Next input section. */ 1262b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper runp = runp->next; 1263b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1264b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper while (runp != h->last); 1265b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1266b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper h->used = used; 1267b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1268b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1269b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.allsections[cnt++] = h; 1270b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1271b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.nusedsections = cnt; 1272b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1273b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper assert (cnt == ld_state.nallsections); 1274b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper} 1275b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1276b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1277b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Add given path to the end of list. */ 1278b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic void 1279b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperadd_rxxpath (struct pathelement **pathp, const char *str) 1280b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 1281b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct pathelement *newp; 1282b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1283b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* The path elements can in theory be freed after we read all the 1284b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper files. But the amount of memory we are talking about is small 1285b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper and the cost of free() calls is not neglectable. */ 1286b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper newp = (struct pathelement *) obstack_alloc (&ld_state.smem, sizeof (*newp)); 1287b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper newp->pname = str; 1288b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper newp->exist = 0; 1289b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#ifndef NDEBUG 1290b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper newp->next = NULL; 1291b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#endif 1292b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1293b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper CSNGL_LIST_ADD_REAR (*pathp, newp); 1294b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper} 1295b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1296b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1297b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Convert lists of possibly colon-separated directory lists into lists 1298b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper where each entry is for a single directory. */ 1299b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic void 1300b08d5a8fb42f4586d756068065186b5af7e48daUlrich Dreppernormalize_dirlist (struct pathelement **pathp) 1301b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 1302b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct pathelement *firstp = *pathp; 1303b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1304b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper do 1305b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1306b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper const char *pname = (*pathp)->pname; 1307b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper const char *colonp = strchrnul (pname, ':'); 1308b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1309b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (colonp != NULL) 1310b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1311b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct pathelement *lastp = *pathp; 1312b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct pathelement *newp; 1313b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1314b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper while (1) 1315b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1316b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (colonp == pname) 1317b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper lastp->pname = "."; 1318b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else 1319b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper lastp->pname = obstack_strndup (&ld_state.smem, pname, 1320b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper colonp - pname); 1321b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1322b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (*colonp == '\0') 1323b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 1324b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper pname = colonp + 1; 1325b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1326b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper newp = (struct pathelement *) obstack_alloc (&ld_state.smem, 1327b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper sizeof (*newp)); 1328b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper newp->next = lastp->next; 1329b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper newp->exist = 0; 1330b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper lastp = lastp->next = newp; 1331b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1332b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper colonp = strchrnul (pname, ':'); 1333b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1334b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1335b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper pathp = &lastp->next; 1336b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1337b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else 1338b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper pathp = &(*pathp)->next; 1339b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1340b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper while (*pathp != firstp); 1341b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper} 1342b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1343b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1344b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Called after all parameters are parsed to bring the runpath/rpath 1345b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper information into a usable form. */ 1346b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic void 1347b08d5a8fb42f4586d756068065186b5af7e48daUlrich Dreppergen_rxxpath_data (void) 1348b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 1349b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper char *ld_library_path2; 1350b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1351b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Convert the information in true single-linked lists for easy use. 1352b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper At this point we also discard the rpath information if runpath 1353b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper information is provided. rpath is deprecated and should not be 1354b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper used (or ever be invented for that matter). */ 1355b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (ld_state.rpath != NULL) 1356b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1357b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct pathelement *endp = ld_state.rpath; 1358b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.rpath = ld_state.rpath->next; 1359b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper endp->next = NULL; 1360b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1361b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (ld_state.rpath_link != NULL) 1362b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1363b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct pathelement *endp = ld_state.rpath_link; 1364b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.rpath_link = ld_state.rpath_link->next; 1365b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper endp->next = NULL; 1366b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1367b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1368b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (ld_state.runpath != NULL) 1369b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1370b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct pathelement *endp = ld_state.runpath; 1371b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.runpath = ld_state.runpath->next; 1372b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper endp->next = NULL; 1373b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1374b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* If rpath information is also available discard it. 1375b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper XXX Should there be a possibility to avoid this? */ 1376b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper while (ld_state.rpath != NULL) 1377b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1378b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct pathelement *old = ld_state.rpath; 1379b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.rpath = ld_state.rpath->next; 1380b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper free (old); 1381b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1382b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1383b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (ld_state.runpath_link != NULL) 1384b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1385b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct pathelement *endp = ld_state.runpath_link; 1386b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.runpath_link = ld_state.runpath_link->next; 1387b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper endp->next = NULL; 1388b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1389b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* If rpath information is also available discard it. 1390b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper XXX Should there be a possibility to avoid this? */ 1391b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper while (ld_state.rpath_link != NULL) 1392b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1393b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct pathelement *old = ld_state.rpath_link; 1394b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.rpath_link = ld_state.rpath_link->next; 1395b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper free (old); 1396b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1397b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1398b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* The information in the strings in the list can actually be 1399b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper directory lists themselves, with entries separated by colons. 1400b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper Convert the list now to a list with one list entry for each 1401b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper directory. */ 1402b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper normalize_dirlist (&ld_state.runpath_link); 1403b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1404b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else if (ld_state.rpath_link != NULL) 1405b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Same as for the runpath_link above. */ 1406b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper normalize_dirlist (&ld_state.rpath_link); 1407b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1408b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1409b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* As a related task, handle the LD_LIBRARY_PATH value here. First 1410b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper we have to possibly split the value found (if it contains a 1411b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper semicolon). Then we have to split the value in list of 1412b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper directories, i.e., split at the colons. */ 1413b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (ld_library_path1 != NULL) 1414b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1415b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_library_path2 = strchr (ld_library_path1, ';'); 1416b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (ld_library_path2 == NULL) 1417b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1418b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* If no semicolon is present the directories are looked at 1419b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper after the -L parameters (-> ld_library_path2). */ 1420b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_library_path2 = ld_library_path1; 1421b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_library_path1 = NULL; 1422b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1423b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else 1424b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1425b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* NUL terminate the first part. */ 1426b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper *ld_library_path2++ = '\0'; 1427b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1428b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Convert the string value in a list. */ 1429b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper add_rxxpath (&ld_state.ld_library_path1, ld_library_path1); 1430b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper normalize_dirlist (&ld_state.ld_library_path1); 1431b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1432b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1433b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper add_rxxpath (&ld_state.ld_library_path2, ld_library_path2); 1434b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper normalize_dirlist (&ld_state.ld_library_path2); 1435b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1436b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper} 1437b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1438b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1439b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic void 1440b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperread_version_script (const char *fname) 1441b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 1442b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Open the file. The name is supposed to be the complete (relative 1443b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper or absolute) path. No search along a path will be performed. */ 1444b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ldin = fopen (fname, "r"); 1445b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (ldin == NULL) 1446e3f9b7db6c7361579ec5cc5eb5e414f7e93baeb6Ulrich Drepper error (EXIT_FAILURE, errno, gettext ("cannot read version script '%s'"), 1447b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper fname); 1448b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* No need for locking. */ 1449b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper __fsetlocking (ldin, FSETLOCKING_BYCALLER); 1450b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1451b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Tell the parser that this is a version script. */ 1452b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_scan_version_script = 1; 1453b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1454b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ldlineno = 1; 1455b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ldin_fname = fname; 1456b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (ldparse () != 0) 1457b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Something went wrong during parsing. */ 1458b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper exit (EXIT_FAILURE); 1459b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1460b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper fclose (ldin); 1461b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper} 1462b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1463b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1464b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic void 1465b08d5a8fb42f4586d756068065186b5af7e48daUlrich Dreppercreate_lscript_symbols (void) 1466b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 1467b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Walk through the data from the linker script and generate all the 1468b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper symbols which are required to be present and and those marked 1469b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper with PROVIDE if there is a undefined reference. */ 1470b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (ld_state.output_segments == NULL) 1471b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper return; 1472b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1473b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct output_segment *segment = ld_state.output_segments->next; 1474b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper do 1475b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1476b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct output_rule *orule; 1477b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1478b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper for (orule = segment->output_rules; orule != NULL; orule = orule->next) 1479b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (orule->tag == output_assignment 1480b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* The assignments to "." (i.e., the PC) have to be 1481b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ignored here. */ 1482b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper && strcmp (orule->val.assignment->variable, ".") != 0) 1483b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1484b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct symbol *s = ld_state.unresolved; 1485b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1486b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Check whether the symbol is needed. */ 1487b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (likely (s != NULL)) 1488b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1489b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct symbol *first = s; 1490b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper const char *providename = orule->val.assignment->variable; 1491b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1492b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Determine whether the provided symbol is still 1493b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper undefined. */ 1494b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper // XXX TODO Loop inside a loop. Gag! Must rewrite. */ 1495b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper do 1496b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (strcmp (s->name, providename) == 0) 1497b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1498b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Not defined but referenced. */ 1499b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (unlikely (!s->defined)) 1500b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1501b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Put on the list of symbols. First remove it from 1502b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper whatever list it currently is on. */ 1503b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper CDBL_LIST_DEL (ld_state.unresolved, s); 1504b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper --ld_state.nunresolved; 1505b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper goto use_it; 1506b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1507b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1508b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (unlikely (!orule->val.assignment->provide_flag)) 1509b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1510b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* The symbol is already defined and now again 1511b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper in the linker script. This is an error. */ 1512b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper error (0, 0, gettext ("\ 1513b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperduplicate definition of '%s' in linker script"), 1514b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper providename); 1515b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper goto next_rule; 1516b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1517b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1518b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper while ((s = s->next) != first); 1519b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1520b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1521b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* If the symbol only has to be provided if it is needed, 1522b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ignore it here since it is not undefined. */ 1523b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (orule->val.assignment->provide_flag) 1524b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper continue; 1525b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1526b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Allocate memory for this new symbol. */ 1527b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper s = (struct symbol *) 1528b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper obstack_calloc (&ld_state.smem, sizeof (struct symbol)); 1529b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1530b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Initialize it. */ 1531b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper s->name = orule->val.assignment->variable; 1532b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1533b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Insert it into the symbol hash table. */ 1534b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper unsigned long int hval = elf_hash (s->name); 1535b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (unlikely (ld_symbol_tab_insert (&ld_state.symbol_tab, 1536b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper hval, s) != 0)) 1537b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1538b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* This means the symbol is defined somewhere else. 1539b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper Maybe it comes from a DSO or so. Get the 1540b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper definition. */ 1541b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper free (s); 1542b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct symbol *old = ld_symbol_tab_find (&ld_state.symbol_tab, 1543b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper hval, s); 1544b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper assert (old != NULL); 1545b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper free (s); 1546b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1547b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* If this is a definition from the application itself 1548b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper this means a duplicate definition. */ 1549b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (! old->in_dso) 1550b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1551b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper error (0, 0, gettext ("\ 1552b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperduplicate definition of '%s' in linker script"), 1553b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper s->name); 1554b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper goto next_rule; 1555b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1556b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1557b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* We use the definition from the linker script. */ 1558b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper s = old; 1559b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1560b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1561b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper use_it: 1562b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* The symbol is (now) defined. */ 1563b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper s->defined = 1; 1564b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper s->type = STT_NOTYPE; 1565b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1566b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Add a reference to the symbol record. We will come 1567b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper across it when creating the output file. */ 1568b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper orule->val.assignment->sym = s; 1569b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1570b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper SNGL_LIST_PUSH (ld_state.lscript_syms, s); 1571b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ++ld_state.nlscript_syms; 1572b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1573b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper next_rule: 1574b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ; 1575b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1576b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1577b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper segment = segment->next; 1578b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1579b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper while (segment != ld_state.output_segments->next); 1580b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper} 1581b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1582b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1583b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Create creation of spection section symbols representing sections in the 1584b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper output file. This is done for symbols like _GLOBAL_OFFSET_TABLE_ and 1585b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper _DYNAMIC. */ 1586b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic void 1587b08d5a8fb42f4586d756068065186b5af7e48daUlrich Dreppercreate_special_section_symbol (struct symbol **symp, const char *name) 1588b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 1589b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (*symp == NULL) 1590b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1591b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* No symbol defined found yet. Create one. */ 1592b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct symbol *newsym = (struct symbol *) 1593b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper obstack_calloc (&ld_state.smem, sizeof (*newsym)); 1594b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1595b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper newsym->name = name; 1596b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper // XXX Should we mark the symbol hidden? They are hardly useful 1597b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper // used outside the current object. 1598b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1599b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Add to the symbol table. */ 1600b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (unlikely (ld_symbol_tab_insert (&ld_state.symbol_tab, 1601b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper elf_hash (name), newsym) != 0)) 1602b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper abort (); 1603b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1604b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper *symp = newsym; 1605b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1606b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else if ((*symp)->defined) 1607b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Cannot happen. We do use this symbol from any input file. */ 1608b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper abort (); 1609b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1610b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper (*symp)->defined = 1; 161128ed895fdc303b2a793506bb1fcdd35d5fd14e70Ulrich Drepper (*symp)->local = 1; 161228ed895fdc303b2a793506bb1fcdd35d5fd14e70Ulrich Drepper (*symp)->hidden = 1; 1613b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper (*symp)->type = STT_OBJECT; 1614b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1615b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ++ld_state.nsymtab; 1616b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper} 16173cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper 16183cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper 16193cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper#include "debugpred.h" 1620