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