Home | History | Annotate | Line # | Download | only in ld
lexsup.c revision 1.9
      1 /* Parse options for the GNU linker.
      2    Copyright (C) 1991-2018 Free Software Foundation, Inc.
      3 
      4    This file is part of the GNU Binutils.
      5 
      6    This program is free software; you can redistribute it and/or modify
      7    it under the terms of the GNU General Public License as published by
      8    the Free Software Foundation; either version 3 of the License, or
      9    (at your option) any later version.
     10 
     11    This program is distributed in the hope that it will be useful,
     12    but WITHOUT ANY WARRANTY; without even the implied warranty of
     13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14    GNU General Public License for more details.
     15 
     16    You should have received a copy of the GNU General Public License
     17    along with this program; if not, write to the Free Software
     18    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
     19    MA 02110-1301, USA.  */
     20 
     21 #include "sysdep.h"
     22 #include "bfd.h"
     23 #include "bfdver.h"
     24 #include "libiberty.h"
     25 #include <stdio.h>
     26 #include <string.h>
     27 #include "safe-ctype.h"
     28 #include "getopt.h"
     29 #include "bfdlink.h"
     30 #include "ld.h"
     31 #include "ldmain.h"
     32 #include "ldmisc.h"
     33 #include "ldexp.h"
     34 #include "ldlang.h"
     35 #include <ldgram.h>
     36 #include "ldlex.h"
     37 #include "ldfile.h"
     38 #include "ldver.h"
     39 #include "ldemul.h"
     40 #include "demangle.h"
     41 #ifdef ENABLE_PLUGINS
     42 #include "plugin.h"
     43 #endif /* ENABLE_PLUGINS */
     44 
     45 #ifndef PATH_SEPARATOR
     46 #if defined (__MSDOS__) || (defined (_WIN32) && ! defined (__CYGWIN32__))
     47 #define PATH_SEPARATOR ';'
     48 #else
     49 #define PATH_SEPARATOR ':'
     50 #endif
     51 #endif
     52 
     53 /* Somewhere above, sys/stat.h got included . . . .  */
     54 #if !defined(S_ISDIR) && defined(S_IFDIR)
     55 #define	S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
     56 #endif
     57 
     58 static void set_default_dirlist (char *);
     59 static void set_section_start (char *, char *);
     60 static void set_segment_start (const char *, char *);
     61 static void help (void);
     62 
     63 /* The long options.  This structure is used for both the option
     64    parsing and the help text.  */
     65 
     66 enum control_enum {
     67   /* Use one dash before long option name.  */
     68   ONE_DASH = 1,
     69   /* Use two dashes before long option name.  */
     70   TWO_DASHES = 2,
     71   /* Only accept two dashes before the long option name.
     72      This is an overloading of the use of this enum, since originally it
     73      was only intended to tell the --help display function how to display
     74      the long option name.  This feature was added in order to resolve
     75      the confusion about the -omagic command line switch.  Is it setting
     76      the output file name to "magic" or is it setting the NMAGIC flag on
     77      the output ?  It has been decided that it is setting the output file
     78      name, and that if you want to set the NMAGIC flag you should use -N
     79      or --omagic.  */
     80   EXACTLY_TWO_DASHES,
     81   /* Don't mention this option in --help output.  */
     82   NO_HELP
     83 };
     84 
     85 struct ld_option
     86 {
     87   /* The long option information.  */
     88   struct option opt;
     89   /* The short option with the same meaning ('\0' if none).  */
     90   char shortopt;
     91   /* The name of the argument (NULL if none).  */
     92   const char *arg;
     93   /* The documentation string.  If this is NULL, this is a synonym for
     94      the previous option.  */
     95   const char *doc;
     96   enum control_enum control;
     97 };
     98 
     99 static const struct ld_option ld_options[] =
    100 {
    101   { {NULL, required_argument, NULL, '\0'},
    102     'a', N_("KEYWORD"), N_("Shared library control for HP/UX compatibility"),
    103     ONE_DASH },
    104   { {"architecture", required_argument, NULL, 'A'},
    105     'A', N_("ARCH"), N_("Set architecture") , TWO_DASHES },
    106   { {"format", required_argument, NULL, 'b'},
    107     'b', N_("TARGET"), N_("Specify target for following input files"),
    108     TWO_DASHES },
    109   { {"mri-script", required_argument, NULL, 'c'},
    110     'c', N_("FILE"), N_("Read MRI format linker script"), TWO_DASHES },
    111   { {"dc", no_argument, NULL, 'd'},
    112     'd', NULL, N_("Force common symbols to be defined"), ONE_DASH },
    113   { {"dp", no_argument, NULL, 'd'},
    114     '\0', NULL, NULL, ONE_DASH },
    115   { {"force-group-allocation", no_argument, NULL,
    116      OPTION_FORCE_GROUP_ALLOCATION},
    117     '\0', NULL, N_("Force group members out of groups"), TWO_DASHES },
    118   { {"entry", required_argument, NULL, 'e'},
    119     'e', N_("ADDRESS"), N_("Set start address"), TWO_DASHES },
    120   { {"export-dynamic", no_argument, NULL, OPTION_EXPORT_DYNAMIC},
    121     'E', NULL, N_("Export all dynamic symbols"), TWO_DASHES },
    122   { {"no-export-dynamic", no_argument, NULL, OPTION_NO_EXPORT_DYNAMIC},
    123     '\0', NULL, N_("Undo the effect of --export-dynamic"), TWO_DASHES },
    124   { {"EB", no_argument, NULL, OPTION_EB},
    125     '\0', NULL, N_("Link big-endian objects"), ONE_DASH },
    126   { {"EL", no_argument, NULL, OPTION_EL},
    127     '\0', NULL, N_("Link little-endian objects"), ONE_DASH },
    128   { {"auxiliary", required_argument, NULL, 'f'},
    129     'f', N_("SHLIB"), N_("Auxiliary filter for shared object symbol table"),
    130     TWO_DASHES },
    131   { {"filter", required_argument, NULL, 'F'},
    132     'F', N_("SHLIB"), N_("Filter for shared object symbol table"),
    133     TWO_DASHES },
    134   { {NULL, no_argument, NULL, '\0'},
    135     'g', NULL, N_("Ignored"), ONE_DASH },
    136   { {"gpsize", required_argument, NULL, 'G'},
    137     'G', N_("SIZE"), N_("Small data size (if no size, same as --shared)"),
    138     TWO_DASHES },
    139   { {"soname", required_argument, NULL, OPTION_SONAME},
    140     'h', N_("FILENAME"), N_("Set internal name of shared library"), ONE_DASH },
    141   { {"dynamic-linker", required_argument, NULL, OPTION_DYNAMIC_LINKER},
    142     'I', N_("PROGRAM"), N_("Set PROGRAM as the dynamic linker to use"),
    143     TWO_DASHES },
    144   { {"no-dynamic-linker", no_argument, NULL, OPTION_NO_DYNAMIC_LINKER},
    145     '\0', NULL, N_("Produce an executable with no program interpreter header"),
    146     TWO_DASHES },
    147   { {"library", required_argument, NULL, 'l'},
    148     'l', N_("LIBNAME"), N_("Search for library LIBNAME"), TWO_DASHES },
    149   { {"library-path", required_argument, NULL, 'L'},
    150     'L', N_("DIRECTORY"), N_("Add DIRECTORY to library search path"),
    151     TWO_DASHES },
    152   { {"sysroot=<DIRECTORY>", required_argument, NULL, OPTION_SYSROOT},
    153     '\0', NULL, N_("Override the default sysroot location"), TWO_DASHES },
    154   { {NULL, required_argument, NULL, '\0'},
    155     'm', N_("EMULATION"), N_("Set emulation"), ONE_DASH },
    156   { {"print-map", no_argument, NULL, 'M'},
    157     'M', NULL, N_("Print map file on standard output"), TWO_DASHES },
    158   { {"nmagic", no_argument, NULL, 'n'},
    159     'n', NULL, N_("Do not page align data"), TWO_DASHES },
    160   { {"omagic", no_argument, NULL, 'N'},
    161     'N', NULL, N_("Do not page align data, do not make text readonly"),
    162     EXACTLY_TWO_DASHES },
    163   { {"no-omagic", no_argument, NULL, OPTION_NO_OMAGIC},
    164     '\0', NULL, N_("Page align data, make text readonly"),
    165     EXACTLY_TWO_DASHES },
    166   { {"output", required_argument, NULL, 'o'},
    167     'o', N_("FILE"), N_("Set output file name"), EXACTLY_TWO_DASHES },
    168   { {NULL, required_argument, NULL, '\0'},
    169     'O', NULL, N_("Optimize output file"), ONE_DASH },
    170   { {"out-implib", required_argument, NULL, OPTION_OUT_IMPLIB},
    171     '\0', N_("FILE"), N_("Generate import library"), TWO_DASHES },
    172 #ifdef ENABLE_PLUGINS
    173   { {"plugin", required_argument, NULL, OPTION_PLUGIN},
    174     '\0', N_("PLUGIN"), N_("Load named plugin"), ONE_DASH },
    175   { {"plugin-opt", required_argument, NULL, OPTION_PLUGIN_OPT},
    176     '\0', N_("ARG"), N_("Send arg to last-loaded plugin"), ONE_DASH },
    177   { {"flto", optional_argument, NULL, OPTION_IGNORE},
    178     '\0', NULL, N_("Ignored for GCC LTO option compatibility"),
    179     ONE_DASH },
    180   { {"flto-partition=", required_argument, NULL, OPTION_IGNORE},
    181     '\0', NULL, N_("Ignored for GCC LTO option compatibility"),
    182     ONE_DASH },
    183 #endif /* ENABLE_PLUGINS */
    184   { {"fuse-ld=", required_argument, NULL, OPTION_IGNORE},
    185     '\0', NULL, N_("Ignored for GCC linker option compatibility"),
    186     ONE_DASH },
    187   { {"map-whole-files", optional_argument, NULL, OPTION_IGNORE},
    188     '\0', NULL, N_("Ignored for gold option compatibility"),
    189     TWO_DASHES },
    190   { {"no-map-whole-files", optional_argument, NULL, OPTION_IGNORE},
    191     '\0', NULL, N_("Ignored for gold option compatibility"),
    192     TWO_DASHES },
    193   { {"Qy", no_argument, NULL, OPTION_IGNORE},
    194     '\0', NULL, N_("Ignored for SVR4 compatibility"), ONE_DASH },
    195   { {"emit-relocs", no_argument, NULL, 'q'},
    196     'q', NULL, "Generate relocations in final output", TWO_DASHES },
    197   { {"relocatable", no_argument, NULL, 'r'},
    198     'r', NULL, N_("Generate relocatable output"), TWO_DASHES },
    199   { {NULL, no_argument, NULL, '\0'},
    200     'i', NULL, NULL, ONE_DASH },
    201   { {"just-symbols", required_argument, NULL, 'R'},
    202     'R', N_("FILE"), N_("Just link symbols (if directory, same as --rpath)"),
    203     TWO_DASHES },
    204   { {"strip-all", no_argument, NULL, 's'},
    205     's', NULL, N_("Strip all symbols"), TWO_DASHES },
    206   { {"strip-debug", no_argument, NULL, 'S'},
    207     'S', NULL, N_("Strip debugging symbols"), TWO_DASHES },
    208   { {"strip-discarded", no_argument, NULL, OPTION_STRIP_DISCARDED},
    209     '\0', NULL, N_("Strip symbols in discarded sections"), TWO_DASHES },
    210   { {"no-strip-discarded", no_argument, NULL, OPTION_NO_STRIP_DISCARDED},
    211     '\0', NULL, N_("Do not strip symbols in discarded sections"), TWO_DASHES },
    212   { {"trace", no_argument, NULL, 't'},
    213     't', NULL, N_("Trace file opens"), TWO_DASHES },
    214   { {"script", required_argument, NULL, 'T'},
    215     'T', N_("FILE"), N_("Read linker script"), TWO_DASHES },
    216   { {"default-script", required_argument, NULL, OPTION_DEFAULT_SCRIPT},
    217     '\0', N_("FILE"), N_("Read default linker script"), TWO_DASHES },
    218   { {"dT", required_argument, NULL, OPTION_DEFAULT_SCRIPT},
    219     '\0', NULL, NULL, ONE_DASH },
    220   { {"undefined", required_argument, NULL, 'u'},
    221     'u', N_("SYMBOL"), N_("Start with undefined reference to SYMBOL"),
    222     TWO_DASHES },
    223   { {"require-defined", required_argument, NULL, OPTION_REQUIRE_DEFINED_SYMBOL},
    224     '\0', N_("SYMBOL"), N_("Require SYMBOL be defined in the final output"),
    225     TWO_DASHES },
    226   { {"unique", optional_argument, NULL, OPTION_UNIQUE},
    227     '\0', N_("[=SECTION]"),
    228     N_("Don't merge input [SECTION | orphan] sections"), TWO_DASHES },
    229   { {"Ur", no_argument, NULL, OPTION_UR},
    230     '\0', NULL, N_("Build global constructor/destructor tables"), ONE_DASH },
    231   { {"version", no_argument, NULL, OPTION_VERSION},
    232     'v', NULL, N_("Print version information"), TWO_DASHES },
    233   { {NULL, no_argument, NULL, '\0'},
    234     'V', NULL, N_("Print version and emulation information"), ONE_DASH },
    235   { {"discard-all", no_argument, NULL, 'x'},
    236     'x', NULL, N_("Discard all local symbols"), TWO_DASHES },
    237   { {"discard-locals", no_argument, NULL, 'X'},
    238     'X', NULL, N_("Discard temporary local symbols (default)"), TWO_DASHES },
    239   { {"discard-none", no_argument, NULL, OPTION_DISCARD_NONE},
    240     '\0', NULL, N_("Don't discard any local symbols"), TWO_DASHES },
    241   { {"trace-symbol", required_argument, NULL, 'y'},
    242     'y', N_("SYMBOL"), N_("Trace mentions of SYMBOL"), TWO_DASHES },
    243   { {NULL, required_argument, NULL, '\0'},
    244     'Y', N_("PATH"), N_("Default search path for Solaris compatibility"),
    245     ONE_DASH },
    246   { {"start-group", no_argument, NULL, '('},
    247     '(', NULL, N_("Start a group"), TWO_DASHES },
    248   { {"end-group", no_argument, NULL, ')'},
    249     ')', NULL, N_("End a group"), TWO_DASHES },
    250   { {"accept-unknown-input-arch", no_argument, NULL,
    251      OPTION_ACCEPT_UNKNOWN_INPUT_ARCH},
    252     '\0', NULL,
    253     N_("Accept input files whose architecture cannot be determined"),
    254     TWO_DASHES },
    255   { {"no-accept-unknown-input-arch", no_argument, NULL,
    256      OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH},
    257     '\0', NULL, N_("Reject input files whose architecture is unknown"),
    258     TWO_DASHES },
    259 
    260   /* The next two options are deprecated because of their similarity to
    261      --as-needed and --no-as-needed.  They have been replaced by
    262      --copy-dt-needed-entries and --no-copy-dt-needed-entries.  */
    263   { {"add-needed", no_argument, NULL, OPTION_ADD_DT_NEEDED_FOR_DYNAMIC},
    264     '\0', NULL, NULL, NO_HELP },
    265   { {"no-add-needed", no_argument, NULL, OPTION_NO_ADD_DT_NEEDED_FOR_DYNAMIC},
    266     '\0', NULL, NULL, NO_HELP },
    267 
    268   { {"as-needed", no_argument, NULL, OPTION_ADD_DT_NEEDED_FOR_REGULAR},
    269     '\0', NULL, N_("Only set DT_NEEDED for following dynamic libs if used"),
    270     TWO_DASHES },
    271   { {"no-as-needed", no_argument, NULL, OPTION_NO_ADD_DT_NEEDED_FOR_REGULAR},
    272     '\0', NULL, N_("Always set DT_NEEDED for dynamic libraries mentioned on\n"
    273 		   "                                the command line"),
    274     TWO_DASHES },
    275   { {"assert", required_argument, NULL, OPTION_ASSERT},
    276     '\0', N_("KEYWORD"), N_("Ignored for SunOS compatibility"), ONE_DASH },
    277   { {"Bdynamic", no_argument, NULL, OPTION_CALL_SHARED},
    278     '\0', NULL, N_("Link against shared libraries"), ONE_DASH },
    279   { {"dy", no_argument, NULL, OPTION_CALL_SHARED},
    280     '\0', NULL, NULL, ONE_DASH },
    281   { {"call_shared", no_argument, NULL, OPTION_CALL_SHARED},
    282     '\0', NULL, NULL, ONE_DASH },
    283   { {"Bstatic", no_argument, NULL, OPTION_NON_SHARED},
    284     '\0', NULL, N_("Do not link against shared libraries"), ONE_DASH },
    285   { {"dn", no_argument, NULL, OPTION_NON_SHARED},
    286     '\0', NULL, NULL, ONE_DASH },
    287   { {"non_shared", no_argument, NULL, OPTION_NON_SHARED},
    288     '\0', NULL, NULL, ONE_DASH },
    289   { {"static", no_argument, NULL, OPTION_NON_SHARED},
    290     '\0', NULL, NULL, ONE_DASH },
    291   { {"Bsymbolic", no_argument, NULL, OPTION_SYMBOLIC},
    292     '\0', NULL, N_("Bind global references locally"), ONE_DASH },
    293   { {"Bsymbolic-functions", no_argument, NULL, OPTION_SYMBOLIC_FUNCTIONS},
    294     '\0', NULL, N_("Bind global function references locally"), ONE_DASH },
    295   { {"check-sections", no_argument, NULL, OPTION_CHECK_SECTIONS},
    296     '\0', NULL, N_("Check section addresses for overlaps (default)"),
    297     TWO_DASHES },
    298   { {"no-check-sections", no_argument, NULL, OPTION_NO_CHECK_SECTIONS},
    299     '\0', NULL, N_("Do not check section addresses for overlaps"),
    300     TWO_DASHES },
    301   { {"copy-dt-needed-entries", no_argument, NULL,
    302      OPTION_ADD_DT_NEEDED_FOR_DYNAMIC},
    303     '\0', NULL, N_("Copy DT_NEEDED links mentioned inside DSOs that follow"),
    304     TWO_DASHES },
    305   { {"no-copy-dt-needed-entries", no_argument, NULL,
    306      OPTION_NO_ADD_DT_NEEDED_FOR_DYNAMIC},
    307     '\0', NULL, N_("Do not copy DT_NEEDED links mentioned inside DSOs that follow"),
    308     TWO_DASHES },
    309 
    310   { {"cref", no_argument, NULL, OPTION_CREF},
    311     '\0', NULL, N_("Output cross reference table"), TWO_DASHES },
    312   { {"defsym", required_argument, NULL, OPTION_DEFSYM},
    313     '\0', N_("SYMBOL=EXPRESSION"), N_("Define a symbol"), TWO_DASHES },
    314   { {"demangle", optional_argument, NULL, OPTION_DEMANGLE},
    315     '\0', N_("[=STYLE]"), N_("Demangle symbol names [using STYLE]"),
    316     TWO_DASHES },
    317   { {"disable-multiple-abs-defs", no_argument, NULL,
    318      OPTION_DISABLE_MULTIPLE_DEFS_ABS},
    319     '\0', NULL, N_("Do not allow multiple definitions with symbols included\n"
    320 		   "           in filename invoked by -R or --just-symbols"),
    321     TWO_DASHES},
    322   { {"embedded-relocs", no_argument, NULL, OPTION_EMBEDDED_RELOCS},
    323     '\0', NULL, N_("Generate embedded relocs"), TWO_DASHES},
    324   { {"fatal-warnings", no_argument, NULL, OPTION_WARN_FATAL},
    325     '\0', NULL, N_("Treat warnings as errors"),
    326     TWO_DASHES },
    327   { {"no-fatal-warnings", no_argument, NULL, OPTION_NO_WARN_FATAL},
    328     '\0', NULL, N_("Do not treat warnings as errors (default)"),
    329     TWO_DASHES },
    330   { {"fini", required_argument, NULL, OPTION_FINI},
    331     '\0', N_("SYMBOL"), N_("Call SYMBOL at unload-time"), ONE_DASH },
    332   { {"force-exe-suffix", no_argument, NULL, OPTION_FORCE_EXE_SUFFIX},
    333     '\0', NULL, N_("Force generation of file with .exe suffix"), TWO_DASHES},
    334   { {"gc-sections", no_argument, NULL, OPTION_GC_SECTIONS},
    335     '\0', NULL, N_("Remove unused sections (on some targets)"),
    336     TWO_DASHES },
    337   { {"no-gc-sections", no_argument, NULL, OPTION_NO_GC_SECTIONS},
    338     '\0', NULL, N_("Don't remove unused sections (default)"),
    339     TWO_DASHES },
    340   { {"print-gc-sections", no_argument, NULL, OPTION_PRINT_GC_SECTIONS},
    341     '\0', NULL, N_("List removed unused sections on stderr"),
    342     TWO_DASHES },
    343   { {"no-print-gc-sections", no_argument, NULL, OPTION_NO_PRINT_GC_SECTIONS},
    344     '\0', NULL, N_("Do not list removed unused sections"),
    345     TWO_DASHES },
    346   { {"gc-keep-exported", no_argument, NULL, OPTION_GC_KEEP_EXPORTED},
    347     '\0', NULL, N_("Keep exported symbols when removing unused sections"),
    348     TWO_DASHES },
    349   { {"hash-size=<NUMBER>", required_argument, NULL, OPTION_HASH_SIZE},
    350     '\0', NULL, N_("Set default hash table size close to <NUMBER>"),
    351     TWO_DASHES },
    352   { {"help", no_argument, NULL, OPTION_HELP},
    353     '\0', NULL, N_("Print option help"), TWO_DASHES },
    354   { {"init", required_argument, NULL, OPTION_INIT},
    355     '\0', N_("SYMBOL"), N_("Call SYMBOL at load-time"), ONE_DASH },
    356   { {"Map", required_argument, NULL, OPTION_MAP},
    357     '\0', N_("FILE"), N_("Write a map file"), ONE_DASH },
    358   { {"no-define-common", no_argument, NULL, OPTION_NO_DEFINE_COMMON},
    359     '\0', NULL, N_("Do not define Common storage"), TWO_DASHES },
    360   { {"no-demangle", no_argument, NULL, OPTION_NO_DEMANGLE },
    361     '\0', NULL, N_("Do not demangle symbol names"), TWO_DASHES },
    362   { {"no-keep-memory", no_argument, NULL, OPTION_NO_KEEP_MEMORY},
    363     '\0', NULL, N_("Use less memory and more disk I/O"), TWO_DASHES },
    364   { {"no-undefined", no_argument, NULL, OPTION_NO_UNDEFINED},
    365     '\0', NULL, N_("Do not allow unresolved references in object files"),
    366     TWO_DASHES },
    367   { {"allow-shlib-undefined", no_argument, NULL, OPTION_ALLOW_SHLIB_UNDEFINED},
    368     '\0', NULL, N_("Allow unresolved references in shared libraries"),
    369     TWO_DASHES },
    370   { {"no-allow-shlib-undefined", no_argument, NULL,
    371      OPTION_NO_ALLOW_SHLIB_UNDEFINED},
    372     '\0', NULL, N_("Do not allow unresolved references in shared libs"),
    373     TWO_DASHES },
    374   { {"allow-multiple-definition", no_argument, NULL,
    375      OPTION_ALLOW_MULTIPLE_DEFINITION},
    376     '\0', NULL, N_("Allow multiple definitions"), TWO_DASHES },
    377   { {"no-undefined-version", no_argument, NULL, OPTION_NO_UNDEFINED_VERSION},
    378     '\0', NULL, N_("Disallow undefined version"), TWO_DASHES },
    379   { {"default-symver", no_argument, NULL, OPTION_DEFAULT_SYMVER},
    380     '\0', NULL, N_("Create default symbol version"), TWO_DASHES },
    381   { {"default-imported-symver", no_argument, NULL,
    382       OPTION_DEFAULT_IMPORTED_SYMVER},
    383     '\0', NULL, N_("Create default symbol version for imported symbols"),
    384     TWO_DASHES },
    385   { {"no-warn-mismatch", no_argument, NULL, OPTION_NO_WARN_MISMATCH},
    386     '\0', NULL, N_("Don't warn about mismatched input files"), TWO_DASHES},
    387   { {"no-warn-search-mismatch", no_argument, NULL,
    388      OPTION_NO_WARN_SEARCH_MISMATCH},
    389     '\0', NULL, N_("Don't warn on finding an incompatible library"),
    390     TWO_DASHES},
    391   { {"no-whole-archive", no_argument, NULL, OPTION_NO_WHOLE_ARCHIVE},
    392     '\0', NULL, N_("Turn off --whole-archive"), TWO_DASHES },
    393   { {"noinhibit-exec", no_argument, NULL, OPTION_NOINHIBIT_EXEC},
    394     '\0', NULL, N_("Create an output file even if errors occur"),
    395     TWO_DASHES },
    396   { {"noinhibit_exec", no_argument, NULL, OPTION_NOINHIBIT_EXEC},
    397     '\0', NULL, NULL, NO_HELP },
    398   { {"nostdlib", no_argument, NULL, OPTION_NOSTDLIB},
    399     '\0', NULL, N_("Only use library directories specified on\n"
    400 		   "                                the command line"),
    401     ONE_DASH },
    402   { {"oformat", required_argument, NULL, OPTION_OFORMAT},
    403     '\0', N_("TARGET"), N_("Specify target of output file"),
    404     EXACTLY_TWO_DASHES },
    405   { {"print-output-format", no_argument, NULL, OPTION_PRINT_OUTPUT_FORMAT},
    406     '\0', NULL, N_("Print default output format"), TWO_DASHES },
    407   { {"print-sysroot", no_argument, NULL, OPTION_PRINT_SYSROOT},
    408     '\0', NULL, N_("Print current sysroot"), TWO_DASHES },
    409   { {"qmagic", no_argument, NULL, OPTION_IGNORE},
    410     '\0', NULL, N_("Ignored for Linux compatibility"), ONE_DASH },
    411   { {"reduce-memory-overheads", no_argument, NULL,
    412      OPTION_REDUCE_MEMORY_OVERHEADS},
    413     '\0', NULL, N_("Reduce memory overheads, possibly taking much longer"),
    414     TWO_DASHES },
    415   { {"relax", no_argument, NULL, OPTION_RELAX},
    416     '\0', NULL, N_("Reduce code size by using target specific optimizations"), TWO_DASHES },
    417   { {"no-relax", no_argument, NULL, OPTION_NO_RELAX},
    418     '\0', NULL, N_("Do not use relaxation techniques to reduce code size"), TWO_DASHES },
    419   { {"retain-symbols-file", required_argument, NULL,
    420      OPTION_RETAIN_SYMBOLS_FILE},
    421     '\0', N_("FILE"), N_("Keep only symbols listed in FILE"), TWO_DASHES },
    422   { {"rpath", required_argument, NULL, OPTION_RPATH},
    423     '\0', N_("PATH"), N_("Set runtime shared library search path"), ONE_DASH },
    424   { {"rpath-link", required_argument, NULL, OPTION_RPATH_LINK},
    425     '\0', N_("PATH"), N_("Set link time shared library search path"),
    426     ONE_DASH },
    427   { {"shared", no_argument, NULL, OPTION_SHARED},
    428     '\0', NULL, N_("Create a shared library"), ONE_DASH },
    429   { {"Bshareable", no_argument, NULL, OPTION_SHARED }, /* FreeBSD, NetBSD.  */
    430     '\0', NULL, NULL, ONE_DASH },
    431   { {"pie", no_argument, NULL, OPTION_PIE},
    432     '\0', NULL, N_("Create a position independent executable"), ONE_DASH },
    433   { {"pic-executable", no_argument, NULL, OPTION_PIE},
    434     '\0', NULL, NULL, TWO_DASHES },
    435   { {"sort-common", optional_argument, NULL, OPTION_SORT_COMMON},
    436     '\0', N_("[=ascending|descending]"),
    437     N_("Sort common symbols by alignment [in specified order]"),
    438     TWO_DASHES },
    439   { {"sort_common", no_argument, NULL, OPTION_SORT_COMMON},
    440     '\0', NULL, NULL, NO_HELP },
    441   { {"sort-section", required_argument, NULL, OPTION_SORT_SECTION},
    442     '\0', N_("name|alignment"),
    443     N_("Sort sections by name or maximum alignment"), TWO_DASHES },
    444   { {"spare-dynamic-tags", required_argument, NULL, OPTION_SPARE_DYNAMIC_TAGS},
    445     '\0', N_("COUNT"), N_("How many tags to reserve in .dynamic section"),
    446     TWO_DASHES },
    447   { {"split-by-file", optional_argument, NULL, OPTION_SPLIT_BY_FILE},
    448     '\0', N_("[=SIZE]"), N_("Split output sections every SIZE octets"),
    449     TWO_DASHES },
    450   { {"split-by-reloc", optional_argument, NULL, OPTION_SPLIT_BY_RELOC},
    451     '\0', N_("[=COUNT]"), N_("Split output sections every COUNT relocs"),
    452     TWO_DASHES },
    453   { {"stats", no_argument, NULL, OPTION_STATS},
    454     '\0', NULL, N_("Print memory usage statistics"), TWO_DASHES },
    455   { {"target-help", no_argument, NULL, OPTION_TARGET_HELP},
    456     '\0', NULL, N_("Display target specific options"), TWO_DASHES },
    457   { {"task-link", required_argument, NULL, OPTION_TASK_LINK},
    458     '\0', N_("SYMBOL"), N_("Do task level linking"), TWO_DASHES },
    459   { {"traditional-format", no_argument, NULL, OPTION_TRADITIONAL_FORMAT},
    460     '\0', NULL, N_("Use same format as native linker"), TWO_DASHES },
    461   { {"section-start", required_argument, NULL, OPTION_SECTION_START},
    462     '\0', N_("SECTION=ADDRESS"), N_("Set address of named section"),
    463     TWO_DASHES },
    464   { {"Tbss", required_argument, NULL, OPTION_TBSS},
    465     '\0', N_("ADDRESS"), N_("Set address of .bss section"), ONE_DASH },
    466   { {"Tdata", required_argument, NULL, OPTION_TDATA},
    467     '\0', N_("ADDRESS"), N_("Set address of .data section"), ONE_DASH },
    468   { {"Ttext", required_argument, NULL, OPTION_TTEXT},
    469     '\0', N_("ADDRESS"), N_("Set address of .text section"), ONE_DASH },
    470   { {"Ttext-segment", required_argument, NULL, OPTION_TTEXT_SEGMENT},
    471     '\0', N_("ADDRESS"), N_("Set address of text segment"), ONE_DASH },
    472   { {"Trodata-segment", required_argument, NULL, OPTION_TRODATA_SEGMENT},
    473     '\0', N_("ADDRESS"), N_("Set address of rodata segment"), ONE_DASH },
    474   { {"Tldata-segment", required_argument, NULL, OPTION_TLDATA_SEGMENT},
    475     '\0', N_("ADDRESS"), N_("Set address of ldata segment"), ONE_DASH },
    476   { {"unresolved-symbols=<method>", required_argument, NULL,
    477      OPTION_UNRESOLVED_SYMBOLS},
    478     '\0', NULL, N_("How to handle unresolved symbols.  <method> is:\n"
    479 		   "                                ignore-all, report-all, ignore-in-object-files,\n"
    480 		   "                                ignore-in-shared-libs"),
    481     TWO_DASHES },
    482   { {"verbose", optional_argument, NULL, OPTION_VERBOSE},
    483     '\0', N_("[=NUMBER]"),
    484     N_("Output lots of information during link"), TWO_DASHES },
    485   { {"dll-verbose", no_argument, NULL, OPTION_VERBOSE}, /* Linux.  */
    486     '\0', NULL, NULL, NO_HELP },
    487   { {"version-script", required_argument, NULL, OPTION_VERSION_SCRIPT },
    488     '\0', N_("FILE"), N_("Read version information script"), TWO_DASHES },
    489   { {"version-exports-section", required_argument, NULL,
    490      OPTION_VERSION_EXPORTS_SECTION },
    491     '\0', N_("SYMBOL"), N_("Take export symbols list from .exports, using\n"
    492 			   "                                SYMBOL as the version."),
    493     TWO_DASHES },
    494   { {"dynamic-list-data", no_argument, NULL, OPTION_DYNAMIC_LIST_DATA},
    495     '\0', NULL, N_("Add data symbols to dynamic list"), TWO_DASHES },
    496   { {"dynamic-list-cpp-new", no_argument, NULL, OPTION_DYNAMIC_LIST_CPP_NEW},
    497     '\0', NULL, N_("Use C++ operator new/delete dynamic list"), TWO_DASHES },
    498   { {"dynamic-list-cpp-typeinfo", no_argument, NULL, OPTION_DYNAMIC_LIST_CPP_TYPEINFO},
    499     '\0', NULL, N_("Use C++ typeinfo dynamic list"), TWO_DASHES },
    500   { {"dynamic-list", required_argument, NULL, OPTION_DYNAMIC_LIST},
    501     '\0', N_("FILE"), N_("Read dynamic list"), TWO_DASHES },
    502   { {"warn-common", no_argument, NULL, OPTION_WARN_COMMON},
    503     '\0', NULL, N_("Warn about duplicate common symbols"), TWO_DASHES },
    504   { {"warn-constructors", no_argument, NULL, OPTION_WARN_CONSTRUCTORS},
    505     '\0', NULL, N_("Warn if global constructors/destructors are seen"),
    506     TWO_DASHES },
    507   { {"warn-multiple-gp", no_argument, NULL, OPTION_WARN_MULTIPLE_GP},
    508     '\0', NULL, N_("Warn if the multiple GP values are used"), TWO_DASHES },
    509   { {"warn-once", no_argument, NULL, OPTION_WARN_ONCE},
    510     '\0', NULL, N_("Warn only once per undefined symbol"), TWO_DASHES },
    511   { {"warn-section-align", no_argument, NULL, OPTION_WARN_SECTION_ALIGN},
    512     '\0', NULL, N_("Warn if start of section changes due to alignment"),
    513     TWO_DASHES },
    514   { {"warn-shared-textrel", no_argument, NULL, OPTION_WARN_SHARED_TEXTREL},
    515     '\0', NULL, N_("Warn if shared object has DT_TEXTREL"),
    516     TWO_DASHES },
    517   { {"warn-alternate-em", no_argument, NULL, OPTION_WARN_ALTERNATE_EM},
    518     '\0', NULL, N_("Warn if an object has alternate ELF machine code"),
    519     TWO_DASHES },
    520   { {"warn-unresolved-symbols", no_argument, NULL,
    521      OPTION_WARN_UNRESOLVED_SYMBOLS},
    522     '\0', NULL, N_("Report unresolved symbols as warnings"), TWO_DASHES },
    523   { {"error-unresolved-symbols", no_argument, NULL,
    524      OPTION_ERROR_UNRESOLVED_SYMBOLS},
    525     '\0', NULL, N_("Report unresolved symbols as errors"), TWO_DASHES },
    526   { {"whole-archive", no_argument, NULL, OPTION_WHOLE_ARCHIVE},
    527     '\0', NULL, N_("Include all objects from following archives"),
    528     TWO_DASHES },
    529   { {"Bforcearchive", no_argument, NULL, OPTION_WHOLE_ARCHIVE},
    530       '\0', NULL, NULL, TWO_DASHES },	/* NetBSD.  */
    531   { {"wrap", required_argument, NULL, OPTION_WRAP},
    532     '\0', N_("SYMBOL"), N_("Use wrapper functions for SYMBOL"), TWO_DASHES },
    533   { {"ignore-unresolved-symbol", required_argument, NULL,
    534     OPTION_IGNORE_UNRESOLVED_SYMBOL},
    535     '\0', N_("SYMBOL"),
    536     N_("Unresolved SYMBOL will not cause an error or warning"), TWO_DASHES },
    537   { {"push-state", no_argument, NULL, OPTION_PUSH_STATE},
    538     '\0', NULL, N_("Push state of flags governing input file handling"),
    539     TWO_DASHES },
    540   { {"pop-state", no_argument, NULL, OPTION_POP_STATE},
    541     '\0', NULL, N_("Pop state of flags governing input file handling"),
    542     TWO_DASHES },
    543   { {"print-memory-usage", no_argument, NULL, OPTION_PRINT_MEMORY_USAGE},
    544     '\0', NULL, N_("Report target memory usage"), TWO_DASHES },
    545   { {"orphan-handling", required_argument, NULL, OPTION_ORPHAN_HANDLING},
    546     '\0', N_("=MODE"), N_("Control how orphan sections are handled."),
    547     TWO_DASHES },
    548 };
    549 
    550 #define OPTION_COUNT ARRAY_SIZE (ld_options)
    551 
    552 void
    553 parse_args (unsigned argc, char **argv)
    554 {
    555   unsigned i;
    556   int is, il, irl;
    557   int ingroup = 0;
    558   char *default_dirlist = NULL;
    559   char *shortopts;
    560   struct option *longopts;
    561   struct option *really_longopts;
    562   int last_optind;
    563   enum report_method how_to_report_unresolved_symbols = RM_GENERATE_ERROR;
    564 
    565   shortopts = (char *) xmalloc (OPTION_COUNT * 3 + 2);
    566   longopts = (struct option *)
    567       xmalloc (sizeof (*longopts) * (OPTION_COUNT + 1));
    568   really_longopts = (struct option *)
    569       malloc (sizeof (*really_longopts) * (OPTION_COUNT + 1));
    570 
    571   /* Starting the short option string with '-' is for programs that
    572      expect options and other ARGV-elements in any order and that care about
    573      the ordering of the two.  We describe each non-option ARGV-element
    574      as if it were the argument of an option with character code 1.  */
    575   shortopts[0] = '-';
    576   is = 1;
    577   il = 0;
    578   irl = 0;
    579   for (i = 0; i < OPTION_COUNT; i++)
    580     {
    581       if (ld_options[i].shortopt != '\0')
    582 	{
    583 	  shortopts[is] = ld_options[i].shortopt;
    584 	  ++is;
    585 	  if (ld_options[i].opt.has_arg == required_argument
    586 	      || ld_options[i].opt.has_arg == optional_argument)
    587 	    {
    588 	      shortopts[is] = ':';
    589 	      ++is;
    590 	      if (ld_options[i].opt.has_arg == optional_argument)
    591 		{
    592 		  shortopts[is] = ':';
    593 		  ++is;
    594 		}
    595 	    }
    596 	}
    597       if (ld_options[i].opt.name != NULL)
    598 	{
    599 	  if (ld_options[i].control == EXACTLY_TWO_DASHES)
    600 	    {
    601 	      really_longopts[irl] = ld_options[i].opt;
    602 	      ++irl;
    603 	    }
    604 	  else
    605 	    {
    606 	      longopts[il] = ld_options[i].opt;
    607 	      ++il;
    608 	    }
    609 	}
    610     }
    611   shortopts[is] = '\0';
    612   longopts[il].name = NULL;
    613   really_longopts[irl].name = NULL;
    614 
    615   ldemul_add_options (is, &shortopts, il, &longopts, irl, &really_longopts);
    616 
    617   /* The -G option is ambiguous on different platforms.  Sometimes it
    618      specifies the largest data size to put into the small data
    619      section.  Sometimes it is equivalent to --shared.  Unfortunately,
    620      the first form takes an argument, while the second does not.
    621 
    622      We need to permit the --shared form because on some platforms,
    623      such as Solaris, gcc -shared will pass -G to the linker.
    624 
    625      To permit either usage, we look through the argument list.  If we
    626      find -G not followed by a number, we change it into --shared.
    627      This will work for most normal cases.  */
    628   for (i = 1; i < argc; i++)
    629     if (strcmp (argv[i], "-G") == 0
    630 	&& (i + 1 >= argc
    631 	    || ! ISDIGIT (argv[i + 1][0])))
    632       argv[i] = (char *) "--shared";
    633 
    634   /* Because we permit long options to start with a single dash, and
    635      we have a --library option, and the -l option is conventionally
    636      used with an immediately following argument, we can have bad
    637      results if somebody tries to use -l with a library whose name
    638      happens to start with "ibrary", as in -li.  We avoid problems by
    639      simply turning -l into --library.  This means that users will
    640      have to use two dashes in order to use --library, which is OK
    641      since that's how it is documented.
    642 
    643      FIXME: It's possible that this problem can arise for other short
    644      options as well, although the user does always have the recourse
    645      of adding a space between the option and the argument.  */
    646   for (i = 1; i < argc; i++)
    647     {
    648       if (argv[i][0] == '-'
    649 	  && argv[i][1] == 'l'
    650 	  && argv[i][2] != '\0')
    651 	{
    652 	  char *n;
    653 
    654 	  n = (char *) xmalloc (strlen (argv[i]) + 20);
    655 	  sprintf (n, "--library=%s", argv[i] + 2);
    656 	  argv[i] = n;
    657 	}
    658     }
    659 
    660   last_optind = -1;
    661   while (1)
    662     {
    663       int longind;
    664       int optc;
    665       static unsigned int defsym_count;
    666 
    667       /* Using last_optind lets us avoid calling ldemul_parse_args
    668 	 multiple times on a single option, which would lead to
    669 	 confusion in the internal static variables maintained by
    670 	 getopt.  This could otherwise happen for an argument like
    671 	 -nx, in which the -n is parsed as a single option, and we
    672 	 loop around to pick up the -x.  */
    673       if (optind != last_optind)
    674 	if (ldemul_parse_args (argc, argv))
    675 	  continue;
    676 
    677       /* getopt_long_only is like getopt_long, but '-' as well as '--'
    678 	 can indicate a long option.  */
    679       opterr = 0;
    680       last_optind = optind;
    681       optc = getopt_long_only (argc, argv, shortopts, longopts, &longind);
    682       if (optc == '?')
    683 	{
    684 	  optind = last_optind;
    685 	  optc = getopt_long (argc, argv, "-", really_longopts, &longind);
    686 	}
    687 
    688       if (ldemul_handle_option (optc))
    689 	continue;
    690 
    691       if (optc == -1)
    692 	break;
    693 
    694       switch (optc)
    695 	{
    696 	case '?':
    697 	  {
    698 	    /* If the last word on the command line is an option that
    699 	       requires an argument, getopt will refuse to recognise it.
    700 	       Try to catch such options here and issue a more helpful
    701 	       error message than just "unrecognized option".  */
    702 	    int opt;
    703 
    704 	    for (opt = ARRAY_SIZE (ld_options); opt--;)
    705 	      if (ld_options[opt].opt.has_arg == required_argument
    706 		  /* FIXME: There are a few short options that do not
    707 		     have long equivalents, but which require arguments.
    708 		     We should handle them too.  */
    709 		  && ld_options[opt].opt.name != NULL
    710 		  && strcmp (argv[last_optind] + ld_options[opt].control, ld_options[opt].opt.name) == 0)
    711 		{
    712 		  einfo (_("%P: %s: missing argument\n"), argv[last_optind]);
    713 		  break;
    714 		}
    715 
    716 	    if (opt == -1)
    717 	      einfo (_("%P: unrecognized option '%s'\n"), argv[last_optind]);
    718 	  }
    719 	  /* Fall through.  */
    720 
    721 	default:
    722 	  einfo (_("%F%P: use the --help option for usage information\n"));
    723 	  break;
    724 
    725 	case 1:			/* File name.  */
    726 	  lang_add_input_file (optarg, lang_input_file_is_file_enum, NULL);
    727 	  break;
    728 
    729 	case OPTION_IGNORE:
    730 	  break;
    731 	case 'a':
    732 	  /* For HP/UX compatibility.  Actually -a shared should mean
    733 	     ``use only shared libraries'' but, then, we don't
    734 	     currently support shared libraries on HP/UX anyhow.  */
    735 	  if (strcmp (optarg, "archive") == 0)
    736 	    input_flags.dynamic = FALSE;
    737 	  else if (strcmp (optarg, "shared") == 0
    738 		   || strcmp (optarg, "default") == 0)
    739 	    input_flags.dynamic = TRUE;
    740 	  else
    741 	    einfo (_("%F%P: unrecognized -a option `%s'\n"), optarg);
    742 	  break;
    743 	case OPTION_ASSERT:
    744 	  /* FIXME: We just ignore these, but we should handle them.  */
    745 	  if (strcmp (optarg, "definitions") == 0)
    746 	    ;
    747 	  else if (strcmp (optarg, "nodefinitions") == 0)
    748 	    ;
    749 	  else if (strcmp (optarg, "nosymbolic") == 0)
    750 	    ;
    751 	  else if (strcmp (optarg, "pure-text") == 0)
    752 	    ;
    753 	  else
    754 	    einfo (_("%F%P: unrecognized -assert option `%s'\n"), optarg);
    755 	  break;
    756 	case 'A':
    757 	  ldfile_add_arch (optarg);
    758 	  break;
    759 	case 'b':
    760 	  lang_add_target (optarg);
    761 	  break;
    762 	case 'c':
    763 	  ldfile_open_command_file (optarg);
    764 	  parser_input = input_mri_script;
    765 	  yyparse ();
    766 	  break;
    767 	case OPTION_CALL_SHARED:
    768 	  input_flags.dynamic = TRUE;
    769 	  break;
    770 	case OPTION_NON_SHARED:
    771 	  input_flags.dynamic = FALSE;
    772 	  break;
    773 	case OPTION_CREF:
    774 	  command_line.cref = TRUE;
    775 	  link_info.notice_all = TRUE;
    776 	  break;
    777 	case 'd':
    778 	  command_line.force_common_definition = TRUE;
    779 	  break;
    780 	case OPTION_FORCE_GROUP_ALLOCATION:
    781 	  command_line.force_group_allocation = TRUE;
    782 	  break;
    783 	case OPTION_DEFSYM:
    784 	  lex_string = optarg;
    785 	  lex_redirect (optarg, "--defsym", ++defsym_count);
    786 	  parser_input = input_defsym;
    787 	  yyparse ();
    788 	  lex_string = NULL;
    789 	  break;
    790 	case OPTION_DEMANGLE:
    791 	  demangling = TRUE;
    792 	  if (optarg != NULL)
    793 	    {
    794 	      enum demangling_styles style;
    795 
    796 	      style = cplus_demangle_name_to_style (optarg);
    797 	      if (style == unknown_demangling)
    798 		einfo (_("%F%P: unknown demangling style `%s'\n"),
    799 		       optarg);
    800 
    801 	      cplus_demangle_set_style (style);
    802 	    }
    803 	  break;
    804 	case 'I':		/* Used on Solaris.  */
    805 	case OPTION_DYNAMIC_LINKER:
    806 	  command_line.interpreter = optarg;
    807 	  link_info.nointerp = 0;
    808 	  break;
    809 	case OPTION_NO_DYNAMIC_LINKER:
    810 	  link_info.nointerp = 1;
    811 	  break;
    812 	case OPTION_SYSROOT:
    813 	  /* Already handled in ldmain.c.  */
    814 	  break;
    815 	case OPTION_EB:
    816 	  command_line.endian = ENDIAN_BIG;
    817 	  break;
    818 	case OPTION_EL:
    819 	  command_line.endian = ENDIAN_LITTLE;
    820 	  break;
    821 	case OPTION_EMBEDDED_RELOCS:
    822 	  command_line.embedded_relocs = TRUE;
    823 	  break;
    824 	case OPTION_EXPORT_DYNAMIC:
    825 	case 'E': /* HP/UX compatibility.  */
    826 	  link_info.export_dynamic = TRUE;
    827 	  break;
    828 	case OPTION_NO_EXPORT_DYNAMIC:
    829 	  link_info.export_dynamic = FALSE;
    830 	  break;
    831 	case 'e':
    832 	  lang_add_entry (optarg, TRUE);
    833 	  break;
    834 	case 'f':
    835 	  if (command_line.auxiliary_filters == NULL)
    836 	    {
    837 	      command_line.auxiliary_filters = (char **)
    838 		xmalloc (2 * sizeof (char *));
    839 	      command_line.auxiliary_filters[0] = optarg;
    840 	      command_line.auxiliary_filters[1] = NULL;
    841 	    }
    842 	  else
    843 	    {
    844 	      int c;
    845 	      char **p;
    846 
    847 	      c = 0;
    848 	      for (p = command_line.auxiliary_filters; *p != NULL; p++)
    849 		++c;
    850 	      command_line.auxiliary_filters = (char **)
    851 		xrealloc (command_line.auxiliary_filters,
    852 			  (c + 2) * sizeof (char *));
    853 	      command_line.auxiliary_filters[c] = optarg;
    854 	      command_line.auxiliary_filters[c + 1] = NULL;
    855 	    }
    856 	  break;
    857 	case 'F':
    858 	  command_line.filter_shlib = optarg;
    859 	  break;
    860 	case OPTION_FORCE_EXE_SUFFIX:
    861 	  command_line.force_exe_suffix = TRUE;
    862 	  break;
    863 	case 'G':
    864 	  {
    865 	    char *end;
    866 	    g_switch_value = strtoul (optarg, &end, 0);
    867 	    if (*end)
    868 	      einfo (_("%F%P: invalid number `%s'\n"), optarg);
    869 	  }
    870 	  break;
    871 	case 'g':
    872 	  /* Ignore.  */
    873 	  break;
    874 	case OPTION_GC_SECTIONS:
    875 	  link_info.gc_sections = TRUE;
    876 	  break;
    877 	case OPTION_PRINT_GC_SECTIONS:
    878 	  link_info.print_gc_sections = TRUE;
    879 	  break;
    880 	case OPTION_GC_KEEP_EXPORTED:
    881 	  link_info.gc_keep_exported = TRUE;
    882 	  break;
    883 	case OPTION_HELP:
    884 	  help ();
    885 	  xexit (0);
    886 	  break;
    887 	case 'L':
    888 	  ldfile_add_library_path (optarg, TRUE);
    889 	  break;
    890 	case 'l':
    891 	  lang_add_input_file (optarg, lang_input_file_is_l_enum, NULL);
    892 	  break;
    893 	case 'M':
    894 	  config.map_filename = "-";
    895 	  break;
    896 	case 'm':
    897 	  /* Ignore.  Was handled in a pre-parse.   */
    898 	  break;
    899 	case OPTION_MAP:
    900 	  config.map_filename = optarg;
    901 	  break;
    902 	case 'N':
    903 	  config.text_read_only = FALSE;
    904 	  config.magic_demand_paged = FALSE;
    905 	  input_flags.dynamic = FALSE;
    906 	  break;
    907 	case OPTION_NO_OMAGIC:
    908 	  config.text_read_only = TRUE;
    909 	  config.magic_demand_paged = TRUE;
    910 	  /* NB/ Does not set input_flags.dynamic to TRUE.
    911 	     Use --call-shared or -Bdynamic for this.  */
    912 	  break;
    913 	case 'n':
    914 	  config.magic_demand_paged = FALSE;
    915 	  input_flags.dynamic = FALSE;
    916 	  break;
    917 	case OPTION_NO_DEFINE_COMMON:
    918 	  link_info.inhibit_common_definition = TRUE;
    919 	  break;
    920 	case OPTION_NO_DEMANGLE:
    921 	  demangling = FALSE;
    922 	  break;
    923 	case OPTION_NO_GC_SECTIONS:
    924 	  link_info.gc_sections = FALSE;
    925 	  break;
    926 	case OPTION_NO_PRINT_GC_SECTIONS:
    927 	  link_info.print_gc_sections = FALSE;
    928 	  break;
    929 	case OPTION_NO_KEEP_MEMORY:
    930 	  link_info.keep_memory = FALSE;
    931 	  break;
    932 	case OPTION_NO_UNDEFINED:
    933 	  link_info.unresolved_syms_in_objects
    934 	    = how_to_report_unresolved_symbols;
    935 	  break;
    936 	case OPTION_ALLOW_SHLIB_UNDEFINED:
    937 	  link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
    938 	  break;
    939 	case OPTION_NO_ALLOW_SHLIB_UNDEFINED:
    940 	  link_info.unresolved_syms_in_shared_libs
    941 	    = how_to_report_unresolved_symbols;
    942 	  break;
    943 	case OPTION_UNRESOLVED_SYMBOLS:
    944 	  if (strcmp (optarg, "ignore-all") == 0)
    945 	    {
    946 	      link_info.unresolved_syms_in_objects = RM_IGNORE;
    947 	      link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
    948 	    }
    949 	  else if (strcmp (optarg, "report-all") == 0)
    950 	    {
    951 	      link_info.unresolved_syms_in_objects
    952 		= how_to_report_unresolved_symbols;
    953 	      link_info.unresolved_syms_in_shared_libs
    954 		= how_to_report_unresolved_symbols;
    955 	    }
    956 	  else if (strcmp (optarg, "ignore-in-object-files") == 0)
    957 	    {
    958 	      link_info.unresolved_syms_in_objects = RM_IGNORE;
    959 	      link_info.unresolved_syms_in_shared_libs
    960 		= how_to_report_unresolved_symbols;
    961 	    }
    962 	  else if (strcmp (optarg, "ignore-in-shared-libs") == 0)
    963 	    {
    964 	      link_info.unresolved_syms_in_objects
    965 		= how_to_report_unresolved_symbols;
    966 	      link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
    967 	    }
    968 	  else
    969 	    einfo (_("%F%P: bad --unresolved-symbols option: %s\n"), optarg);
    970 	  break;
    971 	case OPTION_WARN_UNRESOLVED_SYMBOLS:
    972 	  how_to_report_unresolved_symbols = RM_GENERATE_WARNING;
    973 	  if (link_info.unresolved_syms_in_objects == RM_GENERATE_ERROR)
    974 	    link_info.unresolved_syms_in_objects = RM_GENERATE_WARNING;
    975 	  if (link_info.unresolved_syms_in_shared_libs == RM_GENERATE_ERROR)
    976 	    link_info.unresolved_syms_in_shared_libs = RM_GENERATE_WARNING;
    977 	  break;
    978 
    979 	case OPTION_ERROR_UNRESOLVED_SYMBOLS:
    980 	  how_to_report_unresolved_symbols = RM_GENERATE_ERROR;
    981 	  if (link_info.unresolved_syms_in_objects == RM_GENERATE_WARNING)
    982 	    link_info.unresolved_syms_in_objects = RM_GENERATE_ERROR;
    983 	  if (link_info.unresolved_syms_in_shared_libs == RM_GENERATE_WARNING)
    984 	    link_info.unresolved_syms_in_shared_libs = RM_GENERATE_ERROR;
    985 	  break;
    986 	case OPTION_ALLOW_MULTIPLE_DEFINITION:
    987 	  link_info.allow_multiple_definition = TRUE;
    988 	  break;
    989 	case OPTION_NO_UNDEFINED_VERSION:
    990 	  link_info.allow_undefined_version = FALSE;
    991 	  break;
    992 	case OPTION_DEFAULT_SYMVER:
    993 	  link_info.create_default_symver = TRUE;
    994 	  break;
    995 	case OPTION_DEFAULT_IMPORTED_SYMVER:
    996 	  link_info.default_imported_symver = TRUE;
    997 	  break;
    998 	case OPTION_NO_WARN_MISMATCH:
    999 	  command_line.warn_mismatch = FALSE;
   1000 	  break;
   1001 	case OPTION_NO_WARN_SEARCH_MISMATCH:
   1002 	  command_line.warn_search_mismatch = FALSE;
   1003 	  break;
   1004 	case OPTION_NOINHIBIT_EXEC:
   1005 	  force_make_executable = TRUE;
   1006 	  break;
   1007 	case OPTION_NOSTDLIB:
   1008 	  config.only_cmd_line_lib_dirs = TRUE;
   1009 	  break;
   1010 	case OPTION_NO_WHOLE_ARCHIVE:
   1011 	  input_flags.whole_archive = FALSE;
   1012 	  break;
   1013 	case 'O':
   1014 	  /* FIXME "-O<non-digits> <value>" used to set the address of
   1015 	     section <non-digits>.  Was this for compatibility with
   1016 	     something, or can we create a new option to do that
   1017 	     (with a syntax similar to -defsym)?
   1018 	     getopt can't handle two args to an option without kludges.  */
   1019 
   1020 	  /* Enable optimizations of output files.  */
   1021 	  link_info.optimize = strtoul (optarg, NULL, 0) ? TRUE : FALSE;
   1022 	  break;
   1023 	case 'o':
   1024 	  lang_add_output (optarg, 0);
   1025 	  break;
   1026 	case OPTION_OFORMAT:
   1027 	  lang_add_output_format (optarg, NULL, NULL, 0);
   1028 	  break;
   1029 	case OPTION_OUT_IMPLIB:
   1030 	  command_line.out_implib_filename = xstrdup (optarg);
   1031 	  break;
   1032 	case OPTION_PRINT_SYSROOT:
   1033 	  if (*ld_sysroot)
   1034 	    puts (ld_sysroot);
   1035 	  xexit (0);
   1036 	  break;
   1037 	case OPTION_PRINT_OUTPUT_FORMAT:
   1038 	  command_line.print_output_format = TRUE;
   1039 	  break;
   1040 #ifdef ENABLE_PLUGINS
   1041 	case OPTION_PLUGIN:
   1042 	  plugin_opt_plugin (optarg);
   1043 	  break;
   1044 	case OPTION_PLUGIN_OPT:
   1045 	  if (plugin_opt_plugin_arg (optarg))
   1046 	    einfo (_("%F%P: bad -plugin-opt option\n"));
   1047 	  break;
   1048 #endif /* ENABLE_PLUGINS */
   1049 	case 'q':
   1050 	  link_info.emitrelocations = TRUE;
   1051 	  break;
   1052 	case 'i':
   1053 	case 'r':
   1054 	  if (optind == last_optind)
   1055 	    /* This can happen if the user put "-rpath,a" on the command
   1056 	       line.  (Or something similar.  The comma is important).
   1057 	       Getopt becomes confused and thinks that this is a -r option
   1058 	       but it cannot parse the text after the -r so it refuses to
   1059 	       increment the optind counter.  Detect this case and issue
   1060 	       an error message here.  We cannot just make this a warning,
   1061 	       increment optind, and continue because getopt is too confused
   1062 	       and will seg-fault the next time around.  */
   1063 	    einfo(_("%F%P: unrecognised option: %s\n"), argv[optind]);
   1064 
   1065 	  if (bfd_link_pic (&link_info))
   1066 	    einfo (_("%F%P: -r and %s may not be used together\n"),
   1067 		     bfd_link_dll (&link_info) ? "-shared" : "-pie");
   1068 
   1069 	  link_info.type = type_relocatable;
   1070 	  config.build_constructors = FALSE;
   1071 	  config.magic_demand_paged = FALSE;
   1072 	  config.text_read_only = FALSE;
   1073 	  input_flags.dynamic = FALSE;
   1074 	  break;
   1075 	case 'R':
   1076 	  /* The GNU linker traditionally uses -R to mean to include
   1077 	     only the symbols from a file.  The Solaris linker uses -R
   1078 	     to set the path used by the runtime linker to find
   1079 	     libraries.  This is the GNU linker -rpath argument.  We
   1080 	     try to support both simultaneously by checking the file
   1081 	     named.  If it is a directory, rather than a regular file,
   1082 	     we assume -rpath was meant.  */
   1083 	  {
   1084 	    struct stat s;
   1085 
   1086 	    if (stat (optarg, &s) >= 0
   1087 		&& ! S_ISDIR (s.st_mode))
   1088 	      {
   1089 		lang_add_input_file (optarg,
   1090 				     lang_input_file_is_symbols_only_enum,
   1091 				     NULL);
   1092 		break;
   1093 	      }
   1094 	  }
   1095 	  /* Fall through.  */
   1096 	case OPTION_RPATH:
   1097 	  if (command_line.rpath == NULL)
   1098 	    command_line.rpath = xstrdup (optarg);
   1099 	  else
   1100 	    {
   1101 	      size_t rpath_len = strlen (command_line.rpath);
   1102 	      size_t optarg_len = strlen (optarg);
   1103 	      char *buf;
   1104 	      char *cp = command_line.rpath;
   1105 
   1106 	      /* First see whether OPTARG is already in the path.  */
   1107 	      do
   1108 		{
   1109 		  if (strncmp (optarg, cp, optarg_len) == 0
   1110 		      && (cp[optarg_len] == 0
   1111 			  || cp[optarg_len] == config.rpath_separator))
   1112 		    /* We found it.  */
   1113 		    break;
   1114 
   1115 		  /* Not yet found.  */
   1116 		  cp = strchr (cp, config.rpath_separator);
   1117 		  if (cp != NULL)
   1118 		    ++cp;
   1119 		}
   1120 	      while (cp != NULL);
   1121 
   1122 	      if (cp == NULL)
   1123 		{
   1124 		  buf = (char *) xmalloc (rpath_len + optarg_len + 2);
   1125 		  sprintf (buf, "%s%c%s", command_line.rpath,
   1126 			   config.rpath_separator, optarg);
   1127 		  free (command_line.rpath);
   1128 		  command_line.rpath = buf;
   1129 		}
   1130 	    }
   1131 	  break;
   1132 	case OPTION_RPATH_LINK:
   1133 	  if (command_line.rpath_link == NULL)
   1134 	    command_line.rpath_link = xstrdup (optarg);
   1135 	  else
   1136 	    {
   1137 	      char *buf;
   1138 
   1139 	      buf = (char *) xmalloc (strlen (command_line.rpath_link)
   1140 				      + strlen (optarg)
   1141 				      + 2);
   1142 	      sprintf (buf, "%s%c%s", command_line.rpath_link,
   1143 		       config.rpath_separator, optarg);
   1144 	      free (command_line.rpath_link);
   1145 	      command_line.rpath_link = buf;
   1146 	    }
   1147 	  break;
   1148 	case OPTION_NO_RELAX:
   1149 	  DISABLE_RELAXATION;
   1150 	  break;
   1151 	case OPTION_RELAX:
   1152 	  ENABLE_RELAXATION;
   1153 	  break;
   1154 	case OPTION_RETAIN_SYMBOLS_FILE:
   1155 	  add_keepsyms_file (optarg);
   1156 	  break;
   1157 	case 'S':
   1158 	  link_info.strip = strip_debugger;
   1159 	  break;
   1160 	case 's':
   1161 	  link_info.strip = strip_all;
   1162 	  break;
   1163 	case OPTION_STRIP_DISCARDED:
   1164 	  link_info.strip_discarded = TRUE;
   1165 	  break;
   1166 	case OPTION_NO_STRIP_DISCARDED:
   1167 	  link_info.strip_discarded = FALSE;
   1168 	  break;
   1169 	case OPTION_DISABLE_MULTIPLE_DEFS_ABS:
   1170 	  link_info.prohibit_multiple_definition_absolute = TRUE;
   1171 	  break;
   1172 	case OPTION_SHARED:
   1173 	  if (config.has_shared)
   1174 	    {
   1175 	      if (bfd_link_relocatable (&link_info))
   1176 		einfo (_("%F%P: -r and %s may not be used together\n"),
   1177 		       "-shared");
   1178 
   1179 	      link_info.type = type_dll;
   1180 	      /* When creating a shared library, the default
   1181 		 behaviour is to ignore any unresolved references.  */
   1182 	      if (link_info.unresolved_syms_in_objects == RM_NOT_YET_SET)
   1183 		link_info.unresolved_syms_in_objects = RM_IGNORE;
   1184 	      if (link_info.unresolved_syms_in_shared_libs == RM_NOT_YET_SET)
   1185 		link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
   1186 	    }
   1187 	  else
   1188 	    einfo (_("%F%P: -shared not supported\n"));
   1189 	  break;
   1190 	case OPTION_PIE:
   1191 	  if (config.has_shared)
   1192 	    {
   1193 	      if (bfd_link_relocatable (&link_info))
   1194 		einfo (_("%F%P: -r and %s may not be used together\n"), "-pie");
   1195 
   1196 	      link_info.type = type_pie;
   1197 	    }
   1198 	  else
   1199 	    einfo (_("%F%P: -pie not supported\n"));
   1200 	  break;
   1201 	case 'h':		/* Used on Solaris.  */
   1202 	case OPTION_SONAME:
   1203 	  if (optarg[0] == '\0' && command_line.soname
   1204 	      && command_line.soname[0])
   1205 	    einfo (_("%P: SONAME must not be empty string; keeping previous one\n"));
   1206 	  else
   1207 	    command_line.soname = optarg;
   1208 	  break;
   1209 	case OPTION_SORT_COMMON:
   1210 	  if (optarg == NULL
   1211 	      || strcmp (optarg, N_("descending")) == 0)
   1212 	    config.sort_common = sort_descending;
   1213 	  else if (strcmp (optarg, N_("ascending")) == 0)
   1214 	    config.sort_common = sort_ascending;
   1215 	  else
   1216 	    einfo (_("%F%P: invalid common section sorting option: %s\n"),
   1217 		   optarg);
   1218 	  break;
   1219 	case OPTION_SORT_SECTION:
   1220 	  if (strcmp (optarg, N_("name")) == 0)
   1221 	    sort_section = by_name;
   1222 	  else if (strcmp (optarg, N_("alignment")) == 0)
   1223 	    sort_section = by_alignment;
   1224 	  else
   1225 	    einfo (_("%F%P: invalid section sorting option: %s\n"),
   1226 		   optarg);
   1227 	  break;
   1228 	case OPTION_STATS:
   1229 	  config.stats = TRUE;
   1230 	  break;
   1231 	case OPTION_SYMBOLIC:
   1232 	  command_line.symbolic = symbolic;
   1233 	  break;
   1234 	case OPTION_SYMBOLIC_FUNCTIONS:
   1235 	  command_line.symbolic = symbolic_functions;
   1236 	  break;
   1237 	case 't':
   1238 	  trace_files = TRUE;
   1239 	  break;
   1240 	case 'T':
   1241 	  previous_script_handle = saved_script_handle;
   1242 	  ldfile_open_command_file (optarg);
   1243 	  parser_input = input_script;
   1244 	  yyparse ();
   1245 	  previous_script_handle = NULL;
   1246 	  break;
   1247 	case OPTION_DEFAULT_SCRIPT:
   1248 	  command_line.default_script = optarg;
   1249 	  break;
   1250 	case OPTION_SECTION_START:
   1251 	  {
   1252 	    char *optarg2;
   1253 	    char *sec_name;
   1254 	    int len;
   1255 
   1256 	    /* Check for <something>=<somthing>...  */
   1257 	    optarg2 = strchr (optarg, '=');
   1258 	    if (optarg2 == NULL)
   1259 	      einfo (_("%F%P: invalid argument to option"
   1260 		       " \"--section-start\"\n"));
   1261 
   1262 	    optarg2++;
   1263 
   1264 	    /* So far so good.  Are all the args present?  */
   1265 	    if ((*optarg == '\0') || (*optarg2 == '\0'))
   1266 	      einfo (_("%F%P: missing argument(s) to option"
   1267 		       " \"--section-start\"\n"));
   1268 
   1269 	    /* We must copy the section name as set_section_start
   1270 	       doesn't do it for us.  */
   1271 	    len = optarg2 - optarg;
   1272 	    sec_name = (char *) xmalloc (len);
   1273 	    memcpy (sec_name, optarg, len - 1);
   1274 	    sec_name[len - 1] = 0;
   1275 
   1276 	    /* Then set it...  */
   1277 	    set_section_start (sec_name, optarg2);
   1278 	  }
   1279 	  break;
   1280 	case OPTION_TARGET_HELP:
   1281 	  /* Mention any target specific options.  */
   1282 	  ldemul_list_emulation_options (stdout);
   1283 	  exit (0);
   1284 	case OPTION_TBSS:
   1285 	  set_segment_start (".bss", optarg);
   1286 	  break;
   1287 	case OPTION_TDATA:
   1288 	  set_segment_start (".data", optarg);
   1289 	  break;
   1290 	case OPTION_TTEXT:
   1291 	  set_segment_start (".text", optarg);
   1292 	  break;
   1293 	case OPTION_TTEXT_SEGMENT:
   1294 	  set_segment_start (".text-segment", optarg);
   1295 	  break;
   1296 	case OPTION_TRODATA_SEGMENT:
   1297 	  set_segment_start (".rodata-segment", optarg);
   1298 	  break;
   1299 	case OPTION_TLDATA_SEGMENT:
   1300 	  set_segment_start (".ldata-segment", optarg);
   1301 	  break;
   1302 	case OPTION_TRADITIONAL_FORMAT:
   1303 	  link_info.traditional_format = TRUE;
   1304 	  break;
   1305 	case OPTION_TASK_LINK:
   1306 	  link_info.task_link = TRUE;
   1307 	  /* Fall through.  */
   1308 	case OPTION_UR:
   1309 	  if (bfd_link_pic (&link_info))
   1310 	    einfo (_("%F%P: -r and %s may not be used together\n"),
   1311 		     bfd_link_dll (&link_info) ? "-shared" : "-pie");
   1312 
   1313 	  link_info.type = type_relocatable;
   1314 	  config.build_constructors = TRUE;
   1315 	  config.magic_demand_paged = FALSE;
   1316 	  config.text_read_only = FALSE;
   1317 	  input_flags.dynamic = FALSE;
   1318 	  break;
   1319 	case 'u':
   1320 	  ldlang_add_undef (optarg, TRUE);
   1321 	  break;
   1322 	case OPTION_REQUIRE_DEFINED_SYMBOL:
   1323 	  ldlang_add_require_defined (optarg);
   1324 	  break;
   1325 	case OPTION_UNIQUE:
   1326 	  if (optarg != NULL)
   1327 	    lang_add_unique (optarg);
   1328 	  else
   1329 	    config.unique_orphan_sections = TRUE;
   1330 	  break;
   1331 	case OPTION_VERBOSE:
   1332 	  ldversion (1);
   1333 	  version_printed = TRUE;
   1334 	  verbose = TRUE;
   1335 	  overflow_cutoff_limit = -2;
   1336 	  if (optarg != NULL)
   1337 	    {
   1338 	      char *end;
   1339 	      int level ATTRIBUTE_UNUSED = strtoul (optarg, &end, 0);
   1340 	      if (*end)
   1341 		einfo (_("%F%P: invalid number `%s'\n"), optarg);
   1342 #ifdef ENABLE_PLUGINS
   1343 	      report_plugin_symbols = level > 1;
   1344 #endif /* ENABLE_PLUGINS */
   1345 	    }
   1346 	  break;
   1347 	case 'v':
   1348 	  ldversion (0);
   1349 	  version_printed = TRUE;
   1350 	  break;
   1351 	case 'V':
   1352 	  ldversion (1);
   1353 	  version_printed = TRUE;
   1354 	  break;
   1355 	case OPTION_VERSION:
   1356 	  ldversion (2);
   1357 	  xexit (0);
   1358 	  break;
   1359 	case OPTION_VERSION_SCRIPT:
   1360 	  /* This option indicates a small script that only specifies
   1361 	     version information.  Read it, but don't assume that
   1362 	     we've seen a linker script.  */
   1363 	  {
   1364 	    FILE *hold_script_handle;
   1365 
   1366 	    hold_script_handle = saved_script_handle;
   1367 	    ldfile_open_command_file (optarg);
   1368 	    saved_script_handle = hold_script_handle;
   1369 	    parser_input = input_version_script;
   1370 	    yyparse ();
   1371 	  }
   1372 	  break;
   1373 	case OPTION_VERSION_EXPORTS_SECTION:
   1374 	  /* This option records a version symbol to be applied to the
   1375 	     symbols listed for export to be found in the object files
   1376 	     .exports sections.  */
   1377 	  command_line.version_exports_section = optarg;
   1378 	  break;
   1379 	case OPTION_DYNAMIC_LIST_DATA:
   1380 	  command_line.dynamic_list = dynamic_list_data;
   1381 	  if (command_line.symbolic == symbolic)
   1382 	    command_line.symbolic = symbolic_unset;
   1383 	  break;
   1384 	case OPTION_DYNAMIC_LIST_CPP_TYPEINFO:
   1385 	  lang_append_dynamic_list_cpp_typeinfo ();
   1386 	  if (command_line.dynamic_list != dynamic_list_data)
   1387 	    command_line.dynamic_list = dynamic_list;
   1388 	  if (command_line.symbolic == symbolic)
   1389 	    command_line.symbolic = symbolic_unset;
   1390 	  break;
   1391 	case OPTION_DYNAMIC_LIST_CPP_NEW:
   1392 	  lang_append_dynamic_list_cpp_new ();
   1393 	  if (command_line.dynamic_list != dynamic_list_data)
   1394 	    command_line.dynamic_list = dynamic_list;
   1395 	  if (command_line.symbolic == symbolic)
   1396 	    command_line.symbolic = symbolic_unset;
   1397 	  break;
   1398 	case OPTION_DYNAMIC_LIST:
   1399 	  /* This option indicates a small script that only specifies
   1400 	     a dynamic list.  Read it, but don't assume that we've
   1401 	     seen a linker script.  */
   1402 	  {
   1403 	    FILE *hold_script_handle;
   1404 
   1405 	    hold_script_handle = saved_script_handle;
   1406 	    ldfile_open_command_file (optarg);
   1407 	    saved_script_handle = hold_script_handle;
   1408 	    parser_input = input_dynamic_list;
   1409 	    yyparse ();
   1410 	  }
   1411 	  if (command_line.dynamic_list != dynamic_list_data)
   1412 	    command_line.dynamic_list = dynamic_list;
   1413 	  if (command_line.symbolic == symbolic)
   1414 	    command_line.symbolic = symbolic_unset;
   1415 	  break;
   1416 	case OPTION_WARN_COMMON:
   1417 	  config.warn_common = TRUE;
   1418 	  break;
   1419 	case OPTION_WARN_CONSTRUCTORS:
   1420 	  config.warn_constructors = TRUE;
   1421 	  break;
   1422 	case OPTION_WARN_FATAL:
   1423 	  config.fatal_warnings = TRUE;
   1424 	  break;
   1425 	case OPTION_NO_WARN_FATAL:
   1426 	  config.fatal_warnings = FALSE;
   1427 	  break;
   1428 	case OPTION_WARN_MULTIPLE_GP:
   1429 	  config.warn_multiple_gp = TRUE;
   1430 	  break;
   1431 	case OPTION_WARN_ONCE:
   1432 	  config.warn_once = TRUE;
   1433 	  break;
   1434 	case OPTION_WARN_SECTION_ALIGN:
   1435 	  config.warn_section_align = TRUE;
   1436 	  break;
   1437 	case OPTION_WARN_SHARED_TEXTREL:
   1438 	  link_info.warn_shared_textrel = TRUE;
   1439 	  break;
   1440 	case OPTION_WARN_ALTERNATE_EM:
   1441 	  link_info.warn_alternate_em = TRUE;
   1442 	  break;
   1443 	case OPTION_WHOLE_ARCHIVE:
   1444 	  input_flags.whole_archive = TRUE;
   1445 	  break;
   1446 	case OPTION_ADD_DT_NEEDED_FOR_DYNAMIC:
   1447 	  input_flags.add_DT_NEEDED_for_dynamic = TRUE;
   1448 	  break;
   1449 	case OPTION_NO_ADD_DT_NEEDED_FOR_DYNAMIC:
   1450 	  input_flags.add_DT_NEEDED_for_dynamic = FALSE;
   1451 	  break;
   1452 	case OPTION_ADD_DT_NEEDED_FOR_REGULAR:
   1453 	  input_flags.add_DT_NEEDED_for_regular = TRUE;
   1454 	  break;
   1455 	case OPTION_NO_ADD_DT_NEEDED_FOR_REGULAR:
   1456 	  input_flags.add_DT_NEEDED_for_regular = FALSE;
   1457 	  break;
   1458 	case OPTION_WRAP:
   1459 	  add_wrap (optarg);
   1460 	  break;
   1461 	case OPTION_IGNORE_UNRESOLVED_SYMBOL:
   1462 	  add_ignoresym (&link_info, optarg);
   1463 	  break;
   1464 	case OPTION_DISCARD_NONE:
   1465 	  link_info.discard = discard_none;
   1466 	  break;
   1467 	case 'X':
   1468 	  link_info.discard = discard_l;
   1469 	  break;
   1470 	case 'x':
   1471 	  link_info.discard = discard_all;
   1472 	  break;
   1473 	case 'Y':
   1474 	  if (CONST_STRNEQ (optarg, "P,"))
   1475 	    optarg += 2;
   1476 	  if (default_dirlist != NULL)
   1477 	    free (default_dirlist);
   1478 	  default_dirlist = xstrdup (optarg);
   1479 	  break;
   1480 	case 'y':
   1481 	  add_ysym (optarg);
   1482 	  break;
   1483 	case OPTION_SPARE_DYNAMIC_TAGS:
   1484 	  link_info.spare_dynamic_tags = strtoul (optarg, NULL, 0);
   1485 	  break;
   1486 	case OPTION_SPLIT_BY_RELOC:
   1487 	  if (optarg != NULL)
   1488 	    config.split_by_reloc = strtoul (optarg, NULL, 0);
   1489 	  else
   1490 	    config.split_by_reloc = 32768;
   1491 	  break;
   1492 	case OPTION_SPLIT_BY_FILE:
   1493 	  if (optarg != NULL)
   1494 	    config.split_by_file = bfd_scan_vma (optarg, NULL, 0);
   1495 	  else
   1496 	    config.split_by_file = 1;
   1497 	  break;
   1498 	case OPTION_CHECK_SECTIONS:
   1499 	  command_line.check_section_addresses = 1;
   1500 	  break;
   1501 	case OPTION_NO_CHECK_SECTIONS:
   1502 	  command_line.check_section_addresses = 0;
   1503 	  break;
   1504 	case OPTION_ACCEPT_UNKNOWN_INPUT_ARCH:
   1505 	  command_line.accept_unknown_input_arch = TRUE;
   1506 	  break;
   1507 	case OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH:
   1508 	  command_line.accept_unknown_input_arch = FALSE;
   1509 	  break;
   1510 	case '(':
   1511 	  lang_enter_group ();
   1512 	  ingroup++;
   1513 	  break;
   1514 	case ')':
   1515 	  if (! ingroup)
   1516 	    einfo (_("%F%P: group ended before it began (--help for usage)\n"));
   1517 
   1518 	  lang_leave_group ();
   1519 	  ingroup--;
   1520 	  break;
   1521 
   1522 	case OPTION_INIT:
   1523 	  link_info.init_function = optarg;
   1524 	  break;
   1525 
   1526 	case OPTION_FINI:
   1527 	  link_info.fini_function = optarg;
   1528 	  break;
   1529 
   1530 	case OPTION_REDUCE_MEMORY_OVERHEADS:
   1531 	  link_info.reduce_memory_overheads = TRUE;
   1532 	  if (config.hash_table_size == 0)
   1533 	    config.hash_table_size = 1021;
   1534 	  break;
   1535 
   1536 	case OPTION_HASH_SIZE:
   1537 	  {
   1538 	    bfd_size_type new_size;
   1539 
   1540 	    new_size = strtoul (optarg, NULL, 0);
   1541 	    if (new_size)
   1542 	      config.hash_table_size = new_size;
   1543 	    else
   1544 	      einfo (_("%X%P: --hash-size needs a numeric argument\n"));
   1545 	  }
   1546 	  break;
   1547 
   1548 	case OPTION_PUSH_STATE:
   1549 	  input_flags.pushed = xmemdup (&input_flags,
   1550 					sizeof (input_flags),
   1551 					sizeof (input_flags));
   1552 	  break;
   1553 
   1554 	case OPTION_POP_STATE:
   1555 	  if (input_flags.pushed == NULL)
   1556 	    einfo (_("%F%P: no state pushed before popping\n"));
   1557 	  else
   1558 	    {
   1559 	      struct lang_input_statement_flags *oldp = input_flags.pushed;
   1560 	      memcpy (&input_flags, oldp, sizeof (input_flags));
   1561 	      free (oldp);
   1562 	    }
   1563 	  break;
   1564 
   1565 	case OPTION_PRINT_MEMORY_USAGE:
   1566 	  command_line.print_memory_usage = TRUE;
   1567 	  break;
   1568 
   1569 	case OPTION_ORPHAN_HANDLING:
   1570 	  if (strcasecmp (optarg, "place") == 0)
   1571 	    config.orphan_handling = orphan_handling_place;
   1572 	  else if (strcasecmp (optarg, "warn") == 0)
   1573 	    config.orphan_handling = orphan_handling_warn;
   1574 	  else if (strcasecmp (optarg, "error") == 0)
   1575 	    config.orphan_handling = orphan_handling_error;
   1576 	  else if (strcasecmp (optarg, "discard") == 0)
   1577 	    config.orphan_handling = orphan_handling_discard;
   1578 	  else
   1579 	    einfo (_("%F%P: invalid argument to option"
   1580 		     " \"--orphan-handling\"\n"));
   1581 	  break;
   1582 	}
   1583     }
   1584 
   1585   if (command_line.soname && command_line.soname[0] == '\0')
   1586     {
   1587       einfo (_("%P: SONAME must not be empty string; ignored\n"));
   1588       command_line.soname = NULL;
   1589     }
   1590 
   1591   while (ingroup)
   1592     {
   1593       lang_leave_group ();
   1594       ingroup--;
   1595     }
   1596 
   1597   if (default_dirlist != NULL)
   1598     {
   1599       set_default_dirlist (default_dirlist);
   1600       free (default_dirlist);
   1601     }
   1602 
   1603   if (link_info.unresolved_syms_in_objects == RM_NOT_YET_SET)
   1604     /* FIXME: Should we allow emulations a chance to set this ?  */
   1605     link_info.unresolved_syms_in_objects = how_to_report_unresolved_symbols;
   1606 
   1607   if (link_info.unresolved_syms_in_shared_libs == RM_NOT_YET_SET)
   1608     /* FIXME: Should we allow emulations a chance to set this ?  */
   1609     link_info.unresolved_syms_in_shared_libs = how_to_report_unresolved_symbols;
   1610 
   1611   if (bfd_link_relocatable (&link_info)
   1612       && command_line.check_section_addresses < 0)
   1613     command_line.check_section_addresses = 0;
   1614 
   1615   /* We may have -Bsymbolic, -Bsymbolic-functions, --dynamic-list-data,
   1616      --dynamic-list-cpp-new, --dynamic-list-cpp-typeinfo and
   1617      --dynamic-list FILE.  -Bsymbolic and -Bsymbolic-functions are
   1618      for PIC outputs.  -Bsymbolic overrides all others and vice versa.  */
   1619   switch (command_line.symbolic)
   1620     {
   1621     case symbolic_unset:
   1622       break;
   1623     case symbolic:
   1624       /* -Bsymbolic is for PIC output only.  */
   1625       if (bfd_link_pic (&link_info))
   1626 	{
   1627 	  link_info.symbolic = TRUE;
   1628 	  /* Should we free the unused memory?  */
   1629 	  link_info.dynamic_list = NULL;
   1630 	  command_line.dynamic_list = dynamic_list_unset;
   1631 	}
   1632       break;
   1633     case symbolic_functions:
   1634       /* -Bsymbolic-functions is for PIC output only.  */
   1635       if (bfd_link_pic (&link_info))
   1636 	command_line.dynamic_list = dynamic_list_data;
   1637       break;
   1638     }
   1639 
   1640   switch (command_line.dynamic_list)
   1641     {
   1642     case dynamic_list_unset:
   1643       break;
   1644     case dynamic_list_data:
   1645       link_info.dynamic_data = TRUE;
   1646       /* Fall through.  */
   1647     case dynamic_list:
   1648       link_info.dynamic = TRUE;
   1649       break;
   1650     }
   1651 
   1652   if (!bfd_link_dll (&link_info))
   1653     {
   1654       if (command_line.filter_shlib)
   1655 	einfo (_("%F%P: -F may not be used without -shared\n"));
   1656       if (command_line.auxiliary_filters)
   1657 	einfo (_("%F%P: -f may not be used without -shared\n"));
   1658     }
   1659 
   1660   /* Treat ld -r -s as ld -r -S -x (i.e., strip all local symbols).  I
   1661      don't see how else this can be handled, since in this case we
   1662      must preserve all externally visible symbols.  */
   1663   if (bfd_link_relocatable (&link_info) && link_info.strip == strip_all)
   1664     {
   1665       link_info.strip = strip_debugger;
   1666       if (link_info.discard == discard_sec_merge)
   1667 	link_info.discard = discard_all;
   1668     }
   1669 }
   1670 
   1671 /* Add the (colon-separated) elements of DIRLIST_PTR to the
   1672    library search path.  */
   1673 
   1674 static void
   1675 set_default_dirlist (char *dirlist_ptr)
   1676 {
   1677   char *p;
   1678 
   1679   while (1)
   1680     {
   1681       p = strchr (dirlist_ptr, PATH_SEPARATOR);
   1682       if (p != NULL)
   1683 	*p = '\0';
   1684       if (*dirlist_ptr != '\0')
   1685 	ldfile_add_library_path (dirlist_ptr, TRUE);
   1686       if (p == NULL)
   1687 	break;
   1688       dirlist_ptr = p + 1;
   1689     }
   1690 }
   1691 
   1692 static void
   1693 set_section_start (char *sect, char *valstr)
   1694 {
   1695   const char *end;
   1696   bfd_vma val = bfd_scan_vma (valstr, &end, 16);
   1697   if (*end)
   1698     einfo (_("%F%P: invalid hex number `%s'\n"), valstr);
   1699   lang_section_start (sect, exp_intop (val), NULL);
   1700 }
   1701 
   1702 static void
   1703 set_segment_start (const char *section, char *valstr)
   1704 {
   1705   const char *name;
   1706   const char *end;
   1707   segment_type *seg;
   1708 
   1709   bfd_vma val = bfd_scan_vma (valstr, &end, 16);
   1710   if (*end)
   1711     einfo (_("%F%P: invalid hex number `%s'\n"), valstr);
   1712   /* If we already have an entry for this segment, update the existing
   1713      value.  */
   1714   name = section + 1;
   1715   for (seg = segments; seg; seg = seg->next)
   1716     if (strcmp (seg->name, name) == 0)
   1717       {
   1718 	seg->value = val;
   1719 	lang_section_start (section, exp_intop (val), seg);
   1720 	return;
   1721       }
   1722   /* There was no existing value so we must create a new segment
   1723      entry.  */
   1724   seg = (segment_type *) stat_alloc (sizeof (*seg));
   1725   seg->name = name;
   1726   seg->value = val;
   1727   seg->used = FALSE;
   1728   /* Add it to the linked list of segments.  */
   1729   seg->next = segments;
   1730   segments = seg;
   1731   /* Historically, -Ttext and friends set the base address of a
   1732      particular section.  For backwards compatibility, we still do
   1733      that.  If a SEGMENT_START directive is seen, the section address
   1734      assignment will be disabled.  */
   1735   lang_section_start (section, exp_intop (val), seg);
   1736 }
   1737 
   1738 static void
   1739 elf_shlib_list_options (FILE *file)
   1740 {
   1741   fprintf (file, _("\
   1742   --audit=AUDITLIB            Specify a library to use for auditing\n"));
   1743   fprintf (file, _("\
   1744   -Bgroup                     Selects group name lookup rules for DSO\n"));
   1745   fprintf (file, _("\
   1746   --disable-new-dtags         Disable new dynamic tags\n"));
   1747   fprintf (file, _("\
   1748   --enable-new-dtags          Enable new dynamic tags\n"));
   1749   fprintf (file, _("\
   1750   --eh-frame-hdr              Create .eh_frame_hdr section\n"));
   1751   fprintf (file, _("\
   1752   --no-eh-frame-hdr           Do not create .eh_frame_hdr section\n"));
   1753   fprintf (file, _("\
   1754   --exclude-libs=LIBS         Make all symbols in LIBS hidden\n"));
   1755   fprintf (file, _("\
   1756   --hash-style=STYLE          Set hash style to sysv, gnu or both\n"));
   1757   fprintf (file, _("\
   1758   -P AUDITLIB, --depaudit=AUDITLIB\n" "\
   1759                               Specify a library to use for auditing dependencies\n"));
   1760   fprintf (file, _("\
   1761   -z combreloc                Merge dynamic relocs into one section and sort\n"));
   1762   fprintf (file, _("\
   1763   -z nocombreloc              Don't merge dynamic relocs into one section\n"));
   1764   fprintf (file, _("\
   1765   -z global                   Make symbols in DSO available for subsequently\n\
   1766                                loaded objects\n"));
   1767   fprintf (file, _("\
   1768   -z initfirst                Mark DSO to be initialized first at runtime\n"));
   1769   fprintf (file, _("\
   1770   -z interpose                Mark object to interpose all DSOs but executable\n"));
   1771   fprintf (file, _("\
   1772   -z lazy                     Mark object lazy runtime binding (default)\n"));
   1773   fprintf (file, _("\
   1774   -z loadfltr                 Mark object requiring immediate process\n"));
   1775   fprintf (file, _("\
   1776   -z nocopyreloc              Don't create copy relocs\n"));
   1777   fprintf (file, _("\
   1778   -z nodefaultlib             Mark object not to use default search paths\n"));
   1779   fprintf (file, _("\
   1780   -z nodelete                 Mark DSO non-deletable at runtime\n"));
   1781   fprintf (file, _("\
   1782   -z nodlopen                 Mark DSO not available to dlopen\n"));
   1783   fprintf (file, _("\
   1784   -z nodump                   Mark DSO not available to dldump\n"));
   1785   fprintf (file, _("\
   1786   -z now                      Mark object non-lazy runtime binding\n"));
   1787   fprintf (file, _("\
   1788   -z origin                   Mark object requiring immediate $ORIGIN\n\
   1789                                 processing at runtime\n"));
   1790 #if DEFAULT_LD_Z_RELRO
   1791   fprintf (file, _("\
   1792   -z relro                    Create RELRO program header (default)\n"));
   1793   fprintf (file, _("\
   1794   -z norelro                  Don't create RELRO program header\n"));
   1795 #else
   1796   fprintf (file, _("\
   1797   -z relro                    Create RELRO program header\n"));
   1798   fprintf (file, _("\
   1799   -z norelro                  Don't create RELRO program header (default)\n"));
   1800 #endif
   1801 #if DEFAULT_LD_Z_SEPARATE_CODE
   1802   fprintf (file, _("\
   1803   -z separate-code            Create separate code program header (default)\n"));
   1804   fprintf (file, _("\
   1805   -z noseparate-code          Don't create separate code program header\n"));
   1806 #else
   1807   fprintf (file, _("\
   1808   -z separate-code            Create separate code program header\n"));
   1809   fprintf (file, _("\
   1810   -z noseparate-code          Don't create separate code program header (default)\n"));
   1811 #endif
   1812   fprintf (file, _("\
   1813   -z common                   Generate common symbols with STT_COMMON type\n"));
   1814   fprintf (file, _("\
   1815   -z nocommon                 Generate common symbols with STT_OBJECT type\n"));
   1816   fprintf (file, _("\
   1817   -z stack-size=SIZE          Set size of stack segment\n"));
   1818   fprintf (file, _("\
   1819   -z text                     Treat DT_TEXTREL in shared object as error\n"));
   1820   fprintf (file, _("\
   1821   -z notext                   Don't treat DT_TEXTREL in shared object as error\n"));
   1822   fprintf (file, _("\
   1823   -z textoff                  Don't treat DT_TEXTREL in shared object as error\n"));
   1824 }
   1825 
   1826 static void
   1827 elf_static_list_options (FILE *file)
   1828 {
   1829   fprintf (file, _("\
   1830   --build-id[=STYLE]          Generate build ID note\n"));
   1831   fprintf (file, _("\
   1832   --compress-debug-sections=[none|zlib|zlib-gnu|zlib-gabi]\n\
   1833                               Compress DWARF debug sections using zlib\n"));
   1834 #ifdef DEFAULT_FLAG_COMPRESS_DEBUG
   1835   fprintf (file, _("\
   1836                                Default: zlib-gabi\n"));
   1837 #else
   1838   fprintf (file, _("\
   1839                                Default: none\n"));
   1840 #endif
   1841   fprintf (file, _("\
   1842   -z common-page-size=SIZE    Set common page size to SIZE\n"));
   1843   fprintf (file, _("\
   1844   -z max-page-size=SIZE       Set maximum page size to SIZE\n"));
   1845   fprintf (file, _("\
   1846   -z defs                     Report unresolved symbols in object files\n"));
   1847   fprintf (file, _("\
   1848   -z muldefs                  Allow multiple definitions\n"));
   1849   fprintf (file, _("\
   1850   -z execstack                Mark executable as requiring executable stack\n"));
   1851   fprintf (file, _("\
   1852   -z noexecstack              Mark executable as not requiring executable stack\n"));
   1853   fprintf (file, _("\
   1854   -z globalaudit              Mark executable requiring global auditing\n"));
   1855 }
   1856 
   1857 static void
   1858 elf_plt_unwind_list_options (FILE *file)
   1859 {
   1860   fprintf (file, _("\
   1861   --ld-generated-unwind-info  Generate exception handling info for PLT\n"));
   1862   fprintf (file, _("\
   1863   --no-ld-generated-unwind-info\n\
   1864                               Don't generate exception handling info for PLT\n"));
   1865 }
   1866 
   1867 static void
   1868 ld_list_options (FILE *file, bfd_boolean elf, bfd_boolean shlib,
   1869 		 bfd_boolean plt_unwind)
   1870 {
   1871   if (!elf)
   1872     return;
   1873   printf (_("ELF emulations:\n"));
   1874   if (plt_unwind)
   1875     elf_plt_unwind_list_options (file);
   1876   elf_static_list_options (file);
   1877   if (shlib)
   1878     elf_shlib_list_options (file);
   1879 }
   1880 
   1881 
   1882 /* Print help messages for the options.  */
   1884 
   1885 static void
   1886 help (void)
   1887 {
   1888   unsigned i;
   1889   const char **targets, **pp;
   1890   int len;
   1891 
   1892   printf (_("Usage: %s [options] file...\n"), program_name);
   1893 
   1894   printf (_("Options:\n"));
   1895   for (i = 0; i < OPTION_COUNT; i++)
   1896     {
   1897       if (ld_options[i].doc != NULL)
   1898 	{
   1899 	  bfd_boolean comma;
   1900 	  unsigned j;
   1901 
   1902 	  printf ("  ");
   1903 
   1904 	  comma = FALSE;
   1905 	  len = 2;
   1906 
   1907 	  j = i;
   1908 	  do
   1909 	    {
   1910 	      if (ld_options[j].shortopt != '\0'
   1911 		  && ld_options[j].control != NO_HELP)
   1912 		{
   1913 		  printf ("%s-%c", comma ? ", " : "", ld_options[j].shortopt);
   1914 		  len += (comma ? 2 : 0) + 2;
   1915 		  if (ld_options[j].arg != NULL)
   1916 		    {
   1917 		      if (ld_options[j].opt.has_arg != optional_argument)
   1918 			{
   1919 			  printf (" ");
   1920 			  ++len;
   1921 			}
   1922 		      printf ("%s", _(ld_options[j].arg));
   1923 		      len += strlen (_(ld_options[j].arg));
   1924 		    }
   1925 		  comma = TRUE;
   1926 		}
   1927 	      ++j;
   1928 	    }
   1929 	  while (j < OPTION_COUNT && ld_options[j].doc == NULL);
   1930 
   1931 	  j = i;
   1932 	  do
   1933 	    {
   1934 	      if (ld_options[j].opt.name != NULL
   1935 		  && ld_options[j].control != NO_HELP)
   1936 		{
   1937 		  int two_dashes =
   1938 		    (ld_options[j].control == TWO_DASHES
   1939 		     || ld_options[j].control == EXACTLY_TWO_DASHES);
   1940 
   1941 		  printf ("%s-%s%s",
   1942 			  comma ? ", " : "",
   1943 			  two_dashes ? "-" : "",
   1944 			  ld_options[j].opt.name);
   1945 		  len += ((comma ? 2 : 0)
   1946 			  + 1
   1947 			  + (two_dashes ? 1 : 0)
   1948 			  + strlen (ld_options[j].opt.name));
   1949 		  if (ld_options[j].arg != NULL)
   1950 		    {
   1951 		      printf (" %s", _(ld_options[j].arg));
   1952 		      len += 1 + strlen (_(ld_options[j].arg));
   1953 		    }
   1954 		  comma = TRUE;
   1955 		}
   1956 	      ++j;
   1957 	    }
   1958 	  while (j < OPTION_COUNT && ld_options[j].doc == NULL);
   1959 
   1960 	  if (len >= 30)
   1961 	    {
   1962 	      printf ("\n");
   1963 	      len = 0;
   1964 	    }
   1965 
   1966 	  for (; len < 30; len++)
   1967 	    putchar (' ');
   1968 
   1969 	  printf ("%s\n", _(ld_options[i].doc));
   1970 	}
   1971     }
   1972   printf (_("  @FILE"));
   1973   for (len = strlen ("  @FILE"); len < 30; len++)
   1974     putchar (' ');
   1975   printf (_("Read options from FILE\n"));
   1976 
   1977   /* Note: Various tools (such as libtool) depend upon the
   1978      format of the listings below - do not change them.  */
   1979   /* xgettext:c-format */
   1980   printf (_("%s: supported targets:"), program_name);
   1981   targets = bfd_target_list ();
   1982   for (pp = targets; *pp != NULL; pp++)
   1983     printf (" %s", *pp);
   1984   free (targets);
   1985   printf ("\n");
   1986 
   1987   /* xgettext:c-format */
   1988   printf (_("%s: supported emulations: "), program_name);
   1989   ldemul_list_emulations (stdout);
   1990   printf ("\n");
   1991 
   1992   /* xgettext:c-format */
   1993   printf (_("%s: emulation specific options:\n"), program_name);
   1994   ld_list_options (stdout, ELF_LIST_OPTIONS, ELF_SHLIB_LIST_OPTIONS,
   1995 		   ELF_PLT_UNWIND_LIST_OPTIONS);
   1996   ldemul_list_emulation_options (stdout);
   1997   printf ("\n");
   1998 
   1999   if (REPORT_BUGS_TO[0])
   2000     printf (_("Report bugs to %s\n"), REPORT_BUGS_TO);
   2001 }
   2002