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