1 /* Parse options for the GNU linker.
2 Copyright (C) 1991, 92, 93, 94 Free Software Foundation, Inc.
4 This file is part of GLD, the Gnu Linker.
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)
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.
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. */
36 /* Omit args to avoid the possibility of clashing with a system header
37 that might disagree about consts. */
38 unsigned long strtoul ();
40 static void set_default_dirlist PARAMS ((char *dirlist_ptr));
41 static void set_section_start PARAMS ((char *sect, char *valstr));
44 parse_args (argc, argv)
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. */
53 const char *shortopts = "-A:B::b:cde:F::G:giL:l:Mm:NnO:o:R:rSsT:tu:VvXxY:y:";
55 /* 150 isn't special; it's just an arbitrary non-ASCII char value. */
57 static struct option longopts[] = {
58 #define OPTION_CALL_SHARED 150
59 {"call_shared", no_argument, NULL, OPTION_CALL_SHARED},
60 {"dc", no_argument, NULL, 'd'},
61 #define OPTION_DEFSYM 151
62 {"defsym", required_argument, NULL, OPTION_DEFSYM},
63 {"dn", no_argument, NULL, OPTION_CALL_SHARED},
64 {"dp", no_argument, NULL, 'd'},
66 {"EB", no_argument, NULL, OPTION_EB},
68 {"EL", no_argument, NULL, OPTION_EL},
69 {"format", required_argument, NULL, 'b'},
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},
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},
104 {NULL, no_argument, NULL, 0}
109 /* getopt_long_only is like getopt_long, but '-' as well as '--' can
110 indicate a long option. */
112 int optc = getopt_long_only (argc, argv, shortopts, longopts, &longind);
121 case 1: /* File name. */
122 lang_add_input_file (optarg, lang_input_file_is_file_enum,
127 ldfile_add_arch (optarg);
133 lang_add_target (optarg);
136 ldfile_open_command_file (optarg);
137 parser_input = input_mri_script;
140 case OPTION_CALL_SHARED:
141 set_default_dirlist ((char *) longopts[longind].name);
144 command_line.force_common_definition = true;
147 lex_redirect (optarg);
148 parser_input = input_defsym;
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. */
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. */
162 lang_add_entry (optarg);
170 g_switch_value = strtoul (optarg, &end, 0);
172 einfo ("%P%F: invalid number `%s'\n", optarg);
183 ldfile_add_library_path (optarg);
186 lang_add_input_file (optarg, lang_input_file_is_l_enum,
190 config.map_filename = "-";
193 /* Ignore. Was handled in a pre-parse. */
197 config.map_filename = optarg;
200 config.text_read_only = false;
201 config.magic_demand_paged = false;
204 config.magic_demand_paged = false;
206 case OPTION_NO_KEEP_MEMORY:
207 link_info.keep_memory = false;
209 case OPTION_NOINHIBIT_EXEC:
210 force_make_executable = true;
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);
221 lang_add_output (optarg, 0);
224 lang_add_output_format (optarg, 0);
227 link_info.relocateable = true;
228 config.build_constructors = false;
229 config.magic_demand_paged = false;
230 config.text_read_only = false;
233 lang_add_input_file (optarg,
234 lang_input_file_is_symbols_only_enum,
238 command_line.relax = true;
240 case OPTION_RETAIN_SYMBOLS_FILE:
241 add_keepsyms_file (optarg);
244 link_info.strip = strip_debugger;
247 link_info.strip = strip_all;
249 case OPTION_SORT_COMMON:
250 config.sort_common = true;
259 ldfile_open_command_file (optarg);
260 parser_input = input_script;
264 set_section_start (".bss", optarg);
267 set_section_start (".data", optarg);
270 set_section_start (".text", optarg);
273 link_info.relocateable = true;
274 config.build_constructors = true;
275 config.magic_demand_paged = false;
276 config.text_read_only = false;
279 ldlang_add_undef (optarg);
283 version_printed = true;
284 trace_file_tries = true;
288 version_printed = true;
292 version_printed = true;
294 case OPTION_WARN_COMMON:
295 config.warn_common = true;
298 link_info.discard = discard_l;
301 link_info.discard = discard_all;
304 set_default_dirlist (optarg);
313 /* Add the (colon-separated) elements of DIRLIST_PTR to the
314 library search path. */
317 set_default_dirlist (dirlist_ptr)
324 p = strchr (dirlist_ptr, ':');
328 ldfile_add_library_path (dirlist_ptr);
337 set_section_start (sect, valstr)
341 unsigned long val = strtoul (valstr, &end, 16);
343 einfo ("%P%F: invalid hex number `%s'\n", valstr);
344 lang_section_start (sect, exp_intop (val));