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