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