1 /* Parse options for the GNU linker.
2 Copyright (C) 1991, 92, 93, 94, 95, 96, 97, 1998
3 Free Software Foundation, Inc.
5 This file is part of GLD, the Gnu Linker.
7 GLD is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GLD is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GLD; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
24 #include "libiberty.h"
41 #ifndef PATH_SEPARATOR
42 #if defined (__MSDOS__) || (defined (_WIN32) && ! defined (__CYGWIN32__))
43 #define PATH_SEPARATOR ';'
45 #define PATH_SEPARATOR ':'
49 /* Somewhere above, sys/stat.h got included . . . . */
50 #if !defined(S_ISDIR) && defined(S_IFDIR)
51 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
54 /* Omit args to avoid the possibility of clashing with a system header
55 that might disagree about consts. */
56 unsigned long strtoul ();
58 static void set_default_dirlist PARAMS ((char *dirlist_ptr));
59 static void set_section_start PARAMS ((char *sect, char *valstr));
60 static void help PARAMS ((void));
62 /* Non-zero if we are processing a --defsym from the command line. */
63 int parsing_defsym = 0;
65 /* Codes used for the long options with no short synonyms. 150 isn't
66 special; it's just an arbitrary non-ASCII char value. */
68 #define OPTION_ASSERT 150
69 #define OPTION_CALL_SHARED (OPTION_ASSERT + 1)
70 #define OPTION_CREF (OPTION_CALL_SHARED + 1)
71 #define OPTION_DEFSYM (OPTION_CREF + 1)
72 #define OPTION_DYNAMIC_LINKER (OPTION_DEFSYM + 1)
73 #define OPTION_EB (OPTION_DYNAMIC_LINKER + 1)
74 #define OPTION_EL (OPTION_EB + 1)
75 #define OPTION_EMBEDDED_RELOCS (OPTION_EL + 1)
76 #define OPTION_EXPORT_DYNAMIC (OPTION_EMBEDDED_RELOCS + 1)
77 #define OPTION_HELP (OPTION_EXPORT_DYNAMIC + 1)
78 #define OPTION_IGNORE (OPTION_HELP + 1)
79 #define OPTION_MAP (OPTION_IGNORE + 1)
80 #define OPTION_NO_KEEP_MEMORY (OPTION_MAP + 1)
81 #define OPTION_NO_WARN_MISMATCH (OPTION_NO_KEEP_MEMORY + 1)
82 #define OPTION_NOINHIBIT_EXEC (OPTION_NO_WARN_MISMATCH + 1)
83 #define OPTION_NON_SHARED (OPTION_NOINHIBIT_EXEC + 1)
84 #define OPTION_NO_WHOLE_ARCHIVE (OPTION_NON_SHARED + 1)
85 #define OPTION_OFORMAT (OPTION_NO_WHOLE_ARCHIVE + 1)
86 #define OPTION_RELAX (OPTION_OFORMAT + 1)
87 #define OPTION_RETAIN_SYMBOLS_FILE (OPTION_RELAX + 1)
88 #define OPTION_RPATH (OPTION_RETAIN_SYMBOLS_FILE + 1)
89 #define OPTION_RPATH_LINK (OPTION_RPATH + 1)
90 #define OPTION_SHARED (OPTION_RPATH_LINK + 1)
91 #define OPTION_SONAME (OPTION_SHARED + 1)
92 #define OPTION_SORT_COMMON (OPTION_SONAME + 1)
93 #define OPTION_STATS (OPTION_SORT_COMMON + 1)
94 #define OPTION_SYMBOLIC (OPTION_STATS + 1)
95 #define OPTION_TASK_LINK (OPTION_SYMBOLIC + 1)
96 #define OPTION_TBSS (OPTION_TASK_LINK + 1)
97 #define OPTION_TDATA (OPTION_TBSS + 1)
98 #define OPTION_TTEXT (OPTION_TDATA + 1)
99 #define OPTION_TRADITIONAL_FORMAT (OPTION_TTEXT + 1)
100 #define OPTION_UR (OPTION_TRADITIONAL_FORMAT + 1)
101 #define OPTION_VERBOSE (OPTION_UR + 1)
102 #define OPTION_VERSION (OPTION_VERBOSE + 1)
103 #define OPTION_VERSION_SCRIPT (OPTION_VERSION + 1)
104 #define OPTION_VERSION_EXPORTS_SECTION (OPTION_VERSION_SCRIPT + 1)
105 #define OPTION_WARN_COMMON (OPTION_VERSION_EXPORTS_SECTION + 1)
106 #define OPTION_WARN_CONSTRUCTORS (OPTION_WARN_COMMON + 1)
107 #define OPTION_WARN_MULTIPLE_GP (OPTION_WARN_CONSTRUCTORS + 1)
108 #define OPTION_WARN_ONCE (OPTION_WARN_MULTIPLE_GP + 1)
109 #define OPTION_WARN_SECTION_ALIGN (OPTION_WARN_ONCE + 1)
110 #define OPTION_SPLIT_BY_RELOC (OPTION_WARN_SECTION_ALIGN + 1)
111 #define OPTION_SPLIT_BY_FILE (OPTION_SPLIT_BY_RELOC + 1)
112 #define OPTION_WHOLE_ARCHIVE (OPTION_SPLIT_BY_FILE + 1)
113 #define OPTION_WRAP (OPTION_WHOLE_ARCHIVE + 1)
114 #define OPTION_FORCE_EXE_SUFFIX (OPTION_WRAP + 1)
115 #define OPTION_GC_SECTIONS (OPTION_FORCE_EXE_SUFFIX + 1)
116 #define OPTION_NO_GC_SECTIONS (OPTION_GC_SECTIONS + 1)
117 #define OPTION_CHECK_SECTIONS (OPTION_NO_GC_SECTIONS + 1)
118 #define OPTION_NO_CHECK_SECTIONS (OPTION_CHECK_SECTIONS + 1)
120 /* The long options. This structure is used for both the option
121 parsing and the help text. */
125 /* The long option information. */
127 /* The short option with the same meaning ('\0' if none). */
129 /* The name of the argument (NULL if none). */
131 /* The documentation string. If this is NULL, this is a synonym for
132 the previous option. */
136 /* Use one dash before long option name. */
138 /* Use two dashes before long option name. */
140 /* Don't mention this option in --help output. */
145 static const struct ld_option ld_options[] =
147 { {NULL, required_argument, NULL, '\0'},
148 'a', N_("KEYWORD"), N_("Shared library control for HP/UX compatibility"),
150 { {"architecture", required_argument, NULL, 'A'},
151 'A', N_("ARCH"), N_("Set architecture") , TWO_DASHES },
152 { {"format", required_argument, NULL, 'b'},
153 'b', N_("TARGET"), N_("Specify target for following input files"), TWO_DASHES },
154 { {"mri-script", required_argument, NULL, 'c'},
155 'c', N_("FILE"), N_("Read MRI format linker script"), TWO_DASHES },
156 { {"dc", no_argument, NULL, 'd'},
157 'd', NULL, N_("Force common symbols to be defined"), ONE_DASH },
158 { {"dp", no_argument, NULL, 'd'},
159 '\0', NULL, NULL, ONE_DASH },
160 { {"entry", required_argument, NULL, 'e'},
161 'e', N_("ADDRESS"), N_("Set start address"), TWO_DASHES },
162 { {"export-dynamic", no_argument, NULL, OPTION_EXPORT_DYNAMIC},
163 'E', NULL, N_("Export all dynamic symbols"), TWO_DASHES },
164 { {"EB", no_argument, NULL, OPTION_EB},
165 '\0', NULL, N_("Link big-endian objects"), ONE_DASH },
166 { {"EL", no_argument, NULL, OPTION_EL},
167 '\0', NULL, N_("Link little-endian objects"), ONE_DASH },
168 { {"auxiliary", required_argument, NULL, 'f'},
169 'f', N_("SHLIB"), N_("Auxiliary filter for shared object symbol table"),
171 { {"filter", required_argument, NULL, 'F'},
172 'F', N_("SHLIB"), N_("Filter for shared object symbol table"), TWO_DASHES },
173 { {NULL, no_argument, NULL, '\0'},
174 'g', NULL, N_("Ignored"), ONE_DASH },
175 { {"gpsize", required_argument, NULL, 'G'},
176 'G', N_("SIZE"), N_("Small data size (if no size, same as --shared)"),
178 { {"soname", required_argument, NULL, OPTION_SONAME},
179 'h', N_("FILENAME"), N_("Set internal name of shared library"), ONE_DASH },
180 { {"library", required_argument, NULL, 'l'},
181 'l', N_("LIBNAME"), N_("Search for library LIBNAME"), TWO_DASHES },
182 { {"library-path", required_argument, NULL, 'L'},
183 'L', N_("DIRECTORY"), N_("Add DIRECTORY to library search path"), TWO_DASHES },
184 { {NULL, required_argument, NULL, '\0'},
185 'm', N_("EMULATION"), N_("Set emulation"), ONE_DASH },
186 { {"print-map", no_argument, NULL, 'M'},
187 'M', NULL, N_("Print map file on standard output"), TWO_DASHES },
188 { {"nmagic", no_argument, NULL, 'n'},
189 'n', NULL, N_("Do not page align data"), TWO_DASHES },
190 { {"omagic", no_argument, NULL, 'N'},
191 'N', NULL, N_("Do not page align data, do not make text readonly"),
193 { {"output", required_argument, NULL, 'o'},
194 'o', N_("FILE"), N_("Set output file name"), TWO_DASHES },
195 { {NULL, required_argument, NULL, '\0'},
196 'O', NULL, N_("Optimize output file"), ONE_DASH },
197 { {"Qy", no_argument, NULL, OPTION_IGNORE},
198 '\0', NULL, N_("Ignored for SVR4 compatibility"), ONE_DASH },
199 { {"relocateable", no_argument, NULL, 'r'},
200 'r', NULL, N_("Generate relocateable output"), TWO_DASHES },
201 { {NULL, no_argument, NULL, '\0'},
202 'i', NULL, NULL, ONE_DASH },
203 { {"just-symbols", required_argument, NULL, 'R'},
204 'R', N_("FILE"), N_("Just link symbols (if directory, same as --rpath)"),
206 { {"strip-all", no_argument, NULL, 's'},
207 's', NULL, N_("Strip all symbols"), TWO_DASHES },
208 { {"strip-debug", no_argument, NULL, 'S'},
209 'S', NULL, N_("Strip debugging symbols"), TWO_DASHES },
210 { {"trace", no_argument, NULL, 't'},
211 't', NULL, N_("Trace file opens"), TWO_DASHES },
212 { {"script", required_argument, NULL, 'T'},
213 'T', N_("FILE"), N_("Read linker script"), TWO_DASHES },
214 { {"undefined", required_argument, NULL, 'u'},
215 'u', N_("SYMBOL"), N_("Start with undefined reference to SYMBOL"), TWO_DASHES },
216 { {"Ur", no_argument, NULL, OPTION_UR},
217 '\0', NULL, N_("Build global constructor/destructor tables"), ONE_DASH },
218 { {"version", no_argument, NULL, OPTION_VERSION},
219 'v', NULL, N_("Print version information"), TWO_DASHES },
220 { {NULL, no_argument, NULL, '\0'},
221 'V', NULL, N_("Print version and emulation information"), ONE_DASH },
222 { {"discard-all", no_argument, NULL, 'x'},
223 'x', NULL, N_("Discard all local symbols"), TWO_DASHES },
224 { {"discard-locals", no_argument, NULL, 'X'},
225 'X', NULL, N_("Discard temporary local symbols"), TWO_DASHES },
226 { {"trace-symbol", required_argument, NULL, 'y'},
227 'y', N_("SYMBOL"), N_("Trace mentions of SYMBOL"), TWO_DASHES },
228 { {NULL, required_argument, NULL, '\0'},
229 'Y', N_("PATH"), N_("Default search path for Solaris compatibility"), ONE_DASH },
230 { {NULL, required_argument, NULL, '\0'},
231 'z', N_("KEYWORD"), N_("Ignored for Solaris compatibility"), ONE_DASH },
232 { {"start-group", no_argument, NULL, '('},
233 '(', NULL, N_("Start a group"), TWO_DASHES },
234 { {"end-group", no_argument, NULL, ')'},
235 ')', NULL, N_("End a group"), TWO_DASHES },
236 { {"assert", required_argument, NULL, OPTION_ASSERT},
237 '\0', N_("KEYWORD"), N_("Ignored for SunOS compatibility"), ONE_DASH },
238 { {"Bdynamic", no_argument, NULL, OPTION_CALL_SHARED},
239 '\0', NULL, N_("Link against shared libraries"), ONE_DASH },
240 { {"dy", no_argument, NULL, OPTION_CALL_SHARED},
241 '\0', NULL, NULL, ONE_DASH },
242 { {"call_shared", no_argument, NULL, OPTION_CALL_SHARED},
243 '\0', NULL, NULL, ONE_DASH },
244 { {"Bstatic", no_argument, NULL, OPTION_NON_SHARED},
245 '\0', NULL, N_("Do not link against shared libraries"), ONE_DASH },
246 { {"dn", no_argument, NULL, OPTION_NON_SHARED},
247 '\0', NULL, NULL, ONE_DASH },
248 { {"non_shared", no_argument, NULL, OPTION_NON_SHARED},
249 '\0', NULL, NULL, ONE_DASH },
250 { {"static", no_argument, NULL, OPTION_NON_SHARED},
251 '\0', NULL, NULL, ONE_DASH },
252 { {"Bsymbolic", no_argument, NULL, OPTION_SYMBOLIC},
253 '\0', NULL, N_("Bind global references locally"), ONE_DASH },
254 { {"check-sections", no_argument, NULL, OPTION_CHECK_SECTIONS},
255 '\0', NULL, N_("Check section addresses for overlaps (default)"), TWO_DASHES },
256 { {"no-check-sections", no_argument, NULL, OPTION_NO_CHECK_SECTIONS},
257 '\0', NULL, N_("Do not check section addresses for overlaps"),
259 { {"cref", no_argument, NULL, OPTION_CREF},
260 '\0', NULL, N_("Output cross reference table"), TWO_DASHES },
261 { {"defsym", required_argument, NULL, OPTION_DEFSYM},
262 '\0', N_("SYMBOL=EXPRESSION"), N_("Define a symbol"), TWO_DASHES },
263 { {"dynamic-linker", required_argument, NULL, OPTION_DYNAMIC_LINKER},
264 '\0', N_("PROGRAM"), N_("Set the dynamic linker to use"), TWO_DASHES },
265 { {"embedded-relocs", no_argument, NULL, OPTION_EMBEDDED_RELOCS},
266 '\0', NULL, N_("Generate embedded relocs"), TWO_DASHES},
267 { {"force-exe-suffix", no_argument, NULL, OPTION_FORCE_EXE_SUFFIX},
268 '\0', NULL, N_("Force generation of file with .exe suffix"), TWO_DASHES},
269 { {"gc-sections", no_argument, NULL, OPTION_GC_SECTIONS},
270 '\0', NULL, N_("Remove unused sections (on some targets)"),
272 { {"no-gc-sections", no_argument, NULL, OPTION_NO_GC_SECTIONS},
273 '\0', NULL, N_("Don't remove unused sections (default)"),
275 { {"help", no_argument, NULL, OPTION_HELP},
276 '\0', NULL, N_("Print option help"), TWO_DASHES },
277 { {"Map", required_argument, NULL, OPTION_MAP},
278 '\0', N_("FILE"), N_("Write a map file"), ONE_DASH },
279 { {"no-keep-memory", no_argument, NULL, OPTION_NO_KEEP_MEMORY},
280 '\0', NULL, N_("Use less memory and more disk I/O"), TWO_DASHES },
281 { {"no-warn-mismatch", no_argument, NULL, OPTION_NO_WARN_MISMATCH},
282 '\0', NULL, N_("Don't warn about mismatched input files"), TWO_DASHES},
283 { {"no-whole-archive", no_argument, NULL, OPTION_NO_WHOLE_ARCHIVE},
284 '\0', NULL, N_("Turn off --whole-archive"), TWO_DASHES },
285 { {"noinhibit-exec", no_argument, NULL, OPTION_NOINHIBIT_EXEC},
286 '\0', NULL, N_("Create an output file even if errors occur"), TWO_DASHES },
287 { {"noinhibit_exec", no_argument, NULL, OPTION_NOINHIBIT_EXEC},
288 '\0', NULL, NULL, NO_HELP },
289 { {"oformat", required_argument, NULL, OPTION_OFORMAT},
290 '\0', N_("TARGET"), N_("Specify target of output file"), TWO_DASHES },
291 { {"qmagic", no_argument, NULL, OPTION_IGNORE},
292 '\0', NULL, N_("Ignored for Linux compatibility"), ONE_DASH },
293 { {"relax", no_argument, NULL, OPTION_RELAX},
294 '\0', NULL, N_("Relax branches on certain targets"), TWO_DASHES },
295 { {"retain-symbols-file", required_argument, NULL,
296 OPTION_RETAIN_SYMBOLS_FILE},
297 '\0', N_("FILE"), N_("Keep only symbols listed in FILE"), TWO_DASHES },
298 { {"rpath", required_argument, NULL, OPTION_RPATH},
299 '\0', N_("PATH"), N_("Set runtime shared library search path"), ONE_DASH },
300 { {"rpath-link", required_argument, NULL, OPTION_RPATH_LINK},
301 '\0', N_("PATH"), N_("Set link time shared library search path"), ONE_DASH },
302 { {"shared", no_argument, NULL, OPTION_SHARED},
303 '\0', NULL, N_("Create a shared library"), ONE_DASH },
304 { {"Bshareable", no_argument, NULL, OPTION_SHARED }, /* FreeBSD. */
305 '\0', NULL, NULL, ONE_DASH },
306 { {"sort-common", no_argument, NULL, OPTION_SORT_COMMON},
307 '\0', NULL, N_("Sort common symbols by size"), TWO_DASHES },
308 { {"sort_common", no_argument, NULL, OPTION_SORT_COMMON},
309 '\0', NULL, NULL, NO_HELP },
310 { {"split-by-file", no_argument, NULL, OPTION_SPLIT_BY_FILE},
311 '\0', NULL, N_("Split output sections for each file"), TWO_DASHES },
312 { {"split-by-reloc", required_argument, NULL, OPTION_SPLIT_BY_RELOC},
313 '\0', N_("COUNT"), N_("Split output sections every COUNT relocs"), TWO_DASHES },
314 { {"stats", no_argument, NULL, OPTION_STATS},
315 '\0', NULL, N_("Print memory usage statistics"), TWO_DASHES },
316 { {"task-link", required_argument, NULL, OPTION_TASK_LINK},
317 '\0', N_("SYMBOL"), N_("Do task level linking"), TWO_DASHES },
318 { {"traditional-format", no_argument, NULL, OPTION_TRADITIONAL_FORMAT},
319 '\0', NULL, N_("Use same format as native linker"), TWO_DASHES },
320 { {"Tbss", required_argument, NULL, OPTION_TBSS},
321 '\0', N_("ADDRESS"), N_("Set address of .bss section"), ONE_DASH },
322 { {"Tdata", required_argument, NULL, OPTION_TDATA},
323 '\0', N_("ADDRESS"), N_("Set address of .data section"), ONE_DASH },
324 { {"Ttext", required_argument, NULL, OPTION_TTEXT},
325 '\0', N_("ADDRESS"), N_("Set address of .text section"), ONE_DASH },
326 { {"verbose", no_argument, NULL, OPTION_VERBOSE},
327 '\0', NULL, N_("Output lots of information during link"), TWO_DASHES },
328 { {"dll-verbose", no_argument, NULL, OPTION_VERBOSE}, /* Linux. */
329 '\0', NULL, NULL, NO_HELP },
330 { {"version-script", required_argument, NULL, OPTION_VERSION_SCRIPT },
331 '\0', N_("FILE"), N_("Read version information script"), TWO_DASHES },
332 { {"version-exports-section", required_argument, NULL,
333 OPTION_VERSION_EXPORTS_SECTION },
334 '\0', N_("SYMBOL"), N_("Take export symbols list from .exports, using SYMBOL as the version."),
336 { {"warn-common", no_argument, NULL, OPTION_WARN_COMMON},
337 '\0', NULL, N_("Warn about duplicate common symbols"), TWO_DASHES },
338 { {"warn-constructors", no_argument, NULL, OPTION_WARN_CONSTRUCTORS},
339 '\0', NULL, N_("Warn if global constructors/destructors are seen"),
341 { {"warn-multiple-gp", no_argument, NULL, OPTION_WARN_MULTIPLE_GP},
342 '\0', NULL, N_("Warn if the multiple GP values are used"), TWO_DASHES },
343 { {"warn-once", no_argument, NULL, OPTION_WARN_ONCE},
344 '\0', NULL, N_("Warn only once per undefined symbol"), TWO_DASHES },
345 { {"warn-section-align", no_argument, NULL, OPTION_WARN_SECTION_ALIGN},
346 '\0', NULL, N_("Warn if start of section changes due to alignment"),
348 { {"whole-archive", no_argument, NULL, OPTION_WHOLE_ARCHIVE},
349 '\0', NULL, N_("Include all objects from following archives"), TWO_DASHES },
350 { {"wrap", required_argument, NULL, OPTION_WRAP},
351 '\0', N_("SYMBOL"), N_("Use wrapper functions for SYMBOL"), TWO_DASHES }
354 #define OPTION_COUNT ((int) (sizeof ld_options / sizeof ld_options[0]))
357 parse_args (argc, argv)
363 char *default_dirlist = NULL;
364 char shortopts[OPTION_COUNT * 3 + 2];
365 struct option longopts[OPTION_COUNT + 1];
368 /* Starting the short option string with '-' is for programs that
369 expect options and other ARGV-elements in any order and that care about
370 the ordering of the two. We describe each non-option ARGV-element
371 as if it were the argument of an option with character code 1. */
375 for (i = 0; i < OPTION_COUNT; i++)
377 if (ld_options[i].shortopt != '\0')
379 shortopts[is] = ld_options[i].shortopt;
381 if (ld_options[i].opt.has_arg == required_argument
382 || ld_options[i].opt.has_arg == optional_argument)
386 if (ld_options[i].opt.has_arg == optional_argument)
393 if (ld_options[i].opt.name != NULL)
395 longopts[il] = ld_options[i].opt;
399 shortopts[is] = '\0';
400 longopts[il].name = NULL;
402 /* The -G option is ambiguous on different platforms. Sometimes it
403 specifies the largest data size to put into the small data
404 section. Sometimes it is equivalent to --shared. Unfortunately,
405 the first form takes an argument, while the second does not.
407 We need to permit the --shared form because on some platforms,
408 such as Solaris, gcc -shared will pass -G to the linker.
410 To permit either usage, we look through the argument list. If we
411 find -G not followed by a number, we change it into --shared.
412 This will work for most normal cases. */
413 for (i = 1; i < argc; i++)
414 if (strcmp (argv[i], "-G") == 0
416 || ! isdigit ((unsigned char) argv[i + 1][0])))
417 argv[i] = (char *) "--shared";
419 /* Because we permit long options to start with a single dash, and
420 we have a --library option, and the -l option is conventionally
421 used with an immediately following argument, we can have bad
422 results if somebody tries to use -l with a library whose name
423 happens to start with "ibrary", as in -li. We avoid problems by
424 simply turning -l into --library. This means that users will
425 have to use two dashes in order to use --library, which is OK
426 since that's how it is documented.
428 FIXME: It's possible that this problem can arise for other short
429 options as well, although the user does always have the recourse
430 of adding a space between the option and the argument. */
431 for (i = 1; i < argc; i++)
433 if (argv[i][0] == '-'
435 && argv[i][2] != '\0')
439 n = (char *) xmalloc (strlen (argv[i]) + 20);
440 sprintf (n, "--library=%s", argv[i] + 2);
451 /* Using last_optind lets us avoid calling ldemul_parse_args
452 multiple times on a single option, which would lead to
453 confusion in the internal static variables maintained by
454 getopt. This could otherwise happen for an argument like
455 -nx, in which the -n is parsed as a single option, and we
456 loop around to pick up the -x. */
457 if (optind != last_optind)
459 if (ldemul_parse_args (argc, argv))
461 last_optind = optind;
464 /* getopt_long_only is like getopt_long, but '-' as well as '--'
465 can indicate a long option. */
466 optc = getopt_long_only (argc, argv, shortopts, longopts, &longind);
474 case 1: /* File name. */
475 lang_add_input_file (optarg, lang_input_file_is_file_enum,
482 /* For HP/UX compatibility. Actually -a shared should mean
483 ``use only shared libraries'' but, then, we don't
484 currently support shared libraries on HP/UX anyhow. */
485 if (strcmp (optarg, "archive") == 0)
486 config.dynamic_link = false;
487 else if (strcmp (optarg, "shared") == 0
488 || strcmp (optarg, "default") == 0)
489 config.dynamic_link = true;
491 einfo (_("%P%F: unrecognized -a option `%s'\n"), optarg);
494 /* FIXME: We just ignore these, but we should handle them. */
495 if (strcmp (optarg, "definitions") == 0)
497 else if (strcmp (optarg, "nodefinitions") == 0)
499 else if (strcmp (optarg, "nosymbolic") == 0)
501 else if (strcmp (optarg, "pure-text") == 0)
504 einfo (_("%P%F: unrecognized -assert option `%s'\n"), optarg);
507 ldfile_add_arch (optarg);
510 lang_add_target (optarg);
513 ldfile_open_command_file (optarg);
514 parser_input = input_mri_script;
517 case OPTION_CALL_SHARED:
518 config.dynamic_link = true;
520 case OPTION_NON_SHARED:
521 config.dynamic_link = false;
524 command_line.cref = true;
525 link_info.notice_all = true;
528 command_line.force_common_definition = true;
532 lex_redirect (optarg);
533 parser_input = input_defsym;
539 case OPTION_DYNAMIC_LINKER:
540 command_line.interpreter = optarg;
543 command_line.endian = ENDIAN_BIG;
546 command_line.endian = ENDIAN_LITTLE;
548 case OPTION_EMBEDDED_RELOCS:
549 command_line.embedded_relocs = true;
551 case OPTION_EXPORT_DYNAMIC:
552 case 'E': /* HP/UX compatibility. */
553 command_line.export_dynamic = true;
556 lang_add_entry (optarg, true);
559 if (command_line.auxiliary_filters == NULL)
561 command_line.auxiliary_filters =
562 (char **) xmalloc (2 * sizeof (char *));
563 command_line.auxiliary_filters[0] = optarg;
564 command_line.auxiliary_filters[1] = NULL;
572 for (p = command_line.auxiliary_filters; *p != NULL; p++)
574 command_line.auxiliary_filters =
575 (char **) xrealloc (command_line.auxiliary_filters,
576 (c + 2) * sizeof (char *));
577 command_line.auxiliary_filters[c] = optarg;
578 command_line.auxiliary_filters[c + 1] = NULL;
582 command_line.filter_shlib = optarg;
584 case OPTION_FORCE_EXE_SUFFIX:
585 command_line.force_exe_suffix = true;
590 g_switch_value = strtoul (optarg, &end, 0);
592 einfo (_("%P%F: invalid number `%s'\n"), optarg);
598 case OPTION_GC_SECTIONS:
599 command_line.gc_sections = true;
606 ldfile_add_library_path (optarg, true);
609 lang_add_input_file (optarg, lang_input_file_is_l_enum,
613 config.map_filename = "-";
616 /* Ignore. Was handled in a pre-parse. */
619 config.map_filename = optarg;
622 config.text_read_only = false;
623 config.magic_demand_paged = false;
624 config.dynamic_link = false;
627 config.magic_demand_paged = false;
628 config.dynamic_link = false;
630 case OPTION_NO_GC_SECTIONS:
631 command_line.gc_sections = false;
633 case OPTION_NO_KEEP_MEMORY:
634 link_info.keep_memory = false;
636 case OPTION_NO_WARN_MISMATCH:
637 command_line.warn_mismatch = false;
639 case OPTION_NOINHIBIT_EXEC:
640 force_make_executable = true;
642 case OPTION_NO_WHOLE_ARCHIVE:
643 whole_archive = false;
646 /* FIXME "-O<non-digits> <value>" used to set the address of
647 section <non-digits>. Was this for compatibility with
648 something, or can we create a new option to do that
649 (with a syntax similar to -defsym)?
650 getopt can't handle two args to an option without kludges. */
652 /* Enable optimizations of output files. */
653 link_info.optimize = strtoul (optarg, NULL, 0) ? true : false;
656 lang_add_output (optarg, 0);
659 lang_add_output_format (optarg, (char *) NULL, (char *) NULL, 0);
663 link_info.relocateable = true;
664 config.build_constructors = false;
665 config.magic_demand_paged = false;
666 config.text_read_only = false;
667 config.dynamic_link = false;
670 /* The GNU linker traditionally uses -R to mean to include
671 only the symbols from a file. The Solaris linker uses -R
672 to set the path used by the runtime linker to find
673 libraries. This is the GNU linker -rpath argument. We
674 try to support both simultaneously by checking the file
675 named. If it is a directory, rather than a regular file,
676 we assume -rpath was meant. */
680 if (stat (optarg, &s) >= 0
681 && ! S_ISDIR (s.st_mode))
683 lang_add_input_file (optarg,
684 lang_input_file_is_symbols_only_enum,
691 if (command_line.rpath == NULL)
692 command_line.rpath = buystring (optarg);
695 size_t rpath_len = strlen (command_line.rpath);
696 size_t optarg_len = strlen (optarg);
698 char *cp = command_line.rpath;
700 /* First see whether OPTARG is already in the path. */
704 while (optarg[idx] != '\0' && optarg[idx] == cp[idx])
706 if (optarg[idx] == '\0'
707 && (cp[idx] == '\0' || cp[idx] == ':'))
712 cp = strchr (cp, ':');
720 buf = xmalloc (rpath_len + optarg_len + 2);
721 sprintf (buf, "%s:%s", command_line.rpath, optarg);
722 free (command_line.rpath);
723 command_line.rpath = buf;
727 case OPTION_RPATH_LINK:
728 if (command_line.rpath_link == NULL)
729 command_line.rpath_link = buystring (optarg);
734 buf = xmalloc (strlen (command_line.rpath_link)
737 sprintf (buf, "%s:%s", command_line.rpath_link, optarg);
738 free (command_line.rpath_link);
739 command_line.rpath_link = buf;
743 command_line.relax = true;
745 case OPTION_RETAIN_SYMBOLS_FILE:
746 add_keepsyms_file (optarg);
749 link_info.strip = strip_debugger;
752 link_info.strip = strip_all;
755 if (config.has_shared)
756 link_info.shared = true;
758 einfo (_("%P%F: -shared not supported\n"));
760 case 'h': /* Used on Solaris. */
762 command_line.soname = optarg;
764 case OPTION_SORT_COMMON:
765 config.sort_common = true;
770 case OPTION_SYMBOLIC:
771 link_info.symbolic = true;
777 ldfile_open_command_file (optarg);
778 parser_input = input_script;
782 set_section_start (".bss", optarg);
785 set_section_start (".data", optarg);
788 set_section_start (".text", optarg);
790 case OPTION_TRADITIONAL_FORMAT:
791 link_info.traditional_format = true;
793 case OPTION_TASK_LINK:
794 link_info.task_link = true;
795 /* Fall through - do an implied -r option. */
797 link_info.relocateable = true;
798 config.build_constructors = true;
799 config.magic_demand_paged = false;
800 config.text_read_only = false;
801 config.dynamic_link = false;
804 ldlang_add_undef (optarg);
808 version_printed = true;
809 trace_file_tries = true;
813 version_printed = true;
817 version_printed = true;
820 /* This output is intended to follow the GNU standards document. */
821 printf ("GNU ld %s\n", ld_program_version);
822 printf (_("Copyright 1997 Free Software Foundation, Inc.\n"));
824 This program is free software; you may redistribute it under the terms of\n\
825 the GNU General Public License. This program has absolutely no warranty.\n"));
827 ld_emulation_xfer_type **ptr = ld_emulations;
829 printf (_(" Supported emulations:\n"));
832 printf (" %s\n", (*ptr)->emulation_name);
838 case OPTION_VERSION_SCRIPT:
839 /* This option indicates a small script that only specifies
840 version information. Read it, but don't assume that
841 we've seen a linker script. */
843 boolean hold_had_script;
845 hold_had_script = had_script;
846 ldfile_open_command_file (optarg);
847 had_script = hold_had_script;
848 parser_input = input_version_script;
852 case OPTION_VERSION_EXPORTS_SECTION:
853 /* This option records a version symbol to be applied to the
854 symbols listed for export to be found in the object files
855 .exports sections. */
856 command_line.version_exports_section = optarg;
858 case OPTION_WARN_COMMON:
859 config.warn_common = true;
861 case OPTION_WARN_CONSTRUCTORS:
862 config.warn_constructors = true;
864 case OPTION_WARN_MULTIPLE_GP:
865 config.warn_multiple_gp = true;
867 case OPTION_WARN_ONCE:
868 config.warn_once = true;
870 case OPTION_WARN_SECTION_ALIGN:
871 config.warn_section_align = true;
873 case OPTION_WHOLE_ARCHIVE:
874 whole_archive = true;
880 link_info.discard = discard_l;
883 link_info.discard = discard_all;
886 if (strncmp (optarg, "P,", 2) == 0)
888 default_dirlist = xstrdup (optarg);
894 /* We accept and ignore this option for Solaris
895 compatibility. Actually, on Solaris, optarg is not
896 ignored. Someday we should handle it correctly. FIXME. */
898 case OPTION_SPLIT_BY_RELOC:
899 config.split_by_reloc = atoi (optarg);
901 case OPTION_SPLIT_BY_FILE:
902 config.split_by_file = true;
904 case OPTION_CHECK_SECTIONS:
905 command_line.check_section_addresses = true;
907 case OPTION_NO_CHECK_SECTIONS:
908 command_line.check_section_addresses = false;
914 _("%s: may not nest groups (--help for usage)\n"),
925 _("%s: group ended before it began (--help for usage)\n"),
939 if (default_dirlist != NULL)
940 set_default_dirlist (default_dirlist);
944 /* Add the (colon-separated) elements of DIRLIST_PTR to the
945 library search path. */
948 set_default_dirlist (dirlist_ptr)
955 p = strchr (dirlist_ptr, PATH_SEPARATOR);
958 if (*dirlist_ptr != '\0')
959 ldfile_add_library_path (dirlist_ptr, true);
967 set_section_start (sect, valstr)
971 unsigned long val = strtoul (valstr, &end, 16);
973 einfo (_("%P%F: invalid hex number `%s'\n"), valstr);
974 lang_section_start (sect, exp_intop (val));
977 /* Print help messages for the options. */
983 const char **targets, **pp;
985 printf (_("Usage: %s [options] file...\n"), program_name);
987 printf (_("Options:\n"));
988 for (i = 0; i < OPTION_COUNT; i++)
990 if (ld_options[i].doc != NULL)
1004 if (ld_options[j].shortopt != '\0'
1005 && ld_options[j].control != NO_HELP)
1007 printf ("%s-%c", comma ? ", " : "", ld_options[j].shortopt);
1008 len += (comma ? 2 : 0) + 2;
1009 if (ld_options[j].arg != NULL)
1011 if (ld_options[j].opt.has_arg != optional_argument)
1016 printf ("%s", _(ld_options[j].arg));
1017 len += strlen (_(ld_options[j].arg));
1023 while (j < OPTION_COUNT && ld_options[j].doc == NULL);
1028 if (ld_options[j].opt.name != NULL
1029 && ld_options[j].control != NO_HELP)
1033 ld_options[j].control == TWO_DASHES ? "-" : "",
1034 ld_options[j].opt.name);
1035 len += ((comma ? 2 : 0)
1037 + (ld_options[j].control == TWO_DASHES ? 1 : 0)
1038 + strlen (ld_options[j].opt.name));
1039 if (ld_options[j].arg != NULL)
1041 printf (" %s", _(ld_options[j].arg));
1042 len += 1 + strlen (_(ld_options[j].arg));
1048 while (j < OPTION_COUNT && ld_options[j].doc == NULL);
1056 for (; len < 30; len++)
1059 printf ("%s\n", _(ld_options[i].doc));
1063 /* xgettext:c-format */
1064 printf (_("%s: supported targets:"), program_name);
1065 targets = bfd_target_list ();
1066 for (pp = targets; *pp != NULL; pp++)
1067 printf (" %s", *pp);
1071 /* xgettext:c-format */
1072 printf (_("%s: supported emulations: "), program_name);
1073 ldemul_list_emulations (stdout);
1076 /* xgettext:c-format */
1077 printf (_("%s: emulation specific options:\n"), program_name);
1078 ldemul_list_emulation_options (stdout);
1081 printf (_("\nReport bugs to bug-gnu-utils@gnu.org\n"));