00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "bfd.h"
00032 #include "sysdep.h"
00033 #include "libiberty.h"
00034 #include <stdio.h>
00035 #include <string.h>
00036 #include "safe-ctype.h"
00037 #include "getopt.h"
00038 #include "bfdlink.h"
00039 #include "ld.h"
00040 #include "ldmain.h"
00041 #include "ldmisc.h"
00042 #include "ldexp.h"
00043 #include "ldlang.h"
00044 #include <ldgram.h>
00045 #include "ldlex.h"
00046 #include "ldfile.h"
00047 #include "ldver.h"
00048 #include "ldemul.h"
00049 #include "demangle.h"
00050 #ifdef KEY
00051 #include "ipa_ld.h"
00052 #endif
00053
00054 #ifndef PATH_SEPARATOR
00055 #if defined (__MSDOS__) || (defined (_WIN32) && ! defined (__CYGWIN32__))
00056 #define PATH_SEPARATOR ';'
00057 #else
00058 #define PATH_SEPARATOR ':'
00059 #endif
00060 #endif
00061
00062
00063 #if !defined(S_ISDIR) && defined(S_IFDIR)
00064 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
00065 #endif
00066
00067 static void set_default_dirlist (char *);
00068 static void set_section_start (char *, char *);
00069 static void set_segment_start (const char *, char *);
00070 static void help (void);
00071
00072
00073 int parsing_defsym = 0;
00074
00075
00076
00077 enum option_values
00078 {
00079 OPTION_ASSERT = 150,
00080 OPTION_CALL_SHARED,
00081 OPTION_CREF,
00082 OPTION_DEFSYM,
00083 OPTION_DEMANGLE,
00084 OPTION_DYNAMIC_LINKER,
00085 OPTION_SYSROOT,
00086 OPTION_EB,
00087 OPTION_EL,
00088 OPTION_EMBEDDED_RELOCS,
00089 OPTION_EXPORT_DYNAMIC,
00090 OPTION_HELP,
00091 OPTION_IGNORE,
00092 OPTION_MAP,
00093 OPTION_NO_DEMANGLE,
00094 OPTION_NO_KEEP_MEMORY,
00095 OPTION_NO_WARN_MISMATCH,
00096 OPTION_NOINHIBIT_EXEC,
00097 OPTION_NON_SHARED,
00098 OPTION_NO_WHOLE_ARCHIVE,
00099 OPTION_OFORMAT,
00100 OPTION_RELAX,
00101 OPTION_RETAIN_SYMBOLS_FILE,
00102 OPTION_RPATH,
00103 OPTION_RPATH_LINK,
00104 OPTION_SHARED,
00105 OPTION_SONAME,
00106 OPTION_SORT_COMMON,
00107 OPTION_SORT_SECTION,
00108 OPTION_STATS,
00109 OPTION_SYMBOLIC,
00110 OPTION_TASK_LINK,
00111 OPTION_TBSS,
00112 OPTION_TDATA,
00113 OPTION_TTEXT,
00114 OPTION_TRADITIONAL_FORMAT,
00115 OPTION_UR,
00116 OPTION_VERBOSE,
00117 OPTION_VERSION,
00118 OPTION_VERSION_SCRIPT,
00119 OPTION_VERSION_EXPORTS_SECTION,
00120 OPTION_WARN_COMMON,
00121 OPTION_WARN_CONSTRUCTORS,
00122 OPTION_WARN_FATAL,
00123 OPTION_WARN_MULTIPLE_GP,
00124 OPTION_WARN_ONCE,
00125 OPTION_WARN_SECTION_ALIGN,
00126 OPTION_SPLIT_BY_RELOC,
00127 OPTION_SPLIT_BY_FILE ,
00128 OPTION_WHOLE_ARCHIVE,
00129 OPTION_ADD_NEEDED,
00130 OPTION_NO_ADD_NEEDED,
00131 OPTION_AS_NEEDED,
00132 OPTION_NO_AS_NEEDED,
00133 OPTION_WRAP,
00134 OPTION_FORCE_EXE_SUFFIX,
00135 OPTION_GC_SECTIONS,
00136 OPTION_NO_GC_SECTIONS,
00137 OPTION_HASH_SIZE,
00138 OPTION_CHECK_SECTIONS,
00139 OPTION_NO_CHECK_SECTIONS,
00140 OPTION_NO_UNDEFINED,
00141 OPTION_INIT,
00142 OPTION_FINI,
00143 OPTION_SECTION_START,
00144 OPTION_UNIQUE,
00145 OPTION_TARGET_HELP,
00146 OPTION_ALLOW_SHLIB_UNDEFINED,
00147 OPTION_NO_ALLOW_SHLIB_UNDEFINED,
00148 OPTION_ALLOW_MULTIPLE_DEFINITION,
00149 OPTION_NO_UNDEFINED_VERSION,
00150 OPTION_DEFAULT_SYMVER,
00151 OPTION_DEFAULT_IMPORTED_SYMVER,
00152 OPTION_DISCARD_NONE,
00153 OPTION_SPARE_DYNAMIC_TAGS,
00154 OPTION_NO_DEFINE_COMMON,
00155 OPTION_NOSTDLIB,
00156 OPTION_NO_OMAGIC,
00157 OPTION_STRIP_DISCARDED,
00158 OPTION_NO_STRIP_DISCARDED,
00159 OPTION_ACCEPT_UNKNOWN_INPUT_ARCH,
00160 OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH,
00161 OPTION_PIE,
00162 OPTION_UNRESOLVED_SYMBOLS,
00163 OPTION_WARN_UNRESOLVED_SYMBOLS,
00164 OPTION_ERROR_UNRESOLVED_SYMBOLS,
00165 OPTION_WARN_SHARED_TEXTREL,
00166 OPTION_REDUCE_MEMORY_OVERHEADS,
00167 #ifdef IPA_LINK
00168 OPTION_KEEP,
00169 OPTION_SHOW,
00170 OPTION_IPA,
00171 OPTION_DEFAULT_GROUP,
00172 OPTION_IPA_GROUP,
00173 OPTION_INLINE_GROUP,
00174 OPTION_INTERNAL_GROUP,
00175 OPTION_AR_MEMBERS,
00176 OPTION_IPACOM,
00177 OPTION_OPT_GROUP,
00178 OPTION_TENV_GROUP,
00179 OPTION_LINKER_ONLY,
00180 #endif
00181 };
00182
00183
00184
00185
00186 struct ld_option
00187 {
00188
00189 struct option opt;
00190
00191 char shortopt;
00192
00193 const char *arg;
00194
00195
00196 const char *doc;
00197 enum {
00198
00199 ONE_DASH,
00200
00201 TWO_DASHES,
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211 EXACTLY_TWO_DASHES,
00212
00213 NO_HELP
00214 } control;
00215 };
00216
00217 static const struct ld_option ld_options[] =
00218 {
00219 { {NULL, required_argument, NULL, '\0'},
00220 'a', N_("KEYWORD"), N_("Shared library control for HP/UX compatibility"),
00221 ONE_DASH },
00222 { {"architecture", required_argument, NULL, 'A'},
00223 'A', N_("ARCH"), N_("Set architecture") , TWO_DASHES },
00224 { {"format", required_argument, NULL, 'b'},
00225 'b', N_("TARGET"), N_("Specify target for following input files"),
00226 TWO_DASHES },
00227 { {"mri-script", required_argument, NULL, 'c'},
00228 'c', N_("FILE"), N_("Read MRI format linker script"), TWO_DASHES },
00229 { {"dc", no_argument, NULL, 'd'},
00230 'd', NULL, N_("Force common symbols to be defined"), ONE_DASH },
00231 { {"dp", no_argument, NULL, 'd'},
00232 '\0', NULL, NULL, ONE_DASH },
00233 { {"entry", required_argument, NULL, 'e'},
00234 'e', N_("ADDRESS"), N_("Set start address"), TWO_DASHES },
00235 { {"export-dynamic", no_argument, NULL, OPTION_EXPORT_DYNAMIC},
00236 'E', NULL, N_("Export all dynamic symbols"), TWO_DASHES },
00237 { {"EB", no_argument, NULL, OPTION_EB},
00238 '\0', NULL, N_("Link big-endian objects"), ONE_DASH },
00239 { {"EL", no_argument, NULL, OPTION_EL},
00240 '\0', NULL, N_("Link little-endian objects"), ONE_DASH },
00241 { {"auxiliary", required_argument, NULL, 'f'},
00242 'f', N_("SHLIB"), N_("Auxiliary filter for shared object symbol table"),
00243 TWO_DASHES },
00244 { {"filter", required_argument, NULL, 'F'},
00245 'F', N_("SHLIB"), N_("Filter for shared object symbol table"),
00246 TWO_DASHES },
00247 { {NULL, no_argument, NULL, '\0'},
00248 'g', NULL, N_("Ignored"), ONE_DASH },
00249 { {"gpsize", required_argument, NULL, 'G'},
00250 'G', N_("SIZE"), N_("Small data size (if no size, same as --shared)"),
00251 TWO_DASHES },
00252 { {"soname", required_argument, NULL, OPTION_SONAME},
00253 'h', N_("FILENAME"), N_("Set internal name of shared library"), ONE_DASH },
00254 { {"dynamic-linker", required_argument, NULL, OPTION_DYNAMIC_LINKER},
00255 'I', N_("PROGRAM"), N_("Set PROGRAM as the dynamic linker to use"),
00256 TWO_DASHES },
00257 { {"library", required_argument, NULL, 'l'},
00258 'l', N_("LIBNAME"), N_("Search for library LIBNAME"), TWO_DASHES },
00259 { {"library-path", required_argument, NULL, 'L'},
00260 'L', N_("DIRECTORY"), N_("Add DIRECTORY to library search path"),
00261 TWO_DASHES },
00262 { {"sysroot=<DIRECTORY>", required_argument, NULL, OPTION_SYSROOT},
00263 '\0', NULL, N_("Override the default sysroot location"), TWO_DASHES },
00264 { {NULL, required_argument, NULL, '\0'},
00265 'm', N_("EMULATION"), N_("Set emulation"), ONE_DASH },
00266 { {"print-map", no_argument, NULL, 'M'},
00267 'M', NULL, N_("Print map file on standard output"), TWO_DASHES },
00268 { {"nmagic", no_argument, NULL, 'n'},
00269 'n', NULL, N_("Do not page align data"), TWO_DASHES },
00270 { {"omagic", no_argument, NULL, 'N'},
00271 'N', NULL, N_("Do not page align data, do not make text readonly"),
00272 EXACTLY_TWO_DASHES },
00273 { {"no-omagic", no_argument, NULL, OPTION_NO_OMAGIC},
00274 '\0', NULL, N_("Page align data, make text readonly"),
00275 EXACTLY_TWO_DASHES },
00276 { {"output", required_argument, NULL, 'o'},
00277 'o', N_("FILE"), N_("Set output file name"), EXACTLY_TWO_DASHES },
00278 { {NULL, required_argument, NULL, '\0'},
00279 'O', NULL, N_("Optimize output file"), ONE_DASH },
00280 { {"Qy", no_argument, NULL, OPTION_IGNORE},
00281 '\0', NULL, N_("Ignored for SVR4 compatibility"), ONE_DASH },
00282 { {"emit-relocs", no_argument, NULL, 'q'},
00283 'q', NULL, "Generate relocations in final output", TWO_DASHES },
00284 { {"relocatable", no_argument, NULL, 'r'},
00285 'r', NULL, N_("Generate relocatable output"), TWO_DASHES },
00286 { {NULL, no_argument, NULL, '\0'},
00287 'i', NULL, NULL, ONE_DASH },
00288 { {"just-symbols", required_argument, NULL, 'R'},
00289 'R', N_("FILE"), N_("Just link symbols (if directory, same as --rpath)"),
00290 TWO_DASHES },
00291 { {"strip-all", no_argument, NULL, 's'},
00292 's', NULL, N_("Strip all symbols"), TWO_DASHES },
00293 { {"strip-debug", no_argument, NULL, 'S'},
00294 'S', NULL, N_("Strip debugging symbols"), TWO_DASHES },
00295 { {"strip-discarded", no_argument, NULL, OPTION_STRIP_DISCARDED},
00296 '\0', NULL, N_("Strip symbols in discarded sections"), TWO_DASHES },
00297 { {"no-strip-discarded", no_argument, NULL, OPTION_NO_STRIP_DISCARDED},
00298 '\0', NULL, N_("Do not strip symbols in discarded sections"), TWO_DASHES },
00299 { {"trace", no_argument, NULL, 't'},
00300 't', NULL, N_("Trace file opens"), TWO_DASHES },
00301 { {"script", required_argument, NULL, 'T'},
00302 'T', N_("FILE"), N_("Read linker script"), TWO_DASHES },
00303 { {"undefined", required_argument, NULL, 'u'},
00304 'u', N_("SYMBOL"), N_("Start with undefined reference to SYMBOL"),
00305 TWO_DASHES },
00306 { {"unique", optional_argument, NULL, OPTION_UNIQUE},
00307 '\0', N_("[=SECTION]"),
00308 N_("Don't merge input [SECTION | orphan] sections"), TWO_DASHES },
00309 { {"Ur", no_argument, NULL, OPTION_UR},
00310 '\0', NULL, N_("Build global constructor/destructor tables"), ONE_DASH },
00311 { {"version", no_argument, NULL, OPTION_VERSION},
00312 'v', NULL, N_("Print version information"), TWO_DASHES },
00313 { {NULL, no_argument, NULL, '\0'},
00314 'V', NULL, N_("Print version and emulation information"), ONE_DASH },
00315 { {"discard-all", no_argument, NULL, 'x'},
00316 'x', NULL, N_("Discard all local symbols"), TWO_DASHES },
00317 { {"discard-locals", no_argument, NULL, 'X'},
00318 'X', NULL, N_("Discard temporary local symbols (default)"), TWO_DASHES },
00319 { {"discard-none", no_argument, NULL, OPTION_DISCARD_NONE},
00320 '\0', NULL, N_("Don't discard any local symbols"), TWO_DASHES },
00321 { {"trace-symbol", required_argument, NULL, 'y'},
00322 'y', N_("SYMBOL"), N_("Trace mentions of SYMBOL"), TWO_DASHES },
00323 { {NULL, required_argument, NULL, '\0'},
00324 'Y', N_("PATH"), N_("Default search path for Solaris compatibility"),
00325 ONE_DASH },
00326 { {"start-group", no_argument, NULL, '('},
00327 '(', NULL, N_("Start a group"), TWO_DASHES },
00328 { {"end-group", no_argument, NULL, ')'},
00329 ')', NULL, N_("End a group"), TWO_DASHES },
00330 { {"accept-unknown-input-arch", no_argument, NULL,
00331 OPTION_ACCEPT_UNKNOWN_INPUT_ARCH},
00332 '\0', NULL,
00333 N_("Accept input files whose architecture cannot be determined"),
00334 TWO_DASHES },
00335 { {"no-accept-unknown-input-arch", no_argument, NULL,
00336 OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH},
00337 '\0', NULL, N_("Reject input files whose architecture is unknown"),
00338 TWO_DASHES },
00339 { {"add-needed", no_argument, NULL, OPTION_ADD_NEEDED},
00340 '\0', NULL, N_("Set DT_NEEDED tags for DT_NEEDED entries in\n"
00341 "\t\t\t\tfollowing dynamic libs"), TWO_DASHES },
00342 { {"no-add-needed", no_argument, NULL, OPTION_NO_ADD_NEEDED},
00343 '\0', NULL, N_("Do not set DT_NEEDED tags for DT_NEEDED entries\n"
00344 "\t\t\t\tin following dynamic libs"), TWO_DASHES },
00345 { {"as-needed", no_argument, NULL, OPTION_AS_NEEDED},
00346 '\0', NULL, N_("Only set DT_NEEDED for following dynamic libs if used"),
00347 TWO_DASHES },
00348 { {"no-as-needed", no_argument, NULL, OPTION_NO_AS_NEEDED},
00349 '\0', NULL, N_("Always set DT_NEEDED for following dynamic libs"),
00350 TWO_DASHES },
00351 { {"assert", required_argument, NULL, OPTION_ASSERT},
00352 '\0', N_("KEYWORD"), N_("Ignored for SunOS compatibility"), ONE_DASH },
00353 { {"Bdynamic", no_argument, NULL, OPTION_CALL_SHARED},
00354 '\0', NULL, N_("Link against shared libraries"), ONE_DASH },
00355 { {"dy", no_argument, NULL, OPTION_CALL_SHARED},
00356 '\0', NULL, NULL, ONE_DASH },
00357 { {"call_shared", no_argument, NULL, OPTION_CALL_SHARED},
00358 '\0', NULL, NULL, ONE_DASH },
00359 { {"Bstatic", no_argument, NULL, OPTION_NON_SHARED},
00360 '\0', NULL, N_("Do not link against shared libraries"), ONE_DASH },
00361 { {"dn", no_argument, NULL, OPTION_NON_SHARED},
00362 '\0', NULL, NULL, ONE_DASH },
00363 { {"non_shared", no_argument, NULL, OPTION_NON_SHARED},
00364 '\0', NULL, NULL, ONE_DASH },
00365 { {"static", no_argument, NULL, OPTION_NON_SHARED},
00366 '\0', NULL, NULL, ONE_DASH },
00367 { {"Bsymbolic", no_argument, NULL, OPTION_SYMBOLIC},
00368 '\0', NULL, N_("Bind global references locally"), ONE_DASH },
00369 { {"check-sections", no_argument, NULL, OPTION_CHECK_SECTIONS},
00370 '\0', NULL, N_("Check section addresses for overlaps (default)"),
00371 TWO_DASHES },
00372 { {"no-check-sections", no_argument, NULL, OPTION_NO_CHECK_SECTIONS},
00373 '\0', NULL, N_("Do not check section addresses for overlaps"),
00374 TWO_DASHES },
00375 { {"cref", no_argument, NULL, OPTION_CREF},
00376 '\0', NULL, N_("Output cross reference table"), TWO_DASHES },
00377 { {"defsym", required_argument, NULL, OPTION_DEFSYM},
00378 '\0', N_("SYMBOL=EXPRESSION"), N_("Define a symbol"), TWO_DASHES },
00379 { {"demangle", optional_argument, NULL, OPTION_DEMANGLE},
00380 '\0', N_("[=STYLE]"), N_("Demangle symbol names [using STYLE]"),
00381 TWO_DASHES },
00382 { {"embedded-relocs", no_argument, NULL, OPTION_EMBEDDED_RELOCS},
00383 '\0', NULL, N_("Generate embedded relocs"), TWO_DASHES},
00384 { {"fatal-warnings", no_argument, NULL, OPTION_WARN_FATAL},
00385 '\0', NULL, N_("Treat warnings as errors"),
00386 TWO_DASHES },
00387 { {"fini", required_argument, NULL, OPTION_FINI},
00388 '\0', N_("SYMBOL"), N_("Call SYMBOL at unload-time"), ONE_DASH },
00389 { {"force-exe-suffix", no_argument, NULL, OPTION_FORCE_EXE_SUFFIX},
00390 '\0', NULL, N_("Force generation of file with .exe suffix"), TWO_DASHES},
00391 { {"gc-sections", no_argument, NULL, OPTION_GC_SECTIONS},
00392 '\0', NULL, N_("Remove unused sections (on some targets)"),
00393 TWO_DASHES },
00394 { {"no-gc-sections", no_argument, NULL, OPTION_NO_GC_SECTIONS},
00395 '\0', NULL, N_("Don't remove unused sections (default)"),
00396 TWO_DASHES },
00397 { {"hash-size=<NUMBER>", required_argument, NULL, OPTION_HASH_SIZE},
00398 '\0', NULL, N_("Set default hash table size close to <NUMBER>"),
00399 TWO_DASHES },
00400 { {"help", no_argument, NULL, OPTION_HELP},
00401 '\0', NULL, N_("Print option help"), TWO_DASHES },
00402 { {"init", required_argument, NULL, OPTION_INIT},
00403 '\0', N_("SYMBOL"), N_("Call SYMBOL at load-time"), ONE_DASH },
00404 { {"Map", required_argument, NULL, OPTION_MAP},
00405 '\0', N_("FILE"), N_("Write a map file"), ONE_DASH },
00406 { {"no-define-common", no_argument, NULL, OPTION_NO_DEFINE_COMMON},
00407 '\0', NULL, N_("Do not define Common storage"), TWO_DASHES },
00408 { {"no-demangle", no_argument, NULL, OPTION_NO_DEMANGLE },
00409 '\0', NULL, N_("Do not demangle symbol names"), TWO_DASHES },
00410 { {"no-keep-memory", no_argument, NULL, OPTION_NO_KEEP_MEMORY},
00411 '\0', NULL, N_("Use less memory and more disk I/O"), TWO_DASHES },
00412 { {"no-undefined", no_argument, NULL, OPTION_NO_UNDEFINED},
00413 '\0', NULL, N_("Do not allow unresolved references in object files"),
00414 TWO_DASHES },
00415 { {"allow-shlib-undefined", no_argument, NULL, OPTION_ALLOW_SHLIB_UNDEFINED},
00416 '\0', NULL, N_("Allow unresolved references in shared libaries"),
00417 TWO_DASHES },
00418 { {"no-allow-shlib-undefined", no_argument, NULL,
00419 OPTION_NO_ALLOW_SHLIB_UNDEFINED},
00420 '\0', NULL, N_("Do not allow unresolved references in shared libs"),
00421 TWO_DASHES },
00422 { {"allow-multiple-definition", no_argument, NULL,
00423 OPTION_ALLOW_MULTIPLE_DEFINITION},
00424 '\0', NULL, N_("Allow multiple definitions"), TWO_DASHES },
00425 { {"no-undefined-version", no_argument, NULL, OPTION_NO_UNDEFINED_VERSION},
00426 '\0', NULL, N_("Disallow undefined version"), TWO_DASHES },
00427 { {"default-symver", no_argument, NULL, OPTION_DEFAULT_SYMVER},
00428 '\0', NULL, N_("Create default symbol version"), TWO_DASHES },
00429 { {"default-imported-symver", no_argument, NULL,
00430 OPTION_DEFAULT_IMPORTED_SYMVER},
00431 '\0', NULL, N_("Create default symbol version for imported symbols"),
00432 TWO_DASHES },
00433 { {"no-warn-mismatch", no_argument, NULL, OPTION_NO_WARN_MISMATCH},
00434 '\0', NULL, N_("Don't warn about mismatched input files"), TWO_DASHES},
00435 { {"no-whole-archive", no_argument, NULL, OPTION_NO_WHOLE_ARCHIVE},
00436 '\0', NULL, N_("Turn off --whole-archive"), TWO_DASHES },
00437 { {"noinhibit-exec", no_argument, NULL, OPTION_NOINHIBIT_EXEC},
00438 '\0', NULL, N_("Create an output file even if errors occur"),
00439 TWO_DASHES },
00440 { {"noinhibit_exec", no_argument, NULL, OPTION_NOINHIBIT_EXEC},
00441 '\0', NULL, NULL, NO_HELP },
00442 { {"nostdlib", no_argument, NULL, OPTION_NOSTDLIB},
00443 '\0', NULL, N_("Only use library directories specified on\n"
00444 "\t\t\t\tthe command line"), ONE_DASH },
00445 { {"oformat", required_argument, NULL, OPTION_OFORMAT},
00446 '\0', N_("TARGET"), N_("Specify target of output file"),
00447 EXACTLY_TWO_DASHES },
00448 { {"qmagic", no_argument, NULL, OPTION_IGNORE},
00449 '\0', NULL, N_("Ignored for Linux compatibility"), ONE_DASH },
00450 { {"reduce-memory-overheads", no_argument, NULL,
00451 OPTION_REDUCE_MEMORY_OVERHEADS},
00452 '\0', NULL, N_("Reduce memory overheads, possibly taking much longer"),
00453 TWO_DASHES },
00454 { {"relax", no_argument, NULL, OPTION_RELAX},
00455 '\0', NULL, N_("Relax branches on certain targets"), TWO_DASHES },
00456 { {"retain-symbols-file", required_argument, NULL,
00457 OPTION_RETAIN_SYMBOLS_FILE},
00458 '\0', N_("FILE"), N_("Keep only symbols listed in FILE"), TWO_DASHES },
00459 { {"rpath", required_argument, NULL, OPTION_RPATH},
00460 '\0', N_("PATH"), N_("Set runtime shared library search path"), ONE_DASH },
00461 { {"rpath-link", required_argument, NULL, OPTION_RPATH_LINK},
00462 '\0', N_("PATH"), N_("Set link time shared library search path"),
00463 ONE_DASH },
00464 { {"shared", no_argument, NULL, OPTION_SHARED},
00465 '\0', NULL, N_("Create a shared library"), ONE_DASH },
00466 { {"Bshareable", no_argument, NULL, OPTION_SHARED },
00467 '\0', NULL, NULL, ONE_DASH },
00468 { {"pie", no_argument, NULL, OPTION_PIE},
00469 '\0', NULL, N_("Create a position independent executable"), ONE_DASH },
00470 { {"pic-executable", no_argument, NULL, OPTION_PIE},
00471 '\0', NULL, NULL, TWO_DASHES },
00472 { {"sort-common", no_argument, NULL, OPTION_SORT_COMMON},
00473 '\0', NULL, N_("Sort common symbols by size"), TWO_DASHES },
00474 { {"sort_common", no_argument, NULL, OPTION_SORT_COMMON},
00475 '\0', NULL, NULL, NO_HELP },
00476 { {"sort-section", required_argument, NULL, OPTION_SORT_SECTION},
00477 '\0', N_("name|alignment"),
00478 N_("Sort sections by name or maximum alignment"), TWO_DASHES },
00479 { {"spare-dynamic-tags", required_argument, NULL, OPTION_SPARE_DYNAMIC_TAGS},
00480 '\0', N_("COUNT"), N_("How many tags to reserve in .dynamic section"),
00481 TWO_DASHES },
00482 { {"split-by-file", optional_argument, NULL, OPTION_SPLIT_BY_FILE},
00483 '\0', N_("[=SIZE]"), N_("Split output sections every SIZE octets"),
00484 TWO_DASHES },
00485 { {"split-by-reloc", optional_argument, NULL, OPTION_SPLIT_BY_RELOC},
00486 '\0', N_("[=COUNT]"), N_("Split output sections every COUNT relocs"),
00487 TWO_DASHES },
00488 { {"stats", no_argument, NULL, OPTION_STATS},
00489 '\0', NULL, N_("Print memory usage statistics"), TWO_DASHES },
00490 { {"target-help", no_argument, NULL, OPTION_TARGET_HELP},
00491 '\0', NULL, N_("Display target specific options"), TWO_DASHES },
00492 { {"task-link", required_argument, NULL, OPTION_TASK_LINK},
00493 '\0', N_("SYMBOL"), N_("Do task level linking"), TWO_DASHES },
00494 { {"traditional-format", no_argument, NULL, OPTION_TRADITIONAL_FORMAT},
00495 '\0', NULL, N_("Use same format as native linker"), TWO_DASHES },
00496 { {"section-start", required_argument, NULL, OPTION_SECTION_START},
00497 '\0', N_("SECTION=ADDRESS"), N_("Set address of named section"),
00498 TWO_DASHES },
00499 { {"Tbss", required_argument, NULL, OPTION_TBSS},
00500 '\0', N_("ADDRESS"), N_("Set address of .bss section"), ONE_DASH },
00501 { {"Tdata", required_argument, NULL, OPTION_TDATA},
00502 '\0', N_("ADDRESS"), N_("Set address of .data section"), ONE_DASH },
00503 { {"Ttext", required_argument, NULL, OPTION_TTEXT},
00504 '\0', N_("ADDRESS"), N_("Set address of .text section"), ONE_DASH },
00505 { {"unresolved-symbols=<method>", required_argument, NULL,
00506 OPTION_UNRESOLVED_SYMBOLS},
00507 '\0', NULL, N_("How to handle unresolved symbols. <method> is:\n"
00508 "\t\t\t\tignore-all, report-all, ignore-in-object-files,\n"
00509 "\t\t\t\tignore-in-shared-libs"), TWO_DASHES },
00510 { {"verbose", no_argument, NULL, OPTION_VERBOSE},
00511 '\0', NULL, N_("Output lots of information during link"), TWO_DASHES },
00512 { {"dll-verbose", no_argument, NULL, OPTION_VERBOSE},
00513 '\0', NULL, NULL, NO_HELP },
00514 { {"version-script", required_argument, NULL, OPTION_VERSION_SCRIPT },
00515 '\0', N_("FILE"), N_("Read version information script"), TWO_DASHES },
00516 { {"version-exports-section", required_argument, NULL,
00517 OPTION_VERSION_EXPORTS_SECTION },
00518 '\0', N_("SYMBOL"), N_("Take export symbols list from .exports, using\n"
00519 "\t\t\t\tSYMBOL as the version."), TWO_DASHES },
00520 { {"warn-common", no_argument, NULL, OPTION_WARN_COMMON},
00521 '\0', NULL, N_("Warn about duplicate common symbols"), TWO_DASHES },
00522 { {"warn-constructors", no_argument, NULL, OPTION_WARN_CONSTRUCTORS},
00523 '\0', NULL, N_("Warn if global constructors/destructors are seen"),
00524 TWO_DASHES },
00525 { {"warn-multiple-gp", no_argument, NULL, OPTION_WARN_MULTIPLE_GP},
00526 '\0', NULL, N_("Warn if the multiple GP values are used"), TWO_DASHES },
00527 { {"warn-once", no_argument, NULL, OPTION_WARN_ONCE},
00528 '\0', NULL, N_("Warn only once per undefined symbol"), TWO_DASHES },
00529 { {"warn-section-align", no_argument, NULL, OPTION_WARN_SECTION_ALIGN},
00530 '\0', NULL, N_("Warn if start of section changes due to alignment"),
00531 TWO_DASHES },
00532 { {"warn-shared-textrel", no_argument, NULL, OPTION_WARN_SHARED_TEXTREL},
00533 '\0', NULL, N_("Warn if shared object has DT_TEXTREL"),
00534 TWO_DASHES },
00535 { {"warn-unresolved-symbols", no_argument, NULL,
00536 OPTION_WARN_UNRESOLVED_SYMBOLS},
00537 '\0', NULL, N_("Report unresolved symbols as warnings"), TWO_DASHES },
00538 { {"error-unresolved-symbols", no_argument, NULL,
00539 OPTION_ERROR_UNRESOLVED_SYMBOLS},
00540 '\0', NULL, N_("Report unresolved symbols as errors"), TWO_DASHES },
00541 { {"whole-archive", no_argument, NULL, OPTION_WHOLE_ARCHIVE},
00542 '\0', NULL, N_("Include all objects from following archives"),
00543 TWO_DASHES },
00544 { {"wrap", required_argument, NULL, OPTION_WRAP},
00545 '\0', N_("SYMBOL"), N_("Use wrapper functions for SYMBOL"), TWO_DASHES },
00546 #ifdef IPA_LINK
00547 { {"ipa", no_argument, NULL, OPTION_IPA},
00548 '\0', NULL, N_("Use Inter Process Analysis"), TWO_DASHES },
00549 { {"show", no_argument, NULL, OPTION_SHOW},
00550 '\0', NULL, N_("If IPA then show phases, otherwise unused"), ONE_DASH },
00551 { {"keep", no_argument, NULL, OPTION_KEEP},
00552 '\0', NULL, N_("Don't delete intermediate files"), TWO_DASHES },
00553 { {"DEFAULT", no_argument, NULL, OPTION_DEFAULT_GROUP},
00554 '\0', NULL, N_("Message about xxxxxx"), TWO_DASHES },
00555 { {"IPA:", no_argument, NULL, OPTION_IPA_GROUP},
00556 '\0', NULL, N_("Options passed to IPA"), TWO_DASHES },
00557 { {"INLINE:", no_argument, NULL, OPTION_INLINE_GROUP},
00558 '\0', NULL, N_("Options passed to inliner during ipa phase"), TWO_DASHES },
00559 { {"INTERNAL:", no_argument, NULL, OPTION_INTERNAL_GROUP},
00560 '\0', NULL, N_("Non-user options passed to the backend during ipa phase"),
00561 TWO_DASHES },
00562 { {"ar_members", required_argument, NULL, OPTION_AR_MEMBERS},
00563 '\0', NULL, N_("Designates specific objects within an archive"), TWO_DASHES },
00564 { {"ipacom", no_argument, NULL, OPTION_IPACOM},
00565 '\0', NULL, N_("Message about xxxxxx"), TWO_DASHES },
00566 { {"OPT:", no_argument, NULL, OPTION_OPT_GROUP},
00567 '\0', NULL, N_("Optimization options passed to backend during ipa phase"), TWO_DASHES },
00568 { {"TENV:", no_argument, NULL, OPTION_TENV_GROUP},
00569 '\0', NULL, N_("Target environment options passed to backend during ipa phase"), TWO_DASHES },
00570 { {"pg", no_argument, NULL, OPTION_LINKER_ONLY},
00571 '\0', NULL, N_("-pg flag passed to ipa_link should be passed over to the final linker"), ONE_DASH },
00572 #endif
00573 };
00574
00575 #define OPTION_COUNT ARRAY_SIZE (ld_options)
00576
00577 void
00578 parse_args (unsigned argc, char **argv)
00579 {
00580 unsigned i;
00581 int is, il, irl;
00582 int ingroup = 0;
00583 char *default_dirlist = NULL;
00584 char *shortopts;
00585 struct option *longopts;
00586 struct option *really_longopts;
00587 int last_optind;
00588 enum report_method how_to_report_unresolved_symbols = RM_GENERATE_ERROR;
00589 #ifdef KEY
00590 int extend = 0;
00591 #endif
00592
00593 shortopts = xmalloc (OPTION_COUNT * 3 + 2);
00594 longopts = xmalloc (sizeof (*longopts) * (OPTION_COUNT + 1));
00595 really_longopts = xmalloc (sizeof (*really_longopts) * (OPTION_COUNT + 1));
00596
00597
00598
00599
00600
00601 shortopts[0] = '-';
00602 is = 1;
00603 il = 0;
00604 irl = 0;
00605 for (i = 0; i < OPTION_COUNT; i++)
00606 {
00607 if (ld_options[i].shortopt != '\0')
00608 {
00609 shortopts[is] = ld_options[i].shortopt;
00610 ++is;
00611 if (ld_options[i].opt.has_arg == required_argument
00612 || ld_options[i].opt.has_arg == optional_argument)
00613 {
00614 shortopts[is] = ':';
00615 ++is;
00616 if (ld_options[i].opt.has_arg == optional_argument)
00617 {
00618 shortopts[is] = ':';
00619 ++is;
00620 }
00621 }
00622 }
00623 if (ld_options[i].opt.name != NULL)
00624 {
00625 if (ld_options[i].control == EXACTLY_TWO_DASHES)
00626 {
00627 really_longopts[irl] = ld_options[i].opt;
00628 ++irl;
00629 }
00630 else
00631 {
00632 longopts[il] = ld_options[i].opt;
00633 ++il;
00634 }
00635 }
00636 }
00637 shortopts[is] = '\0';
00638 longopts[il].name = NULL;
00639 really_longopts[irl].name = NULL;
00640
00641 ldemul_add_options (is, &shortopts, il, &longopts, irl, &really_longopts);
00642
00643 #ifdef KEY
00644
00645
00646
00647
00648
00649 for (i = 1; i < argc; i++)
00650 {
00651 if (strncmp("-Wl,", argv[i], 4) == 0)
00652 {
00653 int j, c = 0;
00654
00655 for (j = 4; argv[i][j]; j++)
00656 {
00657 if (argv[i][j] == ',')
00658 c++;
00659 }
00660
00661 extend += c;
00662 }
00663
00664
00665
00666 else if (!strcmp(argv[i], "-static-libgcc") ||
00667 !strcmp(argv[i], "-shared-libgcc")) {
00668 argv[i] = (char *) "-g";
00669 }
00670 }
00671
00672 {
00673 char **new_argv;
00674 int new_argc = argc + extend;
00675 int j;
00676
00677 new_argv = xmalloc(sizeof(*new_argv) * (new_argc + 1));
00678
00679 new_argv[0] = argv[0];
00680
00681 for (i = j = 1; i < argc; i++)
00682 {
00683 if (strncmp("-Wl,", argv[i], 4) == 0)
00684 {
00685 char *s = new_argv[j++] = xstrdup(argv[i] + 4);
00686
00687 while ((s = strchr(s, ',')))
00688 {
00689 *s = '\0';
00690 new_argv[j++] = ++s;
00691 }
00692 }
00693 else
00694 {
00695 new_argv[j++] = argv[i];
00696 }
00697 }
00698 new_argv[j++] = NULL;
00699 argv = new_argv;
00700 argc = new_argc;
00701 }
00702 #endif
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715 for (i = 1; i < argc; i++)
00716 if (strcmp (argv[i], "-G") == 0
00717 && (i + 1 >= argc
00718 || ! ISDIGIT (argv[i + 1][0])))
00719 argv[i] = (char *) "--shared";
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733 for (i = 1; i < argc; i++)
00734 {
00735 if (argv[i][0] == '-'
00736 && argv[i][1] == 'l'
00737 && argv[i][2] != '\0')
00738 {
00739 char *n;
00740
00741 n = xmalloc (strlen (argv[i]) + 20);
00742 sprintf (n, "--library=%s", argv[i] + 2);
00743 argv[i] = n;
00744 }
00745 }
00746
00747 last_optind = -1;
00748 while (1)
00749 {
00750 int longind;
00751 int optc;
00752
00753
00754
00755
00756
00757
00758
00759 if (optind != last_optind)
00760 if (ldemul_parse_args (argc, argv))
00761 continue;
00762
00763
00764
00765 opterr = 0;
00766 last_optind = optind;
00767 optc = getopt_long_only (argc, argv, shortopts, longopts, &longind);
00768 if (optc == '?')
00769 {
00770 optind = last_optind;
00771 optc = getopt_long (argc, argv, "-", really_longopts, &longind);
00772 }
00773
00774 if (ldemul_handle_option (optc))
00775 continue;
00776
00777 if (optc == -1)
00778 break;
00779
00780 switch (optc)
00781 {
00782 case '?':
00783 einfo (_("%P: unrecognized option '%s'\n"), argv[last_optind]);
00784 default:
00785 einfo (_("%P%F: use the --help option for usage information\n"));
00786
00787 case 1:
00788 lang_add_input_file (optarg, lang_input_file_is_file_enum, NULL);
00789 break;
00790
00791 case OPTION_IGNORE:
00792 break;
00793 case 'a':
00794
00795
00796
00797 if (strcmp (optarg, "archive") == 0)
00798 config.dynamic_link = FALSE;
00799 else if (strcmp (optarg, "shared") == 0
00800 || strcmp (optarg, "default") == 0)
00801 config.dynamic_link = TRUE;
00802 else
00803 einfo (_("%P%F: unrecognized -a option `%s'\n"), optarg);
00804 break;
00805 case OPTION_ASSERT:
00806
00807 if (strcmp (optarg, "definitions") == 0)
00808 ;
00809 else if (strcmp (optarg, "nodefinitions") == 0)
00810 ;
00811 else if (strcmp (optarg, "nosymbolic") == 0)
00812 ;
00813 else if (strcmp (optarg, "pure-text") == 0)
00814 ;
00815 else
00816 einfo (_("%P%F: unrecognized -assert option `%s'\n"), optarg);
00817 break;
00818 case 'A':
00819 ldfile_add_arch (optarg);
00820 break;
00821 case 'b':
00822 lang_add_target (optarg);
00823 break;
00824 case 'c':
00825 ldfile_open_command_file (optarg);
00826 parser_input = input_mri_script;
00827 yyparse ();
00828 break;
00829 case OPTION_CALL_SHARED:
00830 config.dynamic_link = TRUE;
00831 break;
00832 case OPTION_NON_SHARED:
00833 config.dynamic_link = FALSE;
00834 break;
00835 case OPTION_CREF:
00836 command_line.cref = TRUE;
00837 link_info.notice_all = TRUE;
00838 break;
00839 case 'd':
00840 command_line.force_common_definition = TRUE;
00841 break;
00842 case OPTION_DEFSYM:
00843 lex_string = optarg;
00844 lex_redirect (optarg);
00845 parser_input = input_defsym;
00846 parsing_defsym = 1;
00847 yyparse ();
00848 parsing_defsym = 0;
00849 lex_string = NULL;
00850 break;
00851 case OPTION_DEMANGLE:
00852 demangling = TRUE;
00853 if (optarg != NULL)
00854 {
00855 enum demangling_styles style;
00856
00857 style = cplus_demangle_name_to_style (optarg);
00858 if (style == unknown_demangling)
00859 einfo (_("%F%P: unknown demangling style `%s'"),
00860 optarg);
00861
00862 cplus_demangle_set_style (style);
00863 }
00864 break;
00865 case 'I':
00866 case OPTION_DYNAMIC_LINKER:
00867 command_line.interpreter = optarg;
00868 break;
00869 case OPTION_SYSROOT:
00870
00871 break;
00872 case OPTION_EB:
00873 command_line.endian = ENDIAN_BIG;
00874 break;
00875 case OPTION_EL:
00876 command_line.endian = ENDIAN_LITTLE;
00877 break;
00878 case OPTION_EMBEDDED_RELOCS:
00879 command_line.embedded_relocs = TRUE;
00880 break;
00881 case OPTION_EXPORT_DYNAMIC:
00882 case 'E':
00883 link_info.export_dynamic = TRUE;
00884 break;
00885 case 'e':
00886 lang_add_entry (optarg, TRUE);
00887 break;
00888 case 'f':
00889 if (command_line.auxiliary_filters == NULL)
00890 {
00891 command_line.auxiliary_filters = xmalloc (2 * sizeof (char *));
00892 command_line.auxiliary_filters[0] = optarg;
00893 command_line.auxiliary_filters[1] = NULL;
00894 }
00895 else
00896 {
00897 int c;
00898 char **p;
00899
00900 c = 0;
00901 for (p = command_line.auxiliary_filters; *p != NULL; p++)
00902 ++c;
00903 command_line.auxiliary_filters
00904 = xrealloc (command_line.auxiliary_filters,
00905 (c + 2) * sizeof (char *));
00906 command_line.auxiliary_filters[c] = optarg;
00907 command_line.auxiliary_filters[c + 1] = NULL;
00908 }
00909 break;
00910 case 'F':
00911 command_line.filter_shlib = optarg;
00912 break;
00913 case OPTION_FORCE_EXE_SUFFIX:
00914 command_line.force_exe_suffix = TRUE;
00915 break;
00916 case 'G':
00917 {
00918 char *end;
00919 g_switch_value = strtoul (optarg, &end, 0);
00920 if (*end)
00921 einfo (_("%P%F: invalid number `%s'\n"), optarg);
00922 }
00923 break;
00924 case 'g':
00925
00926 break;
00927 case OPTION_GC_SECTIONS:
00928 command_line.gc_sections = TRUE;
00929 break;
00930 case OPTION_HELP:
00931 help ();
00932 xexit (0);
00933 break;
00934 case 'L':
00935 ldfile_add_library_path (optarg, TRUE);
00936 break;
00937 case 'l':
00938 lang_add_input_file (optarg, lang_input_file_is_l_enum, NULL);
00939 break;
00940 case 'M':
00941 config.map_filename = "-";
00942 break;
00943 case 'm':
00944
00945 break;
00946 case OPTION_MAP:
00947 config.map_filename = optarg;
00948 break;
00949 case 'N':
00950 config.text_read_only = FALSE;
00951 config.magic_demand_paged = FALSE;
00952 config.dynamic_link = FALSE;
00953 break;
00954 case OPTION_NO_OMAGIC:
00955 config.text_read_only = TRUE;
00956 config.magic_demand_paged = TRUE;
00957
00958
00959 break;
00960 case 'n':
00961 config.magic_demand_paged = FALSE;
00962 config.dynamic_link = FALSE;
00963 break;
00964 case OPTION_NO_DEFINE_COMMON:
00965 command_line.inhibit_common_definition = TRUE;
00966 break;
00967 case OPTION_NO_DEMANGLE:
00968 demangling = FALSE;
00969 break;
00970 case OPTION_NO_GC_SECTIONS:
00971 command_line.gc_sections = FALSE;
00972 break;
00973 case OPTION_NO_KEEP_MEMORY:
00974 link_info.keep_memory = FALSE;
00975 break;
00976 case OPTION_NO_UNDEFINED:
00977 link_info.unresolved_syms_in_objects
00978 = how_to_report_unresolved_symbols;
00979 break;
00980 case OPTION_ALLOW_SHLIB_UNDEFINED:
00981 link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
00982 break;
00983 case OPTION_NO_ALLOW_SHLIB_UNDEFINED:
00984 link_info.unresolved_syms_in_shared_libs
00985 = how_to_report_unresolved_symbols;
00986 break;
00987 case OPTION_UNRESOLVED_SYMBOLS:
00988 if (strcmp (optarg, "ignore-all") == 0)
00989 {
00990 link_info.unresolved_syms_in_objects = RM_IGNORE;
00991 link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
00992 }
00993 else if (strcmp (optarg, "report-all") == 0)
00994 {
00995 link_info.unresolved_syms_in_objects
00996 = how_to_report_unresolved_symbols;
00997 link_info.unresolved_syms_in_shared_libs
00998 = how_to_report_unresolved_symbols;
00999 }
01000 else if (strcmp (optarg, "ignore-in-object-files") == 0)
01001 {
01002 link_info.unresolved_syms_in_objects = RM_IGNORE;
01003 link_info.unresolved_syms_in_shared_libs
01004 = how_to_report_unresolved_symbols;
01005 }
01006 else if (strcmp (optarg, "ignore-in-shared-libs") == 0)
01007 {
01008 link_info.unresolved_syms_in_objects
01009 = how_to_report_unresolved_symbols;
01010 link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
01011 }
01012 else
01013 einfo (_("%P%F: bad --unresolved-symbols option: %s\n"), optarg);
01014 break;
01015 case OPTION_WARN_UNRESOLVED_SYMBOLS:
01016 how_to_report_unresolved_symbols = RM_GENERATE_WARNING;
01017 if (link_info.unresolved_syms_in_objects == RM_GENERATE_ERROR)
01018 link_info.unresolved_syms_in_objects = RM_GENERATE_WARNING;
01019 if (link_info.unresolved_syms_in_shared_libs == RM_GENERATE_ERROR)
01020 link_info.unresolved_syms_in_shared_libs = RM_GENERATE_WARNING;
01021 break;
01022
01023 case OPTION_ERROR_UNRESOLVED_SYMBOLS:
01024 how_to_report_unresolved_symbols = RM_GENERATE_ERROR;
01025 if (link_info.unresolved_syms_in_objects == RM_GENERATE_WARNING)
01026 link_info.unresolved_syms_in_objects = RM_GENERATE_ERROR;
01027 if (link_info.unresolved_syms_in_shared_libs == RM_GENERATE_WARNING)
01028 link_info.unresolved_syms_in_shared_libs = RM_GENERATE_ERROR;
01029 break;
01030 case OPTION_ALLOW_MULTIPLE_DEFINITION:
01031 link_info.allow_multiple_definition = TRUE;
01032 break;
01033 case OPTION_NO_UNDEFINED_VERSION:
01034 link_info.allow_undefined_version = FALSE;
01035 break;
01036 case OPTION_DEFAULT_SYMVER:
01037 link_info.create_default_symver = TRUE;
01038 break;
01039 case OPTION_DEFAULT_IMPORTED_SYMVER:
01040 link_info.default_imported_symver = TRUE;
01041 break;
01042 case OPTION_NO_WARN_MISMATCH:
01043 command_line.warn_mismatch = FALSE;
01044 break;
01045 case OPTION_NOINHIBIT_EXEC:
01046 force_make_executable = TRUE;
01047 break;
01048 case OPTION_NOSTDLIB:
01049 config.only_cmd_line_lib_dirs = TRUE;
01050 break;
01051 case OPTION_NO_WHOLE_ARCHIVE:
01052 whole_archive = FALSE;
01053 break;
01054 case 'O':
01055
01056
01057
01058
01059
01060
01061
01062 link_info.optimize = strtoul (optarg, NULL, 0) ? TRUE : FALSE;
01063 break;
01064 case 'o':
01065 lang_add_output (optarg, 0);
01066 break;
01067 case OPTION_OFORMAT:
01068 lang_add_output_format (optarg, NULL, NULL, 0);
01069 break;
01070 case 'q':
01071 link_info.emitrelocations = TRUE;
01072 break;
01073 case 'i':
01074 case 'r':
01075 if (optind == last_optind)
01076
01077
01078
01079
01080
01081
01082
01083
01084 einfo(_("%P%F: bad -rpath option\n"));
01085
01086 link_info.relocatable = TRUE;
01087 config.build_constructors = FALSE;
01088 config.magic_demand_paged = FALSE;
01089 config.text_read_only = FALSE;
01090 config.dynamic_link = FALSE;
01091 break;
01092 case 'R':
01093
01094
01095
01096
01097
01098
01099
01100 {
01101 struct stat s;
01102
01103 if (stat (optarg, &s) >= 0
01104 && ! S_ISDIR (s.st_mode))
01105 {
01106 lang_add_input_file (optarg,
01107 lang_input_file_is_symbols_only_enum,
01108 NULL);
01109 break;
01110 }
01111 }
01112
01113 case OPTION_RPATH:
01114 if (command_line.rpath == NULL)
01115 command_line.rpath = xstrdup (optarg);
01116 else
01117 {
01118 size_t rpath_len = strlen (command_line.rpath);
01119 size_t optarg_len = strlen (optarg);
01120 char *buf;
01121 char *cp = command_line.rpath;
01122
01123
01124 do
01125 {
01126 size_t idx = 0;
01127
01128 while (optarg[idx] != '\0' && optarg[idx] == cp[idx])
01129 ++idx;
01130 if (optarg[idx] == '\0'
01131 && (cp[idx] == '\0' || cp[idx] == ':'))
01132
01133 break;
01134
01135
01136 cp = strchr (cp, ':');
01137 if (cp != NULL)
01138 ++cp;
01139 }
01140 while (cp != NULL);
01141
01142 if (cp == NULL)
01143 {
01144 buf = xmalloc (rpath_len + optarg_len + 2);
01145 sprintf (buf, "%s:%s", command_line.rpath, optarg);
01146 free (command_line.rpath);
01147 command_line.rpath = buf;
01148 }
01149 }
01150 break;
01151 case OPTION_RPATH_LINK:
01152 if (command_line.rpath_link == NULL)
01153 command_line.rpath_link = xstrdup (optarg);
01154 else
01155 {
01156 char *buf;
01157
01158 buf = xmalloc (strlen (command_line.rpath_link)
01159 + strlen (optarg)
01160 + 2);
01161 sprintf (buf, "%s:%s", command_line.rpath_link, optarg);
01162 free (command_line.rpath_link);
01163 command_line.rpath_link = buf;
01164 }
01165 break;
01166 case OPTION_RELAX:
01167 command_line.relax = TRUE;
01168 break;
01169 case OPTION_RETAIN_SYMBOLS_FILE:
01170 add_keepsyms_file (optarg);
01171 break;
01172 case 'S':
01173 link_info.strip = strip_debugger;
01174 break;
01175 case 's':
01176 link_info.strip = strip_all;
01177 break;
01178 case OPTION_STRIP_DISCARDED:
01179 link_info.strip_discarded = TRUE;
01180 break;
01181 case OPTION_NO_STRIP_DISCARDED:
01182 link_info.strip_discarded = FALSE;
01183 break;
01184 case OPTION_SHARED:
01185 if (config.has_shared)
01186 {
01187 link_info.shared = TRUE;
01188 #ifdef KEY
01189 ld_ipa_opt[LD_IPA_SHARABLE].flag =
01190 ld_ipa_opt[LD_IPA_SHARABLE].set = F_MAKE_SHARABLE;
01191 #endif
01192
01193
01194 if (link_info.unresolved_syms_in_objects == RM_NOT_YET_SET)
01195 link_info.unresolved_syms_in_objects = RM_IGNORE;
01196 if (link_info.unresolved_syms_in_shared_libs == RM_NOT_YET_SET)
01197 link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
01198 }
01199 else
01200 einfo (_("%P%F: -shared not supported\n"));
01201 break;
01202 case OPTION_PIE:
01203 if (config.has_shared)
01204 {
01205 link_info.shared = TRUE;
01206 link_info.pie = TRUE;
01207 }
01208 else
01209 einfo (_("%P%F: -pie not supported\n"));
01210 break;
01211 case 'h':
01212 case OPTION_SONAME:
01213 command_line.soname = optarg;
01214 break;
01215 case OPTION_SORT_COMMON:
01216 config.sort_common = TRUE;
01217 break;
01218 case OPTION_SORT_SECTION:
01219 if (strcmp (optarg, N_("name")) == 0)
01220 sort_section = by_name;
01221 else if (strcmp (optarg, N_("alignment")) == 0)
01222 sort_section = by_alignment;
01223 else
01224 einfo (_("%P%F: invalid section sorting option: %s\n"),
01225 optarg);
01226 break;
01227 case OPTION_STATS:
01228 config.stats = TRUE;
01229 break;
01230 case OPTION_SYMBOLIC:
01231 link_info.symbolic = TRUE;
01232 break;
01233 case 't':
01234 trace_files = TRUE;
01235 break;
01236 case 'T':
01237 ldfile_open_command_file (optarg);
01238 parser_input = input_script;
01239 yyparse ();
01240 break;
01241 case OPTION_SECTION_START:
01242 {
01243 char *optarg2;
01244 char *sec_name;
01245 int len;
01246
01247
01248 optarg2 = strchr (optarg, '=');
01249 if (optarg2 == NULL)
01250 einfo (_("%P%F: invalid argument to option"
01251 " \"--section-start\"\n"));
01252
01253 optarg2++;
01254
01255
01256 if ((*optarg == '\0') || (*optarg2 == '\0'))
01257 einfo (_("%P%F: missing argument(s) to option"
01258 " \"--section-start\"\n"));
01259
01260
01261
01262 len = optarg2 - optarg;
01263 sec_name = xmalloc (len);
01264 memcpy (sec_name, optarg, len - 1);
01265 sec_name[len - 1] = 0;
01266
01267
01268 set_section_start (sec_name, optarg2);
01269 }
01270 break;
01271 case OPTION_TARGET_HELP:
01272
01273 ldemul_list_emulation_options (stdout);
01274 exit (0);
01275 case OPTION_TBSS:
01276 set_segment_start (".bss", optarg);
01277 break;
01278 case OPTION_TDATA:
01279 set_segment_start (".data", optarg);
01280 break;
01281 case OPTION_TTEXT:
01282 set_segment_start (".text", optarg);
01283 break;
01284 case OPTION_TRADITIONAL_FORMAT:
01285 link_info.traditional_format = TRUE;
01286 break;
01287 case OPTION_TASK_LINK:
01288 link_info.task_link = TRUE;
01289
01290 case OPTION_UR:
01291 link_info.relocatable = TRUE;
01292 config.build_constructors = TRUE;
01293 config.magic_demand_paged = FALSE;
01294 config.text_read_only = FALSE;
01295 config.dynamic_link = FALSE;
01296 break;
01297 case 'u':
01298 ldlang_add_undef (optarg);
01299 break;
01300 case OPTION_UNIQUE:
01301 if (optarg != NULL)
01302 lang_add_unique (optarg);
01303 else
01304 config.unique_orphan_sections = TRUE;
01305 break;
01306 case OPTION_VERBOSE:
01307 ldversion (1);
01308 version_printed = TRUE;
01309 trace_file_tries = TRUE;
01310 overflow_cutoff_limit = -2;
01311 break;
01312 case 'v':
01313 ldversion (0);
01314 version_printed = TRUE;
01315 break;
01316 case 'V':
01317 ldversion (1);
01318 version_printed = TRUE;
01319 break;
01320 case OPTION_VERSION:
01321 ldversion (2);
01322 xexit (0);
01323 break;
01324 case OPTION_VERSION_SCRIPT:
01325
01326
01327
01328 {
01329 FILE *hold_script_handle;
01330
01331 hold_script_handle = saved_script_handle;
01332 ldfile_open_command_file (optarg);
01333 saved_script_handle = hold_script_handle;
01334 parser_input = input_version_script;
01335 yyparse ();
01336 }
01337 break;
01338 case OPTION_VERSION_EXPORTS_SECTION:
01339
01340
01341
01342 command_line.version_exports_section = optarg;
01343 break;
01344 case OPTION_WARN_COMMON:
01345 config.warn_common = TRUE;
01346 break;
01347 case OPTION_WARN_CONSTRUCTORS:
01348 config.warn_constructors = TRUE;
01349 break;
01350 case OPTION_WARN_FATAL:
01351 config.fatal_warnings = TRUE;
01352 break;
01353 case OPTION_WARN_MULTIPLE_GP:
01354 config.warn_multiple_gp = TRUE;
01355 break;
01356 case OPTION_WARN_ONCE:
01357 config.warn_once = TRUE;
01358 break;
01359 case OPTION_WARN_SECTION_ALIGN:
01360 config.warn_section_align = TRUE;
01361 break;
01362 case OPTION_WARN_SHARED_TEXTREL:
01363 link_info.warn_shared_textrel = TRUE;
01364 break;
01365 case OPTION_WHOLE_ARCHIVE:
01366 whole_archive = TRUE;
01367 break;
01368 case OPTION_ADD_NEEDED:
01369 add_needed = TRUE;
01370 break;
01371 case OPTION_NO_ADD_NEEDED:
01372 add_needed = FALSE;
01373 break;
01374 case OPTION_AS_NEEDED:
01375 as_needed = TRUE;
01376 break;
01377 case OPTION_NO_AS_NEEDED:
01378 as_needed = FALSE;
01379 break;
01380 case OPTION_WRAP:
01381 add_wrap (optarg);
01382 break;
01383 case OPTION_DISCARD_NONE:
01384 link_info.discard = discard_none;
01385 break;
01386 case 'X':
01387 link_info.discard = discard_l;
01388 break;
01389 case 'x':
01390 link_info.discard = discard_all;
01391 break;
01392 case 'Y':
01393 if (strncmp (optarg, "P,", 2) == 0)
01394 optarg += 2;
01395 if (default_dirlist != NULL)
01396 free (default_dirlist);
01397 default_dirlist = xstrdup (optarg);
01398 break;
01399 case 'y':
01400 add_ysym (optarg);
01401 break;
01402 case OPTION_SPARE_DYNAMIC_TAGS:
01403 link_info.spare_dynamic_tags = strtoul (optarg, NULL, 0);
01404 break;
01405 case OPTION_SPLIT_BY_RELOC:
01406 if (optarg != NULL)
01407 config.split_by_reloc = strtoul (optarg, NULL, 0);
01408 else
01409 config.split_by_reloc = 32768;
01410 break;
01411 case OPTION_SPLIT_BY_FILE:
01412 if (optarg != NULL)
01413 config.split_by_file = bfd_scan_vma (optarg, NULL, 0);
01414 else
01415 config.split_by_file = 1;
01416 break;
01417 case OPTION_CHECK_SECTIONS:
01418 command_line.check_section_addresses = TRUE;
01419 break;
01420 case OPTION_NO_CHECK_SECTIONS:
01421 command_line.check_section_addresses = FALSE;
01422 break;
01423 case OPTION_ACCEPT_UNKNOWN_INPUT_ARCH:
01424 command_line.accept_unknown_input_arch = TRUE;
01425 break;
01426 case OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH:
01427 command_line.accept_unknown_input_arch = FALSE;
01428 break;
01429 case '(':
01430 if (ingroup)
01431 einfo (_("%P%F: may not nest groups (--help for usage)\n"));
01432
01433 lang_enter_group ();
01434 ingroup = 1;
01435 break;
01436 case ')':
01437 if (! ingroup)
01438 einfo (_("%P%F: group ended before it began (--help for usage)\n"));
01439
01440 lang_leave_group ();
01441 ingroup = 0;
01442 break;
01443
01444 case OPTION_INIT:
01445 link_info.init_function = optarg;
01446 break;
01447
01448 case OPTION_FINI:
01449 link_info.fini_function = optarg;
01450 break;
01451
01452 case OPTION_REDUCE_MEMORY_OVERHEADS:
01453 command_line.reduce_memory_overheads = TRUE;
01454 if (config.hash_table_size == 0)
01455 config.hash_table_size = 1021;
01456 break;
01457
01458 case OPTION_HASH_SIZE:
01459 {
01460 bfd_size_type new_size;
01461
01462 new_size = strtoul (optarg, NULL, 0);
01463 if (new_size)
01464 config.hash_table_size = new_size;
01465 else
01466 einfo (_("%P%X: --hash-size needs a numeric argument\n"));
01467 }
01468 break;
01469
01470 #ifdef IPA_LINK
01471
01472 case OPTION_KEEP:
01473 case OPTION_DEFAULT_GROUP:
01474 case OPTION_IPA_GROUP:
01475 case OPTION_INLINE_GROUP:
01476 case OPTION_INTERNAL_GROUP:
01477 case OPTION_IPACOM:
01478 case OPTION_OPT_GROUP:
01479 case OPTION_TENV_GROUP:
01480 case OPTION_IPA:
01481 case OPTION_SHOW:
01482 break;
01483 case OPTION_LINKER_ONLY:
01484
01485 break;
01486
01487 case OPTION_AR_MEMBERS:
01488 lang_add_input_file ( optarg,
01489 lang_input_file_is_file_enum,
01490 (char *) NULL);
01491 break;
01492 #endif
01493 }
01494 }
01495
01496 if (ingroup)
01497 lang_leave_group ();
01498
01499 if (default_dirlist != NULL)
01500 {
01501 set_default_dirlist (default_dirlist);
01502 free (default_dirlist);
01503 }
01504
01505 if (link_info.unresolved_syms_in_objects == RM_NOT_YET_SET)
01506
01507 link_info.unresolved_syms_in_objects = how_to_report_unresolved_symbols;
01508
01509 if (link_info.unresolved_syms_in_shared_libs == RM_NOT_YET_SET)
01510
01511 link_info.unresolved_syms_in_shared_libs = how_to_report_unresolved_symbols;
01512 }
01513
01514
01515
01516
01517 static void
01518 set_default_dirlist (char *dirlist_ptr)
01519 {
01520 char *p;
01521
01522 while (1)
01523 {
01524 p = strchr (dirlist_ptr, PATH_SEPARATOR);
01525 if (p != NULL)
01526 *p = '\0';
01527 if (*dirlist_ptr != '\0')
01528 ldfile_add_library_path (dirlist_ptr, TRUE);
01529 if (p == NULL)
01530 break;
01531 dirlist_ptr = p + 1;
01532 }
01533 }
01534
01535 static void
01536 set_section_start (char *sect, char *valstr)
01537 {
01538 const char *end;
01539 bfd_vma val = bfd_scan_vma (valstr, &end, 16);
01540 if (*end)
01541 einfo (_("%P%F: invalid hex number `%s'\n"), valstr);
01542 lang_section_start (sect, exp_intop (val), NULL);
01543 }
01544
01545 static void
01546 set_segment_start (const char *section, char *valstr)
01547 {
01548 const char *name;
01549 const char *end;
01550 segment_type *seg;
01551
01552 bfd_vma val = bfd_scan_vma (valstr, &end, 16);
01553 if (*end)
01554 einfo (_("%P%F: invalid hex number `%s'\n"), valstr);
01555
01556
01557 name = section + 1;
01558 for (seg = segments; seg; seg = seg->next)
01559 if (strcmp (seg->name, name) == 0)
01560 {
01561 seg->value = val;
01562 return;
01563 }
01564
01565
01566 seg = stat_alloc (sizeof (*seg));
01567 seg->name = name;
01568 seg->value = val;
01569 seg->used = FALSE;
01570
01571 seg->next = segments;
01572 segments = seg;
01573
01574
01575
01576
01577 lang_section_start (section, exp_intop (val), seg);
01578 }
01579
01580
01581
01582
01583 static void
01584 help (void)
01585 {
01586 unsigned i;
01587 const char **targets, **pp;
01588
01589 printf (_("Usage: %s [options] file...\n"), program_name);
01590
01591 printf (_("Options:\n"));
01592 for (i = 0; i < OPTION_COUNT; i++)
01593 {
01594 if (ld_options[i].doc != NULL)
01595 {
01596 bfd_boolean comma;
01597 int len;
01598 unsigned j;
01599
01600 printf (" ");
01601
01602 comma = FALSE;
01603 len = 2;
01604
01605 j = i;
01606 do
01607 {
01608 if (ld_options[j].shortopt != '\0'
01609 && ld_options[j].control != NO_HELP)
01610 {
01611 printf ("%s-%c", comma ? ", " : "", ld_options[j].shortopt);
01612 len += (comma ? 2 : 0) + 2;
01613 if (ld_options[j].arg != NULL)
01614 {
01615 if (ld_options[j].opt.has_arg != optional_argument)
01616 {
01617 printf (" ");
01618 ++len;
01619 }
01620 printf ("%s", _(ld_options[j].arg));
01621 len += strlen (_(ld_options[j].arg));
01622 }
01623 comma = TRUE;
01624 }
01625 ++j;
01626 }
01627 while (j < OPTION_COUNT && ld_options[j].doc == NULL);
01628
01629 j = i;
01630 do
01631 {
01632 if (ld_options[j].opt.name != NULL
01633 && ld_options[j].control != NO_HELP)
01634 {
01635 int two_dashes =
01636 (ld_options[j].control == TWO_DASHES
01637 || ld_options[j].control == EXACTLY_TWO_DASHES);
01638
01639 printf ("%s-%s%s",
01640 comma ? ", " : "",
01641 two_dashes ? "-" : "",
01642 ld_options[j].opt.name);
01643 len += ((comma ? 2 : 0)
01644 + 1
01645 + (two_dashes ? 1 : 0)
01646 + strlen (ld_options[j].opt.name));
01647 if (ld_options[j].arg != NULL)
01648 {
01649 printf (" %s", _(ld_options[j].arg));
01650 len += 1 + strlen (_(ld_options[j].arg));
01651 }
01652 comma = TRUE;
01653 }
01654 ++j;
01655 }
01656 while (j < OPTION_COUNT && ld_options[j].doc == NULL);
01657
01658 if (len >= 30)
01659 {
01660 printf ("\n");
01661 len = 0;
01662 }
01663
01664 for (; len < 30; len++)
01665 putchar (' ');
01666
01667 printf ("%s\n", _(ld_options[i].doc));
01668 }
01669 }
01670
01671
01672
01673
01674 printf (_("%s: supported targets:"), program_name);
01675 targets = bfd_target_list ();
01676 for (pp = targets; *pp != NULL; pp++)
01677 printf (" %s", *pp);
01678 free (targets);
01679 printf ("\n");
01680
01681
01682 printf (_("%s: supported emulations: "), program_name);
01683 ldemul_list_emulations (stdout);
01684 printf ("\n");
01685
01686
01687 printf (_("%s: emulation specific options:\n"), program_name);
01688 ldemul_list_emulation_options (stdout);
01689 printf ("\n");
01690
01691 printf (_("Report bugs to %s\n"), REPORT_BUGS_TO);
01692 }