1 // options.c -- handle command line options for gold
3 // Copyright 2006, 2007 Free Software Foundation, Inc.
4 // Written by Ian Lance Taylor <iant@google.com>.
6 // This file is part of gold.
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.
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.
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.
28 #include "filenames.h"
29 #include "libiberty.h"
37 // The information we keep for a single command line option.
39 struct options::One_option
41 // The single character option name, or '\0' if this is only a long
45 // The long option name, or NULL if this is only a short option.
46 const char* long_option;
48 // Description of the option for --help output, or NULL if there is none.
51 // How to print the option name in --help output, or NULL to use the
53 const char* help_output;
55 // Long option dash control. This is ignored if long_option is
59 // Long option normally takes one dash; two dashes are also
62 // Long option normally takes two dashes; one dash is also
65 // Long option always takes two dashes.
69 // Function for special handling, or NULL. Returns the number of
70 // arguments to skip. This will normally be at least 1, but it may
71 // be 0 if this function changes *argv. ARG points to the location
72 // in *ARGV where the option starts, which may be helpful for a
74 int (*special)(int argc, char** argv, char *arg, bool long_option,
77 // If this is a position independent option which does not take an
78 // argument, this is the member function to call to record it.
79 void (General_options::*general_noarg)();
81 // If this is a position independent function which takes an
82 // argument, this is the member function to call to record it.
83 void (General_options::*general_arg)(const char*);
85 // If this is a position dependent option which does not take an
86 // argument, this is the member function to call to record it.
87 void (Position_dependent_options::*dependent_noarg)();
89 // If this is a position dependent option which takes an argument,
90 // this is the member function to record it.
91 void (Position_dependent_options::*dependent_arg)(const char*);
93 // Return whether this option takes an argument.
95 takes_argument() const
96 { return this->general_arg != NULL || this->dependent_arg != NULL; }
99 // We have a separate table for -z options.
101 struct options::One_z_option
103 // The name of the option.
106 // The member function in General_options called to record it.
107 void (General_options::*set)();
110 // We have a separate table for --debug options.
112 struct options::One_debug_option
114 // The name of the option.
117 // The flags to turn on.
118 unsigned int debug_flags;
121 class options::Command_line_options
124 static const One_option options[];
125 static const int options_size;
126 static const One_z_option z_options[];
127 static const int z_options_size;
128 static const One_debug_option debug_options[];
129 static const int debug_options_size;
132 } // End namespace gold.
137 // Handle the special -l option, which adds an input file.
140 library(int argc, char** argv, char* arg, bool long_option,
141 gold::Command_line* cmdline)
143 return cmdline->process_l_option(argc, argv, arg, long_option);
146 // Handle the special -T/--script option, which reads a linker script.
149 invoke_script(int argc, char** argv, char* arg, bool long_option,
150 gold::Command_line* cmdline)
153 const char* script_name = cmdline->get_special_argument("script", argc, argv,
156 if (!read_commandline_script(script_name, cmdline))
157 gold::gold_error(_("%s: unable to parse script file %s\n"),
158 gold::program_name, arg);
162 // Handle the special --start-group option.
165 start_group(int, char**, char* arg, bool, gold::Command_line* cmdline)
167 cmdline->start_group(arg);
171 // Handle the special --end-group option.
174 end_group(int, char**, char* arg, bool, gold::Command_line* cmdline)
176 cmdline->end_group(arg);
180 // Report usage information for ld --help, and exit.
183 help(int, char**, char*, bool, gold::Command_line*)
185 printf(_("Usage: %s [options] file...\nOptions:\n"), gold::program_name);
187 const int options_size = gold::options::Command_line_options::options_size;
188 const gold::options::One_option* options =
189 gold::options::Command_line_options::options;
190 for (int i = 0; i < options_size; ++i)
192 if (options[i].doc == NULL)
202 if (options[j].help_output != NULL)
209 printf(options[j].help_output);
210 len += std::strlen(options[i].help_output);
215 if (options[j].short_option != '\0')
222 printf("-%c", options[j].short_option);
227 if (options[j].long_option != NULL)
234 if (options[j].dash == gold::options::One_option::ONE_DASH)
244 printf("%s", options[j].long_option);
245 len += std::strlen(options[j].long_option);
251 while (j < options_size && options[j].doc == NULL);
258 for (; len < 30; ++len)
261 std::puts(options[i].doc);
264 ::exit(EXIT_SUCCESS);
269 // Report version information.
272 version(int, char**, char* opt, bool, gold::Command_line*)
274 gold::print_version(opt[0] == 'v' && opt[1] == '\0');
275 ::exit(EXIT_SUCCESS);
279 // If the default sysroot is relocatable, try relocating it based on
283 get_relative_sysroot(const char* from)
285 char* path = make_relative_prefix(gold::program_name, from,
290 if (::stat(path, &s) == 0 && S_ISDIR(s.st_mode))
298 // Return the default sysroot. This is set by the --with-sysroot
299 // option to configure.
302 get_default_sysroot()
304 const char* sysroot = TARGET_SYSTEM_ROOT;
305 if (*sysroot == '\0')
308 if (TARGET_SYSTEM_ROOT_RELOCATABLE)
310 char* path = get_relative_sysroot (BINDIR);
312 path = get_relative_sysroot (TOOLBINDIR);
315 std::string ret = path;
324 } // End anonymous namespace.
329 // Helper macros used to specify the options. We could also do this
330 // using constructors, but then g++ would generate code to initialize
331 // the array. We want the array to be initialized statically so that
332 // we get better startup time.
334 #define GENERAL_NOARG(short_option, long_option, doc, help, dash, func) \
335 { short_option, long_option, doc, help, options::One_option::dash, \
336 NULL, func, NULL, NULL, NULL }
337 #define GENERAL_ARG(short_option, long_option, doc, help, dash, func) \
338 { short_option, long_option, doc, help, options::One_option::dash, \
339 NULL, NULL, func, NULL, NULL }
340 #define POSDEP_NOARG(short_option, long_option, doc, help, dash, func) \
341 { short_option, long_option, doc, help, options::One_option::dash, \
342 NULL, NULL, NULL, func, NULL }
343 #define POSDEP_ARG(short_option, long_option, doc, help, dash, func) \
344 { short_option, long_option, doc, help, options::One_option::dash, \
345 NULL, NULL, NULL, NULL, func }
346 #define SPECIAL(short_option, long_option, doc, help, dash, func) \
347 { short_option, long_option, doc, help, options::One_option::dash, \
348 func, NULL, NULL, NULL, NULL }
350 // Here is the actual list of options which we accept.
352 const options::One_option
353 options::Command_line_options::options[] =
355 GENERAL_NOARG('\0', "allow-shlib-undefined",
356 N_("Allow unresolved references in shared libraries"),
358 &General_options::set_allow_shlib_undefined),
359 GENERAL_NOARG('\0', "no-allow-shlib-undefined",
360 N_("Do not allow unresolved references in shared libraries"),
362 &General_options::set_no_allow_shlib_undefined),
363 POSDEP_NOARG('\0', "as-needed",
364 N_("Only set DT_NEEDED for dynamic libs if used"),
365 NULL, TWO_DASHES, &Position_dependent_options::set_as_needed),
366 POSDEP_NOARG('\0', "no-as-needed",
367 N_("Always DT_NEEDED for dynamic libs (default)"),
368 NULL, TWO_DASHES, &Position_dependent_options::clear_as_needed),
369 POSDEP_NOARG('\0', "Bdynamic",
370 N_("-l searches for shared libraries"),
372 &Position_dependent_options::set_dynamic_search),
373 POSDEP_NOARG('\0', "Bstatic",
374 N_("-l does not search for shared libraries"),
376 &Position_dependent_options::set_static_search),
377 GENERAL_NOARG('\0', "Bsymbolic", N_("Bind defined symbols locally"),
378 NULL, ONE_DASH, &General_options::set_symbolic),
380 # define ZLIB_STR ",zlib"
384 GENERAL_ARG('\0', "compress-debug-sections",
385 N_("Compress .debug_* sections in the output file "
386 "(default is none)"),
387 N_("--compress-debug-sections=[none" ZLIB_STR "]"),
389 &General_options::set_compress_debug_sections),
390 GENERAL_NOARG('\0', "demangle", N_("Demangle C++ symbols in log messages"),
391 NULL, TWO_DASHES, &General_options::set_demangle),
392 GENERAL_NOARG('\0', "no-demangle",
393 N_("Do not demangle C++ symbols in log messages"),
394 NULL, TWO_DASHES, &General_options::clear_demangle),
395 GENERAL_NOARG('\0', "detect-odr-violations",
396 N_("Try to detect violations of the One Definition Rule"),
397 NULL, TWO_DASHES, &General_options::set_detect_odr_violations),
398 GENERAL_NOARG('E', "export-dynamic", N_("Export all dynamic symbols"),
399 NULL, TWO_DASHES, &General_options::set_export_dynamic),
400 GENERAL_NOARG('\0', "eh-frame-hdr", N_("Create exception frame header"),
401 NULL, TWO_DASHES, &General_options::set_create_eh_frame_hdr),
402 GENERAL_ARG('h', "soname", N_("Set shared library name"),
403 N_("-h FILENAME, --soname FILENAME"), ONE_DASH,
404 &General_options::set_soname),
405 GENERAL_ARG('I', "dynamic-linker", N_("Set dynamic linker path"),
406 N_("-I PROGRAM, --dynamic-linker PROGRAM"), TWO_DASHES,
407 &General_options::set_dynamic_linker),
408 SPECIAL('l', "library", N_("Search for library LIBNAME"),
409 N_("-lLIBNAME, --library LIBNAME"), TWO_DASHES,
411 GENERAL_ARG('L', "library-path", N_("Add directory to search path"),
412 N_("-L DIR, --library-path DIR"), TWO_DASHES,
413 &General_options::add_to_search_path),
414 GENERAL_ARG('m', NULL, N_("Ignored for compatibility"), NULL, ONE_DASH,
415 &General_options::ignore),
416 GENERAL_ARG('o', "output", N_("Set output file name"),
417 N_("-o FILE, --output FILE"), TWO_DASHES,
418 &General_options::set_output_file_name),
419 GENERAL_ARG('O', NULL, N_("Optimize output file size"),
420 N_("-O level"), ONE_DASH,
421 &General_options::set_optimization_level),
422 GENERAL_NOARG('r', NULL, N_("Generate relocatable output"), NULL,
423 ONE_DASH, &General_options::set_relocatable),
424 GENERAL_ARG('R', "rpath", N_("Add DIR to runtime search path"),
425 N_("-R DIR, -rpath DIR"), ONE_DASH,
426 &General_options::add_to_rpath),
427 GENERAL_ARG('\0', "rpath-link",
428 N_("Add DIR to link time shared library search path"),
429 N_("--rpath-link DIR"), TWO_DASHES,
430 &General_options::add_to_rpath_link),
431 GENERAL_NOARG('s', "strip-all", N_("Strip all symbols"), NULL,
432 TWO_DASHES, &General_options::set_strip_all),
433 GENERAL_NOARG('\0', "strip-debug-gdb",
434 N_("Strip debug symbols that are unused by gdb "
435 "(at least versions <= 6.7)"),
436 NULL, TWO_DASHES, &General_options::set_strip_debug_gdb),
437 // This must come after -Sdebug since it's a prefix of it.
438 GENERAL_NOARG('S', "strip-debug", N_("Strip debugging information"), NULL,
439 TWO_DASHES, &General_options::set_strip_debug),
440 GENERAL_NOARG('\0', "shared", N_("Generate shared library"),
441 NULL, ONE_DASH, &General_options::set_shared),
442 GENERAL_NOARG('\0', "static", N_("Do not link against shared libraries"),
443 NULL, ONE_DASH, &General_options::set_static),
444 GENERAL_NOARG('\0', "stats", N_("Print resource usage statistics"),
445 NULL, TWO_DASHES, &General_options::set_stats),
446 GENERAL_ARG('\0', "sysroot", N_("Set target system root directory"),
447 N_("--sysroot DIR"), TWO_DASHES, &General_options::set_sysroot),
448 GENERAL_ARG('\0', "Ttext", N_("Set the address of the .text section"),
449 N_("-Ttext ADDRESS"), ONE_DASH,
450 &General_options::set_text_segment_address),
451 // This must come after -Ttext since it's a prefix of it.
452 SPECIAL('T', "script", N_("Read linker script"),
453 N_("-T FILE, --script FILE"), TWO_DASHES,
455 GENERAL_NOARG('\0', "threads", N_("Run the linker multi-threaded"),
456 NULL, TWO_DASHES, &General_options::set_threads),
457 GENERAL_NOARG('\0', "no-threads", N_("Do not run the linker multi-threaded"),
458 NULL, TWO_DASHES, &General_options::clear_threads),
459 GENERAL_ARG('\0', "thread-count", N_("Number of threads to use"),
460 N_("--thread-count COUNT"), TWO_DASHES,
461 &General_options::set_thread_count),
462 GENERAL_ARG('\0', "thread-count-initial",
463 N_("Number of threads to use in initial pass"),
464 N_("--thread-count-initial COUNT"), TWO_DASHES,
465 &General_options::set_thread_count_initial),
466 GENERAL_ARG('\0', "thread-count-middle",
467 N_("Number of threads to use in middle pass"),
468 N_("--thread-count-middle COUNT"), TWO_DASHES,
469 &General_options::set_thread_count_middle),
470 GENERAL_ARG('\0', "thread-count-final",
471 N_("Number of threads to use in final pass"),
472 N_("--thread-count-final COUNT"), TWO_DASHES,
473 &General_options::set_thread_count_final),
474 POSDEP_NOARG('\0', "whole-archive",
475 N_("Include all archive contents"),
477 &Position_dependent_options::set_whole_archive),
478 POSDEP_NOARG('\0', "no-whole-archive",
479 N_("Include only needed archive contents"),
481 &Position_dependent_options::clear_whole_archive),
483 GENERAL_ARG('z', NULL,
484 N_("Subcommands as follows:\n\
485 -z execstack Mark output as requiring executable stack\n\
486 -z noexecstack Mark output as not requiring executable stack"),
487 N_("-z SUBCOMMAND"), ONE_DASH,
488 &General_options::handle_z_option),
490 SPECIAL('(', "start-group", N_("Start a library search group"), NULL,
491 TWO_DASHES, &start_group),
492 SPECIAL(')', "end-group", N_("End a library search group"), NULL,
493 TWO_DASHES, &end_group),
494 SPECIAL('\0', "help", N_("Report usage information"), NULL,
496 SPECIAL('v', "version", N_("Report version information"), NULL,
497 TWO_DASHES, &version),
498 GENERAL_ARG('\0', "debug", N_("Turn on debugging (all,task)"),
499 N_("--debug=TYPE"), TWO_DASHES,
500 &General_options::handle_debug_option)
503 const int options::Command_line_options::options_size =
504 sizeof (options) / sizeof (options[0]);
508 const options::One_z_option
509 options::Command_line_options::z_options[] =
511 { "execstack", &General_options::set_execstack },
512 { "noexecstack", &General_options::set_noexecstack },
515 const int options::Command_line_options::z_options_size =
516 sizeof(z_options) / sizeof(z_options[0]);
518 // The --debug options.
520 const options::One_debug_option
521 options::Command_line_options::debug_options[] =
523 { "all", DEBUG_ALL },
524 { "task", DEBUG_TASK },
527 const int options::Command_line_options::debug_options_size =
528 sizeof(debug_options) / sizeof(debug_options[0]);
530 // The default values for the general options.
532 General_options::General_options()
533 : export_dynamic_(false),
535 dynamic_linker_(NULL),
537 optimization_level_(0),
538 output_file_name_("a.out"),
539 is_relocatable_(false),
541 allow_shlib_undefined_(false),
543 compress_debug_sections_(NO_COMPRESSION),
544 detect_odr_violations_(false),
545 create_eh_frame_hdr_(false),
552 text_segment_address_(-1U), // -1 indicates value not set by user
554 thread_count_initial_(0),
555 thread_count_middle_(0),
556 thread_count_final_(0),
557 execstack_(EXECSTACK_FROM_INPUT),
560 // We initialize demangle_ based on the environment variable
561 // COLLECT_NO_DEMANGLE. The gcc collect2 program will demangle the
562 // output of the linker, unless COLLECT_NO_DEMANGLE is set in the
563 // environment. Acting the same way here lets us provide the same
564 // interface by default.
565 this->demangle_ = getenv("COLLECT_NO_DEMANGLE") == NULL;
568 // The default values for the position dependent options.
570 Position_dependent_options::Position_dependent_options()
571 : do_static_search_(false),
573 include_whole_archive_(false)
577 // Handle the -z option.
580 General_options::handle_z_option(const char* arg)
582 const int z_options_size = options::Command_line_options::z_options_size;
583 const gold::options::One_z_option* z_options =
584 gold::options::Command_line_options::z_options;
585 for (int i = 0; i < z_options_size; ++i)
587 if (strcmp(arg, z_options[i].name) == 0)
589 (this->*(z_options[i].set))();
594 fprintf(stderr, _("%s: unrecognized -z subcommand: %s\n"),
596 ::exit(EXIT_FAILURE);
599 // Handle the --debug option.
602 General_options::handle_debug_option(const char* arg)
604 const int debug_options_size =
605 options::Command_line_options::debug_options_size;
606 const gold::options::One_debug_option* debug_options =
607 options::Command_line_options::debug_options;
608 for (int i = 0; i < debug_options_size; ++i)
610 if (strcmp(arg, debug_options[i].name) == 0)
612 this->set_debug(debug_options[i].debug_flags);
617 fprintf(stderr, _("%s: unrecognized --debug subcommand: %s\n"),
619 ::exit(EXIT_FAILURE);
622 // Add the sysroot, if any, to the search paths.
625 General_options::add_sysroot()
627 if (this->sysroot_.empty())
629 this->sysroot_ = get_default_sysroot();
630 if (this->sysroot_.empty())
634 const char* sysroot = this->sysroot_.c_str();
635 char* canonical_sysroot = lrealpath(sysroot);
637 for (Dir_list::iterator p = this->search_path_.begin();
638 p != this->search_path_.end();
640 p->add_sysroot(sysroot, canonical_sysroot);
642 free(canonical_sysroot);
645 // Search_directory methods.
647 // This is called if we have a sysroot. Apply the sysroot if
648 // appropriate. Record whether the directory is in the sysroot.
651 Search_directory::add_sysroot(const char* sysroot,
652 const char* canonical_sysroot)
654 gold_assert(*sysroot != '\0');
655 if (this->put_in_sysroot_)
657 if (!IS_DIR_SEPARATOR(this->name_[0])
658 && !IS_DIR_SEPARATOR(sysroot[strlen(sysroot) - 1]))
659 this->name_ = '/' + this->name_;
660 this->name_ = sysroot + this->name_;
661 this->is_in_sysroot_ = true;
665 // Check whether this entry is in the sysroot. To do this
666 // correctly, we need to use canonical names. Otherwise we will
667 // get confused by the ../../.. paths that gcc tends to use.
668 char* canonical_name = lrealpath(this->name_.c_str());
669 int canonical_name_len = strlen(canonical_name);
670 int canonical_sysroot_len = strlen(canonical_sysroot);
671 if (canonical_name_len > canonical_sysroot_len
672 && IS_DIR_SEPARATOR(canonical_name[canonical_sysroot_len]))
674 canonical_name[canonical_sysroot_len] = '\0';
675 if (FILENAME_CMP(canonical_name, canonical_sysroot) == 0)
676 this->is_in_sysroot_ = true;
678 free(canonical_name);
682 // Input_arguments methods.
684 // Add a file to the list.
687 Input_arguments::add_file(const Input_file_argument& file)
689 if (!this->in_group_)
690 this->input_argument_list_.push_back(Input_argument(file));
693 gold_assert(!this->input_argument_list_.empty());
694 gold_assert(this->input_argument_list_.back().is_group());
695 this->input_argument_list_.back().group()->add_file(file);
702 Input_arguments::start_group()
704 gold_assert(!this->in_group_);
705 Input_file_group* group = new Input_file_group();
706 this->input_argument_list_.push_back(Input_argument(group));
707 this->in_group_ = true;
713 Input_arguments::end_group()
715 gold_assert(this->in_group_);
716 this->in_group_ = false;
719 // Command_line options.
721 Command_line::Command_line()
722 : options_(), position_options_(), inputs_()
726 // Process the command line options. For process_one_option,
727 // i is the index of argv to process next, and the return value
728 // is the index of the next option to process (i+1 or i+2, or argc
729 // to indicate processing is done). no_more_options is set to true
730 // if (and when) "--" is seen as an option.
733 Command_line::process_one_option(int argc, char** argv, int i,
734 bool* no_more_options)
736 const int options_size = options::Command_line_options::options_size;
737 const options::One_option* options = options::Command_line_options::options;
738 gold_assert(i < argc);
740 if (argv[i][0] != '-' || *no_more_options)
742 this->add_file(argv[i], false);
746 // Option starting with '-'.
748 if (argv[i][1] == '-')
751 if (argv[i][2] == '\0')
753 *no_more_options = true;
758 // Look for a long option match.
759 char* opt = argv[i] + dashes;
762 char* arg = strchr(opt, '=');
763 bool argument_with_equals = arg != NULL;
769 else if (i + 1 < argc)
776 for (j = 0; j < options_size; ++j)
778 if (options[j].long_option != NULL
781 != options::One_option::EXACTLY_TWO_DASHES))
782 && first == options[j].long_option[0]
783 && strcmp(opt, options[j].long_option) == 0)
785 if (options[j].special)
787 // Restore the '=' we clobbered above.
788 if (arg != NULL && skiparg == 0)
790 i += options[j].special(argc - i, argv + i, opt, true, this);
794 if (!options[j].takes_argument())
796 if (argument_with_equals)
797 this->usage(_("unexpected argument"), argv[i]);
804 this->usage(_("missing argument"), argv[i]);
806 this->apply_option(options[j], arg);
812 if (j < options_size)
815 // If we saw two dashes, we needed to have seen a long option.
817 this->usage(_("unknown option"), argv[i]);
819 // Look for a short option match. There may be more than one
820 // short option in a given argument.
822 char* s = argv[i] + 1;
824 while (*s != '\0' && !done)
828 for (j = 0; j < options_size; ++j)
830 if (options[j].short_option == opt)
832 if (options[j].special)
834 // Undo the argument skip done above.
836 i += options[j].special(argc - i, argv + i, s, false,
843 if (options[j].takes_argument())
856 this->usage(_("missing argument"), opt);
858 this->apply_option(options[j], arg);
864 if (j >= options_size)
865 this->usage(_("unknown option"), *s);
874 Command_line::process(int argc, char** argv)
876 bool no_more_options = false;
879 i = process_one_option(argc, argv, i, &no_more_options);
881 if (this->inputs_.in_group())
883 fprintf(stderr, _("%s: missing group end\n"), program_name);
887 // FIXME: We should only do this when configured in native mode.
888 this->options_.add_to_search_path_with_sysroot("/lib");
889 this->options_.add_to_search_path_with_sysroot("/usr/lib");
891 this->options_.add_sysroot();
893 // Ensure options don't contradict each other and are otherwise kosher.
894 this->normalize_options();
897 // Extract an option argument for a special option. LONGNAME is the
898 // long name of the option. This sets *PRET to the return value for
899 // the special function handler to skip to the next option.
902 Command_line::get_special_argument(const char* longname, int argc, char** argv,
903 const char* arg, bool long_option,
908 size_t longlen = strlen(longname);
909 gold_assert(strncmp(arg, longname, longlen) == 0);
918 gold_assert(*arg == '\0');
937 this->usage(_("missing argument"), arg);
940 // Ensure options don't contradict each other and are otherwise kosher.
943 Command_line::normalize_options()
945 // If the user specifies both -s and -r, convert the -s as -S.
946 // -r requires us to keep externally visible symbols!
947 if (this->options_.strip_all() && this->options_.is_relocatable())
949 // Clears the strip_all() status, replacing it with strip_debug().
950 this->options_.set_strip_debug();
953 // FIXME: we can/should be doing a lot more sanity checking here.
957 // Apply a command line option.
960 Command_line::apply_option(const options::One_option& opt,
965 if (opt.general_noarg)
966 (this->options_.*(opt.general_noarg))();
967 else if (opt.dependent_noarg)
968 (this->position_options_.*(opt.dependent_noarg))();
975 (this->options_.*(opt.general_arg))(arg);
976 else if (opt.dependent_arg)
977 (this->position_options_.*(opt.dependent_arg))(arg);
983 // Add an input file or library.
986 Command_line::add_file(const char* name, bool is_lib)
988 Input_file_argument file(name, is_lib, "", this->position_options_);
989 this->inputs_.add_file(file);
992 // Handle the -l option, which requires special treatment.
995 Command_line::process_l_option(int argc, char** argv, char* arg,
999 const char* libname = this->get_special_argument("library", argc, argv, arg,
1001 this->add_file(libname, true);
1005 // Handle the --start-group option.
1008 Command_line::start_group(const char* arg)
1010 if (this->inputs_.in_group())
1011 this->usage(_("may not nest groups"), arg);
1012 this->inputs_.start_group();
1015 // Handle the --end-group option.
1018 Command_line::end_group(const char* arg)
1020 if (!this->inputs_.in_group())
1021 this->usage(_("group end without group start"), arg);
1022 this->inputs_.end_group();
1025 // Report a usage error. */
1028 Command_line::usage()
1031 _("%s: use the --help option for usage information\n"),
1033 ::exit(EXIT_FAILURE);
1037 Command_line::usage(const char* msg, const char *opt)
1041 program_name, opt, msg);
1046 Command_line::usage(const char* msg, char opt)
1050 program_name, opt, msg);
1054 } // End namespace gold.