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