* ldmain.c (main): Remove PE stuff.
[binutils-gdb.git] / ld / lexsup.c
1 /* Parse options for the GNU linker.
2 Copyright (C) 1991, 92, 93, 94, 1995 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 <stdio.h>
23 #include <string.h>
24 #include <ctype.h>
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"
36 #include "ldver.h"
37
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
43 /* Omit args to avoid the possibility of clashing with a system header
44 that might disagree about consts. */
45 unsigned long strtoul ();
46
47 static void set_default_dirlist PARAMS ((char *dirlist_ptr));
48 static void set_section_start PARAMS ((char *sect, char *valstr));
49
50 /* PE format; declare additional functions */
51 static void set_pe_subsystem PARAMS ((void));
52 static void set_pe_stack_heap PARAMS ((bfd_link_pe_info_dval *reserve,
53 bfd_link_pe_info_dval *commit));
54 static void set_pe_value PARAMS ((bfd_link_pe_info_dval *val));
55
56 /* PE info; passed to bfd if any pe options set. */
57 static bfd_link_pe_info pe_info;
58
59
60 void
61 parse_args (argc, argv)
62 int argc;
63 char **argv;
64 {
65 int i;
66 int ingroup = 0;
67
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
73 const char *shortopts =
74 "-a:A:B::b:c:de:F::G:gh:iL:l:Mm:NnO:o:R:rSsT:tu:VvXxY:y:z:()";
75
76 /* 150 isn't special; it's just an arbitrary non-ASCII char value. */
77
78 #define OPTION_CALL_SHARED 150
79 #define OPTION_DEFSYM (OPTION_CALL_SHARED + 1)
80 #define OPTION_DYNAMIC_LINKER (OPTION_DEFSYM + 1)
81 #define OPTION_EB (OPTION_DYNAMIC_LINKER + 1)
82 #define OPTION_EL (OPTION_EB + 1)
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)
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)
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)
99 #define OPTION_STATS (OPTION_SORT_COMMON + 1)
100 #define OPTION_SYMBOLIC (OPTION_STATS + 1)
101 #define OPTION_TBSS (OPTION_SYMBOLIC + 1)
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)
106 #define OPTION_VERBOSE (OPTION_UR + 1)
107 #define OPTION_VERSION (OPTION_VERBOSE + 1)
108 #define OPTION_WARN_COMMON (OPTION_VERSION + 1)
109 #define OPTION_WARN_CONSTRUCTORS (OPTION_WARN_COMMON + 1)
110 #define OPTION_WARN_ONCE (OPTION_WARN_CONSTRUCTORS + 1)
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)
114
115 /* Used for setting flags in the PE header. */
116 #define OPTION_BASE_FILE (OPTION_WHOLE_ARCHIVE + 1)
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
130 static struct option longopts[] = {
131 /* Sorted alphabeticaly, except for the PE options grouped at the end. */
132 {"Bdynamic", no_argument, NULL, OPTION_CALL_SHARED},
133 {"Bstatic", no_argument, NULL, OPTION_NON_SHARED},
134 {"Bsymbolic", no_argument, NULL, OPTION_SYMBOLIC},
135 {"call_shared", no_argument, NULL, OPTION_CALL_SHARED},
136 {"dc", no_argument, NULL, 'd'},
137 {"defsym", required_argument, NULL, OPTION_DEFSYM},
138 {"dll-verbose", no_argument, NULL, OPTION_VERSION}, /* Linux. */
139 {"dn", no_argument, NULL, OPTION_NON_SHARED},
140 {"dp", no_argument, NULL, 'd'},
141 {"dy", no_argument, NULL, OPTION_CALL_SHARED},
142 {"dynamic-linker", required_argument, NULL, OPTION_DYNAMIC_LINKER},
143 {"EB", no_argument, NULL, OPTION_EB},
144 {"EL", no_argument, NULL, OPTION_EL},
145 {"embedded-relocs", no_argument, NULL, OPTION_EMBEDDED_RELOCS},
146 {"end-group", no_argument, NULL, ')'},
147 {"export-dynamic", no_argument, NULL, OPTION_EXPORT_DYNAMIC},
148 {"format", required_argument, NULL, 'b'},
149 {"help", no_argument, NULL, OPTION_HELP},
150 {"Map", required_argument, NULL, OPTION_MAP},
151 {"no-keep-memory", no_argument, NULL, OPTION_NO_KEEP_MEMORY},
152 {"noinhibit-exec", no_argument, NULL, OPTION_NOINHIBIT_EXEC},
153 {"noinhibit_exec", no_argument, NULL, OPTION_NOINHIBIT_EXEC},
154 {"non_shared", no_argument, NULL, OPTION_NON_SHARED},
155 {"oformat", required_argument, NULL, OPTION_OFORMAT},
156 {"Qy", no_argument, NULL, OPTION_IGNORE},
157 {"qmagic", no_argument, NULL, OPTION_IGNORE}, /* Linux compatibility. */
158 {"relax", no_argument, NULL, OPTION_RELAX},
159 {"retain-symbols-file", required_argument, NULL, OPTION_RETAIN_SYMBOLS_FILE},
160 {"rpath", required_argument, NULL, OPTION_RPATH},
161 {"shared", no_argument, NULL, OPTION_SHARED},
162 {"soname", required_argument, NULL, OPTION_SONAME},
163 {"sort-common", no_argument, NULL, OPTION_SORT_COMMON},
164 {"sort_common", no_argument, NULL, OPTION_SORT_COMMON},
165 {"start-group", no_argument, NULL, '('},
166 {"stats", no_argument, NULL, OPTION_STATS},
167 {"static", no_argument, NULL, OPTION_NON_SHARED},
168 {"Tbss", required_argument, NULL, OPTION_TBSS},
169 {"Tdata", required_argument, NULL, OPTION_TDATA},
170 {"Ttext", required_argument, NULL, OPTION_TTEXT},
171 {"traditional-format", no_argument, NULL, OPTION_TRADITIONAL_FORMAT},
172 {"Ur", no_argument, NULL, OPTION_UR},
173 {"verbose", no_argument, NULL, OPTION_VERBOSE},
174 {"version", no_argument, NULL, OPTION_VERSION},
175 {"warn-common", no_argument, NULL, OPTION_WARN_COMMON},
176 {"warn-constructors", no_argument, NULL, OPTION_WARN_CONSTRUCTORS},
177 {"warn-once", no_argument, NULL, OPTION_WARN_ONCE},
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},
181
182 /* PE options */
183 {"base-file", required_argument, NULL, OPTION_BASE_FILE},
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
198 {NULL, no_argument, NULL, 0}
199 };
200
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
218 while (1)
219 {
220 /* getopt_long_only is like getopt_long, but '-' as well as '--' can
221 indicate a long option. */
222 int longind;
223 int optc = getopt_long_only (argc, argv, shortopts, longopts, &longind);
224
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
237 case OPTION_IGNORE:
238 break;
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;
251 case 'A':
252 ldfile_add_arch (optarg);
253 break;
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;
262 case OPTION_CALL_SHARED:
263 config.dynamic_link = true;
264 break;
265 case OPTION_NON_SHARED:
266 config.dynamic_link = false;
267 break;
268 case 'd':
269 command_line.force_common_definition = true;
270 break;
271 case OPTION_DEFSYM:
272 lex_redirect (optarg);
273 parser_input = input_defsym;
274 yyparse ();
275 break;
276 case OPTION_DYNAMIC_LINKER:
277 command_line.interpreter = optarg;
278 break;
279 case OPTION_EB:
280 command_line.endian = ENDIAN_BIG;
281 break;
282 case OPTION_EL:
283 command_line.endian = ENDIAN_LITTLE;
284 break;
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;
291 case 'e':
292 lang_add_entry (optarg, 1);
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)
302 einfo ("%P%F: invalid number `%s'\n", optarg);
303 }
304 break;
305 case 'g':
306 /* Ignore. */
307 break;
308 case OPTION_HELP:
309 help ();
310 xexit (0);
311 break;
312 case 'L':
313 ldfile_add_library_path (optarg, true);
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;
325 case OPTION_MAP:
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;
335 case OPTION_NO_KEEP_MEMORY:
336 link_info.keep_memory = false;
337 break;
338 case OPTION_NOINHIBIT_EXEC:
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;
352 case OPTION_OFORMAT:
353 lang_add_output_format (optarg, (char *) NULL, (char *) NULL, 0);
354 break;
355 case 'i':
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;
361 config.dynamic_link = false;
362 break;
363 case 'R':
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 }
398 break;
399 case OPTION_RELAX:
400 command_line.relax = true;
401 break;
402 case OPTION_RETAIN_SYMBOLS_FILE:
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;
411 case OPTION_SHARED:
412 link_info.shared = true;
413 break;
414 case 'h': /* Used on Solaris. */
415 case OPTION_SONAME:
416 command_line.soname = optarg;
417 break;
418 case OPTION_SORT_COMMON:
419 config.sort_common = true;
420 break;
421 case OPTION_STATS:
422 config.stats = true;
423 break;
424 case OPTION_SYMBOLIC:
425 link_info.symbolic = true;
426 break;
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;
435 case OPTION_TBSS:
436 set_section_start (".bss", optarg);
437 break;
438 case OPTION_TDATA:
439 set_section_start (".data", optarg);
440 break;
441 case OPTION_TTEXT:
442 set_section_start (".text", optarg);
443 break;
444 case OPTION_TRADITIONAL_FORMAT:
445 config.traditional_format = true;
446 break;
447 case OPTION_UR:
448 link_info.relocateable = true;
449 config.build_constructors = true;
450 config.magic_demand_paged = false;
451 config.text_read_only = false;
452 config.dynamic_link = false;
453 break;
454 case 'u':
455 ldlang_add_undef (optarg);
456 break;
457 case OPTION_VERBOSE:
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;
466 case 'V':
467 ldversion (1);
468 version_printed = true;
469 break;
470 case OPTION_VERSION:
471 ldversion (0);
472 version_printed = true;
473 break;
474 case OPTION_WARN_COMMON:
475 config.warn_common = true;
476 break;
477 case OPTION_WARN_CONSTRUCTORS:
478 config.warn_constructors = true;
479 break;
480 case OPTION_WARN_ONCE:
481 config.warn_once = true;
482 break;
483 case OPTION_WHOLE_ARCHIVE:
484 whole_archive = true;
485 break;
486 case 'X':
487 link_info.discard = discard_l;
488 break;
489 case 'x':
490 link_info.discard = discard_all;
491 break;
492 case 'Y':
493 set_default_dirlist (optarg);
494 break;
495 case 'y':
496 add_ysym (optarg);
497 break;
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;
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;
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;
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;
585 }
586 }
587
588 if (ingroup)
589 lang_leave_group ();
590 }
591
592 /* Add the (colon-separated) elements of DIRLIST_PTR to the
593 library search path. */
594
595 static void
596 set_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)
607 ldfile_add_library_path (dirlist_ptr, true);
608 if (p == NULL)
609 break;
610 *p = ':';
611 dirlist_ptr = p + 1;
612 }
613 }
614
615 static void
616 set_section_start (sect, valstr)
617 char *sect, *valstr;
618 {
619 char *end;
620 unsigned long val = strtoul (valstr, &end, 16);
621 if (*end)
622 einfo ("%P%F: invalid hex number `%s'\n", valstr);
623 lang_section_start (sect, exp_intop (val));
624 }
625 \f
626 /* PE/WIN32; added routines to get the subsystem type, heap and/or stack
627 parameters which may be input from the command line */
628
629 static void
630 set_pe_subsystem ()
631 {
632 int i;
633 static struct
634 {
635 char *name ;
636 int value;
637 }
638 v[] =
639 {
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++)
649 {
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 }
657 }
658 einfo ("%P%F: invalid subsystem type `%s'\n", optarg);
659 }
660
661 static void
662 set_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)
668 {
669 einfo ("%P%F: invalid hex number for PE parameter '%s'\n", optarg);
670 }
671
672 optarg = end;
673 ptr->defined = 1;
674 link_info.pe_info = &pe_info;
675 }
676
677 static void
678 set_pe_stack_heap (reserve, commit)
679 bfd_link_pe_info_dval *reserve;
680 bfd_link_pe_info_dval *commit;
681 {
682 char *begin_commit;
683 char *end;
684
685 set_pe_value (reserve);
686 if (*optarg == ',')
687 {
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);
694 }
695 }
696
697