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_EB (OPTION_DEFSYM + 1)
61 #define OPTION_EL (OPTION_EB + 1)
62 #define OPTION_HELP (OPTION_EL + 1)
63 #define OPTION_IGNORE (OPTION_HELP + 1)
64 #define OPTION_MAP (OPTION_IGNORE + 1)
65 #define OPTION_NO_KEEP_MEMORY (OPTION_MAP + 1)
66 #define OPTION_NOINHIBIT_EXEC (OPTION_NO_KEEP_MEMORY + 1)
67 #define OPTION_NON_SHARED (OPTION_NOINHIBIT_EXEC + 1)
68 #define OPTION_OFORMAT (OPTION_NON_SHARED + 1)
69 #define OPTION_RELAX (OPTION_OFORMAT + 1)
70 #define OPTION_RETAIN_SYMBOLS_FILE (OPTION_RELAX + 1)
71 #define OPTION_SORT_COMMON (OPTION_RETAIN_SYMBOLS_FILE + 1)
72 #define OPTION_STATS (OPTION_SORT_COMMON + 1)
73 #define OPTION_TBSS (OPTION_STATS + 1)
74 #define OPTION_TDATA (OPTION_TBSS + 1)
75 #define OPTION_TTEXT (OPTION_TDATA + 1)
76 #define OPTION_TRADITIONAL_FORMAT (OPTION_TTEXT + 1)
77 #define OPTION_UR (OPTION_TRADITIONAL_FORMAT + 1)
78 #define OPTION_VERSION (OPTION_UR + 1)
79 #define OPTION_WARN_COMMON (OPTION_VERSION + 1)
81 static struct option longopts[] = {
82 {"call_shared", no_argument, NULL, OPTION_CALL_SHARED},
83 {"dc", no_argument, NULL, 'd'},
84 {"defsym", required_argument, NULL, OPTION_DEFSYM},
85 {"dn", no_argument, NULL, OPTION_NON_SHARED},
86 {"dp", no_argument, NULL, 'd'},
87 {"dy", no_argument, NULL, OPTION_CALL_SHARED},
88 {"EB", no_argument, NULL, OPTION_EB},
89 {"EL", no_argument, NULL, OPTION_EL},
90 {"format", required_argument, NULL, 'b'},
91 {"help", no_argument, NULL, OPTION_HELP},
92 {"Map", required_argument, NULL, OPTION_MAP},
93 {"no-keep-memory", no_argument, NULL, OPTION_NO_KEEP_MEMORY},
94 {"noinhibit-exec", no_argument, NULL, OPTION_NOINHIBIT_EXEC},
95 {"noinhibit_exec", no_argument, NULL, OPTION_NOINHIBIT_EXEC},
96 {"non_shared", no_argument, NULL, OPTION_NON_SHARED},
97 {"oformat", required_argument, NULL, OPTION_OFORMAT},
98 {"Qy", no_argument, NULL, OPTION_IGNORE},
99 {"relax", no_argument, NULL, OPTION_RELAX},
100 {"retain-symbols-file", no_argument, NULL, OPTION_RETAIN_SYMBOLS_FILE},
101 {"sort-common", no_argument, NULL, OPTION_SORT_COMMON},
102 {"sort_common", no_argument, NULL, OPTION_SORT_COMMON},
103 {"stats", no_argument, NULL, OPTION_STATS},
104 {"Tbss", required_argument, NULL, OPTION_TBSS},
105 {"Tdata", required_argument, NULL, OPTION_TDATA},
106 {"Ttext", required_argument, NULL, OPTION_TTEXT},
107 {"traditional-format", no_argument, NULL, OPTION_TRADITIONAL_FORMAT},
108 {"Ur", no_argument, NULL, OPTION_UR},
109 {"version", no_argument, NULL, OPTION_VERSION},
110 {"warn-common", no_argument, NULL, OPTION_WARN_COMMON},
111 {NULL, no_argument, NULL, 0}
116 /* getopt_long_only is like getopt_long, but '-' as well as '--' can
117 indicate a long option. */
119 int optc = getopt_long_only (argc, argv, shortopts, longopts, &longind);
128 case 1: /* File name. */
129 lang_add_input_file (optarg, lang_input_file_is_file_enum,
136 ldfile_add_arch (optarg);
142 lang_add_target (optarg);
145 ldfile_open_command_file (optarg);
146 parser_input = input_mri_script;
149 case OPTION_CALL_SHARED:
150 config.dynamic_link = true;
152 case OPTION_NON_SHARED:
153 config.dynamic_link = false;
156 command_line.force_common_definition = true;
159 lex_redirect (optarg);
160 parser_input = input_defsym;
164 /* FIXME: This is currently ignored. It means
165 ``produce a big-endian object file''. It could
166 be used to select an output format. */
169 /* FIXME: This is currently ignored. It means
170 ``produce a little-endian object file''. It could
171 be used to select an output format. */
174 lang_add_entry (optarg, 1);
182 g_switch_value = strtoul (optarg, &end, 0);
184 einfo ("%P%F: invalid number `%s'\n", optarg);
195 ldfile_add_library_path (optarg, true);
198 lang_add_input_file (optarg, lang_input_file_is_l_enum,
202 config.map_filename = "-";
205 /* Ignore. Was handled in a pre-parse. */
208 config.map_filename = optarg;
211 config.text_read_only = false;
212 config.magic_demand_paged = false;
215 config.magic_demand_paged = false;
217 case OPTION_NO_KEEP_MEMORY:
218 link_info.keep_memory = false;
220 case OPTION_NOINHIBIT_EXEC:
221 force_make_executable = true;
224 /* FIXME "-O<non-digits> <value>" used to set the address of
225 section <non-digits>. Was this for compatibility with
226 something, or can we create a new option to do that
227 (with a syntax similar to -defsym)?
228 getopt can't handle two args to an option without kludges. */
229 set_default_dirlist (optarg);
232 lang_add_output (optarg, 0);
235 lang_add_output_format (optarg, 0);
239 link_info.relocateable = true;
240 config.build_constructors = false;
241 config.magic_demand_paged = false;
242 config.text_read_only = false;
243 config.dynamic_link = false;
246 lang_add_input_file (optarg,
247 lang_input_file_is_symbols_only_enum,
251 command_line.relax = true;
253 case OPTION_RETAIN_SYMBOLS_FILE:
254 add_keepsyms_file (optarg);
257 link_info.strip = strip_debugger;
260 link_info.strip = strip_all;
262 case OPTION_SORT_COMMON:
263 config.sort_common = true;
272 ldfile_open_command_file (optarg);
273 parser_input = input_script;
277 set_section_start (".bss", optarg);
280 set_section_start (".data", optarg);
283 set_section_start (".text", optarg);
285 case OPTION_TRADITIONAL_FORMAT:
286 config.traditional_format = true;
289 link_info.relocateable = true;
290 config.build_constructors = true;
291 config.magic_demand_paged = false;
292 config.text_read_only = false;
293 config.dynamic_link = false;
296 ldlang_add_undef (optarg);
300 version_printed = true;
301 trace_file_tries = true;
305 version_printed = true;
309 version_printed = true;
311 case OPTION_WARN_COMMON:
312 config.warn_common = true;
315 link_info.discard = discard_l;
318 link_info.discard = discard_all;
321 set_default_dirlist (optarg);
330 /* Add the (colon-separated) elements of DIRLIST_PTR to the
331 library search path. */
334 set_default_dirlist (dirlist_ptr)
341 p = strchr (dirlist_ptr, ':');
345 ldfile_add_library_path (dirlist_ptr, true);
354 set_section_start (sect, valstr)
358 unsigned long val = strtoul (valstr, &end, 16);
360 einfo ("%P%F: invalid hex number `%s'\n", valstr);
361 lang_section_start (sect, exp_intop (val));