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. */
37 /* Omit args to avoid the possibility of clashing with a system header
38 that might disagree about consts. */
39 unsigned long strtoul ();
41 static void set_default_dirlist PARAMS ((char *dirlist_ptr));
42 static void set_section_start PARAMS ((char *sect, char *valstr));
45 parse_args (argc, argv)
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. */
54 const char *shortopts = "-A:B::b:cde:F::G:giL:l:Mm:NnO:o:R:rSsT:tu:VvXxY:y:";
56 /* 150 isn't special; it's just an arbitrary non-ASCII char value. */
58 static struct option longopts[] = {
59 #define OPTION_CALL_SHARED 150
60 {"call_shared", no_argument, NULL, OPTION_CALL_SHARED},
61 {"dc", no_argument, NULL, 'd'},
62 #define OPTION_DEFSYM 151
63 {"defsym", required_argument, NULL, OPTION_DEFSYM},
64 {"dn", no_argument, NULL, OPTION_CALL_SHARED},
65 {"dp", no_argument, NULL, 'd'},
67 {"EB", no_argument, NULL, OPTION_EB},
69 {"EL", no_argument, NULL, OPTION_EL},
70 {"format", required_argument, NULL, 'b'},
71 #define OPTION_HELP 154
72 {"help", no_argument, NULL, OPTION_HELP},
73 #define OPTION_MAP 155
74 {"Map", required_argument, NULL, OPTION_MAP},
75 #define OPTION_NO_KEEP_MEMORY 156
76 {"no-keep-memory", no_argument, NULL, OPTION_NO_KEEP_MEMORY},
77 #define OPTION_NOINHIBIT_EXEC 157
78 {"noinhibit-exec", no_argument, NULL, OPTION_NOINHIBIT_EXEC},
79 {"noinhibit_exec", no_argument, NULL, OPTION_NOINHIBIT_EXEC},
80 {"non_shared", no_argument, NULL, OPTION_CALL_SHARED},
81 #define OPTION_OFORMAT 158
82 {"oformat", required_argument, NULL, OPTION_OFORMAT},
83 {"Qy", no_argument, NULL, OPTION_CALL_SHARED},
84 #define OPTION_RELAX 159
85 {"relax", no_argument, NULL, OPTION_RELAX},
86 #define OPTION_RETAIN_SYMBOLS_FILE 160
87 {"retain-symbols-file", no_argument, NULL, OPTION_RETAIN_SYMBOLS_FILE},
88 #define OPTION_SORT_COMMON 161
89 {"sort-common", no_argument, NULL, OPTION_SORT_COMMON},
90 {"sort_common", no_argument, NULL, OPTION_SORT_COMMON},
91 #define OPTION_STATS 162
92 {"stats", no_argument, NULL, OPTION_STATS},
93 #define OPTION_TBSS 163
94 {"Tbss", required_argument, NULL, OPTION_TBSS},
95 #define OPTION_TDATA 164
96 {"Tdata", required_argument, NULL, OPTION_TDATA},
97 #define OPTION_TTEXT 165
98 {"Ttext", required_argument, NULL, OPTION_TTEXT},
100 {"Ur", no_argument, NULL, OPTION_UR},
101 #define OPTION_VERSION 167
102 {"version", no_argument, NULL, OPTION_VERSION},
103 #define OPTION_WARN_COMMON 168
104 {"warn-common", no_argument, NULL, OPTION_WARN_COMMON},
105 {NULL, no_argument, NULL, 0}
110 /* getopt_long_only is like getopt_long, but '-' as well as '--' can
111 indicate a long option. */
113 int optc = getopt_long_only (argc, argv, shortopts, longopts, &longind);
122 case 1: /* File name. */
123 lang_add_input_file (optarg, lang_input_file_is_file_enum,
128 ldfile_add_arch (optarg);
134 lang_add_target (optarg);
137 ldfile_open_command_file (optarg);
138 parser_input = input_mri_script;
141 case OPTION_CALL_SHARED:
142 set_default_dirlist ((char *) longopts[longind].name);
145 command_line.force_common_definition = true;
148 lex_redirect (optarg);
149 parser_input = input_defsym;
153 /* FIXME: This is currently ignored. It means
154 ``produce a big-endian object file''. It could
155 be used to select an output format. */
158 /* FIXME: This is currently ignored. It means
159 ``produce a little-endian object file''. It could
160 be used to select an output format. */
163 lang_add_entry (optarg);
171 g_switch_value = strtoul (optarg, &end, 0);
173 einfo ("%P%F: invalid number `%s'\n", optarg);
184 ldfile_add_library_path (optarg);
187 lang_add_input_file (optarg, lang_input_file_is_l_enum,
191 config.map_filename = "-";
194 /* Ignore. Was handled in a pre-parse. */
198 config.map_filename = optarg;
201 config.text_read_only = false;
202 config.magic_demand_paged = false;
205 config.magic_demand_paged = false;
207 case OPTION_NO_KEEP_MEMORY:
208 link_info.keep_memory = false;
210 case OPTION_NOINHIBIT_EXEC:
211 force_make_executable = true;
214 /* FIXME "-O<non-digits> <value>" used to set the address of
215 section <non-digits>. Was this for compatibility with
216 something, or can we create a new option to do that
217 (with a syntax similar to -defsym)?
218 getopt can't handle two args to an option without kludges. */
219 set_default_dirlist (optarg);
222 lang_add_output (optarg, 0);
225 lang_add_output_format (optarg, 0);
228 link_info.relocateable = true;
229 config.build_constructors = false;
230 config.magic_demand_paged = false;
231 config.text_read_only = false;
234 lang_add_input_file (optarg,
235 lang_input_file_is_symbols_only_enum,
239 command_line.relax = true;
241 case OPTION_RETAIN_SYMBOLS_FILE:
242 add_keepsyms_file (optarg);
245 link_info.strip = strip_debugger;
248 link_info.strip = strip_all;
250 case OPTION_SORT_COMMON:
251 config.sort_common = true;
260 ldfile_open_command_file (optarg);
261 parser_input = input_script;
265 set_section_start (".bss", optarg);
268 set_section_start (".data", optarg);
271 set_section_start (".text", optarg);
274 link_info.relocateable = true;
275 config.build_constructors = true;
276 config.magic_demand_paged = false;
277 config.text_read_only = false;
280 ldlang_add_undef (optarg);
284 version_printed = true;
285 trace_file_tries = true;
289 version_printed = true;
293 version_printed = true;
295 case OPTION_WARN_COMMON:
296 config.warn_common = true;
299 link_info.discard = discard_l;
302 link_info.discard = discard_all;
305 set_default_dirlist (optarg);
314 /* Add the (colon-separated) elements of DIRLIST_PTR to the
315 library search path. */
318 set_default_dirlist (dirlist_ptr)
325 p = strchr (dirlist_ptr, ':');
329 ldfile_add_library_path (dirlist_ptr);
338 set_section_start (sect, valstr)
342 unsigned long val = strtoul (valstr, &end, 16);
344 einfo ("%P%F: invalid hex number `%s'\n", valstr);
345 lang_section_start (sect, exp_intop (val));