Convert i960 COFF to use COFF backend linker.
[deliverable/binutils-gdb.git] / ld / lexsup.c
CommitLineData
d4e5e3c3 1/* Parse options for the GNU linker.
80fd1f45 2 Copyright (C) 1991, 92, 93, 94, 1995 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"
27#include "config.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"
4725fb48 36#include "ldver.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));
49
229ba4b3
SC
50/* PE format; declare additional functions */
51static void set_pe_subsystem PARAMS ((void));
52static void set_pe_stack_heap PARAMS ((bfd_link_pe_info_dval *reserve,
53 bfd_link_pe_info_dval *commit));
54static void set_pe_value PARAMS ((bfd_link_pe_info_dval *val));
55
56/* PE info; passed to bfd if any pe options set. */
57static bfd_link_pe_info pe_info;
58
de71eb77 59
d4e5e3c3
DM
60void
61parse_args (argc, argv)
62 int argc;
63 char **argv;
64{
22d3533c 65 int i;
db770dfa
ILT
66 int ingroup = 0;
67
d4e5e3c3
DM
68 /* Starting the short option string with '-' is for programs that
69 expect options and other ARGV-elements in any order and that care about
70 the ordering of the two. We describe each non-option ARGV-element
71 as if it were the argument of an option with character code 1. */
72
db770dfa 73 const char *shortopts =
80fd1f45 74 "-a:A:B::b:c:de:F::G:gh:iL:l:Mm:NnO:o:R:rSsT:tu:VvXxY:y:z:()";
d4e5e3c3 75
d5b79a89
DM
76 /* 150 isn't special; it's just an arbitrary non-ASCII char value. */
77
bec7a138
ILT
78#define OPTION_CALL_SHARED 150
79#define OPTION_DEFSYM (OPTION_CALL_SHARED + 1)
7fb9ca5f
ILT
80#define OPTION_DYNAMIC_LINKER (OPTION_DEFSYM + 1)
81#define OPTION_EB (OPTION_DYNAMIC_LINKER + 1)
bec7a138 82#define OPTION_EL (OPTION_EB + 1)
de71eb77
SC
83#define OPTION_HEAP (OPTION_EL + 1)
84#define OPTION_EMBEDDED_RELOCS (OPTION_HEAP + 1)
85#define OPTION_EXPORT_DYNAMIC (OPTION_EMBEDDED_RELOCS + 1)
86#define OPTION_HELP (OPTION_EXPORT_DYNAMIC + 1)
bec7a138
ILT
87#define OPTION_IGNORE (OPTION_HELP + 1)
88#define OPTION_MAP (OPTION_IGNORE + 1)
89#define OPTION_NO_KEEP_MEMORY (OPTION_MAP + 1)
90#define OPTION_NOINHIBIT_EXEC (OPTION_NO_KEEP_MEMORY + 1)
91#define OPTION_NON_SHARED (OPTION_NOINHIBIT_EXEC + 1)
92#define OPTION_OFORMAT (OPTION_NON_SHARED + 1)
93#define OPTION_RELAX (OPTION_OFORMAT + 1)
94#define OPTION_RETAIN_SYMBOLS_FILE (OPTION_RELAX + 1)
809ee7e0
ILT
95#define OPTION_RPATH (OPTION_RETAIN_SYMBOLS_FILE + 1)
96#define OPTION_SHARED (OPTION_RPATH + 1)
97#define OPTION_SONAME (OPTION_SHARED + 1)
98#define OPTION_SORT_COMMON (OPTION_SONAME + 1)
229ba4b3
SC
99#define OPTION_STATS (OPTION_SORT_COMMON + 1)
100#define OPTION_SYMBOLIC (OPTION_STATS + 1)
4551e108 101#define OPTION_TBSS (OPTION_SYMBOLIC + 1)
bec7a138
ILT
102#define OPTION_TDATA (OPTION_TBSS + 1)
103#define OPTION_TTEXT (OPTION_TDATA + 1)
104#define OPTION_TRADITIONAL_FORMAT (OPTION_TTEXT + 1)
105#define OPTION_UR (OPTION_TRADITIONAL_FORMAT + 1)
de71eb77
SC
106#define OPTION_VERBOSE (OPTION_UR + 1)
107#define OPTION_VERSION (OPTION_VERBOSE + 1)
bec7a138 108#define OPTION_WARN_COMMON (OPTION_VERSION + 1)
80fd1f45
ILT
109#define OPTION_WARN_CONSTRUCTORS (OPTION_WARN_COMMON + 1)
110#define OPTION_WARN_ONCE (OPTION_WARN_CONSTRUCTORS + 1)
de71eb77
SC
111#define OPTION_SPLIT_BY_RELOC (OPTION_WARN_ONCE + 1)
112#define OPTION_SPLIT_BY_FILE (OPTION_SPLIT_BY_RELOC + 1)
113#define OPTION_WHOLE_ARCHIVE (OPTION_SPLIT_BY_FILE + 1)
229ba4b3
SC
114
115/* Used for setting flags in the PE header. */
de71eb77 116#define OPTION_BASE_FILE (OPTION_WHOLE_ARCHIVE + 1)
229ba4b3
SC
117#define OPTION_DLL (OPTION_BASE_FILE + 1)
118#define OPTION_FILE_ALIGNMENT (OPTION_DLL + 1)
119#define OPTION_IMAGE_BASE (OPTION_FILE_ALIGNMENT + 1)
120#define OPTION_MAJOR_IMAGE_VERSION (OPTION_IMAGE_BASE + 1)
121#define OPTION_MAJOR_OS_VERSION (OPTION_MAJOR_IMAGE_VERSION + 1)
122#define OPTION_MAJOR_SUBSYSTEM_VERSION (OPTION_MAJOR_OS_VERSION + 1)
123#define OPTION_MINOR_IMAGE_VERSION (OPTION_MAJOR_SUBSYSTEM_VERSION + 1)
124#define OPTION_MINOR_OS_VERSION (OPTION_MINOR_IMAGE_VERSION + 1)
125#define OPTION_MINOR_SUBSYSTEM_VERSION (OPTION_MINOR_OS_VERSION + 1)
126#define OPTION_SECTION_ALIGNMENT (OPTION_MINOR_SUBSYSTEM_VERSION + 1)
127#define OPTION_STACK (OPTION_SECTION_ALIGNMENT + 1)
128#define OPTION_SUBSYSTEM (OPTION_STACK + 1)
129
d5b79a89 130 static struct option longopts[] = {
229ba4b3 131 /* Sorted alphabeticaly, except for the PE options grouped at the end. */
db770dfa
ILT
132 {"Bdynamic", no_argument, NULL, OPTION_CALL_SHARED},
133 {"Bstatic", no_argument, NULL, OPTION_NON_SHARED},
4551e108 134 {"Bsymbolic", no_argument, NULL, OPTION_SYMBOLIC},
d5b79a89 135 {"call_shared", no_argument, NULL, OPTION_CALL_SHARED},
d4e5e3c3 136 {"dc", no_argument, NULL, 'd'},
d5b79a89 137 {"defsym", required_argument, NULL, OPTION_DEFSYM},
809ee7e0 138 {"dll-verbose", no_argument, NULL, OPTION_VERSION}, /* Linux. */
2a9fa50c 139 {"dn", no_argument, NULL, OPTION_NON_SHARED},
d4e5e3c3 140 {"dp", no_argument, NULL, 'd'},
2a9fa50c 141 {"dy", no_argument, NULL, OPTION_CALL_SHARED},
7fb9ca5f 142 {"dynamic-linker", required_argument, NULL, OPTION_DYNAMIC_LINKER},
d5b79a89 143 {"EB", no_argument, NULL, OPTION_EB},
d5b79a89 144 {"EL", no_argument, NULL, OPTION_EL},
de71eb77 145 {"embedded-relocs", no_argument, NULL, OPTION_EMBEDDED_RELOCS},
db770dfa 146 {"end-group", no_argument, NULL, ')'},
de71eb77 147 {"export-dynamic", no_argument, NULL, OPTION_EXPORT_DYNAMIC},
d4e5e3c3 148 {"format", required_argument, NULL, 'b'},
d5b79a89 149 {"help", no_argument, NULL, OPTION_HELP},
d5b79a89 150 {"Map", required_argument, NULL, OPTION_MAP},
d5b79a89 151 {"no-keep-memory", no_argument, NULL, OPTION_NO_KEEP_MEMORY},
d5b79a89
DM
152 {"noinhibit-exec", no_argument, NULL, OPTION_NOINHIBIT_EXEC},
153 {"noinhibit_exec", no_argument, NULL, OPTION_NOINHIBIT_EXEC},
2a9fa50c 154 {"non_shared", no_argument, NULL, OPTION_NON_SHARED},
d5b79a89 155 {"oformat", required_argument, NULL, OPTION_OFORMAT},
2a9fa50c 156 {"Qy", no_argument, NULL, OPTION_IGNORE},
cbbf9608 157 {"qmagic", no_argument, NULL, OPTION_IGNORE}, /* Linux compatibility. */
d5b79a89 158 {"relax", no_argument, NULL, OPTION_RELAX},
db770dfa 159 {"retain-symbols-file", required_argument, NULL, OPTION_RETAIN_SYMBOLS_FILE},
809ee7e0 160 {"rpath", required_argument, NULL, OPTION_RPATH},
db770dfa 161 {"shared", no_argument, NULL, OPTION_SHARED},
809ee7e0 162 {"soname", required_argument, NULL, OPTION_SONAME},
d5b79a89
DM
163 {"sort-common", no_argument, NULL, OPTION_SORT_COMMON},
164 {"sort_common", no_argument, NULL, OPTION_SORT_COMMON},
db770dfa 165 {"start-group", no_argument, NULL, '('},
d5b79a89 166 {"stats", no_argument, NULL, OPTION_STATS},
42792411 167 {"static", no_argument, NULL, OPTION_NON_SHARED},
d5b79a89 168 {"Tbss", required_argument, NULL, OPTION_TBSS},
d5b79a89 169 {"Tdata", required_argument, NULL, OPTION_TDATA},
d5b79a89 170 {"Ttext", required_argument, NULL, OPTION_TTEXT},
c96386c4 171 {"traditional-format", no_argument, NULL, OPTION_TRADITIONAL_FORMAT},
d5b79a89 172 {"Ur", no_argument, NULL, OPTION_UR},
de71eb77 173 {"verbose", no_argument, NULL, OPTION_VERBOSE},
d5b79a89 174 {"version", no_argument, NULL, OPTION_VERSION},
d5b79a89 175 {"warn-common", no_argument, NULL, OPTION_WARN_COMMON},
80fd1f45 176 {"warn-constructors", no_argument, NULL, OPTION_WARN_CONSTRUCTORS},
809ee7e0 177 {"warn-once", no_argument, NULL, OPTION_WARN_ONCE},
de71eb77
SC
178 {"split-by-reloc", required_argument, NULL, OPTION_SPLIT_BY_RELOC},
179 {"split-by-file", no_argument, NULL, OPTION_SPLIT_BY_FILE},
180 {"whole-archive", no_argument, NULL, OPTION_WHOLE_ARCHIVE},
229ba4b3
SC
181
182 /* PE options */
de71eb77 183 {"base-file", required_argument, NULL, OPTION_BASE_FILE},
229ba4b3
SC
184 {"dll", no_argument, NULL, OPTION_DLL},
185 {"file-alignment", required_argument, NULL, OPTION_FILE_ALIGNMENT},
186 {"heap", required_argument, NULL, OPTION_HEAP},
187 {"image-base", required_argument, NULL, OPTION_IMAGE_BASE},
188 {"major-image-version", required_argument, NULL, OPTION_MAJOR_IMAGE_VERSION},
189 {"major-os-version", required_argument, NULL, OPTION_MAJOR_OS_VERSION},
190 {"major-subsystem-version", required_argument, NULL, OPTION_MAJOR_SUBSYSTEM_VERSION},
191 {"minor-image-version", required_argument, NULL, OPTION_MINOR_IMAGE_VERSION},
192 {"minor-os-version", required_argument, NULL, OPTION_MINOR_OS_VERSION},
193 {"minor-subsystem-version", required_argument, NULL, OPTION_MINOR_SUBSYSTEM_VERSION},
194 {"section-alignment", required_argument, NULL, OPTION_SECTION_ALIGNMENT},
195 {"stack", required_argument, NULL, OPTION_STACK},
196 {"subsystem", required_argument, NULL, OPTION_SUBSYSTEM},
197
d4e5e3c3
DM
198 {NULL, no_argument, NULL, 0}
199 };
200
22d3533c
ILT
201 /* The -G option is ambiguous on different platforms. Sometimes it
202 specifies the largest data size to put into the small data
203 section. Sometimes it is equivalent to --shared. Unfortunately,
204 the first form takes an argument, while the second does not.
205
206 We need to permit the --shared form because on some platforms,
207 such as Solaris, gcc -shared will pass -G to the linker.
208
209 To permit either usage, we look through the argument list. If we
210 find -G not followed by a number, we change it into --shared.
211 This will work for most normal cases. */
212 for (i = 1; i < argc; i++)
213 if (strcmp (argv[i], "-G") == 0
214 && (i + 1 >= argc
215 || ! isdigit (argv[i + 1][0])))
216 argv[i] = (char *) "--shared";
217
d4e5e3c3
DM
218 while (1)
219 {
220 /* getopt_long_only is like getopt_long, but '-' as well as '--' can
221 indicate a long option. */
d5b79a89
DM
222 int longind;
223 int optc = getopt_long_only (argc, argv, shortopts, longopts, &longind);
224
d4e5e3c3
DM
225 if (optc == -1)
226 break;
227
228 switch (optc)
229 {
230 default:
231 xexit (1);
232 case 1: /* File name. */
233 lang_add_input_file (optarg, lang_input_file_is_file_enum,
234 (char *) NULL);
235 break;
236
2a9fa50c
ILT
237 case OPTION_IGNORE:
238 break;
de71eb77
SC
239 case 'a':
240 /* For HP/UX compatibility. Actually -a shared should mean
241 ``use only shared libraries'' but, then, we don't
242 currently support shared libraries on HP/UX anyhow. */
243 if (strcmp (optarg, "archive") == 0)
244 config.dynamic_link = false;
245 else if (strcmp (optarg, "shared") == 0
246 || strcmp (optarg, "default") == 0)
247 config.dynamic_link = true;
248 else
249 einfo ("%P%F: unrecognized -a option `%s'\n", optarg);
250 break;
d4e5e3c3
DM
251 case 'A':
252 ldfile_add_arch (optarg);
253 break;
d4e5e3c3
DM
254 case 'b':
255 lang_add_target (optarg);
256 break;
257 case 'c':
258 ldfile_open_command_file (optarg);
259 parser_input = input_mri_script;
260 yyparse ();
261 break;
d5b79a89 262 case OPTION_CALL_SHARED:
2a9fa50c
ILT
263 config.dynamic_link = true;
264 break;
265 case OPTION_NON_SHARED:
266 config.dynamic_link = false;
d4e5e3c3
DM
267 break;
268 case 'd':
269 command_line.force_common_definition = true;
270 break;
d5b79a89 271 case OPTION_DEFSYM:
d4e5e3c3
DM
272 lex_redirect (optarg);
273 parser_input = input_defsym;
274 yyparse ();
275 break;
7fb9ca5f
ILT
276 case OPTION_DYNAMIC_LINKER:
277 command_line.interpreter = optarg;
278 break;
d5b79a89 279 case OPTION_EB:
86037281 280 command_line.endian = ENDIAN_BIG;
d4e5e3c3 281 break;
d5b79a89 282 case OPTION_EL:
86037281 283 command_line.endian = ENDIAN_LITTLE;
d4e5e3c3 284 break;
de71eb77
SC
285 case OPTION_EMBEDDED_RELOCS:
286 command_line.embedded_relocs = true;
287 break;
288 case OPTION_EXPORT_DYNAMIC:
289 command_line.export_dynamic = true;
290 break;
d4e5e3c3 291 case 'e':
60e8a534 292 lang_add_entry (optarg, 1);
d4e5e3c3
DM
293 break;
294 case 'F':
295 /* Ignore. */
296 break;
297 case 'G':
298 {
299 char *end;
300 g_switch_value = strtoul (optarg, &end, 0);
301 if (*end)
9d3898b2 302 einfo ("%P%F: invalid number `%s'\n", optarg);
d4e5e3c3
DM
303 }
304 break;
305 case 'g':
306 /* Ignore. */
307 break;
d5b79a89 308 case OPTION_HELP:
d4e5e3c3
DM
309 help ();
310 xexit (0);
311 break;
312 case 'L':
0cd82d00 313 ldfile_add_library_path (optarg, true);
d4e5e3c3
DM
314 break;
315 case 'l':
316 lang_add_input_file (optarg, lang_input_file_is_l_enum,
317 (char *) NULL);
318 break;
319 case 'M':
320 config.map_filename = "-";
321 break;
322 case 'm':
323 /* Ignore. Was handled in a pre-parse. */
324 break;
d5b79a89 325 case OPTION_MAP:
d4e5e3c3
DM
326 config.map_filename = optarg;
327 break;
328 case 'N':
329 config.text_read_only = false;
330 config.magic_demand_paged = false;
331 break;
332 case 'n':
333 config.magic_demand_paged = false;
334 break;
d5b79a89 335 case OPTION_NO_KEEP_MEMORY:
d4e5e3c3
DM
336 link_info.keep_memory = false;
337 break;
d5b79a89 338 case OPTION_NOINHIBIT_EXEC:
d4e5e3c3
DM
339 force_make_executable = true;
340 break;
341 case 'O':
342 /* FIXME "-O<non-digits> <value>" used to set the address of
343 section <non-digits>. Was this for compatibility with
344 something, or can we create a new option to do that
345 (with a syntax similar to -defsym)?
346 getopt can't handle two args to an option without kludges. */
347 set_default_dirlist (optarg);
348 break;
349 case 'o':
350 lang_add_output (optarg, 0);
351 break;
d5b79a89 352 case OPTION_OFORMAT:
86037281 353 lang_add_output_format (optarg, (char *) NULL, (char *) NULL, 0);
d4e5e3c3 354 break;
3e1fd33d 355 case 'i':
d4e5e3c3
DM
356 case 'r':
357 link_info.relocateable = true;
358 config.build_constructors = false;
359 config.magic_demand_paged = false;
360 config.text_read_only = false;
2a9fa50c 361 config.dynamic_link = false;
d4e5e3c3
DM
362 break;
363 case 'R':
809ee7e0
ILT
364 /* The GNU linker traditionally uses -R to mean to include
365 only the symbols from a file. The Solaris linker uses -R
366 to set the path used by the runtime linker to find
367 libraries. This is the GNU linker -rpath argument. We
368 try to support both simultaneously by checking the file
369 named. If it is a directory, rather than a regular file,
370 we assume -rpath was meant. */
371 {
372 struct stat s;
373
374 if (stat (optarg, &s) >= 0
375 && ! S_ISDIR (s.st_mode))
376 {
377 lang_add_input_file (optarg,
378 lang_input_file_is_symbols_only_enum,
379 (char *) NULL);
380 break;
381 }
382 }
383 /* Fall through. */
384 case OPTION_RPATH:
385 if (command_line.rpath == NULL)
386 command_line.rpath = buystring (optarg);
387 else
388 {
389 char *buf;
390
391 buf = xmalloc (strlen (command_line.rpath)
392 + strlen (optarg)
393 + 2);
394 sprintf (buf, "%s:%s", command_line.rpath, optarg);
395 free (command_line.rpath);
396 command_line.rpath = buf;
397 }
d4e5e3c3 398 break;
d5b79a89 399 case OPTION_RELAX:
d4e5e3c3
DM
400 command_line.relax = true;
401 break;
d5b79a89 402 case OPTION_RETAIN_SYMBOLS_FILE:
d4e5e3c3
DM
403 add_keepsyms_file (optarg);
404 break;
405 case 'S':
406 link_info.strip = strip_debugger;
407 break;
408 case 's':
409 link_info.strip = strip_all;
410 break;
db770dfa
ILT
411 case OPTION_SHARED:
412 link_info.shared = true;
413 break;
80fd1f45 414 case 'h': /* Used on Solaris. */
809ee7e0
ILT
415 case OPTION_SONAME:
416 command_line.soname = optarg;
417 break;
d5b79a89 418 case OPTION_SORT_COMMON:
d4e5e3c3
DM
419 config.sort_common = true;
420 break;
d5b79a89 421 case OPTION_STATS:
d4e5e3c3
DM
422 config.stats = true;
423 break;
4551e108
ILT
424 case OPTION_SYMBOLIC:
425 link_info.symbolic = true;
426 break;
d4e5e3c3
DM
427 case 't':
428 trace_files = true;
429 break;
430 case 'T':
431 ldfile_open_command_file (optarg);
432 parser_input = input_script;
433 yyparse ();
434 break;
d5b79a89 435 case OPTION_TBSS:
d4e5e3c3
DM
436 set_section_start (".bss", optarg);
437 break;
d5b79a89 438 case OPTION_TDATA:
d4e5e3c3
DM
439 set_section_start (".data", optarg);
440 break;
d5b79a89 441 case OPTION_TTEXT:
d4e5e3c3
DM
442 set_section_start (".text", optarg);
443 break;
c96386c4
ILT
444 case OPTION_TRADITIONAL_FORMAT:
445 config.traditional_format = true;
446 break;
d5b79a89 447 case OPTION_UR:
d4e5e3c3
DM
448 link_info.relocateable = true;
449 config.build_constructors = true;
450 config.magic_demand_paged = false;
451 config.text_read_only = false;
2a9fa50c 452 config.dynamic_link = false;
d4e5e3c3
DM
453 break;
454 case 'u':
455 ldlang_add_undef (optarg);
456 break;
de71eb77 457 case OPTION_VERBOSE:
d4e5e3c3
DM
458 ldversion (1);
459 version_printed = true;
460 trace_file_tries = true;
461 break;
462 case 'v':
463 ldversion (0);
464 version_printed = true;
465 break;
de71eb77
SC
466 case 'V':
467 ldversion (1);
468 version_printed = true;
469 break;
d5b79a89 470 case OPTION_VERSION:
d4e5e3c3
DM
471 ldversion (0);
472 version_printed = true;
473 break;
d5b79a89 474 case OPTION_WARN_COMMON:
d4e5e3c3
DM
475 config.warn_common = true;
476 break;
80fd1f45
ILT
477 case OPTION_WARN_CONSTRUCTORS:
478 config.warn_constructors = true;
479 break;
809ee7e0
ILT
480 case OPTION_WARN_ONCE:
481 config.warn_once = true;
482 break;
de71eb77
SC
483 case OPTION_WHOLE_ARCHIVE:
484 whole_archive = true;
485 break;
d4e5e3c3
DM
486 case 'X':
487 link_info.discard = discard_l;
488 break;
489 case 'x':
490 link_info.discard = discard_all;
491 break;
d5b79a89
DM
492 case 'Y':
493 set_default_dirlist (optarg);
494 break;
d4e5e3c3
DM
495 case 'y':
496 add_ysym (optarg);
497 break;
22d3533c
ILT
498 case 'z':
499 /* We accept and ignore this option for Solaris
500 compatibility. Actually, on Solaris, optarg is not
501 ignored. Someday we should handle it correctly. FIXME. */
502 break;
de71eb77
SC
503 case OPTION_SPLIT_BY_RELOC:
504 config.split_by_reloc = atoi (optarg);
505 break;
506 case OPTION_SPLIT_BY_FILE:
507 config.split_by_file = true;
508 break;
db770dfa
ILT
509 case '(':
510 if (ingroup)
511 {
512 fprintf (stderr,
513 "%s: may not nest groups (--help for usage)\n",
514 program_name);
515 xexit (1);
516 }
517 lang_enter_group ();
518 ingroup = 1;
519 break;
520 case ')':
521 if (! ingroup)
522 {
523 fprintf (stderr,
524 "%s: group ended before it began (--help for usage)\n",
525 program_name);
526 xexit (1);
527 }
528 lang_leave_group ();
529 ingroup = 0;
530 break;
229ba4b3
SC
531
532
533
534 case OPTION_BASE_FILE:
535 link_info.base_file = (PTR) fopen (optarg,"w");
536 if (link_info.base_file == NULL)
537 {
538 fprintf (stderr, "%s: Can't open base file %s\n",
539 program_name, optarg);
540 xexit (1);
541 }
542 break;
543
544 /* PE options */
545 case OPTION_HEAP:
546 set_pe_stack_heap (&pe_info.heap_reserve, &pe_info.heap_commit);
547 break;
548 case OPTION_STACK:
549 set_pe_stack_heap (&pe_info.stack_reserve, &pe_info.stack_commit);
550 break;
551 case OPTION_SUBSYSTEM:
552 set_pe_subsystem ();
553 break;
554 case OPTION_MAJOR_OS_VERSION:
555 set_pe_value (&pe_info.major_os_version);
556 break;
557 case OPTION_MINOR_OS_VERSION:
558 set_pe_value (&pe_info.minor_os_version);
559 break;
560 case OPTION_MAJOR_SUBSYSTEM_VERSION:
561 set_pe_value (&pe_info.major_subsystem_version);
562 break;
563 case OPTION_MINOR_SUBSYSTEM_VERSION:
564 set_pe_value (&pe_info.minor_subsystem_version);
565 break;
566 case OPTION_MAJOR_IMAGE_VERSION:
567 set_pe_value (&pe_info.major_image_version);
568 break;
569 case OPTION_MINOR_IMAGE_VERSION:
570 set_pe_value (&pe_info.minor_image_version);
571 break;
572 case OPTION_FILE_ALIGNMENT:
573 set_pe_value (&pe_info.file_alignment);
574 break;
575 case OPTION_SECTION_ALIGNMENT:
576 set_pe_value (&pe_info.section_alignment);
577 break;
578 case OPTION_DLL:
579 pe_info.dll.defined = 1;
580 pe_info.dll.value = 1;
581 break;
582 case OPTION_IMAGE_BASE:
583 set_pe_value (&pe_info.image_base);
584 break;
d4e5e3c3
DM
585 }
586 }
db770dfa
ILT
587
588 if (ingroup)
589 lang_leave_group ();
d4e5e3c3
DM
590}
591
592/* Add the (colon-separated) elements of DIRLIST_PTR to the
593 library search path. */
594
595static void
596set_default_dirlist (dirlist_ptr)
597 char *dirlist_ptr;
598{
599 char *p;
600
601 while (1)
602 {
603 p = strchr (dirlist_ptr, ':');
604 if (p != NULL)
605 *p = 0;
606 if (*dirlist_ptr)
0cd82d00 607 ldfile_add_library_path (dirlist_ptr, true);
d4e5e3c3
DM
608 if (p == NULL)
609 break;
610 *p = ':';
611 dirlist_ptr = p + 1;
612 }
613}
614
615static void
616set_section_start (sect, valstr)
617 char *sect, *valstr;
618{
619 char *end;
620 unsigned long val = strtoul (valstr, &end, 16);
621 if (*end)
d5b79a89 622 einfo ("%P%F: invalid hex number `%s'\n", valstr);
d4e5e3c3
DM
623 lang_section_start (sect, exp_intop (val));
624}
229ba4b3
SC
625\f
626/* PE/WIN32; added routines to get the subsystem type, heap and/or stack
de71eb77 627 parameters which may be input from the command line */
229ba4b3 628
de71eb77 629static void
229ba4b3 630set_pe_subsystem ()
de71eb77 631{
229ba4b3
SC
632 int i;
633 static struct
de71eb77 634 {
229ba4b3
SC
635 char *name ;
636 int value;
de71eb77 637 }
229ba4b3 638 v[] =
de71eb77 639 {
229ba4b3
SC
640 {"native", BFD_PE_NATIVE},
641 {"windows",BFD_PE_WINDOWS},
642 {"console",BFD_PE_CONSOLE},
643 {"os2",BFD_PE_OS2},
644 {"posix", BFD_PE_POSIX},
645 {0,0}
646 };
647
648 for (i = 0; v[i].name; i++)
de71eb77 649 {
229ba4b3
SC
650 if (!strcmp (optarg, v[i].name))
651 {
652 link_info.pe_info = &pe_info;
653 pe_info.subsystem.value = v[i].value;
654 pe_info.subsystem.defined = 1;
655 return;
656 }
de71eb77 657 }
229ba4b3
SC
658 einfo ("%P%F: invalid subsystem type `%s'\n", optarg);
659}
660
661static void
662set_pe_value (ptr)
663 bfd_link_pe_info_dval *ptr;
664{
665 char *end;
666 ptr->value = strtoul (optarg, &end, 16);
667 if (end == optarg)
de71eb77 668 {
229ba4b3 669 einfo ("%P%F: invalid hex number for PE parameter '%s'\n", optarg);
de71eb77 670 }
de71eb77 671
229ba4b3
SC
672 optarg = end;
673 ptr->defined = 1;
674 link_info.pe_info = &pe_info;
de71eb77
SC
675}
676
677static void
229ba4b3
SC
678set_pe_stack_heap (reserve, commit)
679 bfd_link_pe_info_dval *reserve;
680 bfd_link_pe_info_dval *commit;
de71eb77 681{
229ba4b3
SC
682 char *begin_commit;
683 char *end;
684
685 set_pe_value (reserve);
686 if (*optarg == ',')
de71eb77 687 {
229ba4b3
SC
688 optarg++;
689 set_pe_value (commit);
690 }
691 else if (*optarg)
692 {
693 einfo ("%P%F: strange hex info for PE parameter '%s'\n", optarg);
de71eb77 694 }
de71eb77 695}
229ba4b3
SC
696
697
This page took 0.153197 seconds and 4 git commands to generate.