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