133965Sjdp/* Parse options for the GNU linker. 278828Sobrien Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 3218822Sdim 2001, 2002, 2003, 2004, 2005, 2006, 2007 438889Sjdp Free Software Foundation, Inc. 533965Sjdp 6130561Sobrien This file is part of GLD, the Gnu Linker. 733965Sjdp 8130561Sobrien GLD is free software; you can redistribute it and/or modify 9130561Sobrien it under the terms of the GNU General Public License as published by 10130561Sobrien the Free Software Foundation; either version 2, or (at your option) 11130561Sobrien any later version. 1233965Sjdp 13130561Sobrien GLD is distributed in the hope that it will be useful, 14130561Sobrien but WITHOUT ANY WARRANTY; without even the implied warranty of 15130561Sobrien MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16130561Sobrien GNU General Public License for more details. 1733965Sjdp 18130561Sobrien You should have received a copy of the GNU General Public License 19130561Sobrien along with GLD; see the file COPYING. If not, write to the Free 20218822Sdim Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA 21218822Sdim 02110-1301, USA. */ 2233965Sjdp 23218822Sdim#include "sysdep.h" 2433965Sjdp#include "bfd.h" 25218822Sdim#include "bfdver.h" 2633965Sjdp#include "libiberty.h" 2733965Sjdp#include <stdio.h> 2833965Sjdp#include <string.h> 2989857Sobrien#include "safe-ctype.h" 3033965Sjdp#include "getopt.h" 3133965Sjdp#include "bfdlink.h" 3233965Sjdp#include "ld.h" 3333965Sjdp#include "ldmain.h" 3433965Sjdp#include "ldmisc.h" 3533965Sjdp#include "ldexp.h" 3633965Sjdp#include "ldlang.h" 37107492Sobrien#include <ldgram.h> 3833965Sjdp#include "ldlex.h" 3933965Sjdp#include "ldfile.h" 4033965Sjdp#include "ldver.h" 4133965Sjdp#include "ldemul.h" 4277298Sobrien#include "demangle.h" 4333965Sjdp 4438889Sjdp#ifndef PATH_SEPARATOR 4538889Sjdp#if defined (__MSDOS__) || (defined (_WIN32) && ! defined (__CYGWIN32__)) 4638889Sjdp#define PATH_SEPARATOR ';' 4738889Sjdp#else 4838889Sjdp#define PATH_SEPARATOR ':' 4938889Sjdp#endif 5038889Sjdp#endif 5138889Sjdp 5277298Sobrien/* Somewhere above, sys/stat.h got included . . . . */ 5333965Sjdp#if !defined(S_ISDIR) && defined(S_IFDIR) 5433965Sjdp#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) 5533965Sjdp#endif 5633965Sjdp 57130561Sobrienstatic void set_default_dirlist (char *); 58130561Sobrienstatic void set_section_start (char *, char *); 59218822Sdimstatic void set_segment_start (const char *, char *); 60130561Sobrienstatic void help (void); 6133965Sjdp 6233965Sjdp/* Non-zero if we are processing a --defsym from the command line. */ 6333965Sjdpint parsing_defsym = 0; 6433965Sjdp 6533965Sjdp/* Codes used for the long options with no short synonyms. 150 isn't 6633965Sjdp special; it's just an arbitrary non-ASCII char value. */ 67130561Sobrienenum option_values 68130561Sobrien{ 69130561Sobrien OPTION_ASSERT = 150, 70130561Sobrien OPTION_CALL_SHARED, 71130561Sobrien OPTION_CREF, 72130561Sobrien OPTION_DEFSYM, 73130561Sobrien OPTION_DEMANGLE, 74130561Sobrien OPTION_DYNAMIC_LINKER, 75218822Sdim OPTION_SYSROOT, 76130561Sobrien OPTION_EB, 77130561Sobrien OPTION_EL, 78130561Sobrien OPTION_EMBEDDED_RELOCS, 79130561Sobrien OPTION_EXPORT_DYNAMIC, 80130561Sobrien OPTION_HELP, 81130561Sobrien OPTION_IGNORE, 82130561Sobrien OPTION_MAP, 83130561Sobrien OPTION_NO_DEMANGLE, 84130561Sobrien OPTION_NO_KEEP_MEMORY, 85130561Sobrien OPTION_NO_WARN_MISMATCH, 86218822Sdim OPTION_NO_WARN_SEARCH_MISMATCH, 87130561Sobrien OPTION_NOINHIBIT_EXEC, 88130561Sobrien OPTION_NON_SHARED, 89130561Sobrien OPTION_NO_WHOLE_ARCHIVE, 90130561Sobrien OPTION_OFORMAT, 91130561Sobrien OPTION_RELAX, 92130561Sobrien OPTION_RETAIN_SYMBOLS_FILE, 93130561Sobrien OPTION_RPATH, 94130561Sobrien OPTION_RPATH_LINK, 95130561Sobrien OPTION_SHARED, 96130561Sobrien OPTION_SONAME, 97130561Sobrien OPTION_SORT_COMMON, 98218822Sdim OPTION_SORT_SECTION, 99130561Sobrien OPTION_STATS, 100130561Sobrien OPTION_SYMBOLIC, 101218822Sdim OPTION_SYMBOLIC_FUNCTIONS, 102130561Sobrien OPTION_TASK_LINK, 103130561Sobrien OPTION_TBSS, 104130561Sobrien OPTION_TDATA, 105130561Sobrien OPTION_TTEXT, 106130561Sobrien OPTION_TRADITIONAL_FORMAT, 107130561Sobrien OPTION_UR, 108130561Sobrien OPTION_VERBOSE, 109130561Sobrien OPTION_VERSION, 110130561Sobrien OPTION_VERSION_SCRIPT, 111130561Sobrien OPTION_VERSION_EXPORTS_SECTION, 112218822Sdim OPTION_DYNAMIC_LIST, 113218822Sdim OPTION_DYNAMIC_LIST_CPP_NEW, 114218822Sdim OPTION_DYNAMIC_LIST_CPP_TYPEINFO, 115218822Sdim OPTION_DYNAMIC_LIST_DATA, 116130561Sobrien OPTION_WARN_COMMON, 117130561Sobrien OPTION_WARN_CONSTRUCTORS, 118130561Sobrien OPTION_WARN_FATAL, 119130561Sobrien OPTION_WARN_MULTIPLE_GP, 120130561Sobrien OPTION_WARN_ONCE, 121130561Sobrien OPTION_WARN_SECTION_ALIGN, 122130561Sobrien OPTION_SPLIT_BY_RELOC, 123130561Sobrien OPTION_SPLIT_BY_FILE , 124130561Sobrien OPTION_WHOLE_ARCHIVE, 125218822Sdim OPTION_ADD_NEEDED, 126218822Sdim OPTION_NO_ADD_NEEDED, 127130561Sobrien OPTION_AS_NEEDED, 128130561Sobrien OPTION_NO_AS_NEEDED, 129130561Sobrien OPTION_WRAP, 130130561Sobrien OPTION_FORCE_EXE_SUFFIX, 131130561Sobrien OPTION_GC_SECTIONS, 132130561Sobrien OPTION_NO_GC_SECTIONS, 133218822Sdim OPTION_PRINT_GC_SECTIONS, 134218822Sdim OPTION_NO_PRINT_GC_SECTIONS, 135218822Sdim OPTION_HASH_SIZE, 136130561Sobrien OPTION_CHECK_SECTIONS, 137130561Sobrien OPTION_NO_CHECK_SECTIONS, 138130561Sobrien OPTION_NO_UNDEFINED, 139130561Sobrien OPTION_INIT, 140130561Sobrien OPTION_FINI, 141130561Sobrien OPTION_SECTION_START, 142130561Sobrien OPTION_UNIQUE, 143130561Sobrien OPTION_TARGET_HELP, 144130561Sobrien OPTION_ALLOW_SHLIB_UNDEFINED, 145130561Sobrien OPTION_NO_ALLOW_SHLIB_UNDEFINED, 146130561Sobrien OPTION_ALLOW_MULTIPLE_DEFINITION, 147130561Sobrien OPTION_NO_UNDEFINED_VERSION, 148218822Sdim OPTION_DEFAULT_SYMVER, 149218822Sdim OPTION_DEFAULT_IMPORTED_SYMVER, 150130561Sobrien OPTION_DISCARD_NONE, 151130561Sobrien OPTION_SPARE_DYNAMIC_TAGS, 152130561Sobrien OPTION_NO_DEFINE_COMMON, 153130561Sobrien OPTION_NOSTDLIB, 154130561Sobrien OPTION_NO_OMAGIC, 155130561Sobrien OPTION_STRIP_DISCARDED, 156130561Sobrien OPTION_NO_STRIP_DISCARDED, 157130561Sobrien OPTION_ACCEPT_UNKNOWN_INPUT_ARCH, 158130561Sobrien OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH, 159130561Sobrien OPTION_PIE, 160130561Sobrien OPTION_UNRESOLVED_SYMBOLS, 161130561Sobrien OPTION_WARN_UNRESOLVED_SYMBOLS, 162218822Sdim OPTION_ERROR_UNRESOLVED_SYMBOLS, 163218822Sdim OPTION_WARN_SHARED_TEXTREL, 164218822Sdim OPTION_REDUCE_MEMORY_OVERHEADS, 165218822Sdim OPTION_DEFAULT_SCRIPT 166130561Sobrien}; 16733965Sjdp 16833965Sjdp/* The long options. This structure is used for both the option 16933965Sjdp parsing and the help text. */ 17033965Sjdp 17133965Sjdpstruct ld_option 17233965Sjdp{ 17333965Sjdp /* The long option information. */ 17433965Sjdp struct option opt; 17533965Sjdp /* The short option with the same meaning ('\0' if none). */ 17633965Sjdp char shortopt; 17733965Sjdp /* The name of the argument (NULL if none). */ 17833965Sjdp const char *arg; 17933965Sjdp /* The documentation string. If this is NULL, this is a synonym for 18033965Sjdp the previous option. */ 18133965Sjdp const char *doc; 18277298Sobrien enum { 18377298Sobrien /* Use one dash before long option name. */ 18477298Sobrien ONE_DASH, 18577298Sobrien /* Use two dashes before long option name. */ 18677298Sobrien TWO_DASHES, 18777298Sobrien /* Only accept two dashes before the long option name. 18877298Sobrien This is an overloading of the use of this enum, since originally it 18977298Sobrien was only intended to tell the --help display function how to display 19077298Sobrien the long option name. This feature was added in order to resolve 19177298Sobrien the confusion about the -omagic command line switch. Is it setting 19277298Sobrien the output file name to "magic" or is it setting the NMAGIC flag on 19377298Sobrien the output ? It has been decided that it is setting the output file 19477298Sobrien name, and that if you want to set the NMAGIC flag you should use -N 19577298Sobrien or --omagic. */ 19677298Sobrien EXACTLY_TWO_DASHES, 19777298Sobrien /* Don't mention this option in --help output. */ 19877298Sobrien NO_HELP 19977298Sobrien } control; 20033965Sjdp}; 20133965Sjdp 20233965Sjdpstatic const struct ld_option ld_options[] = 20333965Sjdp{ 20433965Sjdp { {NULL, required_argument, NULL, '\0'}, 205218822Sdim 'a', N_("KEYWORD"), N_("Shared library control for HP/UX compatibility"), 206218822Sdim ONE_DASH }, 20733965Sjdp { {"architecture", required_argument, NULL, 'A'}, 208218822Sdim 'A', N_("ARCH"), N_("Set architecture") , TWO_DASHES }, 20933965Sjdp { {"format", required_argument, NULL, 'b'}, 210218822Sdim 'b', N_("TARGET"), N_("Specify target for following input files"), 211218822Sdim TWO_DASHES }, 21233965Sjdp { {"mri-script", required_argument, NULL, 'c'}, 213218822Sdim 'c', N_("FILE"), N_("Read MRI format linker script"), TWO_DASHES }, 21433965Sjdp { {"dc", no_argument, NULL, 'd'}, 215218822Sdim 'd', NULL, N_("Force common symbols to be defined"), ONE_DASH }, 21633965Sjdp { {"dp", no_argument, NULL, 'd'}, 217218822Sdim '\0', NULL, NULL, ONE_DASH }, 21833965Sjdp { {"entry", required_argument, NULL, 'e'}, 219218822Sdim 'e', N_("ADDRESS"), N_("Set start address"), TWO_DASHES }, 22033965Sjdp { {"export-dynamic", no_argument, NULL, OPTION_EXPORT_DYNAMIC}, 221218822Sdim 'E', NULL, N_("Export all dynamic symbols"), TWO_DASHES }, 22260484Sobrien { {"EB", no_argument, NULL, OPTION_EB}, 223218822Sdim '\0', NULL, N_("Link big-endian objects"), ONE_DASH }, 22460484Sobrien { {"EL", no_argument, NULL, OPTION_EL}, 225218822Sdim '\0', NULL, N_("Link little-endian objects"), ONE_DASH }, 22633965Sjdp { {"auxiliary", required_argument, NULL, 'f'}, 227218822Sdim 'f', N_("SHLIB"), N_("Auxiliary filter for shared object symbol table"), 228218822Sdim TWO_DASHES }, 22933965Sjdp { {"filter", required_argument, NULL, 'F'}, 230218822Sdim 'F', N_("SHLIB"), N_("Filter for shared object symbol table"), 231218822Sdim TWO_DASHES }, 23233965Sjdp { {NULL, no_argument, NULL, '\0'}, 233218822Sdim 'g', NULL, N_("Ignored"), ONE_DASH }, 23433965Sjdp { {"gpsize", required_argument, NULL, 'G'}, 235218822Sdim 'G', N_("SIZE"), N_("Small data size (if no size, same as --shared)"), 236218822Sdim TWO_DASHES }, 23733965Sjdp { {"soname", required_argument, NULL, OPTION_SONAME}, 238218822Sdim 'h', N_("FILENAME"), N_("Set internal name of shared library"), ONE_DASH }, 23989857Sobrien { {"dynamic-linker", required_argument, NULL, OPTION_DYNAMIC_LINKER}, 240218822Sdim 'I', N_("PROGRAM"), N_("Set PROGRAM as the dynamic linker to use"), 241218822Sdim TWO_DASHES }, 24233965Sjdp { {"library", required_argument, NULL, 'l'}, 243218822Sdim 'l', N_("LIBNAME"), N_("Search for library LIBNAME"), TWO_DASHES }, 24433965Sjdp { {"library-path", required_argument, NULL, 'L'}, 245218822Sdim 'L', N_("DIRECTORY"), N_("Add DIRECTORY to library search path"), 246218822Sdim TWO_DASHES }, 247218822Sdim { {"sysroot=<DIRECTORY>", required_argument, NULL, OPTION_SYSROOT}, 248218822Sdim '\0', NULL, N_("Override the default sysroot location"), TWO_DASHES }, 24933965Sjdp { {NULL, required_argument, NULL, '\0'}, 250218822Sdim 'm', N_("EMULATION"), N_("Set emulation"), ONE_DASH }, 25133965Sjdp { {"print-map", no_argument, NULL, 'M'}, 252218822Sdim 'M', NULL, N_("Print map file on standard output"), TWO_DASHES }, 25333965Sjdp { {"nmagic", no_argument, NULL, 'n'}, 254218822Sdim 'n', NULL, N_("Do not page align data"), TWO_DASHES }, 25533965Sjdp { {"omagic", no_argument, NULL, 'N'}, 256218822Sdim 'N', NULL, N_("Do not page align data, do not make text readonly"), 257218822Sdim EXACTLY_TWO_DASHES }, 258130561Sobrien { {"no-omagic", no_argument, NULL, OPTION_NO_OMAGIC}, 259218822Sdim '\0', NULL, N_("Page align data, make text readonly"), 260218822Sdim EXACTLY_TWO_DASHES }, 26133965Sjdp { {"output", required_argument, NULL, 'o'}, 262218822Sdim 'o', N_("FILE"), N_("Set output file name"), EXACTLY_TWO_DASHES }, 26333965Sjdp { {NULL, required_argument, NULL, '\0'}, 264218822Sdim 'O', NULL, N_("Optimize output file"), ONE_DASH }, 26560484Sobrien { {"Qy", no_argument, NULL, OPTION_IGNORE}, 266218822Sdim '\0', NULL, N_("Ignored for SVR4 compatibility"), ONE_DASH }, 26777298Sobrien { {"emit-relocs", no_argument, NULL, 'q'}, 268218822Sdim 'q', NULL, "Generate relocations in final output", TWO_DASHES }, 269130561Sobrien { {"relocatable", no_argument, NULL, 'r'}, 270218822Sdim 'r', NULL, N_("Generate relocatable output"), TWO_DASHES }, 27133965Sjdp { {NULL, no_argument, NULL, '\0'}, 272218822Sdim 'i', NULL, NULL, ONE_DASH }, 27333965Sjdp { {"just-symbols", required_argument, NULL, 'R'}, 274218822Sdim 'R', N_("FILE"), N_("Just link symbols (if directory, same as --rpath)"), 275218822Sdim TWO_DASHES }, 27633965Sjdp { {"strip-all", no_argument, NULL, 's'}, 277218822Sdim 's', NULL, N_("Strip all symbols"), TWO_DASHES }, 27833965Sjdp { {"strip-debug", no_argument, NULL, 'S'}, 279218822Sdim 'S', NULL, N_("Strip debugging symbols"), TWO_DASHES }, 280130561Sobrien { {"strip-discarded", no_argument, NULL, OPTION_STRIP_DISCARDED}, 281218822Sdim '\0', NULL, N_("Strip symbols in discarded sections"), TWO_DASHES }, 282130561Sobrien { {"no-strip-discarded", no_argument, NULL, OPTION_NO_STRIP_DISCARDED}, 283218822Sdim '\0', NULL, N_("Do not strip symbols in discarded sections"), TWO_DASHES }, 28433965Sjdp { {"trace", no_argument, NULL, 't'}, 285218822Sdim 't', NULL, N_("Trace file opens"), TWO_DASHES }, 28633965Sjdp { {"script", required_argument, NULL, 'T'}, 287218822Sdim 'T', N_("FILE"), N_("Read linker script"), TWO_DASHES }, 288218822Sdim { {"default-script", required_argument, NULL, OPTION_DEFAULT_SCRIPT}, 289218822Sdim '\0', N_("FILE"), N_("Read default linker script"), TWO_DASHES }, 290218822Sdim { {"dT", required_argument, NULL, OPTION_DEFAULT_SCRIPT}, 291218822Sdim '\0', NULL, NULL, ONE_DASH }, 29233965Sjdp { {"undefined", required_argument, NULL, 'u'}, 293218822Sdim 'u', N_("SYMBOL"), N_("Start with undefined reference to SYMBOL"), 294218822Sdim TWO_DASHES }, 29577298Sobrien { {"unique", optional_argument, NULL, OPTION_UNIQUE}, 296218822Sdim '\0', N_("[=SECTION]"), 297218822Sdim N_("Don't merge input [SECTION | orphan] sections"), TWO_DASHES }, 29860484Sobrien { {"Ur", no_argument, NULL, OPTION_UR}, 299218822Sdim '\0', NULL, N_("Build global constructor/destructor tables"), ONE_DASH }, 30033965Sjdp { {"version", no_argument, NULL, OPTION_VERSION}, 301218822Sdim 'v', NULL, N_("Print version information"), TWO_DASHES }, 30233965Sjdp { {NULL, no_argument, NULL, '\0'}, 303218822Sdim 'V', NULL, N_("Print version and emulation information"), ONE_DASH }, 30433965Sjdp { {"discard-all", no_argument, NULL, 'x'}, 305218822Sdim 'x', NULL, N_("Discard all local symbols"), TWO_DASHES }, 30633965Sjdp { {"discard-locals", no_argument, NULL, 'X'}, 307218822Sdim 'X', NULL, N_("Discard temporary local symbols (default)"), TWO_DASHES }, 30889857Sobrien { {"discard-none", no_argument, NULL, OPTION_DISCARD_NONE}, 309218822Sdim '\0', NULL, N_("Don't discard any local symbols"), TWO_DASHES }, 31033965Sjdp { {"trace-symbol", required_argument, NULL, 'y'}, 311218822Sdim 'y', N_("SYMBOL"), N_("Trace mentions of SYMBOL"), TWO_DASHES }, 31233965Sjdp { {NULL, required_argument, NULL, '\0'}, 313218822Sdim 'Y', N_("PATH"), N_("Default search path for Solaris compatibility"), 314218822Sdim ONE_DASH }, 31533965Sjdp { {"start-group", no_argument, NULL, '('}, 316218822Sdim '(', NULL, N_("Start a group"), TWO_DASHES }, 31733965Sjdp { {"end-group", no_argument, NULL, ')'}, 318218822Sdim ')', NULL, N_("End a group"), TWO_DASHES }, 319218822Sdim { {"accept-unknown-input-arch", no_argument, NULL, 320218822Sdim OPTION_ACCEPT_UNKNOWN_INPUT_ARCH}, 321218822Sdim '\0', NULL, 322218822Sdim N_("Accept input files whose architecture cannot be determined"), 323218822Sdim TWO_DASHES }, 324218822Sdim { {"no-accept-unknown-input-arch", no_argument, NULL, 325218822Sdim OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH}, 326218822Sdim '\0', NULL, N_("Reject input files whose architecture is unknown"), 327218822Sdim TWO_DASHES }, 328218822Sdim { {"add-needed", no_argument, NULL, OPTION_ADD_NEEDED}, 329218822Sdim '\0', NULL, N_("Set DT_NEEDED tags for DT_NEEDED entries in\n" 330218822Sdim "\t\t\t\tfollowing dynamic libs"), TWO_DASHES }, 331218822Sdim { {"no-add-needed", no_argument, NULL, OPTION_NO_ADD_NEEDED}, 332218822Sdim '\0', NULL, N_("Do not set DT_NEEDED tags for DT_NEEDED entries\n" 333218822Sdim "\t\t\t\tin following dynamic libs"), TWO_DASHES }, 334218822Sdim { {"as-needed", no_argument, NULL, OPTION_AS_NEEDED}, 335218822Sdim '\0', NULL, N_("Only set DT_NEEDED for following dynamic libs if used"), 336218822Sdim TWO_DASHES }, 337218822Sdim { {"no-as-needed", no_argument, NULL, OPTION_NO_AS_NEEDED}, 338218822Sdim '\0', NULL, N_("Always set DT_NEEDED for following dynamic libs"), 339218822Sdim TWO_DASHES }, 34033965Sjdp { {"assert", required_argument, NULL, OPTION_ASSERT}, 341218822Sdim '\0', N_("KEYWORD"), N_("Ignored for SunOS compatibility"), ONE_DASH }, 34233965Sjdp { {"Bdynamic", no_argument, NULL, OPTION_CALL_SHARED}, 343218822Sdim '\0', NULL, N_("Link against shared libraries"), ONE_DASH }, 34433965Sjdp { {"dy", no_argument, NULL, OPTION_CALL_SHARED}, 345218822Sdim '\0', NULL, NULL, ONE_DASH }, 34633965Sjdp { {"call_shared", no_argument, NULL, OPTION_CALL_SHARED}, 347218822Sdim '\0', NULL, NULL, ONE_DASH }, 34833965Sjdp { {"Bstatic", no_argument, NULL, OPTION_NON_SHARED}, 349218822Sdim '\0', NULL, N_("Do not link against shared libraries"), ONE_DASH }, 35033965Sjdp { {"dn", no_argument, NULL, OPTION_NON_SHARED}, 351218822Sdim '\0', NULL, NULL, ONE_DASH }, 35233965Sjdp { {"non_shared", no_argument, NULL, OPTION_NON_SHARED}, 353218822Sdim '\0', NULL, NULL, ONE_DASH }, 35433965Sjdp { {"static", no_argument, NULL, OPTION_NON_SHARED}, 355218822Sdim '\0', NULL, NULL, ONE_DASH }, 35633965Sjdp { {"Bsymbolic", no_argument, NULL, OPTION_SYMBOLIC}, 357218822Sdim '\0', NULL, N_("Bind global references locally"), ONE_DASH }, 358218822Sdim { {"Bsymbolic-functions", no_argument, NULL, OPTION_SYMBOLIC_FUNCTIONS}, 359218822Sdim '\0', NULL, N_("Bind global function references locally"), ONE_DASH }, 36060484Sobrien { {"check-sections", no_argument, NULL, OPTION_CHECK_SECTIONS}, 361218822Sdim '\0', NULL, N_("Check section addresses for overlaps (default)"), 362218822Sdim TWO_DASHES }, 36360484Sobrien { {"no-check-sections", no_argument, NULL, OPTION_NO_CHECK_SECTIONS}, 364218822Sdim '\0', NULL, N_("Do not check section addresses for overlaps"), 365218822Sdim TWO_DASHES }, 36633965Sjdp { {"cref", no_argument, NULL, OPTION_CREF}, 367218822Sdim '\0', NULL, N_("Output cross reference table"), TWO_DASHES }, 36833965Sjdp { {"defsym", required_argument, NULL, OPTION_DEFSYM}, 369218822Sdim '\0', N_("SYMBOL=EXPRESSION"), N_("Define a symbol"), TWO_DASHES }, 37077298Sobrien { {"demangle", optional_argument, NULL, OPTION_DEMANGLE}, 371218822Sdim '\0', N_("[=STYLE]"), N_("Demangle symbol names [using STYLE]"), 372218822Sdim TWO_DASHES }, 37333965Sjdp { {"embedded-relocs", no_argument, NULL, OPTION_EMBEDDED_RELOCS}, 374218822Sdim '\0', NULL, N_("Generate embedded relocs"), TWO_DASHES}, 375218822Sdim { {"fatal-warnings", no_argument, NULL, OPTION_WARN_FATAL}, 376218822Sdim '\0', NULL, N_("Treat warnings as errors"), 377218822Sdim TWO_DASHES }, 37860484Sobrien { {"fini", required_argument, NULL, OPTION_FINI}, 379218822Sdim '\0', N_("SYMBOL"), N_("Call SYMBOL at unload-time"), ONE_DASH }, 38033965Sjdp { {"force-exe-suffix", no_argument, NULL, OPTION_FORCE_EXE_SUFFIX}, 381218822Sdim '\0', NULL, N_("Force generation of file with .exe suffix"), TWO_DASHES}, 38260484Sobrien { {"gc-sections", no_argument, NULL, OPTION_GC_SECTIONS}, 383218822Sdim '\0', NULL, N_("Remove unused sections (on some targets)"), 384218822Sdim TWO_DASHES }, 38560484Sobrien { {"no-gc-sections", no_argument, NULL, OPTION_NO_GC_SECTIONS}, 386218822Sdim '\0', NULL, N_("Don't remove unused sections (default)"), 387218822Sdim TWO_DASHES }, 388218822Sdim { {"print-gc-sections", no_argument, NULL, OPTION_PRINT_GC_SECTIONS}, 389218822Sdim '\0', NULL, N_("List removed unused sections on stderr"), 390218822Sdim TWO_DASHES }, 391218822Sdim { {"no-print-gc-sections", no_argument, NULL, OPTION_NO_PRINT_GC_SECTIONS}, 392218822Sdim '\0', NULL, N_("Do not list removed unused sections"), 393218822Sdim TWO_DASHES }, 394218822Sdim { {"hash-size=<NUMBER>", required_argument, NULL, OPTION_HASH_SIZE}, 395218822Sdim '\0', NULL, N_("Set default hash table size close to <NUMBER>"), 396218822Sdim TWO_DASHES }, 39733965Sjdp { {"help", no_argument, NULL, OPTION_HELP}, 398218822Sdim '\0', NULL, N_("Print option help"), TWO_DASHES }, 39960484Sobrien { {"init", required_argument, NULL, OPTION_INIT}, 400218822Sdim '\0', N_("SYMBOL"), N_("Call SYMBOL at load-time"), ONE_DASH }, 40133965Sjdp { {"Map", required_argument, NULL, OPTION_MAP}, 402218822Sdim '\0', N_("FILE"), N_("Write a map file"), ONE_DASH }, 40389857Sobrien { {"no-define-common", no_argument, NULL, OPTION_NO_DEFINE_COMMON}, 404218822Sdim '\0', NULL, N_("Do not define Common storage"), TWO_DASHES }, 40560484Sobrien { {"no-demangle", no_argument, NULL, OPTION_NO_DEMANGLE }, 406218822Sdim '\0', NULL, N_("Do not demangle symbol names"), TWO_DASHES }, 40733965Sjdp { {"no-keep-memory", no_argument, NULL, OPTION_NO_KEEP_MEMORY}, 408218822Sdim '\0', NULL, N_("Use less memory and more disk I/O"), TWO_DASHES }, 40960484Sobrien { {"no-undefined", no_argument, NULL, OPTION_NO_UNDEFINED}, 410218822Sdim '\0', NULL, N_("Do not allow unresolved references in object files"), 411218822Sdim TWO_DASHES }, 41277298Sobrien { {"allow-shlib-undefined", no_argument, NULL, OPTION_ALLOW_SHLIB_UNDEFINED}, 413218822Sdim '\0', NULL, N_("Allow unresolved references in shared libaries"), 414218822Sdim TWO_DASHES }, 415218822Sdim { {"no-allow-shlib-undefined", no_argument, NULL, 416218822Sdim OPTION_NO_ALLOW_SHLIB_UNDEFINED}, 417218822Sdim '\0', NULL, N_("Do not allow unresolved references in shared libs"), 418218822Sdim TWO_DASHES }, 419218822Sdim { {"allow-multiple-definition", no_argument, NULL, 420218822Sdim OPTION_ALLOW_MULTIPLE_DEFINITION}, 421218822Sdim '\0', NULL, N_("Allow multiple definitions"), TWO_DASHES }, 422104834Sobrien { {"no-undefined-version", no_argument, NULL, OPTION_NO_UNDEFINED_VERSION}, 423218822Sdim '\0', NULL, N_("Disallow undefined version"), TWO_DASHES }, 424218822Sdim { {"default-symver", no_argument, NULL, OPTION_DEFAULT_SYMVER}, 425218822Sdim '\0', NULL, N_("Create default symbol version"), TWO_DASHES }, 426218822Sdim { {"default-imported-symver", no_argument, NULL, 427218822Sdim OPTION_DEFAULT_IMPORTED_SYMVER}, 428218822Sdim '\0', NULL, N_("Create default symbol version for imported symbols"), 429218822Sdim TWO_DASHES }, 43038889Sjdp { {"no-warn-mismatch", no_argument, NULL, OPTION_NO_WARN_MISMATCH}, 431218822Sdim '\0', NULL, N_("Don't warn about mismatched input files"), TWO_DASHES}, 432218822Sdim { {"no-warn-search-mismatch", no_argument, NULL, 433218822Sdim OPTION_NO_WARN_SEARCH_MISMATCH}, 434218822Sdim '\0', NULL, N_("Don't warn on finding an incompatible library"), 435218822Sdim TWO_DASHES}, 43633965Sjdp { {"no-whole-archive", no_argument, NULL, OPTION_NO_WHOLE_ARCHIVE}, 437218822Sdim '\0', NULL, N_("Turn off --whole-archive"), TWO_DASHES }, 43833965Sjdp { {"noinhibit-exec", no_argument, NULL, OPTION_NOINHIBIT_EXEC}, 439218822Sdim '\0', NULL, N_("Create an output file even if errors occur"), 440218822Sdim TWO_DASHES }, 44133965Sjdp { {"noinhibit_exec", no_argument, NULL, OPTION_NOINHIBIT_EXEC}, 442218822Sdim '\0', NULL, NULL, NO_HELP }, 44389857Sobrien { {"nostdlib", no_argument, NULL, OPTION_NOSTDLIB}, 444218822Sdim '\0', NULL, N_("Only use library directories specified on\n" 445218822Sdim "\t\t\t\tthe command line"), ONE_DASH }, 44633965Sjdp { {"oformat", required_argument, NULL, OPTION_OFORMAT}, 447218822Sdim '\0', N_("TARGET"), N_("Specify target of output file"), 448218822Sdim EXACTLY_TWO_DASHES }, 44933965Sjdp { {"qmagic", no_argument, NULL, OPTION_IGNORE}, 450218822Sdim '\0', NULL, N_("Ignored for Linux compatibility"), ONE_DASH }, 451218822Sdim { {"reduce-memory-overheads", no_argument, NULL, 452218822Sdim OPTION_REDUCE_MEMORY_OVERHEADS}, 453218822Sdim '\0', NULL, N_("Reduce memory overheads, possibly taking much longer"), 454218822Sdim TWO_DASHES }, 45533965Sjdp { {"relax", no_argument, NULL, OPTION_RELAX}, 456218822Sdim '\0', NULL, N_("Relax branches on certain targets"), TWO_DASHES }, 45733965Sjdp { {"retain-symbols-file", required_argument, NULL, 458218822Sdim OPTION_RETAIN_SYMBOLS_FILE}, 459218822Sdim '\0', N_("FILE"), N_("Keep only symbols listed in FILE"), TWO_DASHES }, 46033965Sjdp { {"rpath", required_argument, NULL, OPTION_RPATH}, 461218822Sdim '\0', N_("PATH"), N_("Set runtime shared library search path"), ONE_DASH }, 46233965Sjdp { {"rpath-link", required_argument, NULL, OPTION_RPATH_LINK}, 463218822Sdim '\0', N_("PATH"), N_("Set link time shared library search path"), 464218822Sdim ONE_DASH }, 46533965Sjdp { {"shared", no_argument, NULL, OPTION_SHARED}, 466218822Sdim '\0', NULL, N_("Create a shared library"), ONE_DASH }, 46733965Sjdp { {"Bshareable", no_argument, NULL, OPTION_SHARED }, /* FreeBSD. */ 468218822Sdim '\0', NULL, NULL, ONE_DASH }, 469130561Sobrien { {"pie", no_argument, NULL, OPTION_PIE}, 470218822Sdim '\0', NULL, N_("Create a position independent executable"), ONE_DASH }, 471130561Sobrien { {"pic-executable", no_argument, NULL, OPTION_PIE}, 472218822Sdim '\0', NULL, NULL, TWO_DASHES }, 47333965Sjdp { {"sort-common", no_argument, NULL, OPTION_SORT_COMMON}, 474218822Sdim '\0', NULL, N_("Sort common symbols by size"), TWO_DASHES }, 47533965Sjdp { {"sort_common", no_argument, NULL, OPTION_SORT_COMMON}, 476218822Sdim '\0', NULL, NULL, NO_HELP }, 477218822Sdim { {"sort-section", required_argument, NULL, OPTION_SORT_SECTION}, 478218822Sdim '\0', N_("name|alignment"), 479218822Sdim N_("Sort sections by name or maximum alignment"), TWO_DASHES }, 48089857Sobrien { {"spare-dynamic-tags", required_argument, NULL, OPTION_SPARE_DYNAMIC_TAGS}, 481218822Sdim '\0', N_("COUNT"), N_("How many tags to reserve in .dynamic section"), 482218822Sdim TWO_DASHES }, 48377298Sobrien { {"split-by-file", optional_argument, NULL, OPTION_SPLIT_BY_FILE}, 484218822Sdim '\0', N_("[=SIZE]"), N_("Split output sections every SIZE octets"), 485218822Sdim TWO_DASHES }, 48677298Sobrien { {"split-by-reloc", optional_argument, NULL, OPTION_SPLIT_BY_RELOC}, 487218822Sdim '\0', N_("[=COUNT]"), N_("Split output sections every COUNT relocs"), 488218822Sdim TWO_DASHES }, 48933965Sjdp { {"stats", no_argument, NULL, OPTION_STATS}, 490218822Sdim '\0', NULL, N_("Print memory usage statistics"), TWO_DASHES }, 49177298Sobrien { {"target-help", no_argument, NULL, OPTION_TARGET_HELP}, 492218822Sdim '\0', NULL, N_("Display target specific options"), TWO_DASHES }, 49338889Sjdp { {"task-link", required_argument, NULL, OPTION_TASK_LINK}, 494218822Sdim '\0', N_("SYMBOL"), N_("Do task level linking"), TWO_DASHES }, 49533965Sjdp { {"traditional-format", no_argument, NULL, OPTION_TRADITIONAL_FORMAT}, 496218822Sdim '\0', NULL, N_("Use same format as native linker"), TWO_DASHES }, 49777298Sobrien { {"section-start", required_argument, NULL, OPTION_SECTION_START}, 498218822Sdim '\0', N_("SECTION=ADDRESS"), N_("Set address of named section"), 499218822Sdim TWO_DASHES }, 50033965Sjdp { {"Tbss", required_argument, NULL, OPTION_TBSS}, 501218822Sdim '\0', N_("ADDRESS"), N_("Set address of .bss section"), ONE_DASH }, 50233965Sjdp { {"Tdata", required_argument, NULL, OPTION_TDATA}, 503218822Sdim '\0', N_("ADDRESS"), N_("Set address of .data section"), ONE_DASH }, 50433965Sjdp { {"Ttext", required_argument, NULL, OPTION_TTEXT}, 505218822Sdim '\0', N_("ADDRESS"), N_("Set address of .text section"), ONE_DASH }, 506218822Sdim { {"unresolved-symbols=<method>", required_argument, NULL, 507218822Sdim OPTION_UNRESOLVED_SYMBOLS}, 508218822Sdim '\0', NULL, N_("How to handle unresolved symbols. <method> is:\n" 509218822Sdim "\t\t\t\tignore-all, report-all, ignore-in-object-files,\n" 510218822Sdim "\t\t\t\tignore-in-shared-libs"), TWO_DASHES }, 51133965Sjdp { {"verbose", no_argument, NULL, OPTION_VERBOSE}, 512218822Sdim '\0', NULL, N_("Output lots of information during link"), TWO_DASHES }, 51333965Sjdp { {"dll-verbose", no_argument, NULL, OPTION_VERBOSE}, /* Linux. */ 514218822Sdim '\0', NULL, NULL, NO_HELP }, 51533965Sjdp { {"version-script", required_argument, NULL, OPTION_VERSION_SCRIPT }, 516218822Sdim '\0', N_("FILE"), N_("Read version information script"), TWO_DASHES }, 51760484Sobrien { {"version-exports-section", required_argument, NULL, 51860484Sobrien OPTION_VERSION_EXPORTS_SECTION }, 519218822Sdim '\0', N_("SYMBOL"), N_("Take export symbols list from .exports, using\n" 520218822Sdim "\t\t\t\tSYMBOL as the version."), TWO_DASHES }, 521218822Sdim { {"dynamic-list-data", no_argument, NULL, OPTION_DYNAMIC_LIST_DATA}, 522218822Sdim '\0', NULL, N_("Add data symbols to dynamic list"), TWO_DASHES }, 523218822Sdim { {"dynamic-list-cpp-new", no_argument, NULL, OPTION_DYNAMIC_LIST_CPP_NEW}, 524218822Sdim '\0', NULL, N_("Use C++ operator new/delete dynamic list"), TWO_DASHES }, 525218822Sdim { {"dynamic-list-cpp-typeinfo", no_argument, NULL, OPTION_DYNAMIC_LIST_CPP_TYPEINFO}, 526218822Sdim '\0', NULL, N_("Use C++ typeinfo dynamic list"), TWO_DASHES }, 527218822Sdim { {"dynamic-list", required_argument, NULL, OPTION_DYNAMIC_LIST}, 528218822Sdim '\0', N_("FILE"), N_("Read dynamic list"), TWO_DASHES }, 52933965Sjdp { {"warn-common", no_argument, NULL, OPTION_WARN_COMMON}, 530218822Sdim '\0', NULL, N_("Warn about duplicate common symbols"), TWO_DASHES }, 53133965Sjdp { {"warn-constructors", no_argument, NULL, OPTION_WARN_CONSTRUCTORS}, 532218822Sdim '\0', NULL, N_("Warn if global constructors/destructors are seen"), 533218822Sdim TWO_DASHES }, 53433965Sjdp { {"warn-multiple-gp", no_argument, NULL, OPTION_WARN_MULTIPLE_GP}, 535218822Sdim '\0', NULL, N_("Warn if the multiple GP values are used"), TWO_DASHES }, 53633965Sjdp { {"warn-once", no_argument, NULL, OPTION_WARN_ONCE}, 537218822Sdim '\0', NULL, N_("Warn only once per undefined symbol"), TWO_DASHES }, 53833965Sjdp { {"warn-section-align", no_argument, NULL, OPTION_WARN_SECTION_ALIGN}, 539218822Sdim '\0', NULL, N_("Warn if start of section changes due to alignment"), 540218822Sdim TWO_DASHES }, 541218822Sdim { {"warn-shared-textrel", no_argument, NULL, OPTION_WARN_SHARED_TEXTREL}, 542218822Sdim '\0', NULL, N_("Warn if shared object has DT_TEXTREL"), 543218822Sdim TWO_DASHES }, 544218822Sdim { {"warn-unresolved-symbols", no_argument, NULL, 545218822Sdim OPTION_WARN_UNRESOLVED_SYMBOLS}, 546130561Sobrien '\0', NULL, N_("Report unresolved symbols as warnings"), TWO_DASHES }, 547218822Sdim { {"error-unresolved-symbols", no_argument, NULL, 548218822Sdim OPTION_ERROR_UNRESOLVED_SYMBOLS}, 549130561Sobrien '\0', NULL, N_("Report unresolved symbols as errors"), TWO_DASHES }, 55033965Sjdp { {"whole-archive", no_argument, NULL, OPTION_WHOLE_ARCHIVE}, 551218822Sdim '\0', NULL, N_("Include all objects from following archives"), 552218822Sdim TWO_DASHES }, 55333965Sjdp { {"wrap", required_argument, NULL, OPTION_WRAP}, 554218822Sdim '\0', N_("SYMBOL"), N_("Use wrapper functions for SYMBOL"), TWO_DASHES }, 55533965Sjdp}; 55633965Sjdp 55777298Sobrien#define OPTION_COUNT ARRAY_SIZE (ld_options) 55833965Sjdp 55933965Sjdpvoid 560130561Sobrienparse_args (unsigned argc, char **argv) 56133965Sjdp{ 56277298Sobrien unsigned i; 56377298Sobrien int is, il, irl; 56433965Sjdp int ingroup = 0; 56533965Sjdp char *default_dirlist = NULL; 566130561Sobrien char *shortopts; 567130561Sobrien struct option *longopts; 568130561Sobrien struct option *really_longopts; 56938889Sjdp int last_optind; 570130561Sobrien enum report_method how_to_report_unresolved_symbols = RM_GENERATE_ERROR; 57133965Sjdp 572130561Sobrien shortopts = xmalloc (OPTION_COUNT * 3 + 2); 573130561Sobrien longopts = xmalloc (sizeof (*longopts) * (OPTION_COUNT + 1)); 574130561Sobrien really_longopts = xmalloc (sizeof (*really_longopts) * (OPTION_COUNT + 1)); 575130561Sobrien 57633965Sjdp /* Starting the short option string with '-' is for programs that 57733965Sjdp expect options and other ARGV-elements in any order and that care about 57833965Sjdp the ordering of the two. We describe each non-option ARGV-element 57933965Sjdp as if it were the argument of an option with character code 1. */ 58033965Sjdp shortopts[0] = '-'; 58133965Sjdp is = 1; 58233965Sjdp il = 0; 58377298Sobrien irl = 0; 58433965Sjdp for (i = 0; i < OPTION_COUNT; i++) 58533965Sjdp { 58633965Sjdp if (ld_options[i].shortopt != '\0') 58733965Sjdp { 58833965Sjdp shortopts[is] = ld_options[i].shortopt; 58933965Sjdp ++is; 59033965Sjdp if (ld_options[i].opt.has_arg == required_argument 59133965Sjdp || ld_options[i].opt.has_arg == optional_argument) 59233965Sjdp { 59333965Sjdp shortopts[is] = ':'; 59433965Sjdp ++is; 59533965Sjdp if (ld_options[i].opt.has_arg == optional_argument) 59633965Sjdp { 59733965Sjdp shortopts[is] = ':'; 59833965Sjdp ++is; 59933965Sjdp } 60033965Sjdp } 60133965Sjdp } 60233965Sjdp if (ld_options[i].opt.name != NULL) 60333965Sjdp { 60477298Sobrien if (ld_options[i].control == EXACTLY_TWO_DASHES) 60577298Sobrien { 60677298Sobrien really_longopts[irl] = ld_options[i].opt; 60777298Sobrien ++irl; 60877298Sobrien } 60977298Sobrien else 61077298Sobrien { 61177298Sobrien longopts[il] = ld_options[i].opt; 61277298Sobrien ++il; 61377298Sobrien } 61433965Sjdp } 61533965Sjdp } 61633965Sjdp shortopts[is] = '\0'; 61733965Sjdp longopts[il].name = NULL; 61877298Sobrien really_longopts[irl].name = NULL; 61933965Sjdp 620130561Sobrien ldemul_add_options (is, &shortopts, il, &longopts, irl, &really_longopts); 621130561Sobrien 62233965Sjdp /* The -G option is ambiguous on different platforms. Sometimes it 62333965Sjdp specifies the largest data size to put into the small data 62433965Sjdp section. Sometimes it is equivalent to --shared. Unfortunately, 62533965Sjdp the first form takes an argument, while the second does not. 62633965Sjdp 62733965Sjdp We need to permit the --shared form because on some platforms, 62833965Sjdp such as Solaris, gcc -shared will pass -G to the linker. 62933965Sjdp 63033965Sjdp To permit either usage, we look through the argument list. If we 63133965Sjdp find -G not followed by a number, we change it into --shared. 63233965Sjdp This will work for most normal cases. */ 63333965Sjdp for (i = 1; i < argc; i++) 63433965Sjdp if (strcmp (argv[i], "-G") == 0 63533965Sjdp && (i + 1 >= argc 63689857Sobrien || ! ISDIGIT (argv[i + 1][0]))) 63733965Sjdp argv[i] = (char *) "--shared"; 63833965Sjdp 63960484Sobrien /* Because we permit long options to start with a single dash, and 64060484Sobrien we have a --library option, and the -l option is conventionally 64160484Sobrien used with an immediately following argument, we can have bad 64260484Sobrien results if somebody tries to use -l with a library whose name 64360484Sobrien happens to start with "ibrary", as in -li. We avoid problems by 64460484Sobrien simply turning -l into --library. This means that users will 64560484Sobrien have to use two dashes in order to use --library, which is OK 64660484Sobrien since that's how it is documented. 64760484Sobrien 64860484Sobrien FIXME: It's possible that this problem can arise for other short 64960484Sobrien options as well, although the user does always have the recourse 65060484Sobrien of adding a space between the option and the argument. */ 65160484Sobrien for (i = 1; i < argc; i++) 65260484Sobrien { 65360484Sobrien if (argv[i][0] == '-' 65460484Sobrien && argv[i][1] == 'l' 65560484Sobrien && argv[i][2] != '\0') 65660484Sobrien { 65760484Sobrien char *n; 65860484Sobrien 659130561Sobrien n = xmalloc (strlen (argv[i]) + 20); 66060484Sobrien sprintf (n, "--library=%s", argv[i] + 2); 66160484Sobrien argv[i] = n; 66260484Sobrien } 66360484Sobrien } 66460484Sobrien 66538889Sjdp last_optind = -1; 66633965Sjdp while (1) 66733965Sjdp { 66833965Sjdp int longind; 66933965Sjdp int optc; 67033965Sjdp 67138889Sjdp /* Using last_optind lets us avoid calling ldemul_parse_args 67238889Sjdp multiple times on a single option, which would lead to 67338889Sjdp confusion in the internal static variables maintained by 67438889Sjdp getopt. This could otherwise happen for an argument like 67538889Sjdp -nx, in which the -n is parsed as a single option, and we 67638889Sjdp loop around to pick up the -x. */ 67738889Sjdp if (optind != last_optind) 67889857Sobrien if (ldemul_parse_args (argc, argv)) 67989857Sobrien continue; 68033965Sjdp 68160484Sobrien /* getopt_long_only is like getopt_long, but '-' as well as '--' 68260484Sobrien can indicate a long option. */ 68377298Sobrien opterr = 0; 68489857Sobrien last_optind = optind; 68533965Sjdp optc = getopt_long_only (argc, argv, shortopts, longopts, &longind); 68677298Sobrien if (optc == '?') 68777298Sobrien { 68889857Sobrien optind = last_optind; 68989857Sobrien optc = getopt_long (argc, argv, "-", really_longopts, &longind); 69077298Sobrien } 69133965Sjdp 692130561Sobrien if (ldemul_handle_option (optc)) 693130561Sobrien continue; 694130561Sobrien 69533965Sjdp if (optc == -1) 69633965Sjdp break; 69777298Sobrien 69833965Sjdp switch (optc) 69933965Sjdp { 70077298Sobrien case '?': 70189857Sobrien einfo (_("%P: unrecognized option '%s'\n"), argv[last_optind]); 702218822Sdim /* Fall through. */ 703218822Sdim 70433965Sjdp default: 70589857Sobrien einfo (_("%P%F: use the --help option for usage information\n")); 70689857Sobrien 70733965Sjdp case 1: /* File name. */ 708130561Sobrien lang_add_input_file (optarg, lang_input_file_is_file_enum, NULL); 70933965Sjdp break; 71033965Sjdp 71133965Sjdp case OPTION_IGNORE: 71233965Sjdp break; 71333965Sjdp case 'a': 71433965Sjdp /* For HP/UX compatibility. Actually -a shared should mean 715130561Sobrien ``use only shared libraries'' but, then, we don't 716130561Sobrien currently support shared libraries on HP/UX anyhow. */ 71733965Sjdp if (strcmp (optarg, "archive") == 0) 718130561Sobrien config.dynamic_link = FALSE; 71933965Sjdp else if (strcmp (optarg, "shared") == 0 72033965Sjdp || strcmp (optarg, "default") == 0) 721130561Sobrien config.dynamic_link = TRUE; 72233965Sjdp else 72360484Sobrien einfo (_("%P%F: unrecognized -a option `%s'\n"), optarg); 72433965Sjdp break; 72533965Sjdp case OPTION_ASSERT: 72633965Sjdp /* FIXME: We just ignore these, but we should handle them. */ 72733965Sjdp if (strcmp (optarg, "definitions") == 0) 72833965Sjdp ; 72933965Sjdp else if (strcmp (optarg, "nodefinitions") == 0) 73033965Sjdp ; 73133965Sjdp else if (strcmp (optarg, "nosymbolic") == 0) 73233965Sjdp ; 73333965Sjdp else if (strcmp (optarg, "pure-text") == 0) 73433965Sjdp ; 73533965Sjdp else 73660484Sobrien einfo (_("%P%F: unrecognized -assert option `%s'\n"), optarg); 73733965Sjdp break; 73833965Sjdp case 'A': 73933965Sjdp ldfile_add_arch (optarg); 74033965Sjdp break; 74133965Sjdp case 'b': 74233965Sjdp lang_add_target (optarg); 74333965Sjdp break; 74433965Sjdp case 'c': 74533965Sjdp ldfile_open_command_file (optarg); 74633965Sjdp parser_input = input_mri_script; 74733965Sjdp yyparse (); 74833965Sjdp break; 74933965Sjdp case OPTION_CALL_SHARED: 750130561Sobrien config.dynamic_link = TRUE; 75133965Sjdp break; 75233965Sjdp case OPTION_NON_SHARED: 753130561Sobrien config.dynamic_link = FALSE; 75433965Sjdp break; 75533965Sjdp case OPTION_CREF: 756130561Sobrien command_line.cref = TRUE; 757130561Sobrien link_info.notice_all = TRUE; 75833965Sjdp break; 75933965Sjdp case 'd': 760130561Sobrien command_line.force_common_definition = TRUE; 76133965Sjdp break; 76233965Sjdp case OPTION_DEFSYM: 76333965Sjdp lex_string = optarg; 76433965Sjdp lex_redirect (optarg); 76533965Sjdp parser_input = input_defsym; 76633965Sjdp parsing_defsym = 1; 76733965Sjdp yyparse (); 76833965Sjdp parsing_defsym = 0; 76933965Sjdp lex_string = NULL; 77033965Sjdp break; 77160484Sobrien case OPTION_DEMANGLE: 772130561Sobrien demangling = TRUE; 77377298Sobrien if (optarg != NULL) 77477298Sobrien { 77577298Sobrien enum demangling_styles style; 77677298Sobrien 77777298Sobrien style = cplus_demangle_name_to_style (optarg); 77877298Sobrien if (style == unknown_demangling) 77977298Sobrien einfo (_("%F%P: unknown demangling style `%s'"), 78077298Sobrien optarg); 78177298Sobrien 78277298Sobrien cplus_demangle_set_style (style); 78377298Sobrien } 78460484Sobrien break; 78589857Sobrien case 'I': /* Used on Solaris. */ 78633965Sjdp case OPTION_DYNAMIC_LINKER: 78733965Sjdp command_line.interpreter = optarg; 78833965Sjdp break; 789218822Sdim case OPTION_SYSROOT: 790218822Sdim /* Already handled in ldmain.c. */ 791218822Sdim break; 79233965Sjdp case OPTION_EB: 79333965Sjdp command_line.endian = ENDIAN_BIG; 79433965Sjdp break; 79533965Sjdp case OPTION_EL: 79633965Sjdp command_line.endian = ENDIAN_LITTLE; 79733965Sjdp break; 79833965Sjdp case OPTION_EMBEDDED_RELOCS: 799130561Sobrien command_line.embedded_relocs = TRUE; 80033965Sjdp break; 80133965Sjdp case OPTION_EXPORT_DYNAMIC: 80233965Sjdp case 'E': /* HP/UX compatibility. */ 803130561Sobrien link_info.export_dynamic = TRUE; 80433965Sjdp break; 80533965Sjdp case 'e': 806130561Sobrien lang_add_entry (optarg, TRUE); 80733965Sjdp break; 80833965Sjdp case 'f': 80933965Sjdp if (command_line.auxiliary_filters == NULL) 81033965Sjdp { 811130561Sobrien command_line.auxiliary_filters = xmalloc (2 * sizeof (char *)); 81233965Sjdp command_line.auxiliary_filters[0] = optarg; 81333965Sjdp command_line.auxiliary_filters[1] = NULL; 81433965Sjdp } 81533965Sjdp else 81633965Sjdp { 81733965Sjdp int c; 81833965Sjdp char **p; 81933965Sjdp 82033965Sjdp c = 0; 82133965Sjdp for (p = command_line.auxiliary_filters; *p != NULL; p++) 82233965Sjdp ++c; 823130561Sobrien command_line.auxiliary_filters 824130561Sobrien = xrealloc (command_line.auxiliary_filters, 825130561Sobrien (c + 2) * sizeof (char *)); 82633965Sjdp command_line.auxiliary_filters[c] = optarg; 82733965Sjdp command_line.auxiliary_filters[c + 1] = NULL; 82833965Sjdp } 82933965Sjdp break; 83033965Sjdp case 'F': 83133965Sjdp command_line.filter_shlib = optarg; 83233965Sjdp break; 83333965Sjdp case OPTION_FORCE_EXE_SUFFIX: 834130561Sobrien command_line.force_exe_suffix = TRUE; 83533965Sjdp break; 83633965Sjdp case 'G': 83733965Sjdp { 83833965Sjdp char *end; 83933965Sjdp g_switch_value = strtoul (optarg, &end, 0); 84033965Sjdp if (*end) 84160484Sobrien einfo (_("%P%F: invalid number `%s'\n"), optarg); 84233965Sjdp } 84333965Sjdp break; 84433965Sjdp case 'g': 84533965Sjdp /* Ignore. */ 84633965Sjdp break; 84760484Sobrien case OPTION_GC_SECTIONS: 848218822Sdim link_info.gc_sections = TRUE; 84960484Sobrien break; 850218822Sdim case OPTION_PRINT_GC_SECTIONS: 851218822Sdim link_info.print_gc_sections = TRUE; 852218822Sdim break; 85333965Sjdp case OPTION_HELP: 85433965Sjdp help (); 85533965Sjdp xexit (0); 85633965Sjdp break; 85733965Sjdp case 'L': 858130561Sobrien ldfile_add_library_path (optarg, TRUE); 85933965Sjdp break; 86033965Sjdp case 'l': 861130561Sobrien lang_add_input_file (optarg, lang_input_file_is_l_enum, NULL); 86233965Sjdp break; 86333965Sjdp case 'M': 86433965Sjdp config.map_filename = "-"; 86533965Sjdp break; 86633965Sjdp case 'm': 86733965Sjdp /* Ignore. Was handled in a pre-parse. */ 86833965Sjdp break; 86933965Sjdp case OPTION_MAP: 87033965Sjdp config.map_filename = optarg; 87133965Sjdp break; 87233965Sjdp case 'N': 873130561Sobrien config.text_read_only = FALSE; 874130561Sobrien config.magic_demand_paged = FALSE; 875130561Sobrien config.dynamic_link = FALSE; 87633965Sjdp break; 877130561Sobrien case OPTION_NO_OMAGIC: 878130561Sobrien config.text_read_only = TRUE; 879130561Sobrien config.magic_demand_paged = TRUE; 880130561Sobrien /* NB/ Does not set dynamic_link to TRUE. 881130561Sobrien Use --call-shared or -Bdynamic for this. */ 882130561Sobrien break; 88333965Sjdp case 'n': 884130561Sobrien config.magic_demand_paged = FALSE; 885130561Sobrien config.dynamic_link = FALSE; 88633965Sjdp break; 88789857Sobrien case OPTION_NO_DEFINE_COMMON: 888130561Sobrien command_line.inhibit_common_definition = TRUE; 88989857Sobrien break; 89060484Sobrien case OPTION_NO_DEMANGLE: 891130561Sobrien demangling = FALSE; 89260484Sobrien break; 89360484Sobrien case OPTION_NO_GC_SECTIONS: 894218822Sdim link_info.gc_sections = FALSE; 89560484Sobrien break; 896218822Sdim case OPTION_NO_PRINT_GC_SECTIONS: 897218822Sdim link_info.print_gc_sections = FALSE; 898218822Sdim break; 89933965Sjdp case OPTION_NO_KEEP_MEMORY: 900130561Sobrien link_info.keep_memory = FALSE; 90133965Sjdp break; 90260484Sobrien case OPTION_NO_UNDEFINED: 903218822Sdim link_info.unresolved_syms_in_objects 904218822Sdim = how_to_report_unresolved_symbols; 90560484Sobrien break; 90677298Sobrien case OPTION_ALLOW_SHLIB_UNDEFINED: 907130561Sobrien link_info.unresolved_syms_in_shared_libs = RM_IGNORE; 90877298Sobrien break; 909130561Sobrien case OPTION_NO_ALLOW_SHLIB_UNDEFINED: 910218822Sdim link_info.unresolved_syms_in_shared_libs 911218822Sdim = how_to_report_unresolved_symbols; 912130561Sobrien break; 913130561Sobrien case OPTION_UNRESOLVED_SYMBOLS: 914130561Sobrien if (strcmp (optarg, "ignore-all") == 0) 915130561Sobrien { 916130561Sobrien link_info.unresolved_syms_in_objects = RM_IGNORE; 917130561Sobrien link_info.unresolved_syms_in_shared_libs = RM_IGNORE; 918130561Sobrien } 919130561Sobrien else if (strcmp (optarg, "report-all") == 0) 920130561Sobrien { 921218822Sdim link_info.unresolved_syms_in_objects 922218822Sdim = how_to_report_unresolved_symbols; 923218822Sdim link_info.unresolved_syms_in_shared_libs 924218822Sdim = how_to_report_unresolved_symbols; 925130561Sobrien } 926130561Sobrien else if (strcmp (optarg, "ignore-in-object-files") == 0) 927130561Sobrien { 928130561Sobrien link_info.unresolved_syms_in_objects = RM_IGNORE; 929218822Sdim link_info.unresolved_syms_in_shared_libs 930218822Sdim = how_to_report_unresolved_symbols; 931130561Sobrien } 932130561Sobrien else if (strcmp (optarg, "ignore-in-shared-libs") == 0) 933130561Sobrien { 934218822Sdim link_info.unresolved_syms_in_objects 935218822Sdim = how_to_report_unresolved_symbols; 936130561Sobrien link_info.unresolved_syms_in_shared_libs = RM_IGNORE; 937130561Sobrien } 938130561Sobrien else 939130561Sobrien einfo (_("%P%F: bad --unresolved-symbols option: %s\n"), optarg); 940130561Sobrien break; 941130561Sobrien case OPTION_WARN_UNRESOLVED_SYMBOLS: 942130561Sobrien how_to_report_unresolved_symbols = RM_GENERATE_WARNING; 943130561Sobrien if (link_info.unresolved_syms_in_objects == RM_GENERATE_ERROR) 944130561Sobrien link_info.unresolved_syms_in_objects = RM_GENERATE_WARNING; 945130561Sobrien if (link_info.unresolved_syms_in_shared_libs == RM_GENERATE_ERROR) 946130561Sobrien link_info.unresolved_syms_in_shared_libs = RM_GENERATE_WARNING; 947130561Sobrien break; 948218822Sdim 949130561Sobrien case OPTION_ERROR_UNRESOLVED_SYMBOLS: 950130561Sobrien how_to_report_unresolved_symbols = RM_GENERATE_ERROR; 951130561Sobrien if (link_info.unresolved_syms_in_objects == RM_GENERATE_WARNING) 952130561Sobrien link_info.unresolved_syms_in_objects = RM_GENERATE_ERROR; 953130561Sobrien if (link_info.unresolved_syms_in_shared_libs == RM_GENERATE_WARNING) 954130561Sobrien link_info.unresolved_syms_in_shared_libs = RM_GENERATE_ERROR; 955218822Sdim break; 956104834Sobrien case OPTION_ALLOW_MULTIPLE_DEFINITION: 957130561Sobrien link_info.allow_multiple_definition = TRUE; 958104834Sobrien break; 959104834Sobrien case OPTION_NO_UNDEFINED_VERSION: 960130561Sobrien link_info.allow_undefined_version = FALSE; 961104834Sobrien break; 962218822Sdim case OPTION_DEFAULT_SYMVER: 963218822Sdim link_info.create_default_symver = TRUE; 964218822Sdim break; 965218822Sdim case OPTION_DEFAULT_IMPORTED_SYMVER: 966218822Sdim link_info.default_imported_symver = TRUE; 967218822Sdim break; 96838889Sjdp case OPTION_NO_WARN_MISMATCH: 969130561Sobrien command_line.warn_mismatch = FALSE; 97038889Sjdp break; 971218822Sdim case OPTION_NO_WARN_SEARCH_MISMATCH: 972218822Sdim command_line.warn_search_mismatch = FALSE; 973218822Sdim break; 97433965Sjdp case OPTION_NOINHIBIT_EXEC: 975130561Sobrien force_make_executable = TRUE; 97633965Sjdp break; 97789857Sobrien case OPTION_NOSTDLIB: 978130561Sobrien config.only_cmd_line_lib_dirs = TRUE; 97989857Sobrien break; 98033965Sjdp case OPTION_NO_WHOLE_ARCHIVE: 981130561Sobrien whole_archive = FALSE; 98233965Sjdp break; 98333965Sjdp case 'O': 98433965Sjdp /* FIXME "-O<non-digits> <value>" used to set the address of 98533965Sjdp section <non-digits>. Was this for compatibility with 98633965Sjdp something, or can we create a new option to do that 98733965Sjdp (with a syntax similar to -defsym)? 98833965Sjdp getopt can't handle two args to an option without kludges. */ 98960484Sobrien 99060484Sobrien /* Enable optimizations of output files. */ 991130561Sobrien link_info.optimize = strtoul (optarg, NULL, 0) ? TRUE : FALSE; 99233965Sjdp break; 99333965Sjdp case 'o': 99477298Sobrien lang_add_output (optarg, 0); 99533965Sjdp break; 99633965Sjdp case OPTION_OFORMAT: 997130561Sobrien lang_add_output_format (optarg, NULL, NULL, 0); 99833965Sjdp break; 99977298Sobrien case 'q': 1000130561Sobrien link_info.emitrelocations = TRUE; 100177298Sobrien break; 100233965Sjdp case 'i': 100333965Sjdp case 'r': 100489857Sobrien if (optind == last_optind) 100589857Sobrien /* This can happen if the user put "-rpath,a" on the command 100689857Sobrien line. (Or something similar. The comma is important). 100789857Sobrien Getopt becomes confused and thinks that this is a -r option 100889857Sobrien but it cannot parse the text after the -r so it refuses to 100989857Sobrien increment the optind counter. Detect this case and issue 101089857Sobrien an error message here. We cannot just make this a warning, 101189857Sobrien increment optind, and continue because getopt is too confused 101289857Sobrien and will seg-fault the next time around. */ 101389857Sobrien einfo(_("%P%F: bad -rpath option\n")); 1014104834Sobrien 1015130561Sobrien link_info.relocatable = TRUE; 1016130561Sobrien config.build_constructors = FALSE; 1017130561Sobrien config.magic_demand_paged = FALSE; 1018130561Sobrien config.text_read_only = FALSE; 1019130561Sobrien config.dynamic_link = FALSE; 102033965Sjdp break; 102133965Sjdp case 'R': 102233965Sjdp /* The GNU linker traditionally uses -R to mean to include 102333965Sjdp only the symbols from a file. The Solaris linker uses -R 102433965Sjdp to set the path used by the runtime linker to find 102533965Sjdp libraries. This is the GNU linker -rpath argument. We 102633965Sjdp try to support both simultaneously by checking the file 102733965Sjdp named. If it is a directory, rather than a regular file, 102833965Sjdp we assume -rpath was meant. */ 102933965Sjdp { 103033965Sjdp struct stat s; 103133965Sjdp 103233965Sjdp if (stat (optarg, &s) >= 0 103333965Sjdp && ! S_ISDIR (s.st_mode)) 103433965Sjdp { 103533965Sjdp lang_add_input_file (optarg, 103633965Sjdp lang_input_file_is_symbols_only_enum, 1037130561Sobrien NULL); 103833965Sjdp break; 103933965Sjdp } 104033965Sjdp } 104133965Sjdp /* Fall through. */ 104233965Sjdp case OPTION_RPATH: 104333965Sjdp if (command_line.rpath == NULL) 104478828Sobrien command_line.rpath = xstrdup (optarg); 104533965Sjdp else 104633965Sjdp { 104760484Sobrien size_t rpath_len = strlen (command_line.rpath); 104860484Sobrien size_t optarg_len = strlen (optarg); 104933965Sjdp char *buf; 105060484Sobrien char *cp = command_line.rpath; 105133965Sjdp 105260484Sobrien /* First see whether OPTARG is already in the path. */ 105360484Sobrien do 105460484Sobrien { 1055218822Sdim if (strncmp (optarg, cp, optarg_len) == 0 1056218822Sdim && (cp[optarg_len] == 0 1057218822Sdim || cp[optarg_len] == config.rpath_separator)) 105860484Sobrien /* We found it. */ 105960484Sobrien break; 106060484Sobrien 106160484Sobrien /* Not yet found. */ 1062218822Sdim cp = strchr (cp, config.rpath_separator); 106360484Sobrien if (cp != NULL) 106460484Sobrien ++cp; 106560484Sobrien } 106660484Sobrien while (cp != NULL); 106760484Sobrien 106860484Sobrien if (cp == NULL) 106960484Sobrien { 107060484Sobrien buf = xmalloc (rpath_len + optarg_len + 2); 1071218822Sdim sprintf (buf, "%s%c%s", command_line.rpath, 1072218822Sdim config.rpath_separator, optarg); 107360484Sobrien free (command_line.rpath); 107460484Sobrien command_line.rpath = buf; 107560484Sobrien } 107633965Sjdp } 107733965Sjdp break; 107833965Sjdp case OPTION_RPATH_LINK: 107933965Sjdp if (command_line.rpath_link == NULL) 108078828Sobrien command_line.rpath_link = xstrdup (optarg); 108133965Sjdp else 108233965Sjdp { 108333965Sjdp char *buf; 108433965Sjdp 108533965Sjdp buf = xmalloc (strlen (command_line.rpath_link) 108633965Sjdp + strlen (optarg) 108733965Sjdp + 2); 1088218822Sdim sprintf (buf, "%s%c%s", command_line.rpath_link, 1089218822Sdim config.rpath_separator, optarg); 109033965Sjdp free (command_line.rpath_link); 109133965Sjdp command_line.rpath_link = buf; 109233965Sjdp } 109333965Sjdp break; 109433965Sjdp case OPTION_RELAX: 1095130561Sobrien command_line.relax = TRUE; 109633965Sjdp break; 109733965Sjdp case OPTION_RETAIN_SYMBOLS_FILE: 109833965Sjdp add_keepsyms_file (optarg); 109933965Sjdp break; 110033965Sjdp case 'S': 110133965Sjdp link_info.strip = strip_debugger; 110233965Sjdp break; 110333965Sjdp case 's': 110433965Sjdp link_info.strip = strip_all; 110533965Sjdp break; 1106130561Sobrien case OPTION_STRIP_DISCARDED: 1107130561Sobrien link_info.strip_discarded = TRUE; 1108130561Sobrien break; 1109130561Sobrien case OPTION_NO_STRIP_DISCARDED: 1110130561Sobrien link_info.strip_discarded = FALSE; 1111130561Sobrien break; 111233965Sjdp case OPTION_SHARED: 111360484Sobrien if (config.has_shared) 1114130561Sobrien { 1115130561Sobrien link_info.shared = TRUE; 1116130561Sobrien /* When creating a shared library, the default 1117130561Sobrien behaviour is to ignore any unresolved references. */ 1118130561Sobrien if (link_info.unresolved_syms_in_objects == RM_NOT_YET_SET) 1119130561Sobrien link_info.unresolved_syms_in_objects = RM_IGNORE; 1120130561Sobrien if (link_info.unresolved_syms_in_shared_libs == RM_NOT_YET_SET) 1121130561Sobrien link_info.unresolved_syms_in_shared_libs = RM_IGNORE; 1122130561Sobrien } 112360484Sobrien else 112460484Sobrien einfo (_("%P%F: -shared not supported\n")); 112533965Sjdp break; 1126130561Sobrien case OPTION_PIE: 1127130561Sobrien if (config.has_shared) 1128130561Sobrien { 1129130561Sobrien link_info.shared = TRUE; 1130130561Sobrien link_info.pie = TRUE; 1131130561Sobrien } 1132130561Sobrien else 1133130561Sobrien einfo (_("%P%F: -pie not supported\n")); 1134130561Sobrien break; 113533965Sjdp case 'h': /* Used on Solaris. */ 113633965Sjdp case OPTION_SONAME: 113733965Sjdp command_line.soname = optarg; 113833965Sjdp break; 113933965Sjdp case OPTION_SORT_COMMON: 1140130561Sobrien config.sort_common = TRUE; 114133965Sjdp break; 1142218822Sdim case OPTION_SORT_SECTION: 1143218822Sdim if (strcmp (optarg, N_("name")) == 0) 1144218822Sdim sort_section = by_name; 1145218822Sdim else if (strcmp (optarg, N_("alignment")) == 0) 1146218822Sdim sort_section = by_alignment; 1147218822Sdim else 1148218822Sdim einfo (_("%P%F: invalid section sorting option: %s\n"), 1149218822Sdim optarg); 1150218822Sdim break; 115133965Sjdp case OPTION_STATS: 1152130561Sobrien config.stats = TRUE; 115333965Sjdp break; 115433965Sjdp case OPTION_SYMBOLIC: 1155218822Sdim command_line.symbolic = symbolic; 115633965Sjdp break; 1157218822Sdim case OPTION_SYMBOLIC_FUNCTIONS: 1158218822Sdim command_line.symbolic = symbolic_functions; 1159218822Sdim break; 116033965Sjdp case 't': 1161130561Sobrien trace_files = TRUE; 116233965Sjdp break; 116333965Sjdp case 'T': 116433965Sjdp ldfile_open_command_file (optarg); 116533965Sjdp parser_input = input_script; 116633965Sjdp yyparse (); 116733965Sjdp break; 1168218822Sdim case OPTION_DEFAULT_SCRIPT: 1169218822Sdim command_line.default_script = optarg; 1170218822Sdim break; 117177298Sobrien case OPTION_SECTION_START: 117277298Sobrien { 117377298Sobrien char *optarg2; 117477298Sobrien char *sec_name; 117577298Sobrien int len; 117677298Sobrien 117777298Sobrien /* Check for <something>=<somthing>... */ 117877298Sobrien optarg2 = strchr (optarg, '='); 117977298Sobrien if (optarg2 == NULL) 1180218822Sdim einfo (_("%P%F: invalid argument to option" 1181218822Sdim " \"--section-start\"\n")); 118277298Sobrien 118377298Sobrien optarg2++; 118477298Sobrien 118577298Sobrien /* So far so good. Are all the args present? */ 118677298Sobrien if ((*optarg == '\0') || (*optarg2 == '\0')) 1187218822Sdim einfo (_("%P%F: missing argument(s) to option" 1188218822Sdim " \"--section-start\"\n")); 118977298Sobrien 119077298Sobrien /* We must copy the section name as set_section_start 119177298Sobrien doesn't do it for us. */ 119277298Sobrien len = optarg2 - optarg; 119377298Sobrien sec_name = xmalloc (len); 119477298Sobrien memcpy (sec_name, optarg, len - 1); 119577298Sobrien sec_name[len - 1] = 0; 119677298Sobrien 119777298Sobrien /* Then set it... */ 119877298Sobrien set_section_start (sec_name, optarg2); 119977298Sobrien } 120077298Sobrien break; 120177298Sobrien case OPTION_TARGET_HELP: 120277298Sobrien /* Mention any target specific options. */ 1203104834Sobrien ldemul_list_emulation_options (stdout); 1204104834Sobrien exit (0); 120533965Sjdp case OPTION_TBSS: 1206218822Sdim set_segment_start (".bss", optarg); 120733965Sjdp break; 120833965Sjdp case OPTION_TDATA: 1209218822Sdim set_segment_start (".data", optarg); 121033965Sjdp break; 121133965Sjdp case OPTION_TTEXT: 1212218822Sdim set_segment_start (".text", optarg); 121333965Sjdp break; 121433965Sjdp case OPTION_TRADITIONAL_FORMAT: 1215130561Sobrien link_info.traditional_format = TRUE; 121633965Sjdp break; 121738889Sjdp case OPTION_TASK_LINK: 1218130561Sobrien link_info.task_link = TRUE; 121938889Sjdp /* Fall through - do an implied -r option. */ 122033965Sjdp case OPTION_UR: 1221130561Sobrien link_info.relocatable = TRUE; 1222130561Sobrien config.build_constructors = TRUE; 1223130561Sobrien config.magic_demand_paged = FALSE; 1224130561Sobrien config.text_read_only = FALSE; 1225130561Sobrien config.dynamic_link = FALSE; 122633965Sjdp break; 122733965Sjdp case 'u': 122833965Sjdp ldlang_add_undef (optarg); 122933965Sjdp break; 123077298Sobrien case OPTION_UNIQUE: 123177298Sobrien if (optarg != NULL) 123277298Sobrien lang_add_unique (optarg); 123377298Sobrien else 1234130561Sobrien config.unique_orphan_sections = TRUE; 123577298Sobrien break; 123633965Sjdp case OPTION_VERBOSE: 123733965Sjdp ldversion (1); 1238130561Sobrien version_printed = TRUE; 1239130561Sobrien trace_file_tries = TRUE; 1240130561Sobrien overflow_cutoff_limit = -2; 124133965Sjdp break; 124233965Sjdp case 'v': 124333965Sjdp ldversion (0); 1244130561Sobrien version_printed = TRUE; 124533965Sjdp break; 124633965Sjdp case 'V': 124733965Sjdp ldversion (1); 1248130561Sobrien version_printed = TRUE; 124933965Sjdp break; 125033965Sjdp case OPTION_VERSION: 125189857Sobrien ldversion (2); 125233965Sjdp xexit (0); 125333965Sjdp break; 125433965Sjdp case OPTION_VERSION_SCRIPT: 125533965Sjdp /* This option indicates a small script that only specifies 1256130561Sobrien version information. Read it, but don't assume that 1257130561Sobrien we've seen a linker script. */ 125833965Sjdp { 1259104834Sobrien FILE *hold_script_handle; 126033965Sjdp 126189857Sobrien hold_script_handle = saved_script_handle; 126233965Sjdp ldfile_open_command_file (optarg); 126389857Sobrien saved_script_handle = hold_script_handle; 126433965Sjdp parser_input = input_version_script; 126533965Sjdp yyparse (); 126633965Sjdp } 126733965Sjdp break; 126860484Sobrien case OPTION_VERSION_EXPORTS_SECTION: 126960484Sobrien /* This option records a version symbol to be applied to the 127060484Sobrien symbols listed for export to be found in the object files 127160484Sobrien .exports sections. */ 127260484Sobrien command_line.version_exports_section = optarg; 127360484Sobrien break; 1274218822Sdim case OPTION_DYNAMIC_LIST_DATA: 1275218822Sdim command_line.dynamic_list = dynamic_list_data; 1276218822Sdim if (command_line.symbolic == symbolic) 1277218822Sdim command_line.symbolic = symbolic_unset; 1278218822Sdim break; 1279218822Sdim case OPTION_DYNAMIC_LIST_CPP_TYPEINFO: 1280218822Sdim lang_append_dynamic_list_cpp_typeinfo (); 1281218822Sdim if (command_line.dynamic_list != dynamic_list_data) 1282218822Sdim command_line.dynamic_list = dynamic_list; 1283218822Sdim if (command_line.symbolic == symbolic) 1284218822Sdim command_line.symbolic = symbolic_unset; 1285218822Sdim break; 1286218822Sdim case OPTION_DYNAMIC_LIST_CPP_NEW: 1287218822Sdim lang_append_dynamic_list_cpp_new (); 1288218822Sdim if (command_line.dynamic_list != dynamic_list_data) 1289218822Sdim command_line.dynamic_list = dynamic_list; 1290218822Sdim if (command_line.symbolic == symbolic) 1291218822Sdim command_line.symbolic = symbolic_unset; 1292218822Sdim break; 1293218822Sdim case OPTION_DYNAMIC_LIST: 1294218822Sdim /* This option indicates a small script that only specifies 1295218822Sdim a dynamic list. Read it, but don't assume that we've 1296218822Sdim seen a linker script. */ 1297218822Sdim { 1298218822Sdim FILE *hold_script_handle; 1299218822Sdim 1300218822Sdim hold_script_handle = saved_script_handle; 1301218822Sdim ldfile_open_command_file (optarg); 1302218822Sdim saved_script_handle = hold_script_handle; 1303218822Sdim parser_input = input_dynamic_list; 1304218822Sdim yyparse (); 1305218822Sdim } 1306218822Sdim if (command_line.dynamic_list != dynamic_list_data) 1307218822Sdim command_line.dynamic_list = dynamic_list; 1308218822Sdim if (command_line.symbolic == symbolic) 1309218822Sdim command_line.symbolic = symbolic_unset; 1310218822Sdim break; 131133965Sjdp case OPTION_WARN_COMMON: 1312130561Sobrien config.warn_common = TRUE; 131333965Sjdp break; 131433965Sjdp case OPTION_WARN_CONSTRUCTORS: 1315130561Sobrien config.warn_constructors = TRUE; 131633965Sjdp break; 131789857Sobrien case OPTION_WARN_FATAL: 1318130561Sobrien config.fatal_warnings = TRUE; 131989857Sobrien break; 132033965Sjdp case OPTION_WARN_MULTIPLE_GP: 1321130561Sobrien config.warn_multiple_gp = TRUE; 132233965Sjdp break; 132333965Sjdp case OPTION_WARN_ONCE: 1324130561Sobrien config.warn_once = TRUE; 132533965Sjdp break; 132633965Sjdp case OPTION_WARN_SECTION_ALIGN: 1327130561Sobrien config.warn_section_align = TRUE; 132833965Sjdp break; 1329218822Sdim case OPTION_WARN_SHARED_TEXTREL: 1330218822Sdim link_info.warn_shared_textrel = TRUE; 1331218822Sdim break; 133233965Sjdp case OPTION_WHOLE_ARCHIVE: 1333130561Sobrien whole_archive = TRUE; 133433965Sjdp break; 1335218822Sdim case OPTION_ADD_NEEDED: 1336218822Sdim add_needed = TRUE; 1337218822Sdim break; 1338218822Sdim case OPTION_NO_ADD_NEEDED: 1339218822Sdim add_needed = FALSE; 1340218822Sdim break; 1341130561Sobrien case OPTION_AS_NEEDED: 1342209867Snwhitehorn/* XXX: --as-needed is broken on powerpc64 */ 1343209867Snwhitehorn#ifndef __powerpc64__ 1344130561Sobrien as_needed = TRUE; 1345130561Sobrien break; 1346209867Snwhitehorn#endif 1347130561Sobrien case OPTION_NO_AS_NEEDED: 1348130561Sobrien as_needed = FALSE; 1349130561Sobrien break; 135033965Sjdp case OPTION_WRAP: 135133965Sjdp add_wrap (optarg); 135233965Sjdp break; 135389857Sobrien case OPTION_DISCARD_NONE: 135489857Sobrien link_info.discard = discard_none; 135589857Sobrien break; 135633965Sjdp case 'X': 135733965Sjdp link_info.discard = discard_l; 135833965Sjdp break; 135933965Sjdp case 'x': 136033965Sjdp link_info.discard = discard_all; 136133965Sjdp break; 136233965Sjdp case 'Y': 1363218822Sdim if (CONST_STRNEQ (optarg, "P,")) 136433965Sjdp optarg += 2; 1365130561Sobrien if (default_dirlist != NULL) 1366130561Sobrien free (default_dirlist); 136733965Sjdp default_dirlist = xstrdup (optarg); 136833965Sjdp break; 136933965Sjdp case 'y': 137033965Sjdp add_ysym (optarg); 137133965Sjdp break; 137289857Sobrien case OPTION_SPARE_DYNAMIC_TAGS: 137389857Sobrien link_info.spare_dynamic_tags = strtoul (optarg, NULL, 0); 137489857Sobrien break; 137577298Sobrien case OPTION_SPLIT_BY_RELOC: 137677298Sobrien if (optarg != NULL) 137777298Sobrien config.split_by_reloc = strtoul (optarg, NULL, 0); 137877298Sobrien else 137977298Sobrien config.split_by_reloc = 32768; 138033965Sjdp break; 138133965Sjdp case OPTION_SPLIT_BY_FILE: 138277298Sobrien if (optarg != NULL) 138377298Sobrien config.split_by_file = bfd_scan_vma (optarg, NULL, 0); 138477298Sobrien else 138577298Sobrien config.split_by_file = 1; 138677298Sobrien break; 138760484Sobrien case OPTION_CHECK_SECTIONS: 1388130561Sobrien command_line.check_section_addresses = TRUE; 138960484Sobrien break; 139060484Sobrien case OPTION_NO_CHECK_SECTIONS: 1391130561Sobrien command_line.check_section_addresses = FALSE; 139260484Sobrien break; 1393130561Sobrien case OPTION_ACCEPT_UNKNOWN_INPUT_ARCH: 1394130561Sobrien command_line.accept_unknown_input_arch = TRUE; 1395130561Sobrien break; 1396130561Sobrien case OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH: 1397130561Sobrien command_line.accept_unknown_input_arch = FALSE; 1398130561Sobrien break; 139933965Sjdp case '(': 140033965Sjdp if (ingroup) 140189857Sobrien einfo (_("%P%F: may not nest groups (--help for usage)\n")); 140289857Sobrien 140333965Sjdp lang_enter_group (); 140433965Sjdp ingroup = 1; 140533965Sjdp break; 140633965Sjdp case ')': 140733965Sjdp if (! ingroup) 140889857Sobrien einfo (_("%P%F: group ended before it began (--help for usage)\n")); 140989857Sobrien 141033965Sjdp lang_leave_group (); 141133965Sjdp ingroup = 0; 141233965Sjdp break; 141333965Sjdp 141460484Sobrien case OPTION_INIT: 141560484Sobrien link_info.init_function = optarg; 141660484Sobrien break; 141777298Sobrien 141860484Sobrien case OPTION_FINI: 141960484Sobrien link_info.fini_function = optarg; 142060484Sobrien break; 1421218822Sdim 1422218822Sdim case OPTION_REDUCE_MEMORY_OVERHEADS: 1423218822Sdim link_info.reduce_memory_overheads = TRUE; 1424218822Sdim if (config.hash_table_size == 0) 1425218822Sdim config.hash_table_size = 1021; 1426218822Sdim break; 1427218822Sdim 1428218822Sdim case OPTION_HASH_SIZE: 1429218822Sdim { 1430218822Sdim bfd_size_type new_size; 1431218822Sdim 1432218822Sdim new_size = strtoul (optarg, NULL, 0); 1433218822Sdim if (new_size) 1434218822Sdim config.hash_table_size = new_size; 1435218822Sdim else 1436218822Sdim einfo (_("%P%X: --hash-size needs a numeric argument\n")); 1437218822Sdim } 1438218822Sdim break; 143933965Sjdp } 144033965Sjdp } 144133965Sjdp 144233965Sjdp if (ingroup) 144333965Sjdp lang_leave_group (); 144433965Sjdp 144533965Sjdp if (default_dirlist != NULL) 1446130561Sobrien { 1447130561Sobrien set_default_dirlist (default_dirlist); 1448130561Sobrien free (default_dirlist); 1449130561Sobrien } 145033965Sjdp 1451130561Sobrien if (link_info.unresolved_syms_in_objects == RM_NOT_YET_SET) 1452130561Sobrien /* FIXME: Should we allow emulations a chance to set this ? */ 1453130561Sobrien link_info.unresolved_syms_in_objects = how_to_report_unresolved_symbols; 1454218822Sdim 1455130561Sobrien if (link_info.unresolved_syms_in_shared_libs == RM_NOT_YET_SET) 1456130561Sobrien /* FIXME: Should we allow emulations a chance to set this ? */ 1457130561Sobrien link_info.unresolved_syms_in_shared_libs = how_to_report_unresolved_symbols; 145833965Sjdp} 145933965Sjdp 146033965Sjdp/* Add the (colon-separated) elements of DIRLIST_PTR to the 146133965Sjdp library search path. */ 146233965Sjdp 146333965Sjdpstatic void 1464130561Sobrienset_default_dirlist (char *dirlist_ptr) 146533965Sjdp{ 146633965Sjdp char *p; 146733965Sjdp 146833965Sjdp while (1) 146933965Sjdp { 147038889Sjdp p = strchr (dirlist_ptr, PATH_SEPARATOR); 147133965Sjdp if (p != NULL) 147233965Sjdp *p = '\0'; 147333965Sjdp if (*dirlist_ptr != '\0') 1474130561Sobrien ldfile_add_library_path (dirlist_ptr, TRUE); 147533965Sjdp if (p == NULL) 147633965Sjdp break; 147733965Sjdp dirlist_ptr = p + 1; 147833965Sjdp } 147933965Sjdp} 148033965Sjdp 148133965Sjdpstatic void 1482130561Sobrienset_section_start (char *sect, char *valstr) 148333965Sjdp{ 148460484Sobrien const char *end; 148560484Sobrien bfd_vma val = bfd_scan_vma (valstr, &end, 16); 148633965Sjdp if (*end) 148760484Sobrien einfo (_("%P%F: invalid hex number `%s'\n"), valstr); 1488218822Sdim lang_section_start (sect, exp_intop (val), NULL); 148933965Sjdp} 1490218822Sdim 1491218822Sdimstatic void 1492218822Sdimset_segment_start (const char *section, char *valstr) 1493218822Sdim{ 1494218822Sdim const char *name; 1495218822Sdim const char *end; 1496218822Sdim segment_type *seg; 1497218822Sdim 1498218822Sdim bfd_vma val = bfd_scan_vma (valstr, &end, 16); 1499218822Sdim if (*end) 1500218822Sdim einfo (_("%P%F: invalid hex number `%s'\n"), valstr); 1501218822Sdim /* If we already have an entry for this segment, update the existing 1502218822Sdim value. */ 1503218822Sdim name = section + 1; 1504218822Sdim for (seg = segments; seg; seg = seg->next) 1505218822Sdim if (strcmp (seg->name, name) == 0) 1506218822Sdim { 1507218822Sdim seg->value = val; 1508218822Sdim return; 1509218822Sdim } 1510218822Sdim /* There was no existing value so we must create a new segment 1511218822Sdim entry. */ 1512218822Sdim seg = stat_alloc (sizeof (*seg)); 1513218822Sdim seg->name = name; 1514218822Sdim seg->value = val; 1515218822Sdim seg->used = FALSE; 1516218822Sdim /* Add it to the linked list of segments. */ 1517218822Sdim seg->next = segments; 1518218822Sdim segments = seg; 1519218822Sdim /* Historically, -Ttext and friends set the base address of a 1520218822Sdim particular section. For backwards compatibility, we still do 1521218822Sdim that. If a SEGMENT_START directive is seen, the section address 1522218822Sdim assignment will be disabled. */ 1523218822Sdim lang_section_start (section, exp_intop (val), seg); 1524218822Sdim} 1525218822Sdim 152633965Sjdp 152733965Sjdp/* Print help messages for the options. */ 152833965Sjdp 152933965Sjdpstatic void 1530130561Sobrienhelp (void) 153133965Sjdp{ 153277298Sobrien unsigned i; 153333965Sjdp const char **targets, **pp; 1534218822Sdim int len; 153533965Sjdp 153660484Sobrien printf (_("Usage: %s [options] file...\n"), program_name); 153733965Sjdp 153860484Sobrien printf (_("Options:\n")); 153933965Sjdp for (i = 0; i < OPTION_COUNT; i++) 154033965Sjdp { 154133965Sjdp if (ld_options[i].doc != NULL) 154233965Sjdp { 1543130561Sobrien bfd_boolean comma; 154477298Sobrien unsigned j; 154533965Sjdp 154633965Sjdp printf (" "); 154733965Sjdp 1548130561Sobrien comma = FALSE; 154933965Sjdp len = 2; 155033965Sjdp 155133965Sjdp j = i; 155233965Sjdp do 155333965Sjdp { 155433965Sjdp if (ld_options[j].shortopt != '\0' 155533965Sjdp && ld_options[j].control != NO_HELP) 155633965Sjdp { 155733965Sjdp printf ("%s-%c", comma ? ", " : "", ld_options[j].shortopt); 155833965Sjdp len += (comma ? 2 : 0) + 2; 155933965Sjdp if (ld_options[j].arg != NULL) 156033965Sjdp { 156133965Sjdp if (ld_options[j].opt.has_arg != optional_argument) 156233965Sjdp { 156333965Sjdp printf (" "); 156433965Sjdp ++len; 156533965Sjdp } 156660484Sobrien printf ("%s", _(ld_options[j].arg)); 156760484Sobrien len += strlen (_(ld_options[j].arg)); 156833965Sjdp } 1569130561Sobrien comma = TRUE; 157033965Sjdp } 157133965Sjdp ++j; 157233965Sjdp } 157333965Sjdp while (j < OPTION_COUNT && ld_options[j].doc == NULL); 157433965Sjdp 157533965Sjdp j = i; 157633965Sjdp do 157733965Sjdp { 157833965Sjdp if (ld_options[j].opt.name != NULL 157933965Sjdp && ld_options[j].control != NO_HELP) 158033965Sjdp { 158177298Sobrien int two_dashes = 158277298Sobrien (ld_options[j].control == TWO_DASHES 158377298Sobrien || ld_options[j].control == EXACTLY_TWO_DASHES); 1584104834Sobrien 158533965Sjdp printf ("%s-%s%s", 158633965Sjdp comma ? ", " : "", 158777298Sobrien two_dashes ? "-" : "", 158833965Sjdp ld_options[j].opt.name); 158933965Sjdp len += ((comma ? 2 : 0) 159033965Sjdp + 1 159177298Sobrien + (two_dashes ? 1 : 0) 159233965Sjdp + strlen (ld_options[j].opt.name)); 159333965Sjdp if (ld_options[j].arg != NULL) 159433965Sjdp { 159560484Sobrien printf (" %s", _(ld_options[j].arg)); 159660484Sobrien len += 1 + strlen (_(ld_options[j].arg)); 159733965Sjdp } 1598130561Sobrien comma = TRUE; 159933965Sjdp } 160033965Sjdp ++j; 160133965Sjdp } 160233965Sjdp while (j < OPTION_COUNT && ld_options[j].doc == NULL); 160333965Sjdp 160433965Sjdp if (len >= 30) 160533965Sjdp { 160633965Sjdp printf ("\n"); 160733965Sjdp len = 0; 160833965Sjdp } 160933965Sjdp 161033965Sjdp for (; len < 30; len++) 161133965Sjdp putchar (' '); 161233965Sjdp 161360484Sobrien printf ("%s\n", _(ld_options[i].doc)); 161433965Sjdp } 161533965Sjdp } 1616218822Sdim printf (_(" @FILE")); 1617218822Sdim for (len = strlen (" @FILE"); len < 30; len++) 1618218822Sdim putchar (' '); 1619218822Sdim printf (_("Read options from FILE\n")); 162033965Sjdp 162160484Sobrien /* Note: Various tools (such as libtool) depend upon the 162260484Sobrien format of the listings below - do not change them. */ 162360484Sobrien /* xgettext:c-format */ 162460484Sobrien printf (_("%s: supported targets:"), program_name); 162533965Sjdp targets = bfd_target_list (); 162633965Sjdp for (pp = targets; *pp != NULL; pp++) 162733965Sjdp printf (" %s", *pp); 162833965Sjdp free (targets); 162933965Sjdp printf ("\n"); 163033965Sjdp 163160484Sobrien /* xgettext:c-format */ 163260484Sobrien printf (_("%s: supported emulations: "), program_name); 163333965Sjdp ldemul_list_emulations (stdout); 163433965Sjdp printf ("\n"); 163560484Sobrien 163660484Sobrien /* xgettext:c-format */ 163760484Sobrien printf (_("%s: emulation specific options:\n"), program_name); 163860484Sobrien ldemul_list_emulation_options (stdout); 163960484Sobrien printf ("\n"); 164060484Sobrien 1641218822Sdim if (REPORT_BUGS_TO[0]) 1642218822Sdim printf (_("Report bugs to %s\n"), REPORT_BUGS_TO); 164333965Sjdp} 1644