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 | |
18 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
19 | ||
20 | #include "bfd.h" | |
21 | #include "sysdep.h" | |
22 | #include <stdio.h> | |
23 | #include <string.h> | |
24 | #include "getopt.h" | |
25 | #include "bfdlink.h" | |
26 | #include "config.h" | |
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" |
d4e5e3c3 DM |
36 | |
37 | /* Omit args to avoid the possibility of clashing with a system header | |
38 | that might disagree about consts. */ | |
39 | unsigned long strtoul (); | |
40 | ||
41 | static void set_default_dirlist PARAMS ((char *dirlist_ptr)); | |
42 | static void set_section_start PARAMS ((char *sect, char *valstr)); | |
43 | ||
44 | void | |
45 | parse_args (argc, argv) | |
46 | int argc; | |
47 | char **argv; | |
48 | { | |
49 | /* Starting the short option string with '-' is for programs that | |
50 | expect options and other ARGV-elements in any order and that care about | |
51 | the ordering of the two. We describe each non-option ARGV-element | |
52 | as if it were the argument of an option with character code 1. */ | |
53 | ||
d5b79a89 | 54 | const char *shortopts = "-A:B::b:cde:F::G:giL:l:Mm:NnO:o:R:rSsT:tu:VvXxY:y:"; |
d4e5e3c3 | 55 | |
d5b79a89 DM |
56 | /* 150 isn't special; it's just an arbitrary non-ASCII char value. */ |
57 | ||
58 | static struct option longopts[] = { | |
59 | #define OPTION_CALL_SHARED 150 | |
2a9fa50c | 60 | #define OPTION_NON_SHARED 151 |
d5b79a89 | 61 | {"call_shared", no_argument, NULL, OPTION_CALL_SHARED}, |
d4e5e3c3 | 62 | {"dc", no_argument, NULL, 'd'}, |
2a9fa50c | 63 | #define OPTION_DEFSYM 152 |
d5b79a89 | 64 | {"defsym", required_argument, NULL, OPTION_DEFSYM}, |
2a9fa50c | 65 | {"dn", no_argument, NULL, OPTION_NON_SHARED}, |
d4e5e3c3 | 66 | {"dp", no_argument, NULL, 'd'}, |
2a9fa50c ILT |
67 | {"dy", no_argument, NULL, OPTION_CALL_SHARED}, |
68 | #define OPTION_EB 153 | |
d5b79a89 | 69 | {"EB", no_argument, NULL, OPTION_EB}, |
2a9fa50c | 70 | #define OPTION_EL 154 |
d5b79a89 | 71 | {"EL", no_argument, NULL, OPTION_EL}, |
d4e5e3c3 | 72 | {"format", required_argument, NULL, 'b'}, |
2a9fa50c | 73 | #define OPTION_HELP 155 |
d5b79a89 | 74 | {"help", no_argument, NULL, OPTION_HELP}, |
2a9fa50c | 75 | #define OPTION_MAP 156 |
d5b79a89 | 76 | {"Map", required_argument, NULL, OPTION_MAP}, |
2a9fa50c | 77 | #define OPTION_NO_KEEP_MEMORY 157 |
d5b79a89 | 78 | {"no-keep-memory", no_argument, NULL, OPTION_NO_KEEP_MEMORY}, |
2a9fa50c | 79 | #define OPTION_NOINHIBIT_EXEC 158 |
d5b79a89 DM |
80 | {"noinhibit-exec", no_argument, NULL, OPTION_NOINHIBIT_EXEC}, |
81 | {"noinhibit_exec", no_argument, NULL, OPTION_NOINHIBIT_EXEC}, | |
2a9fa50c ILT |
82 | {"non_shared", no_argument, NULL, OPTION_NON_SHARED}, |
83 | #define OPTION_OFORMAT 159 | |
d5b79a89 | 84 | {"oformat", required_argument, NULL, OPTION_OFORMAT}, |
2a9fa50c ILT |
85 | #define OPTION_IGNORE 160 |
86 | {"Qy", no_argument, NULL, OPTION_IGNORE}, | |
87 | #define OPTION_RELAX 161 | |
d5b79a89 | 88 | {"relax", no_argument, NULL, OPTION_RELAX}, |
2a9fa50c | 89 | #define OPTION_RETAIN_SYMBOLS_FILE 162 |
d5b79a89 | 90 | {"retain-symbols-file", no_argument, NULL, OPTION_RETAIN_SYMBOLS_FILE}, |
2a9fa50c | 91 | #define OPTION_SORT_COMMON 163 |
d5b79a89 DM |
92 | {"sort-common", no_argument, NULL, OPTION_SORT_COMMON}, |
93 | {"sort_common", no_argument, NULL, OPTION_SORT_COMMON}, | |
2a9fa50c | 94 | #define OPTION_STATS 164 |
d5b79a89 | 95 | {"stats", no_argument, NULL, OPTION_STATS}, |
2a9fa50c | 96 | #define OPTION_TBSS 165 |
d5b79a89 | 97 | {"Tbss", required_argument, NULL, OPTION_TBSS}, |
2a9fa50c | 98 | #define OPTION_TDATA 166 |
d5b79a89 | 99 | {"Tdata", required_argument, NULL, OPTION_TDATA}, |
2a9fa50c | 100 | #define OPTION_TTEXT 167 |
d5b79a89 | 101 | {"Ttext", required_argument, NULL, OPTION_TTEXT}, |
2a9fa50c | 102 | #define OPTION_UR 168 |
d5b79a89 | 103 | {"Ur", no_argument, NULL, OPTION_UR}, |
2a9fa50c | 104 | #define OPTION_VERSION 169 |
d5b79a89 | 105 | {"version", no_argument, NULL, OPTION_VERSION}, |
2a9fa50c | 106 | #define OPTION_WARN_COMMON 170 |
d5b79a89 | 107 | {"warn-common", no_argument, NULL, OPTION_WARN_COMMON}, |
d4e5e3c3 DM |
108 | {NULL, no_argument, NULL, 0} |
109 | }; | |
110 | ||
111 | while (1) | |
112 | { | |
113 | /* getopt_long_only is like getopt_long, but '-' as well as '--' can | |
114 | indicate a long option. */ | |
d5b79a89 DM |
115 | int longind; |
116 | int optc = getopt_long_only (argc, argv, shortopts, longopts, &longind); | |
117 | ||
d4e5e3c3 DM |
118 | if (optc == -1) |
119 | break; | |
120 | ||
121 | switch (optc) | |
122 | { | |
123 | default: | |
124 | xexit (1); | |
125 | case 1: /* File name. */ | |
126 | lang_add_input_file (optarg, lang_input_file_is_file_enum, | |
127 | (char *) NULL); | |
128 | break; | |
129 | ||
2a9fa50c ILT |
130 | case OPTION_IGNORE: |
131 | break; | |
d4e5e3c3 DM |
132 | case 'A': |
133 | ldfile_add_arch (optarg); | |
134 | break; | |
135 | case 'B': | |
136 | /* Ignore. */ | |
137 | break; | |
138 | case 'b': | |
139 | lang_add_target (optarg); | |
140 | break; | |
141 | case 'c': | |
142 | ldfile_open_command_file (optarg); | |
143 | parser_input = input_mri_script; | |
144 | yyparse (); | |
145 | break; | |
d5b79a89 | 146 | case OPTION_CALL_SHARED: |
2a9fa50c ILT |
147 | config.dynamic_link = true; |
148 | break; | |
149 | case OPTION_NON_SHARED: | |
150 | config.dynamic_link = false; | |
d4e5e3c3 DM |
151 | break; |
152 | case 'd': | |
153 | command_line.force_common_definition = true; | |
154 | break; | |
d5b79a89 | 155 | case OPTION_DEFSYM: |
d4e5e3c3 DM |
156 | lex_redirect (optarg); |
157 | parser_input = input_defsym; | |
158 | yyparse (); | |
159 | break; | |
d5b79a89 | 160 | case OPTION_EB: |
d4e5e3c3 DM |
161 | /* FIXME: This is currently ignored. It means |
162 | ``produce a big-endian object file''. It could | |
163 | be used to select an output format. */ | |
164 | break; | |
d5b79a89 | 165 | case OPTION_EL: |
d4e5e3c3 DM |
166 | /* FIXME: This is currently ignored. It means |
167 | ``produce a little-endian object file''. It could | |
168 | be used to select an output format. */ | |
169 | break; | |
170 | case 'e': | |
60e8a534 | 171 | lang_add_entry (optarg, 1); |
d4e5e3c3 DM |
172 | break; |
173 | case 'F': | |
174 | /* Ignore. */ | |
175 | break; | |
176 | case 'G': | |
177 | { | |
178 | char *end; | |
179 | g_switch_value = strtoul (optarg, &end, 0); | |
180 | if (*end) | |
9d3898b2 | 181 | einfo ("%P%F: invalid number `%s'\n", optarg); |
d4e5e3c3 DM |
182 | } |
183 | break; | |
184 | case 'g': | |
185 | /* Ignore. */ | |
186 | break; | |
d5b79a89 | 187 | case OPTION_HELP: |
d4e5e3c3 DM |
188 | help (); |
189 | xexit (0); | |
190 | break; | |
191 | case 'L': | |
192 | ldfile_add_library_path (optarg); | |
193 | break; | |
194 | case 'l': | |
195 | lang_add_input_file (optarg, lang_input_file_is_l_enum, | |
196 | (char *) NULL); | |
197 | break; | |
198 | case 'M': | |
199 | config.map_filename = "-"; | |
200 | break; | |
201 | case 'm': | |
202 | /* Ignore. Was handled in a pre-parse. */ | |
203 | break; | |
d5b79a89 | 204 | case OPTION_MAP: |
d4e5e3c3 DM |
205 | config.map_filename = optarg; |
206 | break; | |
207 | case 'N': | |
208 | config.text_read_only = false; | |
209 | config.magic_demand_paged = false; | |
210 | break; | |
211 | case 'n': | |
212 | config.magic_demand_paged = false; | |
213 | break; | |
d5b79a89 | 214 | case OPTION_NO_KEEP_MEMORY: |
d4e5e3c3 DM |
215 | link_info.keep_memory = false; |
216 | break; | |
d5b79a89 | 217 | case OPTION_NOINHIBIT_EXEC: |
d4e5e3c3 DM |
218 | force_make_executable = true; |
219 | break; | |
220 | case 'O': | |
221 | /* FIXME "-O<non-digits> <value>" used to set the address of | |
222 | section <non-digits>. Was this for compatibility with | |
223 | something, or can we create a new option to do that | |
224 | (with a syntax similar to -defsym)? | |
225 | getopt can't handle two args to an option without kludges. */ | |
226 | set_default_dirlist (optarg); | |
227 | break; | |
228 | case 'o': | |
229 | lang_add_output (optarg, 0); | |
230 | break; | |
d5b79a89 | 231 | case OPTION_OFORMAT: |
d4e5e3c3 DM |
232 | lang_add_output_format (optarg, 0); |
233 | break; | |
234 | case 'r': | |
235 | link_info.relocateable = true; | |
236 | config.build_constructors = false; | |
237 | config.magic_demand_paged = false; | |
238 | config.text_read_only = false; | |
2a9fa50c | 239 | config.dynamic_link = false; |
d4e5e3c3 DM |
240 | break; |
241 | case 'R': | |
242 | lang_add_input_file (optarg, | |
243 | lang_input_file_is_symbols_only_enum, | |
244 | (char *) NULL); | |
245 | break; | |
d5b79a89 | 246 | case OPTION_RELAX: |
d4e5e3c3 DM |
247 | command_line.relax = true; |
248 | break; | |
d5b79a89 | 249 | case OPTION_RETAIN_SYMBOLS_FILE: |
d4e5e3c3 DM |
250 | add_keepsyms_file (optarg); |
251 | break; | |
252 | case 'S': | |
253 | link_info.strip = strip_debugger; | |
254 | break; | |
255 | case 's': | |
256 | link_info.strip = strip_all; | |
257 | break; | |
d5b79a89 | 258 | case OPTION_SORT_COMMON: |
d4e5e3c3 DM |
259 | config.sort_common = true; |
260 | break; | |
d5b79a89 | 261 | case OPTION_STATS: |
d4e5e3c3 DM |
262 | config.stats = true; |
263 | break; | |
264 | case 't': | |
265 | trace_files = true; | |
266 | break; | |
267 | case 'T': | |
268 | ldfile_open_command_file (optarg); | |
269 | parser_input = input_script; | |
270 | yyparse (); | |
271 | break; | |
d5b79a89 | 272 | case OPTION_TBSS: |
d4e5e3c3 DM |
273 | set_section_start (".bss", optarg); |
274 | break; | |
d5b79a89 | 275 | case OPTION_TDATA: |
d4e5e3c3 DM |
276 | set_section_start (".data", optarg); |
277 | break; | |
d5b79a89 | 278 | case OPTION_TTEXT: |
d4e5e3c3 DM |
279 | set_section_start (".text", optarg); |
280 | break; | |
d5b79a89 | 281 | case OPTION_UR: |
d4e5e3c3 DM |
282 | link_info.relocateable = true; |
283 | config.build_constructors = true; | |
284 | config.magic_demand_paged = false; | |
285 | config.text_read_only = false; | |
2a9fa50c | 286 | config.dynamic_link = false; |
d4e5e3c3 DM |
287 | break; |
288 | case 'u': | |
289 | ldlang_add_undef (optarg); | |
290 | break; | |
291 | case 'V': | |
292 | ldversion (1); | |
293 | version_printed = true; | |
294 | trace_file_tries = true; | |
295 | break; | |
296 | case 'v': | |
297 | ldversion (0); | |
298 | version_printed = true; | |
299 | break; | |
d5b79a89 | 300 | case OPTION_VERSION: |
d4e5e3c3 DM |
301 | ldversion (0); |
302 | version_printed = true; | |
303 | break; | |
d5b79a89 | 304 | case OPTION_WARN_COMMON: |
d4e5e3c3 DM |
305 | config.warn_common = true; |
306 | break; | |
307 | case 'X': | |
308 | link_info.discard = discard_l; | |
309 | break; | |
310 | case 'x': | |
311 | link_info.discard = discard_all; | |
312 | break; | |
d5b79a89 DM |
313 | case 'Y': |
314 | set_default_dirlist (optarg); | |
315 | break; | |
d4e5e3c3 DM |
316 | case 'y': |
317 | add_ysym (optarg); | |
318 | break; | |
319 | } | |
320 | } | |
321 | } | |
322 | ||
323 | /* Add the (colon-separated) elements of DIRLIST_PTR to the | |
324 | library search path. */ | |
325 | ||
326 | static void | |
327 | set_default_dirlist (dirlist_ptr) | |
328 | char *dirlist_ptr; | |
329 | { | |
330 | char *p; | |
331 | ||
332 | while (1) | |
333 | { | |
334 | p = strchr (dirlist_ptr, ':'); | |
335 | if (p != NULL) | |
336 | *p = 0; | |
337 | if (*dirlist_ptr) | |
338 | ldfile_add_library_path (dirlist_ptr); | |
339 | if (p == NULL) | |
340 | break; | |
341 | *p = ':'; | |
342 | dirlist_ptr = p + 1; | |
343 | } | |
344 | } | |
345 | ||
346 | static void | |
347 | set_section_start (sect, valstr) | |
348 | char *sect, *valstr; | |
349 | { | |
350 | char *end; | |
351 | unsigned long val = strtoul (valstr, &end, 16); | |
352 | if (*end) | |
d5b79a89 | 353 | einfo ("%P%F: invalid hex number `%s'\n", valstr); |
d4e5e3c3 DM |
354 | lang_section_start (sect, exp_intop (val)); |
355 | } |