ld.c revision 89759c76ee1e3231ee89d4aafed3a88772ce2245
1b770cf9d1045bde04a1d89c63f4d7eb261ff78daUlrich Drepper/* Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 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, 17589759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper N_("Generate build ID note (md5 (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" }, 510b61c4cc4ab5d61d5d7c1a31e700bff8ad39fa079Ulrich Drepper { "-dynamic-linker", "--dynamic-linker" } 511b61c4cc4ab5d61d5d7c1a31e700bff8ad39fa079Ulrich Drepper }; 512b61c4cc4ab5d61d5d7c1a31e700bff8ad39fa079Ulrich Drepper const size_t nargs = sizeof (args) / sizeof (args[0]); 513b61c4cc4ab5d61d5d7c1a31e700bff8ad39fa079Ulrich Drepper 514b61c4cc4ab5d61d5d7c1a31e700bff8ad39fa079Ulrich Drepper for (int i = 1; i < argc; ++i) 515b61c4cc4ab5d61d5d7c1a31e700bff8ad39fa079Ulrich Drepper if (argv[i][0] == '-' && islower (argv[i][1])) 516b61c4cc4ab5d61d5d7c1a31e700bff8ad39fa079Ulrich Drepper for (size_t j = 0; j < nargs; ++j) 517b61c4cc4ab5d61d5d7c1a31e700bff8ad39fa079Ulrich Drepper if (strcmp (argv[i], args[j].from) == 0) 518b61c4cc4ab5d61d5d7c1a31e700bff8ad39fa079Ulrich Drepper { 519b61c4cc4ab5d61d5d7c1a31e700bff8ad39fa079Ulrich Drepper argv[i] = (char *) args[j].to; 520b61c4cc4ab5d61d5d7c1a31e700bff8ad39fa079Ulrich Drepper break; 521b61c4cc4ab5d61d5d7c1a31e700bff8ad39fa079Ulrich Drepper } 522b61c4cc4ab5d61d5d7c1a31e700bff8ad39fa079Ulrich Drepper} 523b61c4cc4ab5d61d5d7c1a31e700bff8ad39fa079Ulrich Drepper 524b61c4cc4ab5d61d5d7c1a31e700bff8ad39fa079Ulrich Drepper 52589759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepperstatic int 52689759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Dreppervalid_hexarg (const char *arg) 52789759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper{ 52889759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper if (strncasecmp (arg, "0x", 2) != 0) 52989759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper return 0; 53089759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper 53189759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper arg += 2; 53289759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper do 53389759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper { 53489759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper if (isxdigit (arg[0]) && isxdigit (arg[1])) 53589759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper { 53689759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper arg += 2; 53789759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper if (arg[0] == '-' || arg[0] == ':') 53889759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper ++arg; 53989759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper } 54089759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper else 54189759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper return 0; 54289759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper } 54389759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper while (*arg != '\0'); 54489759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper 54589759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper return 1; 54689759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper} 54789759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper 54889759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper 549b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Quick scan of the parameter list for options with global effect. */ 550b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic error_t 551b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperparse_opt_1st (int key, char *arg, 552b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct argp_state *state __attribute__ ((unused))) 553b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 554b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper switch (key) 555b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 556b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case 'B': 557b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper parse_B_option (arg); 558b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 559b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 560b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case 'c': 561b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper linker_script = arg; 562b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 563b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 564b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case 'E': 565b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.export_all_dynamic = true; 566b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 567b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 568b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case 'G': 569b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (ld_state.file_type != no_file_type) 570b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper error (EXIT_FAILURE, 0, 571b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper gettext ("only one option of -G and -r is allowed")); 572b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.file_type = dso_file_type; 573b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 574b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* If we generate a DSO we have to export all symbols. */ 575b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.export_all_dynamic = true; 576b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 577b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 578b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case 'h': 579b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.soname = arg; 580b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 581b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 582b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case 'i': 583b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Discard the LD_LIBRARY_PATH value we found. */ 584b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_library_path1 = NULL; 585b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 586b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 587b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case 'I': 588b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.interp = arg; 589b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 590b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 591b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case 'm': 592b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (emulation != NULL) 593b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper error (EXIT_FAILURE, 0, gettext ("more than one '-m' parameter")); 594b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper emulation = arg; 595b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 596b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 597b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case 'Q': 598b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (arg[1] == '\0' && (arg[0] == 'y' || arg[0] == 'Y')) 599b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.add_ld_comment = true; 600b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else if (arg[1] == '\0' && (arg[0] == 'n' || arg[0] == 'N')) 601b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.add_ld_comment = true; 602b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else 603b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper error (EXIT_FAILURE, 0, gettext ("unknown option `-%c %s'"), 'Q', arg); 604b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 605b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 606b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case 'r': 607b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (ld_state.file_type != no_file_type) 608b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper error (EXIT_FAILURE, 0, 609b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper gettext ("only one option of -G and -r is allowed")); 610b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.file_type = relocatable_file_type; 611b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 612b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 613b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case 'S': 614b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.strip = strip_debug; 615b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 616b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 617b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case 't': 618b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.trace_files = true; 619b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 620b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 621b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case 'v': 622b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper verbose = 1; 623b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 624b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 625b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case 'z': 626b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* The SysV linker used 'z' to pass various flags to the linker. 627b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper We follow this. See 'parse_z_option' for the options we 628b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper recognize. */ 629b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper parse_z_option (arg); 630b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 631b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 632b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case ARGP_pagesize: 633b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 634b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper char *endp; 635b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.pagesize = strtoul (arg, &endp, 0); 636b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (*endp != '\0') 637b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 638b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (endp[1] == '\0' && tolower (*endp) == 'k') 639b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.pagesize *= 1024; 640b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else if (endp[1] == '\0' && tolower (*endp) == 'm') 641b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.pagesize *= 1024 * 1024; 642b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else 643b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 644b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper error (0, 0, 645e3f9b7db6c7361579ec5cc5eb5e414f7e93baeb6Ulrich Drepper gettext ("invalid page size value '%s': ignored"), 646b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper arg); 647b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.pagesize = 0; 648b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 649b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 650b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 651b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 652b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 653cbb51e5253e05d98af8bdaf2217fed00b2e489b9Ulrich Drepper case 'R': 654b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper add_rxxpath (&ld_state.rpath, arg); 655b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 656b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 657b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case ARGP_rpath_link: 658b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper add_rxxpath (&ld_state.rpath_link, arg); 659b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 660b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 661b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case ARGP_runpath: 662b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper add_rxxpath (&ld_state.runpath, arg); 663b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 664b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 665b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case ARGP_runpath_link: 666b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper add_rxxpath (&ld_state.runpath_link, arg); 667b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 668b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 669b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case ARGP_gc_sections: 670b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case ARGP_no_gc_sections: 671b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.gc_sections = key == ARGP_gc_sections; 672b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 673b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 67454f33a779527d6764b4fc4068267715a718c422cUlrich Drepper case ARGP_eh_frame_hdr: 67554f33a779527d6764b4fc4068267715a718c422cUlrich Drepper ld_state.eh_frame_hdr = true; 67654f33a779527d6764b4fc4068267715a718c422cUlrich Drepper break; 67754f33a779527d6764b4fc4068267715a718c422cUlrich Drepper 6780e864dd86871c809668c557985ca19344dfff787Ulrich Drepper case ARGP_hash_style: 6790e864dd86871c809668c557985ca19344dfff787Ulrich Drepper if (strcmp (arg, "gnu") == 0) 6800e864dd86871c809668c557985ca19344dfff787Ulrich Drepper ld_state.hash_style = hash_style_gnu; 6810e864dd86871c809668c557985ca19344dfff787Ulrich Drepper else if (strcmp (arg, "both") == 0) 6820e864dd86871c809668c557985ca19344dfff787Ulrich Drepper ld_state.hash_style = hash_style_gnu | hash_style_sysv; 6830e864dd86871c809668c557985ca19344dfff787Ulrich Drepper else if (strcmp (arg, "sysv") == 0) 6840e864dd86871c809668c557985ca19344dfff787Ulrich Drepper ld_state.hash_style = hash_style_sysv; 6850e864dd86871c809668c557985ca19344dfff787Ulrich Drepper else 6860e864dd86871c809668c557985ca19344dfff787Ulrich Drepper error (EXIT_FAILURE, 0, gettext ("invalid hash style '%s'"), arg); 6870e864dd86871c809668c557985ca19344dfff787Ulrich Drepper break; 6880e864dd86871c809668c557985ca19344dfff787Ulrich Drepper 68989759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper case ARGP_build_id: 69089759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper if (arg == NULL) 69189759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper ld_state.build_id = "md5"; 69289759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper else if (strcmp (arg, "uuid") != 0 69389759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper && strcmp (arg, "md5") != 0 69489759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper && !valid_hexarg (arg)) 69589759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper error (EXIT_FAILURE, 0, gettext ("invalid build-ID style '%s'"), arg); 69689759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper else 69789759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper ld_state.build_id = arg; 69889759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper break; 69989759c76ee1e3231ee89d4aafed3a88772ce2245Ulrich Drepper 700b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case 's': 701b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (arg == NULL) 702b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 703b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (ld_state.strip == strip_all) 704b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.strip = strip_everything; 705b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else 706b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.strip = strip_all; 707b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 708b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 709b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* FALLTHROUGH */ 710b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 711b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case 'e': 712b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case 'o': 713b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case 'O': 714b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case ARGP_whole_archive: 715b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case ARGP_no_whole_archive: 7168c56fe3b2c753234beb6f58a81c8b96f008226efUlrich Drepper case ARGP_as_needed: 7178c56fe3b2c753234beb6f58a81c8b96f008226efUlrich Drepper case ARGP_no_as_needed: 718b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case 'L': 719b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case '(': 720b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case ')': 721b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case 'l': 722b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case ARGP_static: 723b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case ARGP_dynamic: 724b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case ARGP_version_script: 725b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* We'll handle these in the second pass. */ 726b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 727b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 728b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case ARGP_KEY_ARG: 729b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 730b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct file_list *newp; 731b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 732b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper newp = (struct file_list *) xmalloc (sizeof (struct file_list)); 733b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper newp->name = arg; 734b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#ifndef NDEBUG 735b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper newp->next = NULL; 736b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#endif 737b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper CSNGL_LIST_ADD_REAR (input_file_list, newp); 738b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 739b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 740b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 741b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#if YYDEBUG 742b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case ARGP_yydebug: 743b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper lddebug = 1; 744b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 745b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#endif 746b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 747b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case ARGP_no_undefined: 748b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.nodefs = false; 749b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 750b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 751b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case ARGP_conserve: 752b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper conserve_memory = 1; 753b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 754b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 755b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper default: 756b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper return ARGP_ERR_UNKNOWN; 757b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 758b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper return 0; 759b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper} 760b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 761b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 762b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Handle program arguments for real. */ 763b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic error_t 764b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperparse_opt_2nd (int key, char *arg, 765b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct argp_state *state __attribute__ ((unused))) 766b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 767b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper static bool group_start_requested; 768b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper static bool group_end_requested; 769b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 770b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper switch (key) 771b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 772b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case 'B': 773b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper parse_B_option_2 (arg); 774b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 775b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 776b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case 'e': 777b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.entry = arg; 778b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 779b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 780b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case 'o': 781b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (ld_state.outfname != NULL) 782b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 783b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper error (0, 0, gettext ("More than one output file name given.")); 784b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper see_help: 785b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper argp_help (&argp_2nd, stderr, ARGP_HELP_SEE, "ld"); 786b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper exit (EXIT_FAILURE); 787b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 788b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.outfname = arg; 789b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 790b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 791b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case 'O': 792b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (arg == NULL) 793b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.optlevel = 1; 794b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else 795b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 796b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper char *endp; 797b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper unsigned long int level = strtoul (arg, &endp, 10); 798b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (*endp != '\0') 799b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 800b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper error (0, 0, gettext ("Invalid optimization level `%s'"), arg); 801b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper goto see_help; 802b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 803b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.optlevel = level; 804b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 805b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 806b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 807b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case ARGP_whole_archive: 808b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.extract_rule = allextract; 809b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 810b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case ARGP_no_whole_archive: 811b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.extract_rule = defaultextract; 812b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 813b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 8148c56fe3b2c753234beb6f58a81c8b96f008226efUlrich Drepper case ARGP_as_needed: 8158c56fe3b2c753234beb6f58a81c8b96f008226efUlrich Drepper ld_state.as_needed = true; 8168c56fe3b2c753234beb6f58a81c8b96f008226efUlrich Drepper break; 8178c56fe3b2c753234beb6f58a81c8b96f008226efUlrich Drepper case ARGP_no_as_needed: 8188c56fe3b2c753234beb6f58a81c8b96f008226efUlrich Drepper ld_state.as_needed = false; 8198c56fe3b2c753234beb6f58a81c8b96f008226efUlrich Drepper break; 8208c56fe3b2c753234beb6f58a81c8b96f008226efUlrich Drepper 821b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case ARGP_static: 822b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case ARGP_dynamic: 823b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Enable/disable use for DSOs. */ 824b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.statically = key == ARGP_static; 825b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 826b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 827b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case 'z': 828b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* The SysV linker used 'z' to pass various flags to the linker. 829b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper We follow this. See 'parse_z_option' for the options we 830b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper recognize. */ 831b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper parse_z_option_2 (arg); 832b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 833b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 834b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case ARGP_version_script: 835b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper read_version_script (arg); 836b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 837b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 838b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case 'L': 839b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Add a new search directory. */ 840b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_new_searchdir (arg); 841b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 842b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 843b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case '(': 844b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Start a link group. We have to be able to determine the object 845b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper file which is named next. Do this by remembering a pointer to 846b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper the pointer which will point to the next object. */ 847b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (verbose && (group_start_requested || !group_end_requested)) 848b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper error (0, 0, gettext ("nested -( -) groups are not allowed")); 849b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 850b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Increment the nesting level. */ 851b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ++group_level; 852b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 853b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Record group start. */ 854b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper group_start_requested = true; 855b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper group_end_requested = false; 856b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 857b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 858b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case ')': 859b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* End a link group. If there is no group open this is clearly 860b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper a bug. If there is a group open insert a back reference 861b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper pointer in the record for the last object of the group. If 862b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper there is no new object or just one don't do anything. */ 863b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (!group_end_requested) 864b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 865b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (group_level == 0) 866b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 867b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper error (0, 0, gettext ("-) without matching -(")); 868b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper goto see_help; 869b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 870b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 871b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else 872b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper last_file->group_end = true; 873b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 874b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (group_level > 0) 875b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper --group_level; 876b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 877b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 878b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case 'l': 879b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper case ARGP_KEY_ARG: 880b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 881b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper while (last_file != NULL) 882b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Try to open the file. */ 883b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper error_loading |= FILE_PROCESS (-1, last_file, &ld_state, &last_file); 884b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 885b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper last_file = ld_new_inputfile (arg, 886b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper key == 'l' 887b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ? archive_file_type 888b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper : relocatable_file_type); 889b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (group_start_requested) 890b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 891b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper last_file->group_start = true; 892b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 893b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper group_start_requested = false; 894b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper group_end_requested = true; 895b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 896b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 897b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 898b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 899b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper default: 900b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* We can catch all other options here. They either have 901b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper already been handled or, if the parameter was not correct, 902b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper the error has been reported. */ 903b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 904b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 905b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper return 0; 906b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper} 907b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 908b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 909b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Load all the DSOs named as dependencies in other DSOs we already 910b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper loaded. */ 911b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic void 912b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperload_needed (void) 913b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 914b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct usedfiles *first; 915b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct usedfiles *runp; 916b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 917b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* XXX There is one problem here: do we allow references from 918b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper regular object files to be satisfied by these implicit 919b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper dependencies? The old linker allows this and several libraries 920b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper depend on this. Solaris' linker does not allow this; it provides 921b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper the user with a comprehensive error message explaining the 922b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper situation. 923b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 924b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper XXX IMO the old ld behavior is correct since this is also how the 925b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper dynamic linker will work. It will look for unresolved references 926b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper in all loaded DSOs. 927b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 928b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper XXX Should we add an option to get Solaris compatibility? */ 929b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (ld_state.needed == NULL) 930b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper return; 931b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 932b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper runp = first = ld_state.needed->next; 933b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper do 934b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 935b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct usedfiles *ignore; 936b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct usedfiles *next = runp->next; 937b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper int err; 938b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 939b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper err = FILE_PROCESS (-1, runp, &ld_state, &ignore); 940b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (err != 0) 941b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Something went wrong. */ 942b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper exit (err); 943b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 944b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper runp = next; 945b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 946b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper while (runp != first); 947b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper} 948b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 949b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 950b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Print the version information. */ 951b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic void 952b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperprint_version (FILE *stream, struct argp_state *state __attribute__ ((unused))) 953b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 954b0243863149acde9e42b25688c7c2959830e69a9Ulrich Drepper fprintf (stream, "ld (%s) %s\n", PACKAGE_NAME, PACKAGE_VERSION); 955b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper fprintf (stream, gettext ("\ 956b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperCopyright (C) %s Red Hat, Inc.\n\ 957b08d5a8fb42f4586d756068065186b5af7e48daUlrich DrepperThis is free software; see the source for copying conditions. There is NO\n\ 958b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\ 959ad024afc93dcd0f4797b3e80bfb6b80c34da5c12Ulrich Drepper"), "2008"); 960b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper fprintf (stream, gettext ("Written by %s.\n"), "Ulrich Drepper"); 961b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper} 962b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 963b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 964b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* There are a lot of -z options, parse them here. Some of them have 965b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper to be parsed in the first pass, others must be handled in the 966b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper second pass. */ 967b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic void 968b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperparse_z_option (const char *arg) 969b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 970b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (strcmp (arg, "nodefaultlib") == 0 971b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* This is only meaningful if we create a DSO. */ 972b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper && ld_state.file_type == dso_file_type) 973b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.dt_flags_1 |= DF_1_NODEFLIB; 974b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else if (strcmp (arg, "muldefs") == 0) 975b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.muldefs = true; 976b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else if (strcmp (arg, "nodefs") == 0) 977b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.nodefs = true; 978b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else if (strcmp (arg, "defs") == 0) 979b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.nodefs = false; 980b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else if (strcmp (arg, "now") == 0) 981b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* We could also set the DF_1_NOW flag in DT_FLAGS_1 but this isn't 982b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper necessary. */ 983b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.dt_flags |= DF_BIND_NOW; 984b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else if (strcmp (arg, "origin") == 0) 985b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* We could also set the DF_1_ORIGIN flag in DT_FLAGS_1 but this isn't 986b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper necessary. */ 987b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.dt_flags |= DF_ORIGIN; 988b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else if (strcmp (arg, "nodelete") == 0 989b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* This is only meaningful if we create a DSO. */ 990b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper && ld_state.file_type == dso_file_type) 991b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.dt_flags_1 |= DF_1_NODELETE; 992b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else if (strcmp (arg, "initfirst") == 0) 993b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.dt_flags_1 |= DF_1_INITFIRST; 994b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else if (strcmp (arg, "nodlopen") == 0 995b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* This is only meaningful if we create a DSO. */ 996b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper && ld_state.file_type == dso_file_type) 997b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.dt_flags_1 |= DF_1_NOOPEN; 998b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else if (strcmp (arg, "systemlibrary") == 0) 999b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.is_system_library = true; 10002d88028a7b30d9e9be8e5af089cd6dcc22f80ce1Ulrich Drepper else if (strcmp (arg, "execstack") == 0) 10012d88028a7b30d9e9be8e5af089cd6dcc22f80ce1Ulrich Drepper ld_state.execstack = execstack_true; 10022d88028a7b30d9e9be8e5af089cd6dcc22f80ce1Ulrich Drepper else if (strcmp (arg, "noexecstack") == 0) 10032d88028a7b30d9e9be8e5af089cd6dcc22f80ce1Ulrich Drepper ld_state.execstack = execstack_false_force; 1004b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else if (strcmp (arg, "allextract") != 0 1005b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper && strcmp (arg, "defaultextract") != 0 1006b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper && strcmp (arg, "weakextract") != 0 1007b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper && strcmp (arg, "lazyload") != 0 10084f0a7a89be199fa86d9c5c7a56f4be9c5cfb2a4eUlrich Drepper && strcmp (arg, "nolazyload") != 0 10094f0a7a89be199fa86d9c5c7a56f4be9c5cfb2a4eUlrich Drepper && strcmp (arg, "ignore") != 0 10104f0a7a89be199fa86d9c5c7a56f4be9c5cfb2a4eUlrich Drepper && strcmp (arg, "record") != 0) 1011b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper error (0, 0, gettext ("unknown option `-%c %s'"), 'z', arg); 1012b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper} 1013b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1014b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1015b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic void 1016b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperparse_z_option_2 (const char *arg) 1017b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 1018b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (strcmp (arg, "allextract") == 0) 1019b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.extract_rule = allextract; 1020b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else if (strcmp (arg, "defaultextract") == 0) 1021b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.extract_rule = defaultextract; 1022b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else if (strcmp (arg, "weakextract") == 0) 1023b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.extract_rule = weakextract; 1024b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else if (strcmp (arg, "lazyload") == 0) 1025b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.lazyload = true; 1026b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else if (strcmp (arg, "nolazyload") == 0) 1027b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.lazyload = false; 10284f0a7a89be199fa86d9c5c7a56f4be9c5cfb2a4eUlrich Drepper else if (strcmp (arg, "ignore") == 0) 10294f0a7a89be199fa86d9c5c7a56f4be9c5cfb2a4eUlrich Drepper ld_state.as_needed = true; 10304f0a7a89be199fa86d9c5c7a56f4be9c5cfb2a4eUlrich Drepper else if (strcmp (arg, "record") == 0) 10314f0a7a89be199fa86d9c5c7a56f4be9c5cfb2a4eUlrich Drepper ld_state.as_needed = false; 1032b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper} 1033b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1034b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1035b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* There are a lot of -B options, parse them here. */ 1036b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic void 1037b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperparse_B_option (const char *arg) 1038b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 1039b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (strcmp (arg, "local") == 0) 1040b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.default_bind_local = true; 1041b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else if (strcmp (arg, "symbolic") != 0 1042b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper && strcmp (arg, "static") != 0 1043b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper && strcmp (arg, "dynamic") != 0) 1044b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper error (0, 0, gettext ("unknown option '-%c %s'"), 'B', arg); 1045b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper} 1046b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1047b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1048b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* The same functionality, but called in the second pass over the 1049b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper parameters. */ 1050b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic void 1051b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperparse_B_option_2 (const char *arg) 1052b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 1053b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (strcmp (arg, "static") == 0) 1054b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.statically = true; 1055b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else if (strcmp (arg, "dynamic") == 0) 1056b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.statically = false; 1057b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else if (strcmp (arg, "symbolic") == 0 1058b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* This is only meaningful if we create a DSO. */ 1059b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper && ld_state.file_type == dso_file_type) 1060b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.dt_flags |= DF_SYMBOLIC; 1061b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper} 1062b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1063b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1064b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic void 1065b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperdetermine_output_format (void) 1066b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 1067b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* First change the 'input_file_list' variable in a simple 1068b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper single-linked list. */ 1069b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct file_list *last = input_file_list; 1070b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper input_file_list = input_file_list->next; 1071b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper last->next = NULL; 1072b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1073b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Determine the target configuration which we are supposed to use. 1074b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper The user can use the '-m' option to select one. If this is 1075b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper missing we are trying to load one file and determine the 1076b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper architecture from that. */ 1077b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (emulation != NULL) 1078b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1079b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.ebl = ebl_openbackend_emulation (emulation); 1080b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1081b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper assert (ld_state.ebl != NULL); 1082b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1083b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else 1084b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1085b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Find an ELF input file and let it determine the ELf backend. */ 1086b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct file_list *runp = input_file_list; 1087b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1088b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper while (runp != NULL) 1089b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1090b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper int fd = open (runp->name, O_RDONLY); 1091b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (fd != -1) 1092b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1093b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper int try (Elf *elf) 1094b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1095b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper int result = 0; 1096b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1097b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (elf == NULL) 1098b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper return 0; 1099b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1100b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (elf_kind (elf) == ELF_K_ELF) 1101b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1102b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* We have an ELF file. We now can find out 1103b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper what the output format should be. */ 1104b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper XElf_Ehdr_vardef(ehdr); 1105b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1106b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Get the ELF header of the object. */ 1107b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper xelf_getehdr (elf, ehdr); 1108b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (ehdr != NULL) 1109b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.ebl = 1110b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ebl_openbackend_machine (ehdr->e_machine); 1111b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1112b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper result = 1; 1113b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1114b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else if (elf_kind (elf) == ELF_K_AR) 1115b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1116b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Try the archive members. This could 1117b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper potentially lead to wrong results if the 1118b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper archive contains files for more than one 1119b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper architecture. But this is the user's 1120b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper problem. */ 1121b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper Elf *subelf; 1122b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper Elf_Cmd cmd = ELF_C_READ_MMAP; 1123b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1124b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper while ((subelf = elf_begin (fd, cmd, elf)) != NULL) 1125b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1126b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper cmd = elf_next (subelf); 1127b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1128b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (try (subelf) != 0) 1129b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 1130b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1131b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1132b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1133b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper elf_end (elf); 1134b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1135b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper return result; 1136b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1137b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1138b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (try (elf_begin (fd, ELF_C_READ_MMAP, NULL)) != 0) 1139b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Found a file. */ 1140b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 1141b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1142b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1143b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper runp = runp->next; 1144b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1145b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1146b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (ld_state.ebl == NULL) 1147b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1148b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper error (0, 0, gettext ("\ 1149b08d5a8fb42f4586d756068065186b5af7e48daUlrich Dreppercould not find input file to determine output file format")); 1150b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper error (EXIT_FAILURE, 0, gettext ("\ 1151b08d5a8fb42f4586d756068065186b5af7e48daUlrich Dreppertry again with an appropriate '-m' parameter")); 1152b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1153b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1154b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1155b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* We don't need the list of input files anymore. The second run over 1156b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper the parameters will handle them. */ 1157b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper while (input_file_list != NULL) 1158b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1159b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct file_list *oldp = input_file_list; 1160b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper input_file_list = input_file_list->next; 1161b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper free (oldp); 1162b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1163b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1164b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* We also know now what kind of file we are supposed to create. If 1165b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper the user hasn't selected anythign we create and executable. */ 1166b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (ld_state.file_type == no_file_type) 1167b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.file_type = executable_file_type; 1168b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper} 1169b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1170b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Add DIR to the list of directories searched for object files and 1171b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper libraries. */ 1172b08d5a8fb42f4586d756068065186b5af7e48daUlrich Dreppervoid 1173b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperld_new_searchdir (const char *dir) 1174b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 1175b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct pathelement *newpath; 1176b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1177b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper newpath = (struct pathelement *) 1178b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper obstack_calloc (&ld_state.smem, sizeof (struct pathelement)); 1179b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1180b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper newpath->pname = dir; 1181b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1182b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Enqueue the file. */ 1183b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (ld_state.tailpaths == NULL) 1184b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.paths = ld_state.tailpaths = newpath; 1185b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else 1186b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1187b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.tailpaths->next = newpath; 1188b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.tailpaths = newpath; 1189b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1190b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper} 1191b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1192b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1193b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstruct usedfiles * 1194b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperld_new_inputfile (const char *fname, enum file_type type) 1195b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 1196b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct usedfiles *newfile = (struct usedfiles *) 1197b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper obstack_calloc (&ld_state.smem, sizeof (struct usedfiles)); 1198b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1199b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper newfile->soname = newfile->fname = newfile->rfname = fname; 1200b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper newfile->file_type = type; 1201b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper newfile->extract_rule = ld_state.extract_rule; 12028c56fe3b2c753234beb6f58a81c8b96f008226efUlrich Drepper newfile->as_needed = ld_state.as_needed; 1203b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper newfile->lazyload = ld_state.lazyload; 1204b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper newfile->status = not_opened; 1205b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1206b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper return newfile; 1207b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper} 1208b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1209b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1210b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Create an array listing all the sections. We will than pass this 1211b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper array to a system specific function which can reorder it at will. 1212b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper The functions can also merge sections if this is what is 1213b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper wanted. */ 1214b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic void 1215b08d5a8fb42f4586d756068065186b5af7e48daUlrich Dreppercollect_sections (void) 1216b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 1217b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper void *p ; 1218b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct scnhead *h; 1219b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper size_t cnt; 1220b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1221b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* We have that many sections. At least for now. */ 1222b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.nallsections = ld_state.section_tab.filled; 1223b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1224b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Allocate the array. We allocate one more entry than computed so 1225b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper far since we might need a new section for the copy relocations. */ 1226b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.allsections = 1227b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper (struct scnhead **) obstack_alloc (&ld_state.smem, 1228b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper (ld_state.nallsections + 1) 1229b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper * sizeof (struct scnhead *)); 1230b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1231b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Fill the array. We rely here on the hash table iterator to 1232b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper return the entries in the order they were added. */ 1233b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper cnt = 0; 1234b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper p = NULL; 1235b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper while ((h = ld_section_tab_iterate (&ld_state.section_tab, &p)) != NULL) 1236b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1237b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct scninfo *runp; 1238b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper bool used = false; 1239b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1240b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (h->kind == scn_normal) 1241b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1242b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper runp = h->last; 1243b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper do 1244b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1245b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (h->type == SHT_REL || h->type == SHT_RELA) 1246b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1247b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (runp->used) 1248b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* This is a relocation section. If the section 1249b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper it is relocating is used in the result so must 1250b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper the relocation section. */ 1251b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper runp->used 1252b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper = runp->fileinfo->scninfo[SCNINFO_SHDR (runp->shdr).sh_info].used; 1253b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1254b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1255b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Accumulate the result. */ 1256b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper used |= runp->used; 1257b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1258b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Next input section. */ 1259b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper runp = runp->next; 1260b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1261b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper while (runp != h->last); 1262b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1263b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper h->used = used; 1264b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1265b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1266b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.allsections[cnt++] = h; 1267b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1268b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.nusedsections = cnt; 1269b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1270b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper assert (cnt == ld_state.nallsections); 1271b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper} 1272b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1273b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1274b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Add given path to the end of list. */ 1275b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic void 1276b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperadd_rxxpath (struct pathelement **pathp, const char *str) 1277b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 1278b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct pathelement *newp; 1279b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1280b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* The path elements can in theory be freed after we read all the 1281b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper files. But the amount of memory we are talking about is small 1282b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper and the cost of free() calls is not neglectable. */ 1283b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper newp = (struct pathelement *) obstack_alloc (&ld_state.smem, sizeof (*newp)); 1284b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper newp->pname = str; 1285b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper newp->exist = 0; 1286b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#ifndef NDEBUG 1287b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper newp->next = NULL; 1288b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#endif 1289b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1290b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper CSNGL_LIST_ADD_REAR (*pathp, newp); 1291b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper} 1292b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1293b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1294b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Convert lists of possibly colon-separated directory lists into lists 1295b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper where each entry is for a single directory. */ 1296b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic void 1297b08d5a8fb42f4586d756068065186b5af7e48daUlrich Dreppernormalize_dirlist (struct pathelement **pathp) 1298b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 1299b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct pathelement *firstp = *pathp; 1300b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1301b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper do 1302b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1303b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper const char *pname = (*pathp)->pname; 1304b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper const char *colonp = strchrnul (pname, ':'); 1305b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1306b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (colonp != NULL) 1307b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1308b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct pathelement *lastp = *pathp; 1309b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct pathelement *newp; 1310b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1311b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper while (1) 1312b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1313b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (colonp == pname) 1314b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper lastp->pname = "."; 1315b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else 1316b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper lastp->pname = obstack_strndup (&ld_state.smem, pname, 1317b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper colonp - pname); 1318b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1319b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (*colonp == '\0') 1320b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper break; 1321b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper pname = colonp + 1; 1322b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1323b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper newp = (struct pathelement *) obstack_alloc (&ld_state.smem, 1324b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper sizeof (*newp)); 1325b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper newp->next = lastp->next; 1326b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper newp->exist = 0; 1327b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper lastp = lastp->next = newp; 1328b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1329b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper colonp = strchrnul (pname, ':'); 1330b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1331b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1332b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper pathp = &lastp->next; 1333b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1334b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else 1335b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper pathp = &(*pathp)->next; 1336b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1337b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper while (*pathp != firstp); 1338b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper} 1339b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1340b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1341b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Called after all parameters are parsed to bring the runpath/rpath 1342b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper information into a usable form. */ 1343b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic void 1344b08d5a8fb42f4586d756068065186b5af7e48daUlrich Dreppergen_rxxpath_data (void) 1345b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 1346b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper char *ld_library_path2; 1347b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1348b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Convert the information in true single-linked lists for easy use. 1349b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper At this point we also discard the rpath information if runpath 1350b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper information is provided. rpath is deprecated and should not be 1351b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper used (or ever be invented for that matter). */ 1352b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (ld_state.rpath != NULL) 1353b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1354b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct pathelement *endp = ld_state.rpath; 1355b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.rpath = ld_state.rpath->next; 1356b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper endp->next = NULL; 1357b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1358b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (ld_state.rpath_link != NULL) 1359b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1360b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct pathelement *endp = ld_state.rpath_link; 1361b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.rpath_link = ld_state.rpath_link->next; 1362b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper endp->next = NULL; 1363b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1364b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1365b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (ld_state.runpath != NULL) 1366b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1367b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct pathelement *endp = ld_state.runpath; 1368b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.runpath = ld_state.runpath->next; 1369b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper endp->next = NULL; 1370b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1371b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* If rpath information is also available discard it. 1372b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper XXX Should there be a possibility to avoid this? */ 1373b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper while (ld_state.rpath != NULL) 1374b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1375b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct pathelement *old = ld_state.rpath; 1376b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.rpath = ld_state.rpath->next; 1377b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper free (old); 1378b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1379b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1380b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (ld_state.runpath_link != NULL) 1381b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1382b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct pathelement *endp = ld_state.runpath_link; 1383b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.runpath_link = ld_state.runpath_link->next; 1384b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper endp->next = NULL; 1385b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1386b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* If rpath information is also available discard it. 1387b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper XXX Should there be a possibility to avoid this? */ 1388b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper while (ld_state.rpath_link != NULL) 1389b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1390b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct pathelement *old = ld_state.rpath_link; 1391b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_state.rpath_link = ld_state.rpath_link->next; 1392b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper free (old); 1393b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1394b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1395b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* The information in the strings in the list can actually be 1396b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper directory lists themselves, with entries separated by colons. 1397b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper Convert the list now to a list with one list entry for each 1398b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper directory. */ 1399b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper normalize_dirlist (&ld_state.runpath_link); 1400b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1401b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else if (ld_state.rpath_link != NULL) 1402b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Same as for the runpath_link above. */ 1403b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper normalize_dirlist (&ld_state.rpath_link); 1404b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1405b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1406b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* As a related task, handle the LD_LIBRARY_PATH value here. First 1407b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper we have to possibly split the value found (if it contains a 1408b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper semicolon). Then we have to split the value in list of 1409b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper directories, i.e., split at the colons. */ 1410b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (ld_library_path1 != NULL) 1411b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1412b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_library_path2 = strchr (ld_library_path1, ';'); 1413b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (ld_library_path2 == NULL) 1414b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1415b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* If no semicolon is present the directories are looked at 1416b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper after the -L parameters (-> ld_library_path2). */ 1417b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_library_path2 = ld_library_path1; 1418b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_library_path1 = NULL; 1419b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1420b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else 1421b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1422b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* NUL terminate the first part. */ 1423b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper *ld_library_path2++ = '\0'; 1424b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1425b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Convert the string value in a list. */ 1426b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper add_rxxpath (&ld_state.ld_library_path1, ld_library_path1); 1427b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper normalize_dirlist (&ld_state.ld_library_path1); 1428b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1429b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1430b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper add_rxxpath (&ld_state.ld_library_path2, ld_library_path2); 1431b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper normalize_dirlist (&ld_state.ld_library_path2); 1432b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1433b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper} 1434b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1435b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1436b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic void 1437b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperread_version_script (const char *fname) 1438b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 1439b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Open the file. The name is supposed to be the complete (relative 1440b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper or absolute) path. No search along a path will be performed. */ 1441b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ldin = fopen (fname, "r"); 1442b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (ldin == NULL) 1443e3f9b7db6c7361579ec5cc5eb5e414f7e93baeb6Ulrich Drepper error (EXIT_FAILURE, errno, gettext ("cannot read version script '%s'"), 1444b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper fname); 1445b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* No need for locking. */ 1446b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper __fsetlocking (ldin, FSETLOCKING_BYCALLER); 1447b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1448b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Tell the parser that this is a version script. */ 1449b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ld_scan_version_script = 1; 1450b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1451b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ldlineno = 1; 1452b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ldin_fname = fname; 1453b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (ldparse () != 0) 1454b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Something went wrong during parsing. */ 1455b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper exit (EXIT_FAILURE); 1456b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1457b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper fclose (ldin); 1458b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper} 1459b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1460b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1461b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic void 1462b08d5a8fb42f4586d756068065186b5af7e48daUlrich Dreppercreate_lscript_symbols (void) 1463b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 1464b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Walk through the data from the linker script and generate all the 1465b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper symbols which are required to be present and and those marked 1466b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper with PROVIDE if there is a undefined reference. */ 1467b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (ld_state.output_segments == NULL) 1468b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper return; 1469b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1470b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct output_segment *segment = ld_state.output_segments->next; 1471b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper do 1472b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1473b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct output_rule *orule; 1474b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1475b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper for (orule = segment->output_rules; orule != NULL; orule = orule->next) 1476b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (orule->tag == output_assignment 1477b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* The assignments to "." (i.e., the PC) have to be 1478b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ignored here. */ 1479b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper && strcmp (orule->val.assignment->variable, ".") != 0) 1480b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1481b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct symbol *s = ld_state.unresolved; 1482b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1483b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Check whether the symbol is needed. */ 1484b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (likely (s != NULL)) 1485b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1486b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct symbol *first = s; 1487b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper const char *providename = orule->val.assignment->variable; 1488b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1489b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Determine whether the provided symbol is still 1490b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper undefined. */ 1491b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper // XXX TODO Loop inside a loop. Gag! Must rewrite. */ 1492b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper do 1493b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (strcmp (s->name, providename) == 0) 1494b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1495b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Not defined but referenced. */ 1496b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (unlikely (!s->defined)) 1497b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1498b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Put on the list of symbols. First remove it from 1499b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper whatever list it currently is on. */ 1500b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper CDBL_LIST_DEL (ld_state.unresolved, s); 1501b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper --ld_state.nunresolved; 1502b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper goto use_it; 1503b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1504b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1505b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (unlikely (!orule->val.assignment->provide_flag)) 1506b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1507b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* The symbol is already defined and now again 1508b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper in the linker script. This is an error. */ 1509b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper error (0, 0, gettext ("\ 1510b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperduplicate definition of '%s' in linker script"), 1511b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper providename); 1512b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper goto next_rule; 1513b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1514b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1515b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper while ((s = s->next) != first); 1516b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1517b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1518b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* If the symbol only has to be provided if it is needed, 1519b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ignore it here since it is not undefined. */ 1520b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (orule->val.assignment->provide_flag) 1521b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper continue; 1522b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1523b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Allocate memory for this new symbol. */ 1524b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper s = (struct symbol *) 1525b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper obstack_calloc (&ld_state.smem, sizeof (struct symbol)); 1526b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1527b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Initialize it. */ 1528b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper s->name = orule->val.assignment->variable; 1529b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1530b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Insert it into the symbol hash table. */ 1531b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper unsigned long int hval = elf_hash (s->name); 1532b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (unlikely (ld_symbol_tab_insert (&ld_state.symbol_tab, 1533b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper hval, s) != 0)) 1534b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1535b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* This means the symbol is defined somewhere else. 1536b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper Maybe it comes from a DSO or so. Get the 1537b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper definition. */ 1538b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper free (s); 1539b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct symbol *old = ld_symbol_tab_find (&ld_state.symbol_tab, 1540b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper hval, s); 1541b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper assert (old != NULL); 1542b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper free (s); 1543b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1544b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* If this is a definition from the application itself 1545b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper this means a duplicate definition. */ 1546b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (! old->in_dso) 1547b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1548b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper error (0, 0, gettext ("\ 1549b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperduplicate definition of '%s' in linker script"), 1550b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper s->name); 1551b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper goto next_rule; 1552b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1553b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1554b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* We use the definition from the linker script. */ 1555b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper s = old; 1556b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1557b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1558b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper use_it: 1559b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* The symbol is (now) defined. */ 1560b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper s->defined = 1; 1561b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper s->type = STT_NOTYPE; 1562b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1563b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Add a reference to the symbol record. We will come 1564b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper across it when creating the output file. */ 1565b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper orule->val.assignment->sym = s; 1566b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1567b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper SNGL_LIST_PUSH (ld_state.lscript_syms, s); 1568b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ++ld_state.nlscript_syms; 1569b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1570b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper next_rule: 1571b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ; 1572b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1573b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1574b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper segment = segment->next; 1575b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1576b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper while (segment != ld_state.output_segments->next); 1577b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper} 1578b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1579b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1580b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Create creation of spection section symbols representing sections in the 1581b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper output file. This is done for symbols like _GLOBAL_OFFSET_TABLE_ and 1582b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper _DYNAMIC. */ 1583b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperstatic void 1584b08d5a8fb42f4586d756068065186b5af7e48daUlrich Dreppercreate_special_section_symbol (struct symbol **symp, const char *name) 1585b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 1586b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (*symp == NULL) 1587b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper { 1588b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* No symbol defined found yet. Create one. */ 1589b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper struct symbol *newsym = (struct symbol *) 1590b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper obstack_calloc (&ld_state.smem, sizeof (*newsym)); 1591b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1592b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper newsym->name = name; 1593b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper // XXX Should we mark the symbol hidden? They are hardly useful 1594b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper // used outside the current object. 1595b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1596b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Add to the symbol table. */ 1597b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper if (unlikely (ld_symbol_tab_insert (&ld_state.symbol_tab, 1598b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper elf_hash (name), newsym) != 0)) 1599b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper abort (); 1600b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1601b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper *symp = newsym; 1602b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper } 1603b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper else if ((*symp)->defined) 1604b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Cannot happen. We do use this symbol from any input file. */ 1605b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper abort (); 1606b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1607b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper (*symp)->defined = 1; 160828ed895fdc303b2a793506bb1fcdd35d5fd14e70Ulrich Drepper (*symp)->local = 1; 160928ed895fdc303b2a793506bb1fcdd35d5fd14e70Ulrich Drepper (*symp)->hidden = 1; 1610b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper (*symp)->type = STT_OBJECT; 1611b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 1612b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ++ld_state.nsymtab; 1613b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper} 16143cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper 16153cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper 16163cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper#include "debugpred.h" 1617