1 /* Parse options for the GNU linker. 2 Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 3 2001, 2002, 2003, 2004 4 Free Software Foundation, Inc. 5 6 This file is part of GLD, the Gnu Linker. 7 8 GLD is free software; you can redistribute it and/or modify 9 it under the terms of the GNU General Public License as published by 10 the Free Software Foundation; either version 2, or (at your option) 11 any later version. 12 13 GLD is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 GNU General Public License for more details. 17 18 You should have received a copy of the GNU General Public License 19 along with GLD; see the file COPYING. If not, write to the Free 20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 21 02111-1307, USA. */ 22 23 #include "bfd.h" 24 #include "sysdep.h" 25 #include "libiberty.h" 26 #include <stdio.h> 27 #include <string.h> 28 #include "safe-ctype.h" 29 #include "getopt.h" 30 #include "bfdlink.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 43 #ifndef PATH_SEPARATOR 44 #if defined (__MSDOS__) || (defined (_WIN32) && ! defined (__CYGWIN32__)) 45 #define PATH_SEPARATOR ';' 46 #else 47 #define PATH_SEPARATOR ':' 48 #endif 49 #endif 50 51 /* Somewhere above, sys/stat.h got included . . . . */ 52 #if !defined(S_ISDIR) && defined(S_IFDIR) 53 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) 54 #endif 55 56 static void set_default_dirlist (char *); 57 static void set_section_start (char *, char *); 58 static void help (void); 59 60 /* Non-zero if we are processing a --defsym from the command line. */ 61 int parsing_defsym = 0; 62 63 /* Codes used for the long options with no short synonyms. 150 isn't 64 special; it's just an arbitrary non-ASCII char value. */ 65 enum option_values 66 { 67 OPTION_ASSERT = 150, 68 OPTION_CALL_SHARED, 69 OPTION_CREF, 70 OPTION_DEFSYM, 71 OPTION_DEMANGLE, 72 OPTION_DYNAMIC_LINKER, 73 OPTION_EB, 74 OPTION_EL, 75 OPTION_EMBEDDED_RELOCS, 76 OPTION_EXPORT_DYNAMIC, 77 OPTION_HELP, 78 OPTION_IGNORE, 79 OPTION_MAP, 80 OPTION_NO_DEMANGLE, 81 OPTION_NO_KEEP_MEMORY, 82 OPTION_NO_WARN_MISMATCH, 83 OPTION_NOINHIBIT_EXEC, 84 OPTION_NON_SHARED, 85 OPTION_NO_WHOLE_ARCHIVE, 86 OPTION_OFORMAT, 87 OPTION_RELAX, 88 OPTION_RETAIN_SYMBOLS_FILE, 89 OPTION_RPATH, 90 OPTION_RPATH_LINK, 91 OPTION_SHARED, 92 OPTION_SONAME, 93 OPTION_SORT_COMMON, 94 OPTION_STATS, 95 OPTION_SYMBOLIC, 96 OPTION_TASK_LINK, 97 OPTION_TBSS, 98 OPTION_TDATA, 99 OPTION_TTEXT, 100 OPTION_TRADITIONAL_FORMAT, 101 OPTION_UR, 102 OPTION_VERBOSE, 103 OPTION_VERSION, 104 OPTION_VERSION_SCRIPT, 105 OPTION_VERSION_EXPORTS_SECTION, 106 OPTION_WARN_COMMON, 107 OPTION_WARN_CONSTRUCTORS, 108 OPTION_WARN_FATAL, 109 OPTION_WARN_MULTIPLE_GP, 110 OPTION_WARN_ONCE, 111 OPTION_WARN_SECTION_ALIGN, 112 OPTION_SPLIT_BY_RELOC, 113 OPTION_SPLIT_BY_FILE , 114 OPTION_WHOLE_ARCHIVE, 115 OPTION_AS_NEEDED, 116 OPTION_NO_AS_NEEDED, 117 OPTION_WRAP, 118 OPTION_FORCE_EXE_SUFFIX, 119 OPTION_GC_SECTIONS, 120 OPTION_NO_GC_SECTIONS, 121 OPTION_CHECK_SECTIONS, 122 OPTION_NO_CHECK_SECTIONS, 123 OPTION_NO_UNDEFINED, 124 OPTION_INIT, 125 OPTION_FINI, 126 OPTION_SECTION_START, 127 OPTION_UNIQUE, 128 OPTION_TARGET_HELP, 129 OPTION_ALLOW_SHLIB_UNDEFINED, 130 OPTION_NO_ALLOW_SHLIB_UNDEFINED, 131 OPTION_ALLOW_MULTIPLE_DEFINITION, 132 OPTION_NO_UNDEFINED_VERSION, 133 OPTION_DISCARD_NONE, 134 OPTION_SPARE_DYNAMIC_TAGS, 135 OPTION_NO_DEFINE_COMMON, 136 OPTION_NOSTDLIB, 137 OPTION_NO_OMAGIC, 138 OPTION_STRIP_DISCARDED, 139 OPTION_NO_STRIP_DISCARDED, 140 OPTION_ACCEPT_UNKNOWN_INPUT_ARCH, 141 OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH, 142 OPTION_PIE, 143 OPTION_UNRESOLVED_SYMBOLS, 144 OPTION_WARN_UNRESOLVED_SYMBOLS, 145 OPTION_ERROR_UNRESOLVED_SYMBOLS 146 }; 147 148 /* The long options. This structure is used for both the option 149 parsing and the help text. */ 150 151 struct ld_option 152 { 153 /* The long option information. */ 154 struct option opt; 155 /* The short option with the same meaning ('\0' if none). */ 156 char shortopt; 157 /* The name of the argument (NULL if none). */ 158 const char *arg; 159 /* The documentation string. If this is NULL, this is a synonym for 160 the previous option. */ 161 const char *doc; 162 enum { 163 /* Use one dash before long option name. */ 164 ONE_DASH, 165 /* Use two dashes before long option name. */ 166 TWO_DASHES, 167 /* Only accept two dashes before the long option name. 168 This is an overloading of the use of this enum, since originally it 169 was only intended to tell the --help display function how to display 170 the long option name. This feature was added in order to resolve 171 the confusion about the -omagic command line switch. Is it setting 172 the output file name to "magic" or is it setting the NMAGIC flag on 173 the output ? It has been decided that it is setting the output file 174 name, and that if you want to set the NMAGIC flag you should use -N 175 or --omagic. */ 176 EXACTLY_TWO_DASHES, 177 /* Don't mention this option in --help output. */ 178 NO_HELP 179 } control; 180 }; 181 182 static const struct ld_option ld_options[] = 183 { 184 { {NULL, required_argument, NULL, '\0'}, 185 'a', N_("KEYWORD"), N_("Shared library control for HP/UX compatibility"), 186 ONE_DASH }, 187 { {"architecture", required_argument, NULL, 'A'}, 188 'A', N_("ARCH"), N_("Set architecture") , TWO_DASHES }, 189 { {"format", required_argument, NULL, 'b'}, 190 'b', N_("TARGET"), N_("Specify target for following input files"), TWO_DASHES }, 191 { {"mri-script", required_argument, NULL, 'c'}, 192 'c', N_("FILE"), N_("Read MRI format linker script"), TWO_DASHES }, 193 { {"dc", no_argument, NULL, 'd'}, 194 'd', NULL, N_("Force common symbols to be defined"), ONE_DASH }, 195 { {"dp", no_argument, NULL, 'd'}, 196 '\0', NULL, NULL, ONE_DASH }, 197 { {"entry", required_argument, NULL, 'e'}, 198 'e', N_("ADDRESS"), N_("Set start address"), TWO_DASHES }, 199 { {"export-dynamic", no_argument, NULL, OPTION_EXPORT_DYNAMIC}, 200 'E', NULL, N_("Export all dynamic symbols"), TWO_DASHES }, 201 { {"EB", no_argument, NULL, OPTION_EB}, 202 '\0', NULL, N_("Link big-endian objects"), ONE_DASH }, 203 { {"EL", no_argument, NULL, OPTION_EL}, 204 '\0', NULL, N_("Link little-endian objects"), ONE_DASH }, 205 { {"auxiliary", required_argument, NULL, 'f'}, 206 'f', N_("SHLIB"), N_("Auxiliary filter for shared object symbol table"), 207 TWO_DASHES }, 208 { {"filter", required_argument, NULL, 'F'}, 209 'F', N_("SHLIB"), N_("Filter for shared object symbol table"), TWO_DASHES }, 210 { {NULL, no_argument, NULL, '\0'}, 211 'g', NULL, N_("Ignored"), ONE_DASH }, 212 { {"gpsize", required_argument, NULL, 'G'}, 213 'G', N_("SIZE"), N_("Small data size (if no size, same as --shared)"), 214 TWO_DASHES }, 215 { {"soname", required_argument, NULL, OPTION_SONAME}, 216 'h', N_("FILENAME"), N_("Set internal name of shared library"), ONE_DASH }, 217 { {"dynamic-linker", required_argument, NULL, OPTION_DYNAMIC_LINKER}, 218 'I', N_("PROGRAM"), N_("Set PROGRAM as the dynamic linker to use"), TWO_DASHES }, 219 { {"library", required_argument, NULL, 'l'}, 220 'l', N_("LIBNAME"), N_("Search for library LIBNAME"), TWO_DASHES }, 221 { {"library-path", required_argument, NULL, 'L'}, 222 'L', N_("DIRECTORY"), N_("Add DIRECTORY to library search path"), TWO_DASHES }, 223 { {NULL, required_argument, NULL, '\0'}, 224 'm', N_("EMULATION"), N_("Set emulation"), ONE_DASH }, 225 { {"print-map", no_argument, NULL, 'M'}, 226 'M', NULL, N_("Print map file on standard output"), TWO_DASHES }, 227 { {"nmagic", no_argument, NULL, 'n'}, 228 'n', NULL, N_("Do not page align data"), TWO_DASHES }, 229 { {"omagic", no_argument, NULL, 'N'}, 230 'N', NULL, N_("Do not page align data, do not make text readonly"), 231 EXACTLY_TWO_DASHES }, 232 { {"no-omagic", no_argument, NULL, OPTION_NO_OMAGIC}, 233 '\0', NULL, N_("Page align data, make text readonly"), EXACTLY_TWO_DASHES }, 234 { {"output", required_argument, NULL, 'o'}, 235 'o', N_("FILE"), N_("Set output file name"), EXACTLY_TWO_DASHES }, 236 { {NULL, required_argument, NULL, '\0'}, 237 'O', NULL, N_("Optimize output file"), ONE_DASH }, 238 { {"Qy", no_argument, NULL, OPTION_IGNORE}, 239 '\0', NULL, N_("Ignored for SVR4 compatibility"), ONE_DASH }, 240 { {"emit-relocs", no_argument, NULL, 'q'}, 241 'q', NULL, "Generate relocations in final output", TWO_DASHES }, 242 { {"relocatable", no_argument, NULL, 'r'}, 243 'r', NULL, N_("Generate relocatable output"), TWO_DASHES }, 244 { {NULL, no_argument, NULL, '\0'}, 245 'i', NULL, NULL, ONE_DASH }, 246 { {"just-symbols", required_argument, NULL, 'R'}, 247 'R', N_("FILE"), N_("Just link symbols (if directory, same as --rpath)"), 248 TWO_DASHES }, 249 { {"strip-all", no_argument, NULL, 's'}, 250 's', NULL, N_("Strip all symbols"), TWO_DASHES }, 251 { {"strip-debug", no_argument, NULL, 'S'}, 252 'S', NULL, N_("Strip debugging symbols"), TWO_DASHES }, 253 { {"strip-discarded", no_argument, NULL, OPTION_STRIP_DISCARDED}, 254 '\0', NULL, N_("Strip symbols in discarded sections"), TWO_DASHES }, 255 { {"no-strip-discarded", no_argument, NULL, OPTION_NO_STRIP_DISCARDED}, 256 '\0', NULL, N_("Do not strip symbols in discarded sections"), TWO_DASHES }, 257 { {"trace", no_argument, NULL, 't'}, 258 't', NULL, N_("Trace file opens"), TWO_DASHES }, 259 { {"script", required_argument, NULL, 'T'}, 260 'T', N_("FILE"), N_("Read linker script"), TWO_DASHES }, 261 { {"undefined", required_argument, NULL, 'u'}, 262 'u', N_("SYMBOL"), N_("Start with undefined reference to SYMBOL"), TWO_DASHES }, 263 { {"unique", optional_argument, NULL, OPTION_UNIQUE}, 264 '\0', N_("[=SECTION]"), N_("Don't merge input [SECTION | orphan] sections"), TWO_DASHES }, 265 { {"Ur", no_argument, NULL, OPTION_UR}, 266 '\0', NULL, N_("Build global constructor/destructor tables"), ONE_DASH }, 267 { {"version", no_argument, NULL, OPTION_VERSION}, 268 'v', NULL, N_("Print version information"), TWO_DASHES }, 269 { {NULL, no_argument, NULL, '\0'}, 270 'V', NULL, N_("Print version and emulation information"), ONE_DASH }, 271 { {"discard-all", no_argument, NULL, 'x'}, 272 'x', NULL, N_("Discard all local symbols"), TWO_DASHES }, 273 { {"discard-locals", no_argument, NULL, 'X'}, 274 'X', NULL, N_("Discard temporary local symbols (default)"), TWO_DASHES }, 275 { {"discard-none", no_argument, NULL, OPTION_DISCARD_NONE}, 276 '\0', NULL, N_("Don't discard any local symbols"), TWO_DASHES }, 277 { {"trace-symbol", required_argument, NULL, 'y'}, 278 'y', N_("SYMBOL"), N_("Trace mentions of SYMBOL"), TWO_DASHES }, 279 { {NULL, required_argument, NULL, '\0'}, 280 'Y', N_("PATH"), N_("Default search path for Solaris compatibility"), ONE_DASH }, 281 { {"Zmagic", no_argument, NULL, 'Z'}, 282 'Z', NULL, N_("Do not page align got/plt, old style executable"), 283 EXACTLY_TWO_DASHES }, 284 { {"start-group", no_argument, NULL, '('}, 285 '(', NULL, N_("Start a group"), TWO_DASHES }, 286 { {"end-group", no_argument, NULL, ')'}, 287 ')', NULL, N_("End a group"), TWO_DASHES }, 288 { {"accept-unknown-input-arch", no_argument, NULL, OPTION_ACCEPT_UNKNOWN_INPUT_ARCH}, 289 '\0', NULL, N_("Accept input files whose architecture cannot be determined"), TWO_DASHES }, 290 { {"no-accept-unknown-input-arch", no_argument, NULL, OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH}, 291 '\0', NULL, N_("Reject input files whose architecture is unknown"), TWO_DASHES }, 292 { {"assert", required_argument, NULL, OPTION_ASSERT}, 293 '\0', N_("KEYWORD"), N_("Ignored for SunOS compatibility"), ONE_DASH }, 294 { {"Bdynamic", no_argument, NULL, OPTION_CALL_SHARED}, 295 '\0', NULL, N_("Link against shared libraries"), ONE_DASH }, 296 { {"dy", no_argument, NULL, OPTION_CALL_SHARED}, 297 '\0', NULL, NULL, ONE_DASH }, 298 { {"call_shared", no_argument, NULL, OPTION_CALL_SHARED}, 299 '\0', NULL, NULL, ONE_DASH }, 300 { {"Bstatic", no_argument, NULL, OPTION_NON_SHARED}, 301 '\0', NULL, N_("Do not link against shared libraries"), ONE_DASH }, 302 { {"dn", no_argument, NULL, OPTION_NON_SHARED}, 303 '\0', NULL, NULL, ONE_DASH }, 304 { {"non_shared", no_argument, NULL, OPTION_NON_SHARED}, 305 '\0', NULL, NULL, ONE_DASH }, 306 { {"static", no_argument, NULL, OPTION_NON_SHARED}, 307 '\0', NULL, NULL, ONE_DASH }, 308 { {"Bsymbolic", no_argument, NULL, OPTION_SYMBOLIC}, 309 '\0', NULL, N_("Bind global references locally"), ONE_DASH }, 310 { {"check-sections", no_argument, NULL, OPTION_CHECK_SECTIONS}, 311 '\0', NULL, N_("Check section addresses for overlaps (default)"), TWO_DASHES }, 312 { {"no-check-sections", no_argument, NULL, OPTION_NO_CHECK_SECTIONS}, 313 '\0', NULL, N_("Do not check section addresses for overlaps"), 314 TWO_DASHES }, 315 { {"cref", no_argument, NULL, OPTION_CREF}, 316 '\0', NULL, N_("Output cross reference table"), TWO_DASHES }, 317 { {"defsym", required_argument, NULL, OPTION_DEFSYM}, 318 '\0', N_("SYMBOL=EXPRESSION"), N_("Define a symbol"), TWO_DASHES }, 319 { {"demangle", optional_argument, NULL, OPTION_DEMANGLE}, 320 '\0', N_("[=STYLE]"), N_("Demangle symbol names [using STYLE]"), TWO_DASHES }, 321 { {"embedded-relocs", no_argument, NULL, OPTION_EMBEDDED_RELOCS}, 322 '\0', NULL, N_("Generate embedded relocs"), TWO_DASHES}, 323 { {"fini", required_argument, NULL, OPTION_FINI}, 324 '\0', N_("SYMBOL"), N_("Call SYMBOL at unload-time"), ONE_DASH }, 325 { {"force-exe-suffix", no_argument, NULL, OPTION_FORCE_EXE_SUFFIX}, 326 '\0', NULL, N_("Force generation of file with .exe suffix"), TWO_DASHES}, 327 { {"gc-sections", no_argument, NULL, OPTION_GC_SECTIONS}, 328 '\0', NULL, N_("Remove unused sections (on some targets)"), 329 TWO_DASHES }, 330 { {"no-gc-sections", no_argument, NULL, OPTION_NO_GC_SECTIONS}, 331 '\0', NULL, N_("Don't remove unused sections (default)"), 332 TWO_DASHES }, 333 { {"help", no_argument, NULL, OPTION_HELP}, 334 '\0', NULL, N_("Print option help"), TWO_DASHES }, 335 { {"init", required_argument, NULL, OPTION_INIT}, 336 '\0', N_("SYMBOL"), N_("Call SYMBOL at load-time"), ONE_DASH }, 337 { {"Map", required_argument, NULL, OPTION_MAP}, 338 '\0', N_("FILE"), N_("Write a map file"), ONE_DASH }, 339 { {"no-define-common", no_argument, NULL, OPTION_NO_DEFINE_COMMON}, 340 '\0', NULL, N_("Do not define Common storage"), TWO_DASHES }, 341 { {"no-demangle", no_argument, NULL, OPTION_NO_DEMANGLE }, 342 '\0', NULL, N_("Do not demangle symbol names"), TWO_DASHES }, 343 { {"no-keep-memory", no_argument, NULL, OPTION_NO_KEEP_MEMORY}, 344 '\0', NULL, N_("Use less memory and more disk I/O"), TWO_DASHES }, 345 { {"no-undefined", no_argument, NULL, OPTION_NO_UNDEFINED}, 346 '\0', NULL, N_("Do not allow unresolved references in object files"), TWO_DASHES }, 347 { {"allow-shlib-undefined", no_argument, NULL, OPTION_ALLOW_SHLIB_UNDEFINED}, 348 '\0', NULL, N_("Allow unresolved references in shared libaries"), TWO_DASHES }, 349 { {"no-allow-shlib-undefined", no_argument, NULL, OPTION_NO_ALLOW_SHLIB_UNDEFINED}, 350 '\0', NULL, N_("Do not allow unresolved references in shared libs"), TWO_DASHES }, 351 { {"allow-multiple-definition", no_argument, NULL, OPTION_ALLOW_MULTIPLE_DEFINITION}, 352 '\0', NULL, N_("Allow multiple definitions"), TWO_DASHES }, 353 { {"no-undefined-version", no_argument, NULL, OPTION_NO_UNDEFINED_VERSION}, 354 '\0', NULL, N_("Disallow undefined version"), TWO_DASHES }, 355 { {"no-warn-mismatch", no_argument, NULL, OPTION_NO_WARN_MISMATCH}, 356 '\0', NULL, N_("Don't warn about mismatched input files"), TWO_DASHES}, 357 { {"no-whole-archive", no_argument, NULL, OPTION_NO_WHOLE_ARCHIVE}, 358 '\0', NULL, N_("Turn off --whole-archive"), TWO_DASHES }, 359 { {"noinhibit-exec", no_argument, NULL, OPTION_NOINHIBIT_EXEC}, 360 '\0', NULL, N_("Create an output file even if errors occur"), TWO_DASHES }, 361 { {"noinhibit_exec", no_argument, NULL, OPTION_NOINHIBIT_EXEC}, 362 '\0', NULL, NULL, NO_HELP }, 363 { {"nostdlib", no_argument, NULL, OPTION_NOSTDLIB}, 364 '\0', NULL, N_("Only use library directories specified on\n\t\t\t\tthe command line"), ONE_DASH }, 365 { {"oformat", required_argument, NULL, OPTION_OFORMAT}, 366 '\0', N_("TARGET"), N_("Specify target of output file"), EXACTLY_TWO_DASHES }, 367 { {"qmagic", no_argument, NULL, OPTION_IGNORE}, 368 '\0', NULL, N_("Ignored for Linux compatibility"), ONE_DASH }, 369 { {"relax", no_argument, NULL, OPTION_RELAX}, 370 '\0', NULL, N_("Relax branches on certain targets"), TWO_DASHES }, 371 { {"retain-symbols-file", required_argument, NULL, 372 OPTION_RETAIN_SYMBOLS_FILE}, 373 '\0', N_("FILE"), N_("Keep only symbols listed in FILE"), TWO_DASHES }, 374 { {"rpath", required_argument, NULL, OPTION_RPATH}, 375 '\0', N_("PATH"), N_("Set runtime shared library search path"), ONE_DASH }, 376 { {"rpath-link", required_argument, NULL, OPTION_RPATH_LINK}, 377 '\0', N_("PATH"), N_("Set link time shared library search path"), ONE_DASH }, 378 { {"shared", no_argument, NULL, OPTION_SHARED}, 379 '\0', NULL, N_("Create a shared library"), ONE_DASH }, 380 { {"Bshareable", no_argument, NULL, OPTION_SHARED }, /* FreeBSD. */ 381 '\0', NULL, NULL, ONE_DASH }, 382 { {"pie", no_argument, NULL, OPTION_PIE}, 383 '\0', NULL, N_("Create a position independent executable"), ONE_DASH }, 384 { {"pic-executable", no_argument, NULL, OPTION_PIE}, 385 '\0', NULL, NULL, TWO_DASHES }, 386 { {"sort-common", no_argument, NULL, OPTION_SORT_COMMON}, 387 '\0', NULL, N_("Sort common symbols by size"), TWO_DASHES }, 388 { {"sort_common", no_argument, NULL, OPTION_SORT_COMMON}, 389 '\0', NULL, NULL, NO_HELP }, 390 { {"spare-dynamic-tags", required_argument, NULL, OPTION_SPARE_DYNAMIC_TAGS}, 391 '\0', N_("COUNT"), N_("How many tags to reserve in .dynamic section"), TWO_DASHES }, 392 { {"split-by-file", optional_argument, NULL, OPTION_SPLIT_BY_FILE}, 393 '\0', N_("[=SIZE]"), N_("Split output sections every SIZE octets"), TWO_DASHES }, 394 { {"split-by-reloc", optional_argument, NULL, OPTION_SPLIT_BY_RELOC}, 395 '\0', N_("[=COUNT]"), N_("Split output sections every COUNT relocs"), TWO_DASHES }, 396 { {"stats", no_argument, NULL, OPTION_STATS}, 397 '\0', NULL, N_("Print memory usage statistics"), TWO_DASHES }, 398 { {"target-help", no_argument, NULL, OPTION_TARGET_HELP}, 399 '\0', NULL, N_("Display target specific options"), TWO_DASHES }, 400 { {"task-link", required_argument, NULL, OPTION_TASK_LINK}, 401 '\0', N_("SYMBOL"), N_("Do task level linking"), TWO_DASHES }, 402 { {"traditional-format", no_argument, NULL, OPTION_TRADITIONAL_FORMAT}, 403 '\0', NULL, N_("Use same format as native linker"), TWO_DASHES }, 404 { {"section-start", required_argument, NULL, OPTION_SECTION_START}, 405 '\0', N_("SECTION=ADDRESS"), N_("Set address of named section"), TWO_DASHES }, 406 { {"Tbss", required_argument, NULL, OPTION_TBSS}, 407 '\0', N_("ADDRESS"), N_("Set address of .bss section"), ONE_DASH }, 408 { {"Tdata", required_argument, NULL, OPTION_TDATA}, 409 '\0', N_("ADDRESS"), N_("Set address of .data section"), ONE_DASH }, 410 { {"Ttext", required_argument, NULL, OPTION_TTEXT}, 411 '\0', N_("ADDRESS"), N_("Set address of .text section"), ONE_DASH }, 412 { {"unresolved-symbols=<method>", required_argument, NULL, OPTION_UNRESOLVED_SYMBOLS}, 413 '\0', NULL, N_("How to handle unresolved symbols. <method> is:\n\t\t\t\tignore-all, report-all, ignore-in-object-files,\n\t\t\t\tignore-in-shared-libs"), 414 TWO_DASHES }, 415 { {"verbose", no_argument, NULL, OPTION_VERBOSE}, 416 '\0', NULL, N_("Output lots of information during link"), TWO_DASHES }, 417 { {"dll-verbose", no_argument, NULL, OPTION_VERBOSE}, /* Linux. */ 418 '\0', NULL, NULL, NO_HELP }, 419 { {"version-script", required_argument, NULL, OPTION_VERSION_SCRIPT }, 420 '\0', N_("FILE"), N_("Read version information script"), TWO_DASHES }, 421 { {"version-exports-section", required_argument, NULL, 422 OPTION_VERSION_EXPORTS_SECTION }, 423 '\0', N_("SYMBOL"), N_("Take export symbols list from .exports, using\n\t\t\t\tSYMBOL as the version."), 424 TWO_DASHES }, 425 { {"warn-common", no_argument, NULL, OPTION_WARN_COMMON}, 426 '\0', NULL, N_("Warn about duplicate common symbols"), TWO_DASHES }, 427 { {"warn-constructors", no_argument, NULL, OPTION_WARN_CONSTRUCTORS}, 428 '\0', NULL, N_("Warn if global constructors/destructors are seen"), 429 TWO_DASHES }, 430 { {"warn-multiple-gp", no_argument, NULL, OPTION_WARN_MULTIPLE_GP}, 431 '\0', NULL, N_("Warn if the multiple GP values are used"), TWO_DASHES }, 432 { {"warn-once", no_argument, NULL, OPTION_WARN_ONCE}, 433 '\0', NULL, N_("Warn only once per undefined symbol"), TWO_DASHES }, 434 { {"warn-section-align", no_argument, NULL, OPTION_WARN_SECTION_ALIGN}, 435 '\0', NULL, N_("Warn if start of section changes due to alignment"), 436 TWO_DASHES }, 437 { {"warn-unresolved-symbols", no_argument, NULL, OPTION_WARN_UNRESOLVED_SYMBOLS}, 438 '\0', NULL, N_("Report unresolved symbols as warnings"), TWO_DASHES }, 439 { {"error-unresolved-symbols", no_argument, NULL, OPTION_ERROR_UNRESOLVED_SYMBOLS}, 440 '\0', NULL, N_("Report unresolved symbols as errors"), TWO_DASHES }, 441 { {"fatal-warnings", no_argument, NULL, OPTION_WARN_FATAL}, 442 '\0', NULL, N_("Treat warnings as errors"), 443 TWO_DASHES }, 444 { {"whole-archive", no_argument, NULL, OPTION_WHOLE_ARCHIVE}, 445 '\0', NULL, N_("Include all objects from following archives"), TWO_DASHES }, 446 { {"as-needed", no_argument, NULL, OPTION_AS_NEEDED}, 447 '\0', NULL, N_("Only set DT_NEEDED for following dynamic libs if used"), TWO_DASHES }, 448 { {"no-as-needed", no_argument, NULL, OPTION_NO_AS_NEEDED}, 449 '\0', NULL, N_("Always set DT_NEEDED for following dynamic libs"), TWO_DASHES }, 450 { {"wrap", required_argument, NULL, OPTION_WRAP}, 451 '\0', N_("SYMBOL"), N_("Use wrapper functions for SYMBOL"), TWO_DASHES } 452 }; 453 454 #define OPTION_COUNT ARRAY_SIZE (ld_options) 455 456 void 457 parse_args (unsigned argc, char **argv) 458 { 459 unsigned i; 460 int is, il, irl; 461 int ingroup = 0; 462 char *default_dirlist = NULL; 463 char *shortopts; 464 struct option *longopts; 465 struct option *really_longopts; 466 int last_optind; 467 enum report_method how_to_report_unresolved_symbols = RM_GENERATE_ERROR; 468 469 shortopts = xmalloc (OPTION_COUNT * 3 + 2); 470 longopts = xmalloc (sizeof (*longopts) * (OPTION_COUNT + 1)); 471 really_longopts = xmalloc (sizeof (*really_longopts) * (OPTION_COUNT + 1)); 472 473 /* Starting the short option string with '-' is for programs that 474 expect options and other ARGV-elements in any order and that care about 475 the ordering of the two. We describe each non-option ARGV-element 476 as if it were the argument of an option with character code 1. */ 477 shortopts[0] = '-'; 478 is = 1; 479 il = 0; 480 irl = 0; 481 for (i = 0; i < OPTION_COUNT; i++) 482 { 483 if (ld_options[i].shortopt != '\0') 484 { 485 shortopts[is] = ld_options[i].shortopt; 486 ++is; 487 if (ld_options[i].opt.has_arg == required_argument 488 || ld_options[i].opt.has_arg == optional_argument) 489 { 490 shortopts[is] = ':'; 491 ++is; 492 if (ld_options[i].opt.has_arg == optional_argument) 493 { 494 shortopts[is] = ':'; 495 ++is; 496 } 497 } 498 } 499 if (ld_options[i].opt.name != NULL) 500 { 501 if (ld_options[i].control == EXACTLY_TWO_DASHES) 502 { 503 really_longopts[irl] = ld_options[i].opt; 504 ++irl; 505 } 506 else 507 { 508 longopts[il] = ld_options[i].opt; 509 ++il; 510 } 511 } 512 } 513 shortopts[is] = '\0'; 514 longopts[il].name = NULL; 515 really_longopts[irl].name = NULL; 516 517 ldemul_add_options (is, &shortopts, il, &longopts, irl, &really_longopts); 518 519 /* The -G option is ambiguous on different platforms. Sometimes it 520 specifies the largest data size to put into the small data 521 section. Sometimes it is equivalent to --shared. Unfortunately, 522 the first form takes an argument, while the second does not. 523 524 We need to permit the --shared form because on some platforms, 525 such as Solaris, gcc -shared will pass -G to the linker. 526 527 To permit either usage, we look through the argument list. If we 528 find -G not followed by a number, we change it into --shared. 529 This will work for most normal cases. */ 530 for (i = 1; i < argc; i++) 531 if (strcmp (argv[i], "-G") == 0 532 && (i + 1 >= argc 533 || ! ISDIGIT (argv[i + 1][0]))) 534 argv[i] = (char *) "--shared"; 535 536 /* Because we permit long options to start with a single dash, and 537 we have a --library option, and the -l option is conventionally 538 used with an immediately following argument, we can have bad 539 results if somebody tries to use -l with a library whose name 540 happens to start with "ibrary", as in -li. We avoid problems by 541 simply turning -l into --library. This means that users will 542 have to use two dashes in order to use --library, which is OK 543 since that's how it is documented. 544 545 FIXME: It's possible that this problem can arise for other short 546 options as well, although the user does always have the recourse 547 of adding a space between the option and the argument. */ 548 for (i = 1; i < argc; i++) 549 { 550 if (argv[i][0] == '-' 551 && argv[i][1] == 'l' 552 && argv[i][2] != '\0') 553 { 554 char *n; 555 556 n = xmalloc (strlen (argv[i]) + 20); 557 sprintf (n, "--library=%s", argv[i] + 2); 558 argv[i] = n; 559 } 560 } 561 562 last_optind = -1; 563 while (1) 564 { 565 int longind; 566 int optc; 567 568 /* Using last_optind lets us avoid calling ldemul_parse_args 569 multiple times on a single option, which would lead to 570 confusion in the internal static variables maintained by 571 getopt. This could otherwise happen for an argument like 572 -nx, in which the -n is parsed as a single option, and we 573 loop around to pick up the -x. */ 574 if (optind != last_optind) 575 if (ldemul_parse_args (argc, argv)) 576 continue; 577 578 /* getopt_long_only is like getopt_long, but '-' as well as '--' 579 can indicate a long option. */ 580 opterr = 0; 581 last_optind = optind; 582 optc = getopt_long_only (argc, argv, shortopts, longopts, &longind); 583 if (optc == '?') 584 { 585 optind = last_optind; 586 optc = getopt_long (argc, argv, "-", really_longopts, &longind); 587 } 588 589 if (ldemul_handle_option (optc)) 590 continue; 591 592 if (optc == -1) 593 break; 594 595 switch (optc) 596 { 597 case '?': 598 einfo (_("%P: unrecognized option '%s'\n"), argv[last_optind]); 599 default: 600 einfo (_("%P%F: use the --help option for usage information\n")); 601 602 case 1: /* File name. */ 603 lang_add_input_file (optarg, lang_input_file_is_file_enum, NULL); 604 break; 605 606 case OPTION_IGNORE: 607 break; 608 case 'a': 609 /* For HP/UX compatibility. Actually -a shared should mean 610 ``use only shared libraries'' but, then, we don't 611 currently support shared libraries on HP/UX anyhow. */ 612 if (strcmp (optarg, "archive") == 0) 613 config.dynamic_link = FALSE; 614 else if (strcmp (optarg, "shared") == 0 615 || strcmp (optarg, "default") == 0) 616 config.dynamic_link = TRUE; 617 else 618 einfo (_("%P%F: unrecognized -a option `%s'\n"), optarg); 619 break; 620 case OPTION_ASSERT: 621 /* FIXME: We just ignore these, but we should handle them. */ 622 if (strcmp (optarg, "definitions") == 0) 623 ; 624 else if (strcmp (optarg, "nodefinitions") == 0) 625 ; 626 else if (strcmp (optarg, "nosymbolic") == 0) 627 ; 628 else if (strcmp (optarg, "pure-text") == 0) 629 ; 630 else 631 einfo (_("%P%F: unrecognized -assert option `%s'\n"), optarg); 632 break; 633 case 'A': 634 ldfile_add_arch (optarg); 635 break; 636 case 'b': 637 lang_add_target (optarg); 638 break; 639 case 'c': 640 ldfile_open_command_file (optarg); 641 parser_input = input_mri_script; 642 yyparse (); 643 break; 644 case OPTION_CALL_SHARED: 645 config.dynamic_link = TRUE; 646 break; 647 case OPTION_NON_SHARED: 648 config.dynamic_link = FALSE; 649 break; 650 case OPTION_CREF: 651 command_line.cref = TRUE; 652 link_info.notice_all = TRUE; 653 break; 654 case 'd': 655 command_line.force_common_definition = TRUE; 656 break; 657 case OPTION_DEFSYM: 658 lex_string = optarg; 659 lex_redirect (optarg); 660 parser_input = input_defsym; 661 parsing_defsym = 1; 662 yyparse (); 663 parsing_defsym = 0; 664 lex_string = NULL; 665 break; 666 case OPTION_DEMANGLE: 667 demangling = TRUE; 668 if (optarg != NULL) 669 { 670 enum demangling_styles style; 671 672 style = cplus_demangle_name_to_style (optarg); 673 if (style == unknown_demangling) 674 einfo (_("%F%P: unknown demangling style `%s'"), 675 optarg); 676 677 cplus_demangle_set_style (style); 678 } 679 break; 680 case 'I': /* Used on Solaris. */ 681 case OPTION_DYNAMIC_LINKER: 682 command_line.interpreter = optarg; 683 break; 684 case OPTION_EB: 685 command_line.endian = ENDIAN_BIG; 686 break; 687 case OPTION_EL: 688 command_line.endian = ENDIAN_LITTLE; 689 break; 690 case OPTION_EMBEDDED_RELOCS: 691 command_line.embedded_relocs = TRUE; 692 break; 693 case OPTION_EXPORT_DYNAMIC: 694 case 'E': /* HP/UX compatibility. */ 695 link_info.export_dynamic = TRUE; 696 break; 697 case 'e': 698 lang_add_entry (optarg, TRUE); 699 break; 700 case 'f': 701 if (command_line.auxiliary_filters == NULL) 702 { 703 command_line.auxiliary_filters = xmalloc (2 * sizeof (char *)); 704 command_line.auxiliary_filters[0] = optarg; 705 command_line.auxiliary_filters[1] = NULL; 706 } 707 else 708 { 709 int c; 710 char **p; 711 712 c = 0; 713 for (p = command_line.auxiliary_filters; *p != NULL; p++) 714 ++c; 715 command_line.auxiliary_filters 716 = xrealloc (command_line.auxiliary_filters, 717 (c + 2) * sizeof (char *)); 718 command_line.auxiliary_filters[c] = optarg; 719 command_line.auxiliary_filters[c + 1] = NULL; 720 } 721 break; 722 case 'F': 723 command_line.filter_shlib = optarg; 724 break; 725 case OPTION_FORCE_EXE_SUFFIX: 726 command_line.force_exe_suffix = TRUE; 727 break; 728 case 'G': 729 { 730 char *end; 731 g_switch_value = strtoul (optarg, &end, 0); 732 if (*end) 733 einfo (_("%P%F: invalid number `%s'\n"), optarg); 734 } 735 break; 736 case 'g': 737 /* Ignore. */ 738 break; 739 case OPTION_GC_SECTIONS: 740 command_line.gc_sections = TRUE; 741 break; 742 case OPTION_HELP: 743 help (); 744 xexit (0); 745 break; 746 case 'L': 747 ldfile_add_library_path (optarg, TRUE); 748 break; 749 case 'l': 750 lang_add_input_file (optarg, lang_input_file_is_l_enum, NULL); 751 break; 752 case 'M': 753 config.map_filename = "-"; 754 break; 755 case 'm': 756 /* Ignore. Was handled in a pre-parse. */ 757 break; 758 case OPTION_MAP: 759 config.map_filename = optarg; 760 break; 761 case 'N': 762 config.text_read_only = FALSE; 763 config.magic_demand_paged = FALSE; 764 config.dynamic_link = FALSE; 765 break; 766 case OPTION_NO_OMAGIC: 767 config.text_read_only = TRUE; 768 config.magic_demand_paged = TRUE; 769 /* NB/ Does not set dynamic_link to TRUE. 770 Use --call-shared or -Bdynamic for this. */ 771 break; 772 case 'n': 773 config.magic_demand_paged = FALSE; 774 config.dynamic_link = FALSE; 775 break; 776 case OPTION_NO_DEFINE_COMMON: 777 command_line.inhibit_common_definition = TRUE; 778 break; 779 case OPTION_NO_DEMANGLE: 780 demangling = FALSE; 781 break; 782 case OPTION_NO_GC_SECTIONS: 783 command_line.gc_sections = FALSE; 784 break; 785 case OPTION_NO_KEEP_MEMORY: 786 link_info.keep_memory = FALSE; 787 break; 788 case OPTION_NO_UNDEFINED: 789 link_info.unresolved_syms_in_objects = how_to_report_unresolved_symbols; 790 break; 791 case OPTION_ALLOW_SHLIB_UNDEFINED: 792 link_info.unresolved_syms_in_shared_libs = RM_IGNORE; 793 break; 794 case OPTION_NO_ALLOW_SHLIB_UNDEFINED: 795 link_info.unresolved_syms_in_shared_libs = how_to_report_unresolved_symbols; 796 break; 797 case OPTION_UNRESOLVED_SYMBOLS: 798 if (strcmp (optarg, "ignore-all") == 0) 799 { 800 link_info.unresolved_syms_in_objects = RM_IGNORE; 801 link_info.unresolved_syms_in_shared_libs = RM_IGNORE; 802 } 803 else if (strcmp (optarg, "report-all") == 0) 804 { 805 link_info.unresolved_syms_in_objects = how_to_report_unresolved_symbols; 806 link_info.unresolved_syms_in_shared_libs = how_to_report_unresolved_symbols; 807 } 808 else if (strcmp (optarg, "ignore-in-object-files") == 0) 809 { 810 link_info.unresolved_syms_in_objects = RM_IGNORE; 811 link_info.unresolved_syms_in_shared_libs = how_to_report_unresolved_symbols; 812 } 813 else if (strcmp (optarg, "ignore-in-shared-libs") == 0) 814 { 815 link_info.unresolved_syms_in_objects = how_to_report_unresolved_symbols; 816 link_info.unresolved_syms_in_shared_libs = RM_IGNORE; 817 } 818 else 819 einfo (_("%P%F: bad --unresolved-symbols option: %s\n"), optarg); 820 break; 821 case OPTION_WARN_UNRESOLVED_SYMBOLS: 822 how_to_report_unresolved_symbols = RM_GENERATE_WARNING; 823 if (link_info.unresolved_syms_in_objects == RM_GENERATE_ERROR) 824 link_info.unresolved_syms_in_objects = RM_GENERATE_WARNING; 825 if (link_info.unresolved_syms_in_shared_libs == RM_GENERATE_ERROR) 826 link_info.unresolved_syms_in_shared_libs = RM_GENERATE_WARNING; 827 break; 828 829 case OPTION_ERROR_UNRESOLVED_SYMBOLS: 830 how_to_report_unresolved_symbols = RM_GENERATE_ERROR; 831 if (link_info.unresolved_syms_in_objects == RM_GENERATE_WARNING) 832 link_info.unresolved_syms_in_objects = RM_GENERATE_ERROR; 833 if (link_info.unresolved_syms_in_shared_libs == RM_GENERATE_WARNING) 834 link_info.unresolved_syms_in_shared_libs = RM_GENERATE_ERROR; 835 break; 836 case OPTION_ALLOW_MULTIPLE_DEFINITION: 837 link_info.allow_multiple_definition = TRUE; 838 break; 839 case OPTION_NO_UNDEFINED_VERSION: 840 link_info.allow_undefined_version = FALSE; 841 break; 842 case OPTION_NO_WARN_MISMATCH: 843 command_line.warn_mismatch = FALSE; 844 break; 845 case OPTION_NOINHIBIT_EXEC: 846 force_make_executable = TRUE; 847 break; 848 case OPTION_NOSTDLIB: 849 config.only_cmd_line_lib_dirs = TRUE; 850 break; 851 case OPTION_NO_WHOLE_ARCHIVE: 852 whole_archive = FALSE; 853 break; 854 case 'O': 855 /* FIXME "-O<non-digits> <value>" used to set the address of 856 section <non-digits>. Was this for compatibility with 857 something, or can we create a new option to do that 858 (with a syntax similar to -defsym)? 859 getopt can't handle two args to an option without kludges. */ 860 861 /* Enable optimizations of output files. */ 862 link_info.optimize = strtoul (optarg, NULL, 0) ? TRUE : FALSE; 863 break; 864 case 'o': 865 lang_add_output (optarg, 0); 866 break; 867 case OPTION_OFORMAT: 868 lang_add_output_format (optarg, NULL, NULL, 0); 869 break; 870 case 'q': 871 link_info.emitrelocations = TRUE; 872 break; 873 case 'i': 874 case 'r': 875 if (optind == last_optind) 876 /* This can happen if the user put "-rpath,a" on the command 877 line. (Or something similar. The comma is important). 878 Getopt becomes confused and thinks that this is a -r option 879 but it cannot parse the text after the -r so it refuses to 880 increment the optind counter. Detect this case and issue 881 an error message here. We cannot just make this a warning, 882 increment optind, and continue because getopt is too confused 883 and will seg-fault the next time around. */ 884 einfo(_("%P%F: bad -rpath option\n")); 885 886 link_info.relocatable = TRUE; 887 config.build_constructors = FALSE; 888 config.magic_demand_paged = FALSE; 889 config.text_read_only = FALSE; 890 config.dynamic_link = FALSE; 891 break; 892 case 'R': 893 /* The GNU linker traditionally uses -R to mean to include 894 only the symbols from a file. The Solaris linker uses -R 895 to set the path used by the runtime linker to find 896 libraries. This is the GNU linker -rpath argument. We 897 try to support both simultaneously by checking the file 898 named. If it is a directory, rather than a regular file, 899 we assume -rpath was meant. */ 900 { 901 struct stat s; 902 903 if (stat (optarg, &s) >= 0 904 && ! S_ISDIR (s.st_mode)) 905 { 906 lang_add_input_file (optarg, 907 lang_input_file_is_symbols_only_enum, 908 NULL); 909 break; 910 } 911 } 912 /* Fall through. */ 913 case OPTION_RPATH: 914 if (command_line.rpath == NULL) 915 command_line.rpath = xstrdup (optarg); 916 else 917 { 918 size_t rpath_len = strlen (command_line.rpath); 919 size_t optarg_len = strlen (optarg); 920 char *buf; 921 char *cp = command_line.rpath; 922 923 /* First see whether OPTARG is already in the path. */ 924 do 925 { 926 size_t idx = 0; 927 928 while (optarg[idx] != '\0' && optarg[idx] == cp[idx]) 929 ++idx; 930 if (optarg[idx] == '\0' 931 && (cp[idx] == '\0' || cp[idx] == ':')) 932 /* We found it. */ 933 break; 934 935 /* Not yet found. */ 936 cp = strchr (cp, ':'); 937 if (cp != NULL) 938 ++cp; 939 } 940 while (cp != NULL); 941 942 if (cp == NULL) 943 { 944 buf = xmalloc (rpath_len + optarg_len + 2); 945 sprintf (buf, "%s:%s", command_line.rpath, optarg); 946 free (command_line.rpath); 947 command_line.rpath = buf; 948 } 949 } 950 break; 951 case OPTION_RPATH_LINK: 952 if (command_line.rpath_link == NULL) 953 command_line.rpath_link = xstrdup (optarg); 954 else 955 { 956 char *buf; 957 958 buf = xmalloc (strlen (command_line.rpath_link) 959 + strlen (optarg) 960 + 2); 961 sprintf (buf, "%s:%s", command_line.rpath_link, optarg); 962 free (command_line.rpath_link); 963 command_line.rpath_link = buf; 964 } 965 break; 966 case OPTION_RELAX: 967 command_line.relax = TRUE; 968 break; 969 case OPTION_RETAIN_SYMBOLS_FILE: 970 add_keepsyms_file (optarg); 971 break; 972 case 'S': 973 link_info.strip = strip_debugger; 974 break; 975 case 's': 976 link_info.strip = strip_all; 977 break; 978 case OPTION_STRIP_DISCARDED: 979 link_info.strip_discarded = TRUE; 980 break; 981 case OPTION_NO_STRIP_DISCARDED: 982 link_info.strip_discarded = FALSE; 983 break; 984 case OPTION_SHARED: 985 if (config.has_shared) 986 { 987 link_info.shared = TRUE; 988 /* When creating a shared library, the default 989 behaviour is to ignore any unresolved references. */ 990 if (link_info.unresolved_syms_in_objects == RM_NOT_YET_SET) 991 link_info.unresolved_syms_in_objects = RM_IGNORE; 992 if (link_info.unresolved_syms_in_shared_libs == RM_NOT_YET_SET) 993 link_info.unresolved_syms_in_shared_libs = RM_IGNORE; 994 } 995 else 996 einfo (_("%P%F: -shared not supported\n")); 997 break; 998 case OPTION_PIE: 999 if (config.has_shared) 1000 { 1001 link_info.shared = TRUE; 1002 link_info.pie = TRUE; 1003 } 1004 else 1005 einfo (_("%P%F: -pie not supported\n")); 1006 break; 1007 case 'h': /* Used on Solaris. */ 1008 case OPTION_SONAME: 1009 command_line.soname = optarg; 1010 break; 1011 case OPTION_SORT_COMMON: 1012 config.sort_common = TRUE; 1013 break; 1014 case OPTION_STATS: 1015 config.stats = TRUE; 1016 break; 1017 case OPTION_SYMBOLIC: 1018 link_info.symbolic = TRUE; 1019 break; 1020 case 't': 1021 trace_files = TRUE; 1022 break; 1023 case 'T': 1024 ldfile_open_command_file (optarg); 1025 parser_input = input_script; 1026 yyparse (); 1027 break; 1028 case OPTION_SECTION_START: 1029 { 1030 char *optarg2; 1031 char *sec_name; 1032 int len; 1033 1034 /* Check for <something>=<somthing>... */ 1035 optarg2 = strchr (optarg, '='); 1036 if (optarg2 == NULL) 1037 einfo (_("%P%F: invalid argument to option \"--section-start\"\n")); 1038 1039 optarg2++; 1040 1041 /* So far so good. Are all the args present? */ 1042 if ((*optarg == '\0') || (*optarg2 == '\0')) 1043 einfo (_("%P%F: missing argument(s) to option \"--section-start\"\n")); 1044 1045 /* We must copy the section name as set_section_start 1046 doesn't do it for us. */ 1047 len = optarg2 - optarg; 1048 sec_name = xmalloc (len); 1049 memcpy (sec_name, optarg, len - 1); 1050 sec_name[len - 1] = 0; 1051 1052 /* Then set it... */ 1053 set_section_start (sec_name, optarg2); 1054 } 1055 break; 1056 case OPTION_TARGET_HELP: 1057 /* Mention any target specific options. */ 1058 ldemul_list_emulation_options (stdout); 1059 exit (0); 1060 case OPTION_TBSS: 1061 set_section_start (".bss", optarg); 1062 break; 1063 case OPTION_TDATA: 1064 set_section_start (".data", optarg); 1065 break; 1066 case OPTION_TTEXT: 1067 set_section_start (".text", optarg); 1068 break; 1069 case OPTION_TRADITIONAL_FORMAT: 1070 link_info.traditional_format = TRUE; 1071 break; 1072 case OPTION_TASK_LINK: 1073 link_info.task_link = TRUE; 1074 /* Fall through - do an implied -r option. */ 1075 case OPTION_UR: 1076 link_info.relocatable = TRUE; 1077 config.build_constructors = TRUE; 1078 config.magic_demand_paged = FALSE; 1079 config.text_read_only = FALSE; 1080 config.dynamic_link = FALSE; 1081 break; 1082 case 'u': 1083 ldlang_add_undef (optarg); 1084 break; 1085 case OPTION_UNIQUE: 1086 if (optarg != NULL) 1087 lang_add_unique (optarg); 1088 else 1089 config.unique_orphan_sections = TRUE; 1090 break; 1091 case OPTION_VERBOSE: 1092 ldversion (1); 1093 version_printed = TRUE; 1094 trace_file_tries = TRUE; 1095 overflow_cutoff_limit = -2; 1096 break; 1097 case 'v': 1098 ldversion (0); 1099 version_printed = TRUE; 1100 break; 1101 case 'V': 1102 ldversion (1); 1103 version_printed = TRUE; 1104 break; 1105 case OPTION_VERSION: 1106 ldversion (2); 1107 xexit (0); 1108 break; 1109 case OPTION_VERSION_SCRIPT: 1110 /* This option indicates a small script that only specifies 1111 version information. Read it, but don't assume that 1112 we've seen a linker script. */ 1113 { 1114 FILE *hold_script_handle; 1115 1116 hold_script_handle = saved_script_handle; 1117 ldfile_open_command_file (optarg); 1118 saved_script_handle = hold_script_handle; 1119 parser_input = input_version_script; 1120 yyparse (); 1121 } 1122 break; 1123 case OPTION_VERSION_EXPORTS_SECTION: 1124 /* This option records a version symbol to be applied to the 1125 symbols listed for export to be found in the object files 1126 .exports sections. */ 1127 command_line.version_exports_section = optarg; 1128 break; 1129 case OPTION_WARN_COMMON: 1130 config.warn_common = TRUE; 1131 break; 1132 case OPTION_WARN_CONSTRUCTORS: 1133 config.warn_constructors = TRUE; 1134 break; 1135 case OPTION_WARN_FATAL: 1136 config.fatal_warnings = TRUE; 1137 break; 1138 case OPTION_WARN_MULTIPLE_GP: 1139 config.warn_multiple_gp = TRUE; 1140 break; 1141 case OPTION_WARN_ONCE: 1142 config.warn_once = TRUE; 1143 break; 1144 case OPTION_WARN_SECTION_ALIGN: 1145 config.warn_section_align = TRUE; 1146 break; 1147 case OPTION_WHOLE_ARCHIVE: 1148 whole_archive = TRUE; 1149 break; 1150 case OPTION_AS_NEEDED: 1151 as_needed = TRUE; 1152 break; 1153 case OPTION_NO_AS_NEEDED: 1154 as_needed = FALSE; 1155 break; 1156 case OPTION_WRAP: 1157 add_wrap (optarg); 1158 break; 1159 case OPTION_DISCARD_NONE: 1160 link_info.discard = discard_none; 1161 break; 1162 case 'X': 1163 link_info.discard = discard_l; 1164 break; 1165 case 'x': 1166 link_info.discard = discard_all; 1167 break; 1168 case 'Y': 1169 if (strncmp (optarg, "P,", 2) == 0) 1170 optarg += 2; 1171 if (default_dirlist != NULL) 1172 free (default_dirlist); 1173 default_dirlist = xstrdup (optarg); 1174 break; 1175 case 'y': 1176 add_ysym (optarg); 1177 break; 1178 case 'Z': 1179 config.data_bss_contig = TRUE; 1180 break; 1181 case OPTION_SPARE_DYNAMIC_TAGS: 1182 link_info.spare_dynamic_tags = strtoul (optarg, NULL, 0); 1183 break; 1184 case OPTION_SPLIT_BY_RELOC: 1185 if (optarg != NULL) 1186 config.split_by_reloc = strtoul (optarg, NULL, 0); 1187 else 1188 config.split_by_reloc = 32768; 1189 break; 1190 case OPTION_SPLIT_BY_FILE: 1191 if (optarg != NULL) 1192 config.split_by_file = bfd_scan_vma (optarg, NULL, 0); 1193 else 1194 config.split_by_file = 1; 1195 break; 1196 case OPTION_CHECK_SECTIONS: 1197 command_line.check_section_addresses = TRUE; 1198 break; 1199 case OPTION_NO_CHECK_SECTIONS: 1200 command_line.check_section_addresses = FALSE; 1201 break; 1202 case OPTION_ACCEPT_UNKNOWN_INPUT_ARCH: 1203 command_line.accept_unknown_input_arch = TRUE; 1204 break; 1205 case OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH: 1206 command_line.accept_unknown_input_arch = FALSE; 1207 break; 1208 case '(': 1209 if (ingroup) 1210 einfo (_("%P%F: may not nest groups (--help for usage)\n")); 1211 1212 lang_enter_group (); 1213 ingroup = 1; 1214 break; 1215 case ')': 1216 if (! ingroup) 1217 einfo (_("%P%F: group ended before it began (--help for usage)\n")); 1218 1219 lang_leave_group (); 1220 ingroup = 0; 1221 break; 1222 1223 case OPTION_INIT: 1224 link_info.init_function = optarg; 1225 break; 1226 1227 case OPTION_FINI: 1228 link_info.fini_function = optarg; 1229 break; 1230 } 1231 } 1232 1233 if (ingroup) 1234 lang_leave_group (); 1235 1236 if (default_dirlist != NULL) 1237 { 1238 set_default_dirlist (default_dirlist); 1239 free (default_dirlist); 1240 } 1241 1242 if (link_info.unresolved_syms_in_objects == RM_NOT_YET_SET) 1243 /* FIXME: Should we allow emulations a chance to set this ? */ 1244 link_info.unresolved_syms_in_objects = how_to_report_unresolved_symbols; 1245 1246 if (link_info.unresolved_syms_in_shared_libs == RM_NOT_YET_SET) 1247 /* FIXME: Should we allow emulations a chance to set this ? */ 1248 link_info.unresolved_syms_in_shared_libs = how_to_report_unresolved_symbols; 1249 } 1250 1251 /* Add the (colon-separated) elements of DIRLIST_PTR to the 1252 library search path. */ 1253 1254 static void 1255 set_default_dirlist (char *dirlist_ptr) 1256 { 1257 char *p; 1258 1259 while (1) 1260 { 1261 p = strchr (dirlist_ptr, PATH_SEPARATOR); 1262 if (p != NULL) 1263 *p = '\0'; 1264 if (*dirlist_ptr != '\0') 1265 ldfile_add_library_path (dirlist_ptr, TRUE); 1266 if (p == NULL) 1267 break; 1268 dirlist_ptr = p + 1; 1269 } 1270 } 1271 1272 static void 1273 set_section_start (char *sect, char *valstr) 1274 { 1275 const char *end; 1276 bfd_vma val = bfd_scan_vma (valstr, &end, 16); 1277 if (*end) 1278 einfo (_("%P%F: invalid hex number `%s'\n"), valstr); 1279 lang_section_start (sect, exp_intop (val)); 1280 } 1281 1282 /* Print help messages for the options. */ 1283 1284 static void 1285 help (void) 1286 { 1287 unsigned i; 1288 const char **targets, **pp; 1289 1290 printf (_("Usage: %s [options] file...\n"), program_name); 1291 1292 printf (_("Options:\n")); 1293 for (i = 0; i < OPTION_COUNT; i++) 1294 { 1295 if (ld_options[i].doc != NULL) 1296 { 1297 bfd_boolean comma; 1298 int len; 1299 unsigned j; 1300 1301 printf (" "); 1302 1303 comma = FALSE; 1304 len = 2; 1305 1306 j = i; 1307 do 1308 { 1309 if (ld_options[j].shortopt != '\0' 1310 && ld_options[j].control != NO_HELP) 1311 { 1312 printf ("%s-%c", comma ? ", " : "", ld_options[j].shortopt); 1313 len += (comma ? 2 : 0) + 2; 1314 if (ld_options[j].arg != NULL) 1315 { 1316 if (ld_options[j].opt.has_arg != optional_argument) 1317 { 1318 printf (" "); 1319 ++len; 1320 } 1321 printf ("%s", _(ld_options[j].arg)); 1322 len += strlen (_(ld_options[j].arg)); 1323 } 1324 comma = TRUE; 1325 } 1326 ++j; 1327 } 1328 while (j < OPTION_COUNT && ld_options[j].doc == NULL); 1329 1330 j = i; 1331 do 1332 { 1333 if (ld_options[j].opt.name != NULL 1334 && ld_options[j].control != NO_HELP) 1335 { 1336 int two_dashes = 1337 (ld_options[j].control == TWO_DASHES 1338 || ld_options[j].control == EXACTLY_TWO_DASHES); 1339 1340 printf ("%s-%s%s", 1341 comma ? ", " : "", 1342 two_dashes ? "-" : "", 1343 ld_options[j].opt.name); 1344 len += ((comma ? 2 : 0) 1345 + 1 1346 + (two_dashes ? 1 : 0) 1347 + strlen (ld_options[j].opt.name)); 1348 if (ld_options[j].arg != NULL) 1349 { 1350 printf (" %s", _(ld_options[j].arg)); 1351 len += 1 + strlen (_(ld_options[j].arg)); 1352 } 1353 comma = TRUE; 1354 } 1355 ++j; 1356 } 1357 while (j < OPTION_COUNT && ld_options[j].doc == NULL); 1358 1359 if (len >= 30) 1360 { 1361 printf ("\n"); 1362 len = 0; 1363 } 1364 1365 for (; len < 30; len++) 1366 putchar (' '); 1367 1368 printf ("%s\n", _(ld_options[i].doc)); 1369 } 1370 } 1371 1372 /* Note: Various tools (such as libtool) depend upon the 1373 format of the listings below - do not change them. */ 1374 /* xgettext:c-format */ 1375 printf (_("%s: supported targets:"), program_name); 1376 targets = bfd_target_list (); 1377 for (pp = targets; *pp != NULL; pp++) 1378 printf (" %s", *pp); 1379 free (targets); 1380 printf ("\n"); 1381 1382 /* xgettext:c-format */ 1383 printf (_("%s: supported emulations: "), program_name); 1384 ldemul_list_emulations (stdout); 1385 printf ("\n"); 1386 1387 /* xgettext:c-format */ 1388 printf (_("%s: emulation specific options:\n"), program_name); 1389 ldemul_list_emulation_options (stdout); 1390 printf ("\n"); 1391 1392 printf (_("Report bugs to %s\n"), REPORT_BUGS_TO); 1393 } 1394