]>
Commit | Line | Data |
---|---|---|
bae7f79e ILT |
1 | // options.c -- handle command line options for gold |
2 | ||
e5756efb | 3 | // Copyright 2006, 2007, 2008 Free Software Foundation, Inc. |
6cb15b7f ILT |
4 | // Written by Ian Lance Taylor <[email protected]>. |
5 | ||
6 | // This file is part of gold. | |
7 | ||
8 | // This program is free software; you can redistribute it and/or modify | |
9 | // it under the terms of the GNU General Public License as published by | |
10 | // the Free Software Foundation; either version 3 of the License, or | |
11 | // (at your option) any later version. | |
12 | ||
13 | // This program is distributed in the hope that it will be useful, | |
14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | // GNU General Public License for more details. | |
17 | ||
18 | // You should have received a copy of the GNU General Public License | |
19 | // along with this program; if not, write to the Free Software | |
20 | // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, | |
21 | // MA 02110-1301, USA. | |
22 | ||
ad2d6943 ILT |
23 | #include "gold.h" |
24 | ||
a2b1aa12 | 25 | #include <cstdlib> |
bae7f79e | 26 | #include <iostream> |
ad2d6943 ILT |
27 | #include <sys/stat.h> |
28 | #include "filenames.h" | |
29 | #include "libiberty.h" | |
bae7f79e | 30 | |
c7912668 | 31 | #include "debug.h" |
e5756efb | 32 | #include "script.h" |
bae7f79e ILT |
33 | #include "options.h" |
34 | ||
61ba1cf9 ILT |
35 | namespace gold |
36 | { | |
37 | ||
bae7f79e ILT |
38 | // The information we keep for a single command line option. |
39 | ||
61ba1cf9 | 40 | struct options::One_option |
bae7f79e ILT |
41 | { |
42 | // The single character option name, or '\0' if this is only a long | |
43 | // option. | |
44 | char short_option; | |
45 | ||
46 | // The long option name, or NULL if this is only a short option. | |
47 | const char* long_option; | |
48 | ||
49 | // Description of the option for --help output, or NULL if there is none. | |
50 | const char* doc; | |
51 | ||
52 | // How to print the option name in --help output, or NULL to use the | |
53 | // default. | |
54 | const char* help_output; | |
55 | ||
56 | // Long option dash control. This is ignored if long_option is | |
57 | // NULL. | |
58 | enum | |
59 | { | |
60 | // Long option normally takes one dash; two dashes are also | |
61 | // accepted. | |
62 | ONE_DASH, | |
63 | // Long option normally takes two dashes; one dash is also | |
64 | // accepted. | |
65 | TWO_DASHES, | |
66 | // Long option always takes two dashes. | |
67 | EXACTLY_TWO_DASHES | |
68 | } dash; | |
69 | ||
70 | // Function for special handling, or NULL. Returns the number of | |
71 | // arguments to skip. This will normally be at least 1, but it may | |
72 | // be 0 if this function changes *argv. ARG points to the location | |
73 | // in *ARGV where the option starts, which may be helpful for a | |
74 | // short option. | |
3c2fafa5 ILT |
75 | int (*special)(int argc, char** argv, char *arg, bool long_option, |
76 | Command_line*); | |
bae7f79e ILT |
77 | |
78 | // If this is a position independent option which does not take an | |
79 | // argument, this is the member function to call to record it. | |
61ba1cf9 | 80 | void (General_options::*general_noarg)(); |
bae7f79e ILT |
81 | |
82 | // If this is a position independent function which takes an | |
83 | // argument, this is the member function to call to record it. | |
61ba1cf9 | 84 | void (General_options::*general_arg)(const char*); |
bae7f79e ILT |
85 | |
86 | // If this is a position dependent option which does not take an | |
87 | // argument, this is the member function to call to record it. | |
61ba1cf9 | 88 | void (Position_dependent_options::*dependent_noarg)(); |
bae7f79e ILT |
89 | |
90 | // If this is a position dependent option which takes an argument, | |
91 | // this is the member function to record it. | |
61ba1cf9 | 92 | void (Position_dependent_options::*dependent_arg)(const char*); |
bae7f79e ILT |
93 | |
94 | // Return whether this option takes an argument. | |
95 | bool | |
96 | takes_argument() const | |
97 | { return this->general_arg != NULL || this->dependent_arg != NULL; } | |
98 | }; | |
99 | ||
35cdfc9a ILT |
100 | // We have a separate table for -z options. |
101 | ||
102 | struct options::One_z_option | |
103 | { | |
104 | // The name of the option. | |
105 | const char* name; | |
106 | ||
107 | // The member function in General_options called to record it. | |
108 | void (General_options::*set)(); | |
109 | }; | |
110 | ||
c7912668 ILT |
111 | // We have a separate table for --debug options. |
112 | ||
113 | struct options::One_debug_option | |
114 | { | |
115 | // The name of the option. | |
116 | const char* name; | |
117 | ||
118 | // The flags to turn on. | |
119 | unsigned int debug_flags; | |
120 | }; | |
121 | ||
61ba1cf9 | 122 | class options::Command_line_options |
bae7f79e ILT |
123 | { |
124 | public: | |
125 | static const One_option options[]; | |
126 | static const int options_size; | |
35cdfc9a ILT |
127 | static const One_z_option z_options[]; |
128 | static const int z_options_size; | |
c7912668 ILT |
129 | static const One_debug_option debug_options[]; |
130 | static const int debug_options_size; | |
bae7f79e ILT |
131 | }; |
132 | ||
61ba1cf9 ILT |
133 | } // End namespace gold. |
134 | ||
bae7f79e ILT |
135 | namespace |
136 | { | |
137 | ||
61ba1cf9 ILT |
138 | // Handle the special -l option, which adds an input file. |
139 | ||
140 | int | |
3c2fafa5 ILT |
141 | library(int argc, char** argv, char* arg, bool long_option, |
142 | gold::Command_line* cmdline) | |
61ba1cf9 | 143 | { |
3c2fafa5 ILT |
144 | return cmdline->process_l_option(argc, argv, arg, long_option); |
145 | } | |
146 | ||
88dd47ac ILT |
147 | // Handle the -R option. Historically the GNU linker made -R a |
148 | // synonym for --just-symbols. ELF linkers have traditionally made -R | |
149 | // a synonym for -rpath. When ELF support was added to the GNU | |
150 | // linker, -R was changed to switch based on the argument: if the | |
151 | // argument is an ordinary file, we treat it as --just-symbols, | |
152 | // otherwise we treat it as -rpath. We need to be compatible with | |
153 | // this, because existing build scripts rely on it. | |
154 | ||
155 | int | |
156 | handle_r_option(int argc, char** argv, char* arg, bool long_option, | |
157 | gold::Command_line* cmdline) | |
158 | { | |
159 | int ret; | |
160 | const char* val = cmdline->get_special_argument("R", argc, argv, arg, | |
161 | long_option, &ret); | |
162 | struct stat s; | |
163 | if (::stat(val, &s) != 0 || S_ISDIR(s.st_mode)) | |
164 | cmdline->add_to_rpath(val); | |
165 | else | |
166 | cmdline->add_just_symbols_file(val); | |
167 | return ret; | |
168 | } | |
169 | ||
170 | // Handle the --just-symbols option. | |
171 | ||
172 | int | |
173 | handle_just_symbols_option(int argc, char** argv, char* arg, | |
174 | bool long_option, gold::Command_line* cmdline) | |
175 | { | |
176 | int ret; | |
177 | const char* val = cmdline->get_special_argument("just-symbols", argc, argv, | |
178 | arg, long_option, &ret); | |
179 | cmdline->add_just_symbols_file(val); | |
180 | return ret; | |
181 | } | |
182 | ||
3c2fafa5 ILT |
183 | // Handle the special -T/--script option, which reads a linker script. |
184 | ||
185 | int | |
186 | invoke_script(int argc, char** argv, char* arg, bool long_option, | |
187 | gold::Command_line* cmdline) | |
188 | { | |
189 | int ret; | |
190 | const char* script_name = cmdline->get_special_argument("script", argc, argv, | |
191 | arg, long_option, | |
192 | &ret); | |
193 | if (!read_commandline_script(script_name, cmdline)) | |
09124467 ILT |
194 | gold::gold_fatal(_("unable to parse script file %s"), script_name); |
195 | return ret; | |
196 | } | |
197 | ||
198 | // Handle the special --version-script option, which reads a version script. | |
199 | ||
200 | int | |
201 | invoke_version_script(int argc, char** argv, char* arg, bool long_option, | |
202 | gold::Command_line* cmdline) | |
203 | { | |
204 | int ret; | |
205 | const char* script_name = cmdline->get_special_argument("version-script", | |
206 | argc, argv, | |
207 | arg, long_option, | |
208 | &ret); | |
209 | if (!read_version_script(script_name, cmdline)) | |
210 | gold::gold_fatal(_("unable to parse version script file %s"), script_name); | |
3c2fafa5 | 211 | return ret; |
61ba1cf9 ILT |
212 | } |
213 | ||
ead1e424 ILT |
214 | // Handle the special --start-group option. |
215 | ||
216 | int | |
3c2fafa5 | 217 | start_group(int, char**, char* arg, bool, gold::Command_line* cmdline) |
ead1e424 ILT |
218 | { |
219 | cmdline->start_group(arg); | |
220 | return 1; | |
221 | } | |
222 | ||
223 | // Handle the special --end-group option. | |
224 | ||
225 | int | |
3c2fafa5 | 226 | end_group(int, char**, char* arg, bool, gold::Command_line* cmdline) |
ead1e424 ILT |
227 | { |
228 | cmdline->end_group(arg); | |
229 | return 1; | |
230 | } | |
231 | ||
bae7f79e ILT |
232 | // Report usage information for ld --help, and exit. |
233 | ||
234 | int | |
3c2fafa5 | 235 | help(int, char**, char*, bool, gold::Command_line*) |
bae7f79e ILT |
236 | { |
237 | printf(_("Usage: %s [options] file...\nOptions:\n"), gold::program_name); | |
238 | ||
239 | const int options_size = gold::options::Command_line_options::options_size; | |
240 | const gold::options::One_option* options = | |
241 | gold::options::Command_line_options::options; | |
242 | for (int i = 0; i < options_size; ++i) | |
243 | { | |
244 | if (options[i].doc == NULL) | |
245 | continue; | |
246 | ||
247 | printf(" "); | |
248 | int len = 2; | |
249 | bool comma = false; | |
250 | ||
251 | int j = i; | |
252 | do | |
253 | { | |
254 | if (options[j].help_output != NULL) | |
255 | { | |
256 | if (comma) | |
257 | { | |
258 | printf(", "); | |
259 | len += 2; | |
260 | } | |
261 | printf(options[j].help_output); | |
88dd47ac | 262 | len += std::strlen(options[j].help_output); |
a6badf5a | 263 | comma = true; |
bae7f79e ILT |
264 | } |
265 | else | |
266 | { | |
267 | if (options[j].short_option != '\0') | |
268 | { | |
269 | if (comma) | |
270 | { | |
271 | printf(", "); | |
272 | len += 2; | |
273 | } | |
274 | printf("-%c", options[j].short_option); | |
275 | len += 2; | |
a6badf5a | 276 | comma = true; |
bae7f79e ILT |
277 | } |
278 | ||
279 | if (options[j].long_option != NULL) | |
280 | { | |
281 | if (comma) | |
282 | { | |
283 | printf(", "); | |
284 | len += 2; | |
285 | } | |
286 | if (options[j].dash == gold::options::One_option::ONE_DASH) | |
287 | { | |
288 | printf("-"); | |
289 | ++len; | |
290 | } | |
291 | else | |
292 | { | |
293 | printf("--"); | |
294 | len += 2; | |
295 | } | |
296 | printf("%s", options[j].long_option); | |
297 | len += std::strlen(options[j].long_option); | |
a6badf5a | 298 | comma = true; |
bae7f79e ILT |
299 | } |
300 | } | |
301 | ++j; | |
302 | } | |
303 | while (j < options_size && options[j].doc == NULL); | |
304 | ||
a6badf5a | 305 | if (len >= 30) |
bae7f79e ILT |
306 | { |
307 | printf("\n"); | |
308 | len = 0; | |
309 | } | |
310 | for (; len < 30; ++len) | |
311 | std::putchar(' '); | |
312 | ||
313 | std::puts(options[i].doc); | |
314 | } | |
315 | ||
c7912668 | 316 | ::exit(EXIT_SUCCESS); |
bae7f79e ILT |
317 | |
318 | return 0; | |
319 | } | |
320 | ||
8486ee48 ILT |
321 | // Report version information. |
322 | ||
323 | int | |
3c2fafa5 | 324 | version(int, char**, char* opt, bool, gold::Command_line*) |
8486ee48 ILT |
325 | { |
326 | gold::print_version(opt[0] == 'v' && opt[1] == '\0'); | |
c7912668 | 327 | ::exit(EXIT_SUCCESS); |
8486ee48 ILT |
328 | return 0; |
329 | } | |
330 | ||
ad2d6943 ILT |
331 | // If the default sysroot is relocatable, try relocating it based on |
332 | // the prefix FROM. | |
333 | ||
334 | char* | |
335 | get_relative_sysroot(const char* from) | |
336 | { | |
337 | char* path = make_relative_prefix(gold::program_name, from, | |
338 | TARGET_SYSTEM_ROOT); | |
339 | if (path != NULL) | |
340 | { | |
341 | struct stat s; | |
342 | if (::stat(path, &s) == 0 && S_ISDIR(s.st_mode)) | |
343 | return path; | |
344 | free(path); | |
345 | } | |
346 | ||
347 | return NULL; | |
348 | } | |
349 | ||
350 | // Return the default sysroot. This is set by the --with-sysroot | |
351 | // option to configure. | |
352 | ||
353 | std::string | |
354 | get_default_sysroot() | |
355 | { | |
356 | const char* sysroot = TARGET_SYSTEM_ROOT; | |
357 | if (*sysroot == '\0') | |
358 | return ""; | |
359 | ||
360 | if (TARGET_SYSTEM_ROOT_RELOCATABLE) | |
361 | { | |
362 | char* path = get_relative_sysroot (BINDIR); | |
363 | if (path == NULL) | |
364 | path = get_relative_sysroot (TOOLBINDIR); | |
365 | if (path != NULL) | |
366 | { | |
367 | std::string ret = path; | |
368 | free(path); | |
369 | return ret; | |
370 | } | |
371 | } | |
372 | ||
373 | return sysroot; | |
374 | } | |
375 | ||
61ba1cf9 ILT |
376 | } // End anonymous namespace. |
377 | ||
378 | namespace gold | |
379 | { | |
bae7f79e ILT |
380 | |
381 | // Helper macros used to specify the options. We could also do this | |
382 | // using constructors, but then g++ would generate code to initialize | |
383 | // the array. We want the array to be initialized statically so that | |
384 | // we get better startup time. | |
385 | ||
386 | #define GENERAL_NOARG(short_option, long_option, doc, help, dash, func) \ | |
61ba1cf9 | 387 | { short_option, long_option, doc, help, options::One_option::dash, \ |
bae7f79e ILT |
388 | NULL, func, NULL, NULL, NULL } |
389 | #define GENERAL_ARG(short_option, long_option, doc, help, dash, func) \ | |
61ba1cf9 | 390 | { short_option, long_option, doc, help, options::One_option::dash, \ |
bae7f79e ILT |
391 | NULL, NULL, func, NULL, NULL } |
392 | #define POSDEP_NOARG(short_option, long_option, doc, help, dash, func) \ | |
61ba1cf9 | 393 | { short_option, long_option, doc, help, options::One_option::dash, \ |
bae7f79e ILT |
394 | NULL, NULL, NULL, func, NULL } |
395 | #define POSDEP_ARG(short_option, long_option, doc, help, dash, func) \ | |
61ba1cf9 | 396 | { short_option, long_option, doc, help, options::One_option::dash, \ |
bae7f79e ILT |
397 | NULL, NULL, NULL, NULL, func } |
398 | #define SPECIAL(short_option, long_option, doc, help, dash, func) \ | |
61ba1cf9 | 399 | { short_option, long_option, doc, help, options::One_option::dash, \ |
bae7f79e ILT |
400 | func, NULL, NULL, NULL, NULL } |
401 | ||
402 | // Here is the actual list of options which we accept. | |
403 | ||
61ba1cf9 ILT |
404 | const options::One_option |
405 | options::Command_line_options::options[] = | |
bae7f79e | 406 | { |
e2827e5f ILT |
407 | GENERAL_NOARG('\0', "allow-shlib-undefined", |
408 | N_("Allow unresolved references in shared libraries"), | |
409 | NULL, TWO_DASHES, | |
410 | &General_options::set_allow_shlib_undefined), | |
411 | GENERAL_NOARG('\0', "no-allow-shlib-undefined", | |
412 | N_("Do not allow unresolved references in shared libraries"), | |
413 | NULL, TWO_DASHES, | |
414 | &General_options::set_no_allow_shlib_undefined), | |
0c5e9c22 ILT |
415 | POSDEP_NOARG('\0', "as-needed", |
416 | N_("Only set DT_NEEDED for dynamic libs if used"), | |
417 | NULL, TWO_DASHES, &Position_dependent_options::set_as_needed), | |
418 | POSDEP_NOARG('\0', "no-as-needed", | |
419 | N_("Always DT_NEEDED for dynamic libs (default)"), | |
420 | NULL, TWO_DASHES, &Position_dependent_options::clear_as_needed), | |
61611222 ILT |
421 | POSDEP_NOARG('\0', "Bdynamic", |
422 | N_("-l searches for shared libraries"), | |
423 | NULL, ONE_DASH, | |
424 | &Position_dependent_options::set_dynamic_search), | |
425 | POSDEP_NOARG('\0', "Bstatic", | |
426 | N_("-l does not search for shared libraries"), | |
427 | NULL, ONE_DASH, | |
428 | &Position_dependent_options::set_static_search), | |
51b08ebe ILT |
429 | GENERAL_NOARG('\0', "Bsymbolic", N_("Bind defined symbols locally"), |
430 | NULL, ONE_DASH, &General_options::set_symbolic), | |
9a0910c3 ILT |
431 | #ifdef HAVE_ZLIB_H |
432 | # define ZLIB_STR ",zlib" | |
433 | #else | |
434 | # define ZLIB_STR "" | |
435 | #endif | |
436 | GENERAL_ARG('\0', "compress-debug-sections", | |
437 | N_("Compress .debug_* sections in the output file " | |
438 | "(default is none)"), | |
439 | N_("--compress-debug-sections=[none" ZLIB_STR "]"), | |
440 | TWO_DASHES, | |
bc2c67ff | 441 | &General_options::set_compress_debug_sections), |
e5756efb ILT |
442 | GENERAL_ARG('\0', "defsym", N_("Define a symbol"), |
443 | N_("--defsym SYMBOL=EXPRESSION"), TWO_DASHES, | |
444 | &General_options::define_symbol), | |
a2b1aa12 ILT |
445 | GENERAL_NOARG('\0', "demangle", N_("Demangle C++ symbols in log messages"), |
446 | NULL, TWO_DASHES, &General_options::set_demangle), | |
447 | GENERAL_NOARG('\0', "no-demangle", | |
448 | N_("Do not demangle C++ symbols in log messages"), | |
449 | NULL, TWO_DASHES, &General_options::clear_demangle), | |
a55ce7fe ILT |
450 | GENERAL_NOARG('\0', "detect-odr-violations", |
451 | N_("Try to detect violations of the One Definition Rule"), | |
452 | NULL, TWO_DASHES, &General_options::set_detect_odr_violations), | |
d391083d ILT |
453 | GENERAL_ARG('e', "entry", N_("Set program start address"), |
454 | N_("-e ADDRESS, --entry ADDRESS"), TWO_DASHES, | |
455 | &General_options::set_entry), | |
a6badf5a ILT |
456 | GENERAL_NOARG('E', "export-dynamic", N_("Export all dynamic symbols"), |
457 | NULL, TWO_DASHES, &General_options::set_export_dynamic), | |
0c5e9c22 ILT |
458 | GENERAL_NOARG('\0', "eh-frame-hdr", N_("Create exception frame header"), |
459 | NULL, TWO_DASHES, &General_options::set_create_eh_frame_hdr), | |
fced7afd | 460 | GENERAL_ARG('h', "soname", N_("Set shared library name"), |
d391083d | 461 | N_("-h FILENAME, -soname FILENAME"), ONE_DASH, |
fced7afd | 462 | &General_options::set_soname), |
dbe717ef ILT |
463 | GENERAL_ARG('I', "dynamic-linker", N_("Set dynamic linker path"), |
464 | N_("-I PROGRAM, --dynamic-linker PROGRAM"), TWO_DASHES, | |
465 | &General_options::set_dynamic_linker), | |
0c5e9c22 ILT |
466 | SPECIAL('l', "library", N_("Search for library LIBNAME"), |
467 | N_("-lLIBNAME, --library LIBNAME"), TWO_DASHES, | |
468 | &library), | |
bae7f79e ILT |
469 | GENERAL_ARG('L', "library-path", N_("Add directory to search path"), |
470 | N_("-L DIR, --library-path DIR"), TWO_DASHES, | |
61ba1cf9 | 471 | &General_options::add_to_search_path), |
652ec9bd ILT |
472 | GENERAL_ARG('m', NULL, N_("Ignored for compatibility"), NULL, ONE_DASH, |
473 | &General_options::ignore), | |
61ba1cf9 ILT |
474 | GENERAL_ARG('o', "output", N_("Set output file name"), |
475 | N_("-o FILE, --output FILE"), TWO_DASHES, | |
476 | &General_options::set_output_file_name), | |
0c5e9c22 ILT |
477 | GENERAL_ARG('O', NULL, N_("Optimize output file size"), |
478 | N_("-O level"), ONE_DASH, | |
479 | &General_options::set_optimization_level), | |
bae7f79e | 480 | GENERAL_NOARG('r', NULL, N_("Generate relocatable output"), NULL, |
61ba1cf9 | 481 | ONE_DASH, &General_options::set_relocatable), |
88dd47ac ILT |
482 | // -R really means -rpath, but can mean --just-symbols for |
483 | // compatibility with GNU ld. -rpath is always -rpath, so we list | |
484 | // it separately. | |
485 | SPECIAL('R', NULL, N_("Add DIR to runtime search path"), | |
486 | N_("-R DIR"), ONE_DASH, &handle_r_option), | |
487 | GENERAL_ARG('\0', "rpath", NULL, N_("-rpath DIR"), ONE_DASH, | |
488 | &General_options::add_to_rpath), | |
489 | SPECIAL('\0', "just-symbols", N_("Read only symbol values from file"), | |
490 | N_("-R FILE, --just-symbols FILE"), TWO_DASHES, | |
491 | &handle_just_symbols_option), | |
15b3cfae ILT |
492 | GENERAL_ARG('\0', "rpath-link", |
493 | N_("Add DIR to link time shared library search path"), | |
494 | N_("--rpath-link DIR"), TWO_DASHES, | |
495 | &General_options::add_to_rpath_link), | |
0c5e9c22 ILT |
496 | GENERAL_NOARG('s', "strip-all", N_("Strip all symbols"), NULL, |
497 | TWO_DASHES, &General_options::set_strip_all), | |
02d2ba74 ILT |
498 | GENERAL_NOARG('\0', "strip-debug-gdb", |
499 | N_("Strip debug symbols that are unused by gdb " | |
500 | "(at least versions <= 6.7)"), | |
501 | NULL, TWO_DASHES, &General_options::set_strip_debug_gdb), | |
502 | // This must come after -Sdebug since it's a prefix of it. | |
0c5e9c22 ILT |
503 | GENERAL_NOARG('S', "strip-debug", N_("Strip debugging information"), NULL, |
504 | TWO_DASHES, &General_options::set_strip_debug), | |
92e059d8 ILT |
505 | GENERAL_NOARG('\0', "shared", N_("Generate shared library"), |
506 | NULL, ONE_DASH, &General_options::set_shared), | |
bae7f79e | 507 | GENERAL_NOARG('\0', "static", N_("Do not link against shared libraries"), |
61ba1cf9 | 508 | NULL, ONE_DASH, &General_options::set_static), |
e44fcf3b ILT |
509 | GENERAL_NOARG('\0', "stats", N_("Print resource usage statistics"), |
510 | NULL, TWO_DASHES, &General_options::set_stats), | |
ad2d6943 ILT |
511 | GENERAL_ARG('\0', "sysroot", N_("Set target system root directory"), |
512 | N_("--sysroot DIR"), TWO_DASHES, &General_options::set_sysroot), | |
0c5e9c22 ILT |
513 | GENERAL_ARG('\0', "Ttext", N_("Set the address of the .text section"), |
514 | N_("-Ttext ADDRESS"), ONE_DASH, | |
515 | &General_options::set_text_segment_address), | |
a0451b38 ILT |
516 | // This must come after -Ttext since it's a prefix of it. |
517 | SPECIAL('T', "script", N_("Read linker script"), | |
518 | N_("-T FILE, --script FILE"), TWO_DASHES, | |
519 | &invoke_script), | |
09124467 ILT |
520 | SPECIAL('\0', "version-script", N_("Read version script"), |
521 | N_("--version-script FILE"), TWO_DASHES, | |
522 | &invoke_version_script), | |
fe9a4c12 ILT |
523 | GENERAL_NOARG('\0', "threads", N_("Run the linker multi-threaded"), |
524 | NULL, TWO_DASHES, &General_options::set_threads), | |
525 | GENERAL_NOARG('\0', "no-threads", N_("Do not run the linker multi-threaded"), | |
526 | NULL, TWO_DASHES, &General_options::clear_threads), | |
527 | GENERAL_ARG('\0', "thread-count", N_("Number of threads to use"), | |
528 | N_("--thread-count COUNT"), TWO_DASHES, | |
529 | &General_options::set_thread_count), | |
530 | GENERAL_ARG('\0', "thread-count-initial", | |
531 | N_("Number of threads to use in initial pass"), | |
532 | N_("--thread-count-initial COUNT"), TWO_DASHES, | |
533 | &General_options::set_thread_count_initial), | |
534 | GENERAL_ARG('\0', "thread-count-middle", | |
535 | N_("Number of threads to use in middle pass"), | |
536 | N_("--thread-count-middle COUNT"), TWO_DASHES, | |
537 | &General_options::set_thread_count_middle), | |
538 | GENERAL_ARG('\0', "thread-count-final", | |
539 | N_("Number of threads to use in final pass"), | |
540 | N_("--thread-count-final COUNT"), TWO_DASHES, | |
541 | &General_options::set_thread_count_final), | |
4973341a ILT |
542 | POSDEP_NOARG('\0', "whole-archive", |
543 | N_("Include all archive contents"), | |
544 | NULL, TWO_DASHES, | |
545 | &Position_dependent_options::set_whole_archive), | |
546 | POSDEP_NOARG('\0', "no-whole-archive", | |
547 | N_("Include only needed archive contents"), | |
548 | NULL, TWO_DASHES, | |
549 | &Position_dependent_options::clear_whole_archive), | |
35cdfc9a ILT |
550 | |
551 | GENERAL_ARG('z', NULL, | |
552 | N_("Subcommands as follows:\n\ | |
553 | -z execstack Mark output as requiring executable stack\n\ | |
554 | -z noexecstack Mark output as not requiring executable stack"), | |
555 | N_("-z SUBCOMMAND"), ONE_DASH, | |
556 | &General_options::handle_z_option), | |
557 | ||
0c5e9c22 ILT |
558 | SPECIAL('(', "start-group", N_("Start a library search group"), NULL, |
559 | TWO_DASHES, &start_group), | |
560 | SPECIAL(')', "end-group", N_("End a library search group"), NULL, | |
561 | TWO_DASHES, &end_group), | |
bae7f79e | 562 | SPECIAL('\0', "help", N_("Report usage information"), NULL, |
8486ee48 ILT |
563 | TWO_DASHES, &help), |
564 | SPECIAL('v', "version", N_("Report version information"), NULL, | |
c7912668 | 565 | TWO_DASHES, &version), |
494e05f4 | 566 | GENERAL_ARG('\0', "debug", N_("Turn on debugging (all,task,script)"), |
c7912668 ILT |
567 | N_("--debug=TYPE"), TWO_DASHES, |
568 | &General_options::handle_debug_option) | |
bae7f79e ILT |
569 | }; |
570 | ||
61ba1cf9 | 571 | const int options::Command_line_options::options_size = |
bae7f79e ILT |
572 | sizeof (options) / sizeof (options[0]); |
573 | ||
35cdfc9a ILT |
574 | // The -z options. |
575 | ||
576 | const options::One_z_option | |
577 | options::Command_line_options::z_options[] = | |
578 | { | |
579 | { "execstack", &General_options::set_execstack }, | |
580 | { "noexecstack", &General_options::set_noexecstack }, | |
581 | }; | |
582 | ||
583 | const int options::Command_line_options::z_options_size = | |
584 | sizeof(z_options) / sizeof(z_options[0]); | |
585 | ||
c7912668 ILT |
586 | // The --debug options. |
587 | ||
588 | const options::One_debug_option | |
589 | options::Command_line_options::debug_options[] = | |
590 | { | |
591 | { "all", DEBUG_ALL }, | |
592 | { "task", DEBUG_TASK }, | |
494e05f4 | 593 | { "script", DEBUG_SCRIPT } |
c7912668 ILT |
594 | }; |
595 | ||
596 | const int options::Command_line_options::debug_options_size = | |
597 | sizeof(debug_options) / sizeof(debug_options[0]); | |
598 | ||
bae7f79e ILT |
599 | // The default values for the general options. |
600 | ||
e5756efb ILT |
601 | General_options::General_options(Script_options* script_options) |
602 | : export_dynamic_(false), | |
fced7afd | 603 | soname_(NULL), |
a6badf5a | 604 | dynamic_linker_(NULL), |
dbe717ef | 605 | search_path_(), |
ca3a67a5 | 606 | optimization_level_(0), |
61ba1cf9 ILT |
607 | output_file_name_("a.out"), |
608 | is_relocatable_(false), | |
9e2dcb77 | 609 | strip_(STRIP_NONE), |
9a2d6984 | 610 | allow_shlib_undefined_(false), |
51b08ebe | 611 | symbolic_(false), |
9a0910c3 | 612 | compress_debug_sections_(NO_COMPRESSION), |
a55ce7fe | 613 | detect_odr_violations_(false), |
7da52175 | 614 | create_eh_frame_hdr_(false), |
4973341a | 615 | rpath_(), |
15b3cfae | 616 | rpath_link_(), |
92e059d8 | 617 | is_shared_(false), |
ad2d6943 | 618 | is_static_(false), |
e44fcf3b | 619 | print_stats_(false), |
0c5e9c22 | 620 | sysroot_(), |
fe9a4c12 ILT |
621 | text_segment_address_(-1U), // -1 indicates value not set by user |
622 | threads_(false), | |
623 | thread_count_initial_(0), | |
624 | thread_count_middle_(0), | |
35cdfc9a | 625 | thread_count_final_(0), |
c7912668 | 626 | execstack_(EXECSTACK_FROM_INPUT), |
e5756efb ILT |
627 | debug_(0), |
628 | script_options_(script_options) | |
bae7f79e | 629 | { |
a2b1aa12 ILT |
630 | // We initialize demangle_ based on the environment variable |
631 | // COLLECT_NO_DEMANGLE. The gcc collect2 program will demangle the | |
632 | // output of the linker, unless COLLECT_NO_DEMANGLE is set in the | |
633 | // environment. Acting the same way here lets us provide the same | |
634 | // interface by default. | |
635 | this->demangle_ = getenv("COLLECT_NO_DEMANGLE") == NULL; | |
bae7f79e ILT |
636 | } |
637 | ||
e5756efb | 638 | // Handle the --defsym option. |
bae7f79e | 639 | |
e5756efb ILT |
640 | void |
641 | General_options::define_symbol(const char* arg) | |
bae7f79e | 642 | { |
e5756efb | 643 | this->script_options_->define_symbol(arg); |
bae7f79e ILT |
644 | } |
645 | ||
35cdfc9a ILT |
646 | // Handle the -z option. |
647 | ||
648 | void | |
649 | General_options::handle_z_option(const char* arg) | |
650 | { | |
651 | const int z_options_size = options::Command_line_options::z_options_size; | |
652 | const gold::options::One_z_option* z_options = | |
653 | gold::options::Command_line_options::z_options; | |
654 | for (int i = 0; i < z_options_size; ++i) | |
655 | { | |
656 | if (strcmp(arg, z_options[i].name) == 0) | |
657 | { | |
658 | (this->*(z_options[i].set))(); | |
659 | return; | |
660 | } | |
661 | } | |
662 | ||
663 | fprintf(stderr, _("%s: unrecognized -z subcommand: %s\n"), | |
664 | program_name, arg); | |
c7912668 ILT |
665 | ::exit(EXIT_FAILURE); |
666 | } | |
667 | ||
668 | // Handle the --debug option. | |
669 | ||
670 | void | |
671 | General_options::handle_debug_option(const char* arg) | |
672 | { | |
673 | const int debug_options_size = | |
674 | options::Command_line_options::debug_options_size; | |
675 | const gold::options::One_debug_option* debug_options = | |
676 | options::Command_line_options::debug_options; | |
677 | for (int i = 0; i < debug_options_size; ++i) | |
678 | { | |
679 | if (strcmp(arg, debug_options[i].name) == 0) | |
680 | { | |
681 | this->set_debug(debug_options[i].debug_flags); | |
682 | return; | |
683 | } | |
684 | } | |
685 | ||
686 | fprintf(stderr, _("%s: unrecognized --debug subcommand: %s\n"), | |
687 | program_name, arg); | |
688 | ::exit(EXIT_FAILURE); | |
35cdfc9a ILT |
689 | } |
690 | ||
ad2d6943 ILT |
691 | // Add the sysroot, if any, to the search paths. |
692 | ||
693 | void | |
694 | General_options::add_sysroot() | |
695 | { | |
696 | if (this->sysroot_.empty()) | |
697 | { | |
698 | this->sysroot_ = get_default_sysroot(); | |
699 | if (this->sysroot_.empty()) | |
700 | return; | |
701 | } | |
702 | ||
703 | const char* sysroot = this->sysroot_.c_str(); | |
704 | char* canonical_sysroot = lrealpath(sysroot); | |
705 | ||
706 | for (Dir_list::iterator p = this->search_path_.begin(); | |
707 | p != this->search_path_.end(); | |
708 | ++p) | |
709 | p->add_sysroot(sysroot, canonical_sysroot); | |
710 | ||
711 | free(canonical_sysroot); | |
712 | } | |
713 | ||
e5756efb ILT |
714 | // The default values for the position dependent options. |
715 | ||
716 | Position_dependent_options::Position_dependent_options() | |
717 | : do_static_search_(false), | |
718 | as_needed_(false), | |
719 | include_whole_archive_(false) | |
720 | { | |
721 | } | |
722 | ||
ad2d6943 ILT |
723 | // Search_directory methods. |
724 | ||
725 | // This is called if we have a sysroot. Apply the sysroot if | |
726 | // appropriate. Record whether the directory is in the sysroot. | |
727 | ||
728 | void | |
729 | Search_directory::add_sysroot(const char* sysroot, | |
730 | const char* canonical_sysroot) | |
731 | { | |
732 | gold_assert(*sysroot != '\0'); | |
733 | if (this->put_in_sysroot_) | |
734 | { | |
735 | if (!IS_DIR_SEPARATOR(this->name_[0]) | |
736 | && !IS_DIR_SEPARATOR(sysroot[strlen(sysroot) - 1])) | |
737 | this->name_ = '/' + this->name_; | |
738 | this->name_ = sysroot + this->name_; | |
739 | this->is_in_sysroot_ = true; | |
740 | } | |
741 | else | |
742 | { | |
743 | // Check whether this entry is in the sysroot. To do this | |
744 | // correctly, we need to use canonical names. Otherwise we will | |
745 | // get confused by the ../../.. paths that gcc tends to use. | |
746 | char* canonical_name = lrealpath(this->name_.c_str()); | |
747 | int canonical_name_len = strlen(canonical_name); | |
748 | int canonical_sysroot_len = strlen(canonical_sysroot); | |
749 | if (canonical_name_len > canonical_sysroot_len | |
750 | && IS_DIR_SEPARATOR(canonical_name[canonical_sysroot_len])) | |
751 | { | |
752 | canonical_name[canonical_sysroot_len] = '\0'; | |
753 | if (FILENAME_CMP(canonical_name, canonical_sysroot) == 0) | |
754 | this->is_in_sysroot_ = true; | |
755 | } | |
756 | free(canonical_name); | |
757 | } | |
758 | } | |
759 | ||
dbe717ef ILT |
760 | // Input_arguments methods. |
761 | ||
762 | // Add a file to the list. | |
763 | ||
764 | void | |
765 | Input_arguments::add_file(const Input_file_argument& file) | |
766 | { | |
767 | if (!this->in_group_) | |
768 | this->input_argument_list_.push_back(Input_argument(file)); | |
769 | else | |
770 | { | |
a3ad94ed ILT |
771 | gold_assert(!this->input_argument_list_.empty()); |
772 | gold_assert(this->input_argument_list_.back().is_group()); | |
dbe717ef ILT |
773 | this->input_argument_list_.back().group()->add_file(file); |
774 | } | |
775 | } | |
776 | ||
777 | // Start a group. | |
778 | ||
779 | void | |
780 | Input_arguments::start_group() | |
781 | { | |
a3ad94ed | 782 | gold_assert(!this->in_group_); |
dbe717ef ILT |
783 | Input_file_group* group = new Input_file_group(); |
784 | this->input_argument_list_.push_back(Input_argument(group)); | |
785 | this->in_group_ = true; | |
786 | } | |
787 | ||
788 | // End a group. | |
789 | ||
790 | void | |
791 | Input_arguments::end_group() | |
792 | { | |
a3ad94ed | 793 | gold_assert(this->in_group_); |
dbe717ef ILT |
794 | this->in_group_ = false; |
795 | } | |
796 | ||
ead1e424 | 797 | // Command_line options. |
bae7f79e | 798 | |
e5756efb ILT |
799 | Command_line::Command_line(Script_options* script_options) |
800 | : options_(script_options), position_options_(), inputs_() | |
bae7f79e ILT |
801 | { |
802 | } | |
803 | ||
a0451b38 ILT |
804 | // Process the command line options. For process_one_option, |
805 | // i is the index of argv to process next, and the return value | |
806 | // is the index of the next option to process (i+1 or i+2, or argc | |
807 | // to indicate processing is done). no_more_options is set to true | |
808 | // if (and when) "--" is seen as an option. | |
bae7f79e | 809 | |
a0451b38 ILT |
810 | int |
811 | Command_line::process_one_option(int argc, char** argv, int i, | |
812 | bool* no_more_options) | |
bae7f79e | 813 | { |
61ba1cf9 | 814 | const int options_size = options::Command_line_options::options_size; |
a0451b38 ILT |
815 | const options::One_option* options = options::Command_line_options::options; |
816 | gold_assert(i < argc); | |
817 | ||
818 | if (argv[i][0] != '-' || *no_more_options) | |
bae7f79e | 819 | { |
a0451b38 ILT |
820 | this->add_file(argv[i], false); |
821 | return i + 1; | |
822 | } | |
bae7f79e | 823 | |
a0451b38 ILT |
824 | // Option starting with '-'. |
825 | int dashes = 1; | |
826 | if (argv[i][1] == '-') | |
827 | { | |
828 | dashes = 2; | |
829 | if (argv[i][2] == '\0') | |
830 | { | |
831 | *no_more_options = true; | |
832 | return i + 1; | |
833 | } | |
834 | } | |
bae7f79e | 835 | |
a0451b38 ILT |
836 | // Look for a long option match. |
837 | char* opt = argv[i] + dashes; | |
838 | char first = opt[0]; | |
839 | int skiparg = 0; | |
840 | char* arg = strchr(opt, '='); | |
841 | bool argument_with_equals = arg != NULL; | |
842 | if (arg != NULL) | |
843 | { | |
844 | *arg = '\0'; | |
845 | ++arg; | |
846 | } | |
847 | else if (i + 1 < argc) | |
848 | { | |
849 | arg = argv[i + 1]; | |
850 | skiparg = 1; | |
851 | } | |
bae7f79e | 852 | |
a0451b38 ILT |
853 | int j; |
854 | for (j = 0; j < options_size; ++j) | |
855 | { | |
856 | if (options[j].long_option != NULL | |
857 | && (dashes == 2 | |
858 | || (options[j].dash | |
859 | != options::One_option::EXACTLY_TWO_DASHES)) | |
860 | && first == options[j].long_option[0] | |
861 | && strcmp(opt, options[j].long_option) == 0) | |
862 | { | |
863 | if (options[j].special) | |
864 | { | |
865 | // Restore the '=' we clobbered above. | |
866 | if (arg != NULL && skiparg == 0) | |
867 | arg[-1] = '='; | |
868 | i += options[j].special(argc - i, argv + i, opt, true, this); | |
869 | } | |
870 | else | |
871 | { | |
872 | if (!options[j].takes_argument()) | |
873 | { | |
874 | if (argument_with_equals) | |
875 | this->usage(_("unexpected argument"), argv[i]); | |
876 | arg = NULL; | |
877 | skiparg = 0; | |
878 | } | |
879 | else | |
880 | { | |
881 | if (arg == NULL) | |
882 | this->usage(_("missing argument"), argv[i]); | |
883 | } | |
884 | this->apply_option(options[j], arg); | |
885 | i += skiparg + 1; | |
886 | } | |
887 | break; | |
888 | } | |
889 | } | |
890 | if (j < options_size) | |
891 | return i; | |
892 | ||
893 | // If we saw two dashes, we needed to have seen a long option. | |
894 | if (dashes == 2) | |
895 | this->usage(_("unknown option"), argv[i]); | |
896 | ||
897 | // Look for a short option match. There may be more than one | |
898 | // short option in a given argument. | |
899 | bool done = false; | |
900 | char* s = argv[i] + 1; | |
901 | ++i; | |
902 | while (*s != '\0' && !done) | |
903 | { | |
904 | char opt = *s; | |
bae7f79e ILT |
905 | int j; |
906 | for (j = 0; j < options_size; ++j) | |
a0451b38 ILT |
907 | { |
908 | if (options[j].short_option == opt) | |
909 | { | |
910 | if (options[j].special) | |
911 | { | |
912 | // Undo the argument skip done above. | |
913 | --i; | |
914 | i += options[j].special(argc - i, argv + i, s, false, | |
915 | this); | |
916 | done = true; | |
917 | } | |
918 | else | |
919 | { | |
920 | arg = NULL; | |
921 | if (options[j].takes_argument()) | |
922 | { | |
923 | if (s[1] != '\0') | |
924 | { | |
925 | arg = s + 1; | |
926 | done = true; | |
927 | } | |
928 | else if (i < argc) | |
929 | { | |
930 | arg = argv[i]; | |
931 | ++i; | |
932 | } | |
933 | else | |
934 | this->usage(_("missing argument"), opt); | |
935 | } | |
936 | this->apply_option(options[j], arg); | |
937 | } | |
938 | break; | |
939 | } | |
940 | } | |
941 | ||
942 | if (j >= options_size) | |
943 | this->usage(_("unknown option"), *s); | |
944 | ||
945 | ++s; | |
946 | } | |
947 | return i; | |
948 | } | |
bae7f79e | 949 | |
bae7f79e | 950 | |
a0451b38 ILT |
951 | void |
952 | Command_line::process(int argc, char** argv) | |
953 | { | |
954 | bool no_more_options = false; | |
955 | int i = 0; | |
956 | while (i < argc) | |
957 | i = process_one_option(argc, argv, i, &no_more_options); | |
61ba1cf9 | 958 | |
dbe717ef | 959 | if (this->inputs_.in_group()) |
ead1e424 | 960 | { |
35cdfc9a | 961 | fprintf(stderr, _("%s: missing group end\n"), program_name); |
ead1e424 ILT |
962 | this->usage(); |
963 | } | |
964 | ||
61ba1cf9 | 965 | // FIXME: We should only do this when configured in native mode. |
ad2d6943 ILT |
966 | this->options_.add_to_search_path_with_sysroot("/lib"); |
967 | this->options_.add_to_search_path_with_sysroot("/usr/lib"); | |
968 | ||
969 | this->options_.add_sysroot(); | |
46738c9a ILT |
970 | |
971 | // Ensure options don't contradict each other and are otherwise kosher. | |
972 | this->normalize_options(); | |
973 | } | |
974 | ||
3c2fafa5 ILT |
975 | // Extract an option argument for a special option. LONGNAME is the |
976 | // long name of the option. This sets *PRET to the return value for | |
977 | // the special function handler to skip to the next option. | |
978 | ||
979 | const char* | |
980 | Command_line::get_special_argument(const char* longname, int argc, char** argv, | |
981 | const char* arg, bool long_option, | |
982 | int *pret) | |
983 | { | |
984 | if (long_option) | |
985 | { | |
986 | size_t longlen = strlen(longname); | |
987 | gold_assert(strncmp(arg, longname, longlen) == 0); | |
988 | arg += longlen; | |
989 | if (*arg == '=') | |
990 | { | |
991 | *pret = 1; | |
992 | return arg + 1; | |
993 | } | |
994 | else if (argc > 1) | |
995 | { | |
996 | gold_assert(*arg == '\0'); | |
997 | *pret = 2; | |
998 | return argv[1]; | |
999 | } | |
1000 | } | |
1001 | else | |
1002 | { | |
1003 | if (arg[1] != '\0') | |
1004 | { | |
1005 | *pret = 1; | |
1006 | return arg + 1; | |
1007 | } | |
1008 | else if (argc > 1) | |
1009 | { | |
1010 | *pret = 2; | |
1011 | return argv[1]; | |
1012 | } | |
1013 | } | |
1014 | ||
1015 | this->usage(_("missing argument"), arg); | |
1016 | } | |
1017 | ||
46738c9a ILT |
1018 | // Ensure options don't contradict each other and are otherwise kosher. |
1019 | ||
1020 | void | |
1021 | Command_line::normalize_options() | |
1022 | { | |
6a74a719 ILT |
1023 | if (this->options_.is_shared() && this->options_.is_relocatable()) |
1024 | gold_fatal(_("-shared and -r are incompatible")); | |
1025 | ||
46738c9a ILT |
1026 | // If the user specifies both -s and -r, convert the -s as -S. |
1027 | // -r requires us to keep externally visible symbols! | |
1028 | if (this->options_.strip_all() && this->options_.is_relocatable()) | |
1029 | { | |
1030 | // Clears the strip_all() status, replacing it with strip_debug(). | |
1031 | this->options_.set_strip_debug(); | |
1032 | } | |
1033 | ||
1034 | // FIXME: we can/should be doing a lot more sanity checking here. | |
bae7f79e ILT |
1035 | } |
1036 | ||
46738c9a | 1037 | |
bae7f79e ILT |
1038 | // Apply a command line option. |
1039 | ||
1040 | void | |
61ba1cf9 ILT |
1041 | Command_line::apply_option(const options::One_option& opt, |
1042 | const char* arg) | |
bae7f79e ILT |
1043 | { |
1044 | if (arg == NULL) | |
1045 | { | |
1046 | if (opt.general_noarg) | |
1047 | (this->options_.*(opt.general_noarg))(); | |
1048 | else if (opt.dependent_noarg) | |
1049 | (this->position_options_.*(opt.dependent_noarg))(); | |
1050 | else | |
61ba1cf9 | 1051 | gold_unreachable(); |
bae7f79e ILT |
1052 | } |
1053 | else | |
1054 | { | |
1055 | if (opt.general_arg) | |
1056 | (this->options_.*(opt.general_arg))(arg); | |
1057 | else if (opt.dependent_arg) | |
1058 | (this->position_options_.*(opt.dependent_arg))(arg); | |
1059 | else | |
61ba1cf9 | 1060 | gold_unreachable(); |
bae7f79e ILT |
1061 | } |
1062 | } | |
1063 | ||
ead1e424 ILT |
1064 | // Add an input file or library. |
1065 | ||
1066 | void | |
1067 | Command_line::add_file(const char* name, bool is_lib) | |
1068 | { | |
88dd47ac | 1069 | Input_file_argument file(name, is_lib, "", false, this->position_options_); |
dbe717ef | 1070 | this->inputs_.add_file(file); |
ead1e424 ILT |
1071 | } |
1072 | ||
61ba1cf9 ILT |
1073 | // Handle the -l option, which requires special treatment. |
1074 | ||
1075 | int | |
3c2fafa5 ILT |
1076 | Command_line::process_l_option(int argc, char** argv, char* arg, |
1077 | bool long_option) | |
61ba1cf9 ILT |
1078 | { |
1079 | int ret; | |
3c2fafa5 ILT |
1080 | const char* libname = this->get_special_argument("library", argc, argv, arg, |
1081 | long_option, &ret); | |
ead1e424 | 1082 | this->add_file(libname, true); |
61ba1cf9 ILT |
1083 | return ret; |
1084 | } | |
1085 | ||
ead1e424 ILT |
1086 | // Handle the --start-group option. |
1087 | ||
1088 | void | |
1089 | Command_line::start_group(const char* arg) | |
1090 | { | |
dbe717ef | 1091 | if (this->inputs_.in_group()) |
ead1e424 | 1092 | this->usage(_("may not nest groups"), arg); |
dbe717ef | 1093 | this->inputs_.start_group(); |
ead1e424 ILT |
1094 | } |
1095 | ||
1096 | // Handle the --end-group option. | |
1097 | ||
1098 | void | |
1099 | Command_line::end_group(const char* arg) | |
1100 | { | |
dbe717ef | 1101 | if (!this->inputs_.in_group()) |
ead1e424 | 1102 | this->usage(_("group end without group start"), arg); |
dbe717ef | 1103 | this->inputs_.end_group(); |
ead1e424 ILT |
1104 | } |
1105 | ||
bae7f79e ILT |
1106 | // Report a usage error. */ |
1107 | ||
1108 | void | |
61ba1cf9 | 1109 | Command_line::usage() |
bae7f79e ILT |
1110 | { |
1111 | fprintf(stderr, | |
1112 | _("%s: use the --help option for usage information\n"), | |
61ba1cf9 | 1113 | program_name); |
c7912668 | 1114 | ::exit(EXIT_FAILURE); |
bae7f79e ILT |
1115 | } |
1116 | ||
1117 | void | |
61ba1cf9 | 1118 | Command_line::usage(const char* msg, const char *opt) |
bae7f79e ILT |
1119 | { |
1120 | fprintf(stderr, | |
1121 | _("%s: %s: %s\n"), | |
61ba1cf9 | 1122 | program_name, opt, msg); |
bae7f79e ILT |
1123 | this->usage(); |
1124 | } | |
1125 | ||
1126 | void | |
61ba1cf9 | 1127 | Command_line::usage(const char* msg, char opt) |
bae7f79e ILT |
1128 | { |
1129 | fprintf(stderr, | |
1130 | _("%s: -%c: %s\n"), | |
61ba1cf9 | 1131 | program_name, opt, msg); |
bae7f79e ILT |
1132 | this->usage(); |
1133 | } | |
61ba1cf9 ILT |
1134 | |
1135 | } // End namespace gold. |