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 #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)
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 {"static", no_argument, NULL, OPTION_NON_SHARED},
108 {"Tbss", required_argument, NULL, OPTION_TBSS},
109 {"Tdata", required_argument, NULL, OPTION_TDATA},
110 {"Ttext", required_argument, NULL, OPTION_TTEXT},
111 {"traditional-format", no_argument, NULL, OPTION_TRADITIONAL_FORMAT},
112 {"Ur", no_argument, NULL, OPTION_UR},
113 {"version", no_argument, NULL, OPTION_VERSION},
114 {"warn-common", no_argument, NULL, OPTION_WARN_COMMON},
115 {NULL, no_argument, NULL, 0}
120 /* getopt_long_only is like getopt_long, but '-' as well as '--' can
121 indicate a long option. */
123 int optc = getopt_long_only (argc, argv, shortopts, longopts, &longind);
132 case 1: /* File name. */
133 lang_add_input_file (optarg, lang_input_file_is_file_enum,
140 ldfile_add_arch (optarg);
146 lang_add_target (optarg);
149 ldfile_open_command_file (optarg);
150 parser_input = input_mri_script;
153 case OPTION_CALL_SHARED:
154 config.dynamic_link = true;
156 case OPTION_NON_SHARED:
157 config.dynamic_link = false;
160 command_line.force_common_definition = true;
163 lex_redirect (optarg);
164 parser_input = input_defsym;
167 case OPTION_DYNAMIC_LINKER:
168 command_line.interpreter = optarg;
171 /* FIXME: This is currently ignored. It means
172 ``produce a big-endian object file''. It could
173 be used to select an output format. */
176 /* FIXME: This is currently ignored. It means
177 ``produce a little-endian object file''. It could
178 be used to select an output format. */
181 lang_add_entry (optarg, 1);
189 g_switch_value = strtoul (optarg, &end, 0);
191 einfo ("%P%F: invalid number `%s'\n", optarg);
202 ldfile_add_library_path (optarg, true);
205 lang_add_input_file (optarg, lang_input_file_is_l_enum,
209 config.map_filename = "-";
212 /* Ignore. Was handled in a pre-parse. */
215 config.map_filename = optarg;
218 config.text_read_only = false;
219 config.magic_demand_paged = false;
222 config.magic_demand_paged = false;
224 case OPTION_NO_KEEP_MEMORY:
225 link_info.keep_memory = false;
227 case OPTION_NOINHIBIT_EXEC:
228 force_make_executable = true;
231 /* FIXME "-O<non-digits> <value>" used to set the address of
232 section <non-digits>. Was this for compatibility with
233 something, or can we create a new option to do that
234 (with a syntax similar to -defsym)?
235 getopt can't handle two args to an option without kludges. */
236 set_default_dirlist (optarg);
239 lang_add_output (optarg, 0);
242 lang_add_output_format (optarg, 0);
246 link_info.relocateable = true;
247 config.build_constructors = false;
248 config.magic_demand_paged = false;
249 config.text_read_only = false;
250 config.dynamic_link = false;
253 lang_add_input_file (optarg,
254 lang_input_file_is_symbols_only_enum,
258 command_line.relax = true;
260 case OPTION_RETAIN_SYMBOLS_FILE:
261 add_keepsyms_file (optarg);
264 link_info.strip = strip_debugger;
267 link_info.strip = strip_all;
269 case OPTION_SORT_COMMON:
270 config.sort_common = true;
279 ldfile_open_command_file (optarg);
280 parser_input = input_script;
284 set_section_start (".bss", optarg);
287 set_section_start (".data", optarg);
290 set_section_start (".text", optarg);
292 case OPTION_TRADITIONAL_FORMAT:
293 config.traditional_format = true;
296 link_info.relocateable = true;
297 config.build_constructors = true;
298 config.magic_demand_paged = false;
299 config.text_read_only = false;
300 config.dynamic_link = false;
303 ldlang_add_undef (optarg);
307 version_printed = true;
308 trace_file_tries = true;
312 version_printed = true;
316 version_printed = true;
318 case OPTION_WARN_COMMON:
319 config.warn_common = true;
322 link_info.discard = discard_l;
325 link_info.discard = discard_all;
328 set_default_dirlist (optarg);
337 /* Add the (colon-separated) elements of DIRLIST_PTR to the
338 library search path. */
341 set_default_dirlist (dirlist_ptr)
348 p = strchr (dirlist_ptr, ':');
352 ldfile_add_library_path (dirlist_ptr, true);
361 set_section_start (sect, valstr)
365 unsigned long val = strtoul (valstr, &end, 16);
367 einfo ("%P%F: invalid hex number `%s'\n", valstr);
368 lang_section_start (sect, exp_intop (val));