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:";
55 static struct option longopts
[] =
57 {"call_shared", no_argument
, NULL
, 158},
58 {"dc", no_argument
, NULL
, 'd'},
59 {"defsym", required_argument
, NULL
, 160},
60 {"dn", no_argument
, NULL
, 158},
61 {"dp", no_argument
, NULL
, 'd'},
62 {"EB", no_argument
, NULL
, 150},
63 {"EL", no_argument
, NULL
, 151},
64 {"format", required_argument
, NULL
, 'b'},
65 {"help", no_argument
, NULL
, 164},
66 {"Map", required_argument
, NULL
, 152},
67 {"no-keep-memory", no_argument
, NULL
, 168},
68 {"noinhibit-exec", no_argument
, NULL
, 169},
69 {"noinhibit_exec", no_argument
, NULL
, 169},
70 {"non_shared", no_argument
, NULL
, 158},
71 {"oformat", required_argument
, NULL
, 172},
72 {"Qy", no_argument
, NULL
, 158},
73 {"relax", no_argument
, NULL
, 173},
74 {"retain-symbols-file", no_argument
, NULL
, 174},
75 {"sort-common", no_argument
, NULL
, 175},
76 {"sort_common", no_argument
, NULL
, 175},
77 {"stats", no_argument
, NULL
, 176},
78 {"Tbss", required_argument
, NULL
, 154},
79 {"Tdata", required_argument
, NULL
, 155},
80 {"Ttext", required_argument
, NULL
, 156},
81 {"Ur", no_argument
, NULL
, 157},
82 {"version", no_argument
, NULL
, 178},
83 {"warn-common", no_argument
, NULL
, 177},
84 {"YP,", required_argument
, NULL
, 158},
85 {NULL
, no_argument
, NULL
, 0}
90 /* getopt_long_only is like getopt_long, but '-' as well as '--' can
91 indicate a long option. */
92 int optc
= getopt_long_only (argc
, argv
, shortopts
, longopts
,
101 case 1: /* File name. */
102 lang_add_input_file (optarg
, lang_input_file_is_file_enum
,
107 ldfile_add_arch (optarg
);
113 lang_add_target (optarg
);
116 ldfile_open_command_file (optarg
);
117 parser_input
= input_mri_script
;
120 case 158: /* call_shared, dn, non_shared, Qy, YP */
121 set_default_dirlist (optarg
);
124 command_line
.force_common_definition
= true;
126 case 160: /* defsym */
127 lex_redirect (optarg
);
128 parser_input
= input_defsym
;
132 /* FIXME: This is currently ignored. It means
133 ``produce a big-endian object file''. It could
134 be used to select an output format. */
137 /* FIXME: This is currently ignored. It means
138 ``produce a little-endian object file''. It could
139 be used to select an output format. */
142 lang_add_entry (optarg
);
150 g_switch_value
= strtoul (optarg
, &end
, 0);
152 einfo ("%P%F: invalid number `%s'", optarg
);
163 ldfile_add_library_path (optarg
);
166 lang_add_input_file (optarg
, lang_input_file_is_l_enum
,
170 config
.map_filename
= "-";
173 /* Ignore. Was handled in a pre-parse. */
177 config
.map_filename
= optarg
;
180 config
.text_read_only
= false;
181 config
.magic_demand_paged
= false;
184 config
.magic_demand_paged
= false;
186 case 168: /* no-keep-memory */
187 link_info
.keep_memory
= false;
189 case 169: /* noinhibit-exec */
190 force_make_executable
= true;
193 /* FIXME "-O<non-digits> <value>" used to set the address of
194 section <non-digits>. Was this for compatibility with
195 something, or can we create a new option to do that
196 (with a syntax similar to -defsym)?
197 getopt can't handle two args to an option without kludges. */
198 set_default_dirlist (optarg
);
201 lang_add_output (optarg
, 0);
203 case 172: /* oformat */
204 lang_add_output_format (optarg
, 0);
207 link_info
.relocateable
= true;
208 config
.build_constructors
= false;
209 config
.magic_demand_paged
= false;
210 config
.text_read_only
= false;
213 lang_add_input_file (optarg
,
214 lang_input_file_is_symbols_only_enum
,
217 case 173: /* relax */
218 command_line
.relax
= true;
220 case 174: /* retain-symbols-file */
221 add_keepsyms_file (optarg
);
224 link_info
.strip
= strip_debugger
;
227 link_info
.strip
= strip_all
;
229 case 175: /* sort-common */
230 config
.sort_common
= true;
232 case 176: /* stats */
239 ldfile_open_command_file (optarg
);
240 parser_input
= input_script
;
244 set_section_start (".bss", optarg
);
246 case 155: /* Tdata */
247 set_section_start (".data", optarg
);
249 case 156: /* Ttext */
250 set_section_start (".text", optarg
);
253 link_info
.relocateable
= true;
254 config
.build_constructors
= true;
255 config
.magic_demand_paged
= false;
256 config
.text_read_only
= false;
259 ldlang_add_undef (optarg
);
263 version_printed
= true;
264 trace_file_tries
= true;
268 version_printed
= true;
270 case 178: /* version */
272 version_printed
= true;
274 case 177: /* warn-common */
275 config
.warn_common
= true;
278 link_info
.discard
= discard_l
;
281 link_info
.discard
= discard_all
;
290 /* Add the (colon-separated) elements of DIRLIST_PTR to the
291 library search path. */
294 set_default_dirlist (dirlist_ptr
)
301 p
= strchr (dirlist_ptr
, ':');
305 ldfile_add_library_path (dirlist_ptr
);
314 set_section_start (sect
, valstr
)
318 unsigned long val
= strtoul (valstr
, &end
, 16);
320 einfo ("%P%F: invalid hex number `%s'", valstr
);
321 lang_section_start (sect
, exp_intop (val
));