* lexsup.c (ld_options): Fix typo in --rpath-link description.
[deliverable/binutils-gdb.git] / ld / lexsup.c
1 /* Parse options for the GNU linker.
2 Copyright (C) 1991, 92, 93, 94, 95, 1996 Free Software Foundation, Inc.
3
4 This file is part of GLD, the Gnu Linker.
5
6 GLD is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GLD is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GLD; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
19
20 #include "bfd.h"
21 #include "sysdep.h"
22 #include "libiberty.h"
23 #include <stdio.h>
24 #include <string.h>
25 #include <ctype.h>
26 #include "getopt.h"
27 #include "bfdlink.h"
28 #include "ld.h"
29 #include "ldmain.h"
30 #include "ldmisc.h"
31 #include "ldexp.h"
32 #include "ldlang.h"
33 #include "ldgram.h"
34 #include "ldlex.h"
35 #include "ldfile.h"
36 #include "ldver.h"
37 #include "ldemul.h"
38
39 /* Somewhere above, sys/stat.h got included . . . . */
40 #if !defined(S_ISDIR) && defined(S_IFDIR)
41 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
42 #endif
43
44 /* Omit args to avoid the possibility of clashing with a system header
45 that might disagree about consts. */
46 unsigned long strtoul ();
47
48 static void set_default_dirlist PARAMS ((char *dirlist_ptr));
49 static void set_section_start PARAMS ((char *sect, char *valstr));
50 static void help PARAMS ((void));
51
52 /* Non-zero if we are processing a --defsym from the command line. */
53 int parsing_defsym = 0;
54
55 /* Codes used for the long options with no short synonyms. 150 isn't
56 special; it's just an arbitrary non-ASCII char value. */
57
58 #define OPTION_ASSERT 150
59 #define OPTION_CALL_SHARED (OPTION_ASSERT + 1)
60 #define OPTION_CREF (OPTION_CALL_SHARED + 1)
61 #define OPTION_DEFSYM (OPTION_CREF + 1)
62 #define OPTION_DYNAMIC_LINKER (OPTION_DEFSYM + 1)
63 #define OPTION_EB (OPTION_DYNAMIC_LINKER + 1)
64 #define OPTION_EL (OPTION_EB + 1)
65 #define OPTION_EMBEDDED_RELOCS (OPTION_EL + 1)
66 #define OPTION_EXPORT_DYNAMIC (OPTION_EMBEDDED_RELOCS + 1)
67 #define OPTION_HELP (OPTION_EXPORT_DYNAMIC + 1)
68 #define OPTION_IGNORE (OPTION_HELP + 1)
69 #define OPTION_MAP (OPTION_IGNORE + 1)
70 #define OPTION_NO_KEEP_MEMORY (OPTION_MAP + 1)
71 #define OPTION_NOINHIBIT_EXEC (OPTION_NO_KEEP_MEMORY + 1)
72 #define OPTION_NON_SHARED (OPTION_NOINHIBIT_EXEC + 1)
73 #define OPTION_NO_WHOLE_ARCHIVE (OPTION_NON_SHARED + 1)
74 #define OPTION_OFORMAT (OPTION_NO_WHOLE_ARCHIVE + 1)
75 #define OPTION_RELAX (OPTION_OFORMAT + 1)
76 #define OPTION_RETAIN_SYMBOLS_FILE (OPTION_RELAX + 1)
77 #define OPTION_RPATH (OPTION_RETAIN_SYMBOLS_FILE + 1)
78 #define OPTION_RPATH_LINK (OPTION_RPATH + 1)
79 #define OPTION_SHARED (OPTION_RPATH_LINK + 1)
80 #define OPTION_SONAME (OPTION_SHARED + 1)
81 #define OPTION_SORT_COMMON (OPTION_SONAME + 1)
82 #define OPTION_STATS (OPTION_SORT_COMMON + 1)
83 #define OPTION_SYMBOLIC (OPTION_STATS + 1)
84 #define OPTION_TBSS (OPTION_SYMBOLIC + 1)
85 #define OPTION_TDATA (OPTION_TBSS + 1)
86 #define OPTION_TTEXT (OPTION_TDATA + 1)
87 #define OPTION_TRADITIONAL_FORMAT (OPTION_TTEXT + 1)
88 #define OPTION_UR (OPTION_TRADITIONAL_FORMAT + 1)
89 #define OPTION_VERBOSE (OPTION_UR + 1)
90 #define OPTION_VERSION (OPTION_VERBOSE + 1)
91 #define OPTION_WARN_COMMON (OPTION_VERSION + 1)
92 #define OPTION_WARN_CONSTRUCTORS (OPTION_WARN_COMMON + 1)
93 #define OPTION_WARN_MULTIPLE_GP (OPTION_WARN_CONSTRUCTORS + 1)
94 #define OPTION_WARN_ONCE (OPTION_WARN_MULTIPLE_GP + 1)
95 #define OPTION_SPLIT_BY_RELOC (OPTION_WARN_ONCE + 1)
96 #define OPTION_SPLIT_BY_FILE (OPTION_SPLIT_BY_RELOC + 1)
97 #define OPTION_WHOLE_ARCHIVE (OPTION_SPLIT_BY_FILE + 1)
98 #define OPTION_WRAP (OPTION_WHOLE_ARCHIVE + 1)
99 #define OPTION_FORCE_EXE_SUFFIX (OPTION_WRAP + 1)
100
101 /* The long options. This structure is used for both the option
102 parsing and the help text. */
103
104 struct ld_option
105 {
106 /* The long option information. */
107 struct option opt;
108 /* The short option with the same meaning ('\0' if none). */
109 char shortopt;
110 /* The name of the argument (NULL if none). */
111 const char *arg;
112 /* The documentation string. If this is NULL, this is a synonym for
113 the previous option. */
114 const char *doc;
115 enum
116 {
117 /* Use one dash before long option name. */
118 ONE_DASH,
119 /* Use two dashes before long option name. */
120 TWO_DASHES,
121 /* Don't mention this option in --help output. */
122 NO_HELP
123 } control;
124 };
125
126 static const struct ld_option ld_options[] =
127 {
128 { {NULL, required_argument, NULL, '\0'},
129 'a', "KEYWORD", "Shared library control for HP/UX compatibility",
130 ONE_DASH },
131 { {"architecture", required_argument, NULL, 'A'},
132 'A', "ARCH", "Set architecture" , TWO_DASHES },
133 { {"format", required_argument, NULL, 'b'},
134 'b', "TARGET", "Specify target for following input files", TWO_DASHES },
135 { {"mri-script", required_argument, NULL, 'c'},
136 'c', "FILE", "Read MRI format linker script", TWO_DASHES },
137 { {"dc", no_argument, NULL, 'd'},
138 'd', NULL, "Force common symbols to be defined", ONE_DASH },
139 { {"dp", no_argument, NULL, 'd'},
140 '\0', NULL, NULL, ONE_DASH },
141 { {"entry", required_argument, NULL, 'e'},
142 'e', "ADDRESS", "Set start address", TWO_DASHES },
143 { {"export-dynamic", no_argument, NULL, OPTION_EXPORT_DYNAMIC},
144 'E', NULL, "Export all dynamic symbols", TWO_DASHES },
145 { {NULL, optional_argument, NULL, '\0'},
146 'F', "[FORMAT]", "Ignored", ONE_DASH },
147 { {NULL, no_argument, NULL, '\0'},
148 'g', NULL, "Ignored", ONE_DASH },
149 { {"gpsize", required_argument, NULL, 'G'},
150 'G', "SIZE", "Small data size (if no size, same as --shared)",
151 TWO_DASHES },
152 { {"soname", required_argument, NULL, OPTION_SONAME},
153 'h', "FILENAME", "Set internal name of shared library", ONE_DASH },
154 { {"library", required_argument, NULL, 'l'},
155 'l', "LIBNAME", "Search for library LIBNAME", TWO_DASHES },
156 { {"library-path", required_argument, NULL, 'L'},
157 'L', "DIRECTORY", "Add DIRECTORY to library search path", TWO_DASHES },
158 { {NULL, required_argument, NULL, '\0'},
159 'm', "EMULATION", "Set emulation", ONE_DASH },
160 { {"print-map", no_argument, NULL, 'M'},
161 'M', NULL, "Print map file on standard output", TWO_DASHES },
162 { {"nmagic", no_argument, NULL, 'n'},
163 'n', NULL, "Do not page align data", TWO_DASHES },
164 { {"omagic", no_argument, NULL, 'N'},
165 'N', NULL, "Do not page align data, do not make text readonly",
166 TWO_DASHES },
167 { {"output", required_argument, NULL, 'o'},
168 'o', "FILE", "Set output file name", TWO_DASHES },
169 { {NULL, required_argument, NULL, '\0'},
170 'O', NULL, "Ignored", ONE_DASH },
171 { {"relocateable", no_argument, NULL, 'r'},
172 'r', NULL, "Generate relocateable output", TWO_DASHES },
173 { {NULL, no_argument, NULL, '\0'},
174 'i', NULL, NULL, ONE_DASH },
175 { {"just-symbols", required_argument, NULL, 'R'},
176 'R', "FILE", "Just link symbols (if directory, same as --rpath)",
177 TWO_DASHES },
178 { {"strip-all", no_argument, NULL, 's'},
179 's', NULL, "Strip all symbols", TWO_DASHES },
180 { {"strip-debug", no_argument, NULL, 'S'},
181 'S', NULL, "Strip debugging symbols", TWO_DASHES },
182 { {"trace", no_argument, NULL, 't'},
183 't', NULL, "Trace file opens", TWO_DASHES },
184 { {"script", required_argument, NULL, 'T'},
185 'T', "FILE", "Read linker script", TWO_DASHES },
186 { {"undefined", required_argument, NULL, 'u'},
187 'u', "SYMBOL", "Start with undefined reference to SYMBOL", TWO_DASHES },
188 { {"version", no_argument, NULL, OPTION_VERSION},
189 'v', NULL, "Print version information", TWO_DASHES },
190 { {NULL, no_argument, NULL, '\0'},
191 'V', NULL, "Print version and emulation information", ONE_DASH },
192 { {"discard-all", no_argument, NULL, 'x'},
193 'x', NULL, "Discard all local symbols", TWO_DASHES },
194 { {"discard-locals", no_argument, NULL, 'X'},
195 'X', NULL, "Discard temporary local symbols", TWO_DASHES },
196 { {"trace-symbol", required_argument, NULL, 'y'},
197 'y', "SYMBOL", "Trace mentions of SYMBOL", TWO_DASHES },
198 { {NULL, required_argument, NULL, '\0'},
199 'Y', "PATH", "Default search path for Solaris compatibility", ONE_DASH },
200 { {NULL, required_argument, NULL, '\0'},
201 'z', "KEYWORD", "Ignored for Solaris compatibility", ONE_DASH },
202 { {"start-group", no_argument, NULL, '('},
203 '(', NULL, "Start a group", TWO_DASHES },
204 { {"end-group", no_argument, NULL, ')'},
205 ')', NULL, "End a group", TWO_DASHES },
206 { {"assert", required_argument, NULL, OPTION_ASSERT},
207 '\0', "KEYWORD", "Ignored for SunOS compatibility", ONE_DASH },
208 { {"Bdynamic", no_argument, NULL, OPTION_CALL_SHARED},
209 '\0', NULL, "Link against shared libraries", ONE_DASH },
210 { {"dy", no_argument, NULL, OPTION_CALL_SHARED},
211 '\0', NULL, NULL, ONE_DASH },
212 { {"call_shared", no_argument, NULL, OPTION_CALL_SHARED},
213 '\0', NULL, NULL, ONE_DASH },
214 { {"Bstatic", no_argument, NULL, OPTION_NON_SHARED},
215 '\0', NULL, "Do not link against shared libraries", ONE_DASH },
216 { {"dn", no_argument, NULL, OPTION_NON_SHARED},
217 '\0', NULL, NULL, ONE_DASH },
218 { {"non_shared", no_argument, NULL, OPTION_NON_SHARED},
219 '\0', NULL, NULL, ONE_DASH },
220 { {"static", no_argument, NULL, OPTION_NON_SHARED},
221 '\0', NULL, NULL, ONE_DASH },
222 { {"Bsymbolic", no_argument, NULL, OPTION_SYMBOLIC},
223 '\0', NULL, "Bind global references locally", ONE_DASH },
224 { {"cref", no_argument, NULL, OPTION_CREF},
225 '\0', NULL, "Output cross reference table", TWO_DASHES },
226 { {"defsym", required_argument, NULL, OPTION_DEFSYM},
227 '\0', "SYMBOL=EXPRESSION", "Define a symbol", TWO_DASHES },
228 { {"dynamic-linker", required_argument, NULL, OPTION_DYNAMIC_LINKER},
229 '\0', "PROGRAM", "Set the dynamic linker to use", TWO_DASHES },
230 { {"EB", no_argument, NULL, OPTION_EB},
231 '\0', NULL, "Link big-endian objects", ONE_DASH },
232 { {"EL", no_argument, NULL, OPTION_EL},
233 '\0', NULL, "Link little-endian objects", ONE_DASH },
234 { {"embedded-relocs", no_argument, NULL, OPTION_EMBEDDED_RELOCS},
235 '\0', NULL, "Generate embedded relocs", TWO_DASHES},
236 { {"force-exe-suffix", no_argument, NULL, OPTION_FORCE_EXE_SUFFIX},
237 '\0', NULL, "Force generation of file with .exe suffix", TWO_DASHES},
238 { {"help", no_argument, NULL, OPTION_HELP},
239 '\0', NULL, "Print option help", TWO_DASHES },
240 { {"Map", required_argument, NULL, OPTION_MAP},
241 '\0', "FILE", "Write a map file", ONE_DASH },
242 { {"no-keep-memory", no_argument, NULL, OPTION_NO_KEEP_MEMORY},
243 '\0', NULL, "Use less memory and more disk I/O", TWO_DASHES },
244 { {"no-whole-archive", no_argument, NULL, OPTION_NO_WHOLE_ARCHIVE},
245 '\0', NULL, "Turn off --whole-archive", TWO_DASHES },
246 { {"noinhibit-exec", no_argument, NULL, OPTION_NOINHIBIT_EXEC},
247 '\0', NULL, "Create an output file even if errors occur", TWO_DASHES },
248 { {"noinhibit_exec", no_argument, NULL, OPTION_NOINHIBIT_EXEC},
249 '\0', NULL, NULL, NO_HELP },
250 { {"oformat", required_argument, NULL, OPTION_OFORMAT},
251 '\0', "TARGET", "Specify target of output file", TWO_DASHES },
252 { {"qmagic", no_argument, NULL, OPTION_IGNORE},
253 '\0', NULL, "Ignored for Linux compatibility", ONE_DASH },
254 { {"Qy", no_argument, NULL, OPTION_IGNORE},
255 '\0', NULL, "Ignored for SVR4 compatibility", ONE_DASH },
256 { {"relax", no_argument, NULL, OPTION_RELAX},
257 '\0', NULL, "Relax branches on certain targets", TWO_DASHES },
258 { {"retain-symbols-file", required_argument, NULL,
259 OPTION_RETAIN_SYMBOLS_FILE},
260 '\0', "FILE", "Keep only symbols listed in FILE", TWO_DASHES },
261 { {"rpath", required_argument, NULL, OPTION_RPATH},
262 '\0', "PATH", "Set runtime shared library search path", ONE_DASH },
263 { {"rpath-link", required_argument, NULL, OPTION_RPATH_LINK},
264 '\0', "PATH", "Set link time shared library search path", ONE_DASH },
265 { {"shared", no_argument, NULL, OPTION_SHARED},
266 '\0', NULL, "Create a shared library", ONE_DASH },
267 { {"Bshareable", no_argument, NULL, OPTION_SHARED }, /* FreeBSD. */
268 '\0', NULL, NULL, ONE_DASH },
269 { {"sort-common", no_argument, NULL, OPTION_SORT_COMMON},
270 '\0', NULL, "Sort common symbols by size", TWO_DASHES },
271 { {"sort_common", no_argument, NULL, OPTION_SORT_COMMON},
272 '\0', NULL, NULL, NO_HELP },
273 { {"split-by-file", no_argument, NULL, OPTION_SPLIT_BY_FILE},
274 '\0', NULL, "Split output sections for each file", TWO_DASHES },
275 { {"split-by-reloc", required_argument, NULL, OPTION_SPLIT_BY_RELOC},
276 '\0', "COUNT", "Split output sections every COUNT relocs", TWO_DASHES },
277 { {"stats", no_argument, NULL, OPTION_STATS},
278 '\0', NULL, "Print memory usage statistics", TWO_DASHES },
279 { {"traditional-format", no_argument, NULL, OPTION_TRADITIONAL_FORMAT},
280 '\0', NULL, "Use same format as native linker", TWO_DASHES },
281 { {"Tbss", required_argument, NULL, OPTION_TBSS},
282 '\0', "ADDRESS", "Set address of .bss section", ONE_DASH },
283 { {"Tdata", required_argument, NULL, OPTION_TDATA},
284 '\0', "ADDRESS", "Set address of .data section", ONE_DASH },
285 { {"Ttext", required_argument, NULL, OPTION_TTEXT},
286 '\0', "ADDRESS", "Set address of .text section", ONE_DASH },
287 { {"Ur", no_argument, NULL, OPTION_UR},
288 '\0', NULL, "Build global constructor/destructor tables", ONE_DASH },
289 { {"verbose", no_argument, NULL, OPTION_VERBOSE},
290 '\0', NULL, "Output lots of information during link", TWO_DASHES },
291 { {"dll-verbose", no_argument, NULL, OPTION_VERBOSE}, /* Linux. */
292 '\0', NULL, NULL, NO_HELP },
293 { {"warn-common", no_argument, NULL, OPTION_WARN_COMMON},
294 '\0', NULL, "Warn about duplicate common symbols", TWO_DASHES },
295 { {"warn-constructors", no_argument, NULL, OPTION_WARN_CONSTRUCTORS},
296 '\0', NULL, "Warn if global constructors/destructors are seen",
297 TWO_DASHES },
298 { {"warn-multiple-gp", no_argument, NULL, OPTION_WARN_MULTIPLE_GP},
299 '\0', NULL, "Warn if the multiple GP values are used", TWO_DASHES },
300 { {"warn-once", no_argument, NULL, OPTION_WARN_ONCE},
301 '\0', NULL, "Warn only once per undefined symbol", TWO_DASHES },
302 { {"whole-archive", no_argument, NULL, OPTION_WHOLE_ARCHIVE},
303 '\0', NULL, "Include all objects from following archives", TWO_DASHES },
304 { {"wrap", required_argument, NULL, OPTION_WRAP},
305 '\0', "SYMBOL", "Use wrapper functions for SYMBOL", TWO_DASHES }
306 };
307
308 #define OPTION_COUNT (sizeof ld_options / sizeof ld_options[0])
309
310 void
311 parse_args (argc, argv)
312 int argc;
313 char **argv;
314 {
315 int i, is, il;
316 int ingroup = 0;
317 char *default_dirlist = NULL;
318 char shortopts[OPTION_COUNT * 3 + 2];
319 struct option longopts[OPTION_COUNT + 1];
320
321 /* Starting the short option string with '-' is for programs that
322 expect options and other ARGV-elements in any order and that care about
323 the ordering of the two. We describe each non-option ARGV-element
324 as if it were the argument of an option with character code 1. */
325 shortopts[0] = '-';
326 is = 1;
327 il = 0;
328 for (i = 0; i < OPTION_COUNT; i++)
329 {
330 if (ld_options[i].shortopt != '\0')
331 {
332 shortopts[is] = ld_options[i].shortopt;
333 ++is;
334 if (ld_options[i].opt.has_arg == required_argument
335 || ld_options[i].opt.has_arg == optional_argument)
336 {
337 shortopts[is] = ':';
338 ++is;
339 if (ld_options[i].opt.has_arg == optional_argument)
340 {
341 shortopts[is] = ':';
342 ++is;
343 }
344 }
345 }
346 if (ld_options[i].opt.name != NULL)
347 {
348 longopts[il] = ld_options[i].opt;
349 ++il;
350 }
351 }
352 shortopts[is] = '\0';
353 longopts[il].name = NULL;
354
355 /* The -G option is ambiguous on different platforms. Sometimes it
356 specifies the largest data size to put into the small data
357 section. Sometimes it is equivalent to --shared. Unfortunately,
358 the first form takes an argument, while the second does not.
359
360 We need to permit the --shared form because on some platforms,
361 such as Solaris, gcc -shared will pass -G to the linker.
362
363 To permit either usage, we look through the argument list. If we
364 find -G not followed by a number, we change it into --shared.
365 This will work for most normal cases. */
366 for (i = 1; i < argc; i++)
367 if (strcmp (argv[i], "-G") == 0
368 && (i + 1 >= argc
369 || ! isdigit (argv[i + 1][0])))
370 argv[i] = (char *) "--shared";
371
372 while (1)
373 {
374 /* getopt_long_only is like getopt_long, but '-' as well as '--' can
375 indicate a long option. */
376 int longind;
377 int optc;
378
379 if (ldemul_parse_args (argc, argv))
380 continue;
381
382 optc = getopt_long_only (argc, argv, shortopts, longopts, &longind);
383
384 if (optc == -1)
385 break;
386 switch (optc)
387 {
388 default:
389 xexit (1);
390 case 1: /* File name. */
391 lang_add_input_file (optarg, lang_input_file_is_file_enum,
392 (char *) NULL);
393 break;
394
395 case OPTION_IGNORE:
396 break;
397 case 'a':
398 /* For HP/UX compatibility. Actually -a shared should mean
399 ``use only shared libraries'' but, then, we don't
400 currently support shared libraries on HP/UX anyhow. */
401 if (strcmp (optarg, "archive") == 0)
402 config.dynamic_link = false;
403 else if (strcmp (optarg, "shared") == 0
404 || strcmp (optarg, "default") == 0)
405 config.dynamic_link = true;
406 else
407 einfo ("%P%F: unrecognized -a option `%s'\n", optarg);
408 break;
409 case OPTION_ASSERT:
410 /* FIXME: We just ignore these, but we should handle them. */
411 if (strcmp (optarg, "definitions") == 0)
412 ;
413 else if (strcmp (optarg, "nodefinitions") == 0)
414 ;
415 else if (strcmp (optarg, "nosymbolic") == 0)
416 ;
417 else if (strcmp (optarg, "pure-text") == 0)
418 ;
419 else
420 einfo ("%P%F: unrecognized -assert option `%s'\n", optarg);
421 break;
422 case 'A':
423 ldfile_add_arch (optarg);
424 break;
425 case 'b':
426 lang_add_target (optarg);
427 break;
428 case 'c':
429 ldfile_open_command_file (optarg);
430 parser_input = input_mri_script;
431 yyparse ();
432 break;
433 case OPTION_CALL_SHARED:
434 config.dynamic_link = true;
435 break;
436 case OPTION_NON_SHARED:
437 config.dynamic_link = false;
438 break;
439 case OPTION_CREF:
440 command_line.cref = true;
441 link_info.notice_all = true;
442 break;
443 case 'd':
444 command_line.force_common_definition = true;
445 break;
446 case OPTION_DEFSYM:
447 lex_string = optarg;
448 lex_redirect (optarg);
449 parser_input = input_defsym;
450 parsing_defsym = 1;
451 yyparse ();
452 parsing_defsym = 0;
453 lex_string = NULL;
454 break;
455 case OPTION_DYNAMIC_LINKER:
456 command_line.interpreter = optarg;
457 break;
458 case OPTION_EB:
459 command_line.endian = ENDIAN_BIG;
460 break;
461 case OPTION_EL:
462 command_line.endian = ENDIAN_LITTLE;
463 break;
464 case OPTION_EMBEDDED_RELOCS:
465 command_line.embedded_relocs = true;
466 break;
467 case OPTION_EXPORT_DYNAMIC:
468 case 'E': /* HP/UX compatibility. */
469 command_line.export_dynamic = true;
470 break;
471 case 'e':
472 lang_add_entry (optarg, true);
473 break;
474 case 'F':
475 /* Ignore. */
476 break;
477 case OPTION_FORCE_EXE_SUFFIX:
478 command_line.force_exe_suffix = true;
479 break;
480 case 'G':
481 {
482 char *end;
483 g_switch_value = strtoul (optarg, &end, 0);
484 if (*end)
485 einfo ("%P%F: invalid number `%s'\n", optarg);
486 }
487 break;
488 case 'g':
489 /* Ignore. */
490 break;
491 case OPTION_HELP:
492 help ();
493 xexit (0);
494 break;
495 case 'L':
496 ldfile_add_library_path (optarg, true);
497 break;
498 case 'l':
499 lang_add_input_file (optarg, lang_input_file_is_l_enum,
500 (char *) NULL);
501 break;
502 case 'M':
503 config.map_filename = "-";
504 break;
505 case 'm':
506 /* Ignore. Was handled in a pre-parse. */
507 break;
508 case OPTION_MAP:
509 config.map_filename = optarg;
510 break;
511 case 'N':
512 config.text_read_only = false;
513 config.magic_demand_paged = false;
514 config.dynamic_link = false;
515 break;
516 case 'n':
517 config.magic_demand_paged = false;
518 config.dynamic_link = false;
519 break;
520 case OPTION_NO_KEEP_MEMORY:
521 link_info.keep_memory = false;
522 break;
523 case OPTION_NOINHIBIT_EXEC:
524 force_make_executable = true;
525 break;
526 case OPTION_NO_WHOLE_ARCHIVE:
527 whole_archive = false;
528 break;
529 case 'O':
530 /* FIXME "-O<non-digits> <value>" used to set the address of
531 section <non-digits>. Was this for compatibility with
532 something, or can we create a new option to do that
533 (with a syntax similar to -defsym)?
534 getopt can't handle two args to an option without kludges. */
535 break;
536 case 'o':
537 lang_add_output (optarg, 0);
538 break;
539 case OPTION_OFORMAT:
540 lang_add_output_format (optarg, (char *) NULL, (char *) NULL, 0);
541 break;
542 case 'i':
543 case 'r':
544 link_info.relocateable = true;
545 config.build_constructors = false;
546 config.magic_demand_paged = false;
547 config.text_read_only = false;
548 config.dynamic_link = false;
549 break;
550 case 'R':
551 /* The GNU linker traditionally uses -R to mean to include
552 only the symbols from a file. The Solaris linker uses -R
553 to set the path used by the runtime linker to find
554 libraries. This is the GNU linker -rpath argument. We
555 try to support both simultaneously by checking the file
556 named. If it is a directory, rather than a regular file,
557 we assume -rpath was meant. */
558 {
559 struct stat s;
560
561 if (stat (optarg, &s) >= 0
562 && ! S_ISDIR (s.st_mode))
563 {
564 lang_add_input_file (optarg,
565 lang_input_file_is_symbols_only_enum,
566 (char *) NULL);
567 break;
568 }
569 }
570 /* Fall through. */
571 case OPTION_RPATH:
572 if (command_line.rpath == NULL)
573 command_line.rpath = buystring (optarg);
574 else
575 {
576 char *buf;
577
578 buf = xmalloc (strlen (command_line.rpath)
579 + strlen (optarg)
580 + 2);
581 sprintf (buf, "%s:%s", command_line.rpath, optarg);
582 free (command_line.rpath);
583 command_line.rpath = buf;
584 }
585 break;
586 case OPTION_RPATH_LINK:
587 if (command_line.rpath_link == NULL)
588 command_line.rpath_link = buystring (optarg);
589 else
590 {
591 char *buf;
592
593 buf = xmalloc (strlen (command_line.rpath_link)
594 + strlen (optarg)
595 + 2);
596 sprintf (buf, "%s:%s", command_line.rpath_link, optarg);
597 free (command_line.rpath_link);
598 command_line.rpath_link = buf;
599 }
600 break;
601 case OPTION_RELAX:
602 command_line.relax = true;
603 break;
604 case OPTION_RETAIN_SYMBOLS_FILE:
605 add_keepsyms_file (optarg);
606 break;
607 case 'S':
608 link_info.strip = strip_debugger;
609 break;
610 case 's':
611 link_info.strip = strip_all;
612 break;
613 case OPTION_SHARED:
614 link_info.shared = true;
615 break;
616 case 'h': /* Used on Solaris. */
617 case OPTION_SONAME:
618 command_line.soname = optarg;
619 break;
620 case OPTION_SORT_COMMON:
621 config.sort_common = true;
622 break;
623 case OPTION_STATS:
624 config.stats = true;
625 break;
626 case OPTION_SYMBOLIC:
627 link_info.symbolic = true;
628 break;
629 case 't':
630 trace_files = true;
631 break;
632 case 'T':
633 ldfile_open_command_file (optarg);
634 parser_input = input_script;
635 yyparse ();
636 break;
637 case OPTION_TBSS:
638 set_section_start (".bss", optarg);
639 break;
640 case OPTION_TDATA:
641 set_section_start (".data", optarg);
642 break;
643 case OPTION_TTEXT:
644 set_section_start (".text", optarg);
645 break;
646 case OPTION_TRADITIONAL_FORMAT:
647 link_info.traditional_format = true;
648 break;
649 case OPTION_UR:
650 link_info.relocateable = true;
651 config.build_constructors = true;
652 config.magic_demand_paged = false;
653 config.text_read_only = false;
654 config.dynamic_link = false;
655 break;
656 case 'u':
657 ldlang_add_undef (optarg);
658 break;
659 case OPTION_VERBOSE:
660 ldversion (1);
661 version_printed = true;
662 trace_file_tries = true;
663 break;
664 case 'v':
665 ldversion (0);
666 version_printed = true;
667 break;
668 case 'V':
669 ldversion (1);
670 version_printed = true;
671 break;
672 case OPTION_VERSION:
673 /* This output is intended to follow the GNU standards document. */
674 printf ("GNU ld %s\n", ld_program_version);
675 printf ("Copyright 1996 Free Software Foundation, Inc.\n");
676 printf ("\
677 This program is free software; you may redistribute it under the terms of\n\
678 the GNU General Public License. This program has absolutely no warranty.\n");
679 {
680 ld_emulation_xfer_type **ptr = ld_emulations;
681
682 printf (" Supported emulations:\n");
683 while (*ptr)
684 {
685 printf (" %s\n", (*ptr)->emulation_name);
686 ptr++;
687 }
688 }
689 xexit (0);
690 break;
691 case OPTION_WARN_COMMON:
692 config.warn_common = true;
693 break;
694 case OPTION_WARN_CONSTRUCTORS:
695 config.warn_constructors = true;
696 break;
697 case OPTION_WARN_MULTIPLE_GP:
698 config.warn_multiple_gp = true;
699 break;
700 case OPTION_WARN_ONCE:
701 config.warn_once = true;
702 break;
703 case OPTION_WHOLE_ARCHIVE:
704 whole_archive = true;
705 break;
706 case OPTION_WRAP:
707 add_wrap (optarg);
708 break;
709 case 'X':
710 link_info.discard = discard_l;
711 break;
712 case 'x':
713 link_info.discard = discard_all;
714 break;
715 case 'Y':
716 if (strncmp (optarg, "P,", 2) == 0)
717 optarg += 2;
718 default_dirlist = xstrdup (optarg);
719 break;
720 case 'y':
721 add_ysym (optarg);
722 break;
723 case 'z':
724 /* We accept and ignore this option for Solaris
725 compatibility. Actually, on Solaris, optarg is not
726 ignored. Someday we should handle it correctly. FIXME. */
727 break;
728 case OPTION_SPLIT_BY_RELOC:
729 config.split_by_reloc = atoi (optarg);
730 break;
731 case OPTION_SPLIT_BY_FILE:
732 config.split_by_file = true;
733 break;
734 case '(':
735 if (ingroup)
736 {
737 fprintf (stderr,
738 "%s: may not nest groups (--help for usage)\n",
739 program_name);
740 xexit (1);
741 }
742 lang_enter_group ();
743 ingroup = 1;
744 break;
745 case ')':
746 if (! ingroup)
747 {
748 fprintf (stderr,
749 "%s: group ended before it began (--help for usage)\n",
750 program_name);
751 xexit (1);
752 }
753 lang_leave_group ();
754 ingroup = 0;
755 break;
756
757 }
758 }
759
760 if (ingroup)
761 lang_leave_group ();
762
763 if (default_dirlist != NULL)
764 set_default_dirlist (default_dirlist);
765
766 }
767
768 /* Add the (colon-separated) elements of DIRLIST_PTR to the
769 library search path. */
770
771 static void
772 set_default_dirlist (dirlist_ptr)
773 char *dirlist_ptr;
774 {
775 char *p;
776
777 while (1)
778 {
779 p = strchr (dirlist_ptr, ':');
780 if (p != NULL)
781 *p = '\0';
782 if (*dirlist_ptr != '\0')
783 ldfile_add_library_path (dirlist_ptr, true);
784 if (p == NULL)
785 break;
786 dirlist_ptr = p + 1;
787 }
788 }
789
790 static void
791 set_section_start (sect, valstr)
792 char *sect, *valstr;
793 {
794 char *end;
795 unsigned long val = strtoul (valstr, &end, 16);
796 if (*end)
797 einfo ("%P%F: invalid hex number `%s'\n", valstr);
798 lang_section_start (sect, exp_intop (val));
799 }
800 \f
801 /* Print help messages for the options. */
802
803 static void
804 help ()
805 {
806 int i;
807 const char **targets, **pp;
808
809 printf ("Usage: %s [options] file...\n", program_name);
810
811 printf ("Options:\n");
812 for (i = 0; i < OPTION_COUNT; i++)
813 {
814 if (ld_options[i].doc != NULL)
815 {
816 boolean comma;
817 int len;
818 int j;
819
820 printf (" ");
821
822 comma = false;
823 len = 2;
824
825 j = i;
826 do
827 {
828 if (ld_options[j].shortopt != '\0'
829 && ld_options[j].control != NO_HELP)
830 {
831 printf ("%s-%c", comma ? ", " : "", ld_options[j].shortopt);
832 len += (comma ? 2 : 0) + 2;
833 if (ld_options[j].arg != NULL)
834 {
835 if (ld_options[j].opt.has_arg != optional_argument)
836 {
837 printf (" ");
838 ++len;
839 }
840 printf ("%s", ld_options[j].arg);
841 len += strlen (ld_options[j].arg);
842 }
843 comma = true;
844 }
845 ++j;
846 }
847 while (j < OPTION_COUNT && ld_options[j].doc == NULL);
848
849 j = i;
850 do
851 {
852 if (ld_options[j].opt.name != NULL
853 && ld_options[j].control != NO_HELP)
854 {
855 printf ("%s-%s%s",
856 comma ? ", " : "",
857 ld_options[j].control == TWO_DASHES ? "-" : "",
858 ld_options[j].opt.name);
859 len += ((comma ? 2 : 0)
860 + 1
861 + (ld_options[j].control == TWO_DASHES ? 1 : 0)
862 + strlen (ld_options[j].opt.name));
863 if (ld_options[j].arg != NULL)
864 {
865 printf (" %s", ld_options[j].arg);
866 len += 1 + strlen (ld_options[j].arg);
867 }
868 comma = true;
869 }
870 ++j;
871 }
872 while (j < OPTION_COUNT && ld_options[j].doc == NULL);
873
874 if (len >= 30)
875 {
876 printf ("\n");
877 len = 0;
878 }
879
880 for (; len < 30; len++)
881 putchar (' ');
882
883 printf ("%s\n", ld_options[i].doc);
884 }
885 }
886
887 printf ("%s: supported targets:", program_name);
888 targets = bfd_target_list ();
889 for (pp = targets; *pp != NULL; pp++)
890 printf (" %s", *pp);
891 free (targets);
892 printf ("\n");
893
894 printf ("%s: supported emulations: ", program_name);
895 ldemul_list_emulations (stdout);
896 printf ("\n");
897 printf ("\nReport bugs to bug-gnu-utils@prep.ai.mit.edu\n");
898 }
This page took 0.049036 seconds and 5 git commands to generate.