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