From Craig Silverstein: Minimal --script implementation.
[external/binutils.git] / gold / options.cc
1 // options.c -- handle command line options for gold
2
3 // Copyright 2006, 2007 Free Software Foundation, Inc.
4 // Written by Ian Lance Taylor <iant@google.com>.
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
23 #include "gold.h"
24
25 #include <iostream>
26 #include <sys/stat.h>
27 #include "filenames.h"
28 #include "libiberty.h"
29
30 #include "options.h"
31
32 namespace gold
33 {
34
35 // The information we keep for a single command line option.
36
37 struct options::One_option
38 {
39   // The single character option name, or '\0' if this is only a long
40   // option.
41   char short_option;
42
43   // The long option name, or NULL if this is only a short option.
44   const char* long_option;
45
46   // Description of the option for --help output, or NULL if there is none.
47   const char* doc;
48
49   // How to print the option name in --help output, or NULL to use the
50   // default.
51   const char* help_output;
52
53   // Long option dash control.  This is ignored if long_option is
54   // NULL.
55   enum
56     {
57       // Long option normally takes one dash; two dashes are also
58       // accepted.
59       ONE_DASH,
60       // Long option normally takes two dashes; one dash is also
61       // accepted.
62       TWO_DASHES,
63       // Long option always takes two dashes.
64       EXACTLY_TWO_DASHES
65     } dash;
66
67   // Function for special handling, or NULL.  Returns the number of
68   // arguments to skip.  This will normally be at least 1, but it may
69   // be 0 if this function changes *argv.  ARG points to the location
70   // in *ARGV where the option starts, which may be helpful for a
71   // short option.
72   int (*special)(int argc, char** argv, char *arg, Command_line*);
73
74   // If this is a position independent option which does not take an
75   // argument, this is the member function to call to record it.
76   void (General_options::*general_noarg)();
77
78   // If this is a position independent function which takes an
79   // argument, this is the member function to call to record it.
80   void (General_options::*general_arg)(const char*);
81
82   // If this is a position dependent option which does not take an
83   // argument, this is the member function to call to record it.
84   void (Position_dependent_options::*dependent_noarg)();
85
86   // If this is a position dependent option which takes an argument,
87   // this is the member function to record it.
88   void (Position_dependent_options::*dependent_arg)(const char*);
89
90   // Return whether this option takes an argument.
91   bool
92   takes_argument() const
93   { return this->general_arg != NULL || this->dependent_arg != NULL; }
94 };
95
96 // We have a separate table for -z options.
97
98 struct options::One_z_option
99 {
100   // The name of the option.
101   const char* name;
102
103   // The member function in General_options called to record it.
104   void (General_options::*set)();
105 };
106
107 class options::Command_line_options
108 {
109  public:
110   static const One_option options[];
111   static const int options_size;
112   static const One_z_option z_options[];
113   static const int z_options_size;
114 };
115
116 } // End namespace gold.
117
118 namespace
119 {
120
121 // Handle the special -l option, which adds an input file.
122
123 int
124 library(int argc, char** argv, char* arg, gold::Command_line* cmdline)
125 {
126   return cmdline->process_l_option(argc, argv, arg);
127 }
128
129 // Handle the special --start-group option.
130
131 int
132 start_group(int, char**, char* arg, gold::Command_line* cmdline)
133 {
134   cmdline->start_group(arg);
135   return 1;
136 }
137
138 // Handle the special --end-group option.
139
140 int
141 end_group(int, char**, char* arg, gold::Command_line* cmdline)
142 {
143   cmdline->end_group(arg);
144   return 1;
145 }
146
147 // Report usage information for ld --help, and exit.
148
149 int
150 help(int, char**, char*, gold::Command_line*)
151 {
152   printf(_("Usage: %s [options] file...\nOptions:\n"), gold::program_name);
153
154   const int options_size = gold::options::Command_line_options::options_size;
155   const gold::options::One_option* options =
156     gold::options::Command_line_options::options;
157   for (int i = 0; i < options_size; ++i)
158     {
159       if (options[i].doc == NULL)
160         continue;
161
162       printf("  ");
163       int len = 2;
164       bool comma = false;
165
166       int j = i;
167       do
168         {
169           if (options[j].help_output != NULL)
170             {
171               if (comma)
172                 {
173                   printf(", ");
174                   len += 2;
175                 }
176               printf(options[j].help_output);
177               len += std::strlen(options[i].help_output);
178               comma = true;
179             }
180           else
181             {
182               if (options[j].short_option != '\0')
183                 {
184                   if (comma)
185                     {
186                       printf(", ");
187                       len += 2;
188                     }
189                   printf("-%c", options[j].short_option);
190                   len += 2;
191                   comma = true;
192                 }
193
194               if (options[j].long_option != NULL)
195                 {
196                   if (comma)
197                     {
198                       printf(", ");
199                       len += 2;
200                     }
201                   if (options[j].dash == gold::options::One_option::ONE_DASH)
202                     {
203                       printf("-");
204                       ++len;
205                     }
206                   else
207                     {
208                       printf("--");
209                       len += 2;
210                     }
211                   printf("%s", options[j].long_option);
212                   len += std::strlen(options[j].long_option);
213                   comma = true;
214                 }
215             }
216           ++j;
217         }
218       while (j < options_size && options[j].doc == NULL);
219
220       if (len >= 30)
221         {
222           printf("\n");
223           len = 0;
224         }
225       for (; len < 30; ++len)
226         std::putchar(' ');
227
228       std::puts(options[i].doc);
229     }
230
231   ::exit(0);
232
233   return 0;
234 }
235
236 // Report version information.
237
238 int
239 version(int, char**, char* opt, gold::Command_line*)
240 {
241   gold::print_version(opt[0] == 'v' && opt[1] == '\0');
242   ::exit(0);
243   return 0;
244 }
245
246 // If the default sysroot is relocatable, try relocating it based on
247 // the prefix FROM.
248
249 char*
250 get_relative_sysroot(const char* from)
251 {
252   char* path = make_relative_prefix(gold::program_name, from,
253                                     TARGET_SYSTEM_ROOT);
254   if (path != NULL)
255     {
256       struct stat s;
257       if (::stat(path, &s) == 0 && S_ISDIR(s.st_mode))
258         return path;
259       free(path);
260     }
261
262   return NULL;
263 }
264
265 // Return the default sysroot.  This is set by the --with-sysroot
266 // option to configure.
267
268 std::string
269 get_default_sysroot()
270 {
271   const char* sysroot = TARGET_SYSTEM_ROOT;
272   if (*sysroot == '\0')
273     return "";
274
275   if (TARGET_SYSTEM_ROOT_RELOCATABLE)
276     {
277       char* path = get_relative_sysroot (BINDIR);
278       if (path == NULL)
279         path = get_relative_sysroot (TOOLBINDIR);
280       if (path != NULL)
281         {
282           std::string ret = path;
283           free(path);
284           return ret;
285         }
286     }
287
288   return sysroot;
289 }
290
291 } // End anonymous namespace.
292
293 namespace gold
294 {
295
296 // Helper macros used to specify the options.  We could also do this
297 // using constructors, but then g++ would generate code to initialize
298 // the array.  We want the array to be initialized statically so that
299 // we get better startup time.
300
301 #define GENERAL_NOARG(short_option, long_option, doc, help, dash, func) \
302   { short_option, long_option, doc, help, options::One_option::dash, \
303       NULL, func, NULL, NULL, NULL }
304 #define GENERAL_ARG(short_option, long_option, doc, help, dash, func)   \
305   { short_option, long_option, doc, help, options::One_option::dash, \
306       NULL, NULL, func, NULL, NULL }
307 #define POSDEP_NOARG(short_option, long_option, doc, help, dash, func)  \
308   { short_option, long_option, doc, help, options::One_option::dash, \
309       NULL,  NULL, NULL, func, NULL }
310 #define POSDEP_ARG(short_option, long_option, doc, help, dash, func)    \
311   { short_option, long_option, doc, help, options::One_option::dash, \
312       NULL, NULL, NULL, NULL, func }
313 #define SPECIAL(short_option, long_option, doc, help, dash, func)       \
314   { short_option, long_option, doc, help, options::One_option::dash, \
315       func, NULL, NULL, NULL, NULL }
316
317 // Here is the actual list of options which we accept.
318
319 const options::One_option
320 options::Command_line_options::options[] =
321 {
322   POSDEP_NOARG('\0', "as-needed",
323                N_("Only set DT_NEEDED for dynamic libs if used"),
324                NULL, TWO_DASHES, &Position_dependent_options::set_as_needed),
325   POSDEP_NOARG('\0', "no-as-needed",
326                N_("Always DT_NEEDED for dynamic libs (default)"),
327                NULL, TWO_DASHES, &Position_dependent_options::clear_as_needed),
328   POSDEP_NOARG('\0', "Bdynamic",
329                N_("-l searches for shared libraries"),
330                NULL, ONE_DASH,
331                &Position_dependent_options::set_dynamic_search),
332   POSDEP_NOARG('\0', "Bstatic",
333                N_("-l does not search for shared libraries"),
334                NULL, ONE_DASH,
335                &Position_dependent_options::set_static_search),
336   GENERAL_NOARG('\0', "Bsymbolic", N_("Bind defined symbols locally"),
337                 NULL, ONE_DASH, &General_options::set_symbolic),
338   GENERAL_NOARG('E', "export-dynamic", N_("Export all dynamic symbols"),
339                 NULL, TWO_DASHES, &General_options::set_export_dynamic),
340   GENERAL_NOARG('\0', "eh-frame-hdr", N_("Create exception frame header"),
341                 NULL, TWO_DASHES, &General_options::set_create_eh_frame_hdr),
342   GENERAL_ARG('I', "dynamic-linker", N_("Set dynamic linker path"),
343               N_("-I PROGRAM, --dynamic-linker PROGRAM"), TWO_DASHES,
344               &General_options::set_dynamic_linker),
345   SPECIAL('l', "library", N_("Search for library LIBNAME"),
346           N_("-lLIBNAME, --library LIBNAME"), TWO_DASHES,
347           &library),
348   GENERAL_ARG('L', "library-path", N_("Add directory to search path"),
349               N_("-L DIR, --library-path DIR"), TWO_DASHES,
350               &General_options::add_to_search_path),
351   GENERAL_ARG('m', NULL, N_("Ignored for compatibility"), NULL, ONE_DASH,
352               &General_options::ignore),
353   GENERAL_ARG('o', "output", N_("Set output file name"),
354               N_("-o FILE, --output FILE"), TWO_DASHES,
355               &General_options::set_output_file_name),
356   GENERAL_ARG('O', NULL, N_("Optimize output file size"),
357               N_("-O level"), ONE_DASH,
358               &General_options::set_optimization_level),
359   GENERAL_NOARG('r', NULL, N_("Generate relocatable output"), NULL,
360                 ONE_DASH, &General_options::set_relocatable),
361   GENERAL_ARG('R', "rpath", N_("Add DIR to runtime search path"),
362               N_("-R DIR, -rpath DIR"), ONE_DASH,
363               &General_options::add_to_rpath),
364   GENERAL_ARG('\0', "rpath-link",
365               N_("Add DIR to link time shared library search path"),
366               N_("--rpath-link DIR"), TWO_DASHES,
367               &General_options::add_to_rpath_link),
368   GENERAL_NOARG('s', "strip-all", N_("Strip all symbols"), NULL,
369                 TWO_DASHES, &General_options::set_strip_all),
370   GENERAL_NOARG('S', "strip-debug", N_("Strip debugging information"), NULL,
371                 TWO_DASHES, &General_options::set_strip_debug),
372   GENERAL_NOARG('\0', "shared", N_("Generate shared library"),
373                 NULL, ONE_DASH, &General_options::set_shared),
374   GENERAL_NOARG('\0', "static", N_("Do not link against shared libraries"),
375                 NULL, ONE_DASH, &General_options::set_static),
376   GENERAL_NOARG('\0', "stats", N_("Print resource usage statistics"),
377                 NULL, TWO_DASHES, &General_options::set_stats),
378   GENERAL_ARG('\0', "sysroot", N_("Set target system root directory"),
379               N_("--sysroot DIR"), TWO_DASHES, &General_options::set_sysroot),
380   GENERAL_ARG('T', "script", N_("Read linker script"),
381               N_("-T FILE, --script FILE"), TWO_DASHES,
382               &General_options::set_script),
383   GENERAL_ARG('\0', "Ttext", N_("Set the address of the .text section"),
384               N_("-Ttext ADDRESS"), ONE_DASH,
385               &General_options::set_text_segment_address),
386   GENERAL_NOARG('\0', "threads", N_("Run the linker multi-threaded"),
387                 NULL, TWO_DASHES, &General_options::set_threads),
388   GENERAL_NOARG('\0', "no-threads", N_("Do not run the linker multi-threaded"),
389                 NULL, TWO_DASHES, &General_options::clear_threads),
390   GENERAL_ARG('\0', "thread-count", N_("Number of threads to use"),
391               N_("--thread-count COUNT"), TWO_DASHES,
392               &General_options::set_thread_count),
393   GENERAL_ARG('\0', "thread-count-initial",
394               N_("Number of threads to use in initial pass"),
395               N_("--thread-count-initial COUNT"), TWO_DASHES,
396               &General_options::set_thread_count_initial),
397   GENERAL_ARG('\0', "thread-count-middle",
398               N_("Number of threads to use in middle pass"),
399               N_("--thread-count-middle COUNT"), TWO_DASHES,
400               &General_options::set_thread_count_middle),
401   GENERAL_ARG('\0', "thread-count-final",
402               N_("Number of threads to use in final pass"),
403               N_("--thread-count-final COUNT"), TWO_DASHES,
404               &General_options::set_thread_count_final),
405   POSDEP_NOARG('\0', "whole-archive",
406                N_("Include all archive contents"),
407                NULL, TWO_DASHES,
408                &Position_dependent_options::set_whole_archive),
409   POSDEP_NOARG('\0', "no-whole-archive",
410                N_("Include only needed archive contents"),
411                NULL, TWO_DASHES,
412                &Position_dependent_options::clear_whole_archive),
413
414   GENERAL_ARG('z', NULL,
415               N_("Subcommands as follows:\n\
416     -z execstack              Mark output as requiring executable stack\n\
417     -z noexecstack            Mark output as not requiring executable stack"),
418               N_("-z SUBCOMMAND"), ONE_DASH,
419               &General_options::handle_z_option),
420
421   SPECIAL('(', "start-group", N_("Start a library search group"), NULL,
422           TWO_DASHES, &start_group),
423   SPECIAL(')', "end-group", N_("End a library search group"), NULL,
424           TWO_DASHES, &end_group),
425   SPECIAL('\0', "help", N_("Report usage information"), NULL,
426           TWO_DASHES, &help),
427   SPECIAL('v', "version", N_("Report version information"), NULL,
428           TWO_DASHES, &version)
429 };
430
431 const int options::Command_line_options::options_size =
432   sizeof (options) / sizeof (options[0]);
433
434 // The -z options.
435
436 const options::One_z_option
437 options::Command_line_options::z_options[] =
438 {
439   { "execstack", &General_options::set_execstack },
440   { "noexecstack", &General_options::set_noexecstack },
441 };
442
443 const int options::Command_line_options::z_options_size =
444   sizeof(z_options) / sizeof(z_options[0]);
445
446 // The default values for the general options.
447
448 General_options::General_options()
449   : export_dynamic_(false),
450     dynamic_linker_(NULL),
451     search_path_(),
452     optimization_level_(0),
453     output_file_name_("a.out"),
454     is_relocatable_(false),
455     strip_(STRIP_NONE),
456     symbolic_(false),
457     create_eh_frame_hdr_(false),
458     rpath_(),
459     rpath_link_(),
460     is_shared_(false),
461     is_static_(false),
462     print_stats_(false),
463     sysroot_(),
464     text_segment_address_(-1U),   // -1 indicates value not set by user
465     threads_(false),
466     thread_count_initial_(0),
467     thread_count_middle_(0),
468     thread_count_final_(0),
469     execstack_(EXECSTACK_FROM_INPUT)
470 {
471 }
472
473 // The default values for the position dependent options.
474
475 Position_dependent_options::Position_dependent_options()
476   : do_static_search_(false),
477     as_needed_(false),
478     include_whole_archive_(false)
479 {
480 }
481
482 // Handle the -z option.
483
484 void
485 General_options::handle_z_option(const char* arg)
486 {
487   const int z_options_size = options::Command_line_options::z_options_size;
488   const gold::options::One_z_option* z_options =
489     gold::options::Command_line_options::z_options;
490   for (int i = 0; i < z_options_size; ++i)
491     {
492       if (strcmp(arg, z_options[i].name) == 0)
493         {
494           (this->*(z_options[i].set))();
495           return;
496         }
497     }
498
499   fprintf(stderr, _("%s: unrecognized -z subcommand: %s\n"),
500           program_name, arg);
501   ::exit(1);
502 }
503
504 // Add the sysroot, if any, to the search paths.
505
506 void
507 General_options::add_sysroot()
508 {
509   if (this->sysroot_.empty())
510     {
511       this->sysroot_ = get_default_sysroot();
512       if (this->sysroot_.empty())
513         return;
514     }
515
516   const char* sysroot = this->sysroot_.c_str();
517   char* canonical_sysroot = lrealpath(sysroot);
518
519   for (Dir_list::iterator p = this->search_path_.begin();
520        p != this->search_path_.end();
521        ++p)
522     p->add_sysroot(sysroot, canonical_sysroot);
523
524   free(canonical_sysroot);
525 }
526
527 // Search_directory methods.
528
529 // This is called if we have a sysroot.  Apply the sysroot if
530 // appropriate.  Record whether the directory is in the sysroot.
531
532 void
533 Search_directory::add_sysroot(const char* sysroot,
534                               const char* canonical_sysroot)
535 {
536   gold_assert(*sysroot != '\0');
537   if (this->put_in_sysroot_)
538     {
539       if (!IS_DIR_SEPARATOR(this->name_[0])
540           && !IS_DIR_SEPARATOR(sysroot[strlen(sysroot) - 1]))
541         this->name_ = '/' + this->name_;
542       this->name_ = sysroot + this->name_;
543       this->is_in_sysroot_ = true;
544     }
545   else
546     {
547       // Check whether this entry is in the sysroot.  To do this
548       // correctly, we need to use canonical names.  Otherwise we will
549       // get confused by the ../../.. paths that gcc tends to use.
550       char* canonical_name = lrealpath(this->name_.c_str());
551       int canonical_name_len = strlen(canonical_name);
552       int canonical_sysroot_len = strlen(canonical_sysroot);
553       if (canonical_name_len > canonical_sysroot_len
554           && IS_DIR_SEPARATOR(canonical_name[canonical_sysroot_len]))
555         {
556           canonical_name[canonical_sysroot_len] = '\0';
557           if (FILENAME_CMP(canonical_name, canonical_sysroot) == 0)
558             this->is_in_sysroot_ = true;
559         }
560       free(canonical_name);
561     }
562 }
563
564 // Input_arguments methods.
565
566 // Add a file to the list.
567
568 void
569 Input_arguments::add_file(const Input_file_argument& file)
570 {
571   if (!this->in_group_)
572     this->input_argument_list_.push_back(Input_argument(file));
573   else
574     {
575       gold_assert(!this->input_argument_list_.empty());
576       gold_assert(this->input_argument_list_.back().is_group());
577       this->input_argument_list_.back().group()->add_file(file);
578     }
579 }
580
581 // Start a group.
582
583 void
584 Input_arguments::start_group()
585 {
586   gold_assert(!this->in_group_);
587   Input_file_group* group = new Input_file_group();
588   this->input_argument_list_.push_back(Input_argument(group));
589   this->in_group_ = true;
590 }
591
592 // End a group.
593
594 void
595 Input_arguments::end_group()
596 {
597   gold_assert(this->in_group_);
598   this->in_group_ = false;
599 }
600
601 // Command_line options.
602
603 Command_line::Command_line()
604   : options_(), position_options_(), inputs_()
605 {
606 }
607
608 // Process the command line options.
609
610 void
611 Command_line::process(int argc, char** argv)
612 {
613   const int options_size = options::Command_line_options::options_size;
614   const options::One_option* options =
615     options::Command_line_options::options;
616   bool no_more_options = false;
617   int i = 0;
618   while (i < argc)
619     {
620       if (argv[i][0] != '-' || no_more_options)
621         {
622           this->add_file(argv[i], false);
623           ++i;
624           continue;
625         }
626
627       // Option starting with '-'.
628       int dashes = 1;
629       if (argv[i][1] == '-')
630         {
631           dashes = 2;
632           if (argv[i][2] == '\0')
633             {
634               no_more_options = true;
635               continue;
636             }
637         }
638
639       // Look for a long option match.
640       char* opt = argv[i] + dashes;
641       char first = opt[0];
642       int skiparg = 0;
643       char* arg = strchr(opt, '=');
644       bool argument_with_equals = arg != NULL;
645       if (arg != NULL)
646         {
647           *arg = '\0';
648           ++arg;
649         }
650       else if (i + 1 < argc)
651         {
652           arg = argv[i + 1];
653           skiparg = 1;
654         }
655
656       int j;
657       for (j = 0; j < options_size; ++j)
658         {
659           if (options[j].long_option != NULL
660               && (dashes == 2
661                   || (options[j].dash
662                       != options::One_option::EXACTLY_TWO_DASHES))
663               && first == options[j].long_option[0]
664               && strcmp(opt, options[j].long_option) == 0)
665             {
666               if (options[j].special)
667                 i += options[j].special(argc - 1, argv + i, opt, this);
668               else
669                 {
670                   if (!options[j].takes_argument())
671                     {
672                       if (argument_with_equals)
673                         this->usage(_("unexpected argument"), argv[i]);
674                       arg = NULL;
675                       skiparg = 0;
676                     }
677                   else
678                     {
679                       if (arg == NULL)
680                         this->usage(_("missing argument"), argv[i]);
681                     }
682                   this->apply_option(options[j], arg);
683                   i += skiparg + 1;
684                 }
685               break;
686             }
687         }
688       if (j < options_size)
689         continue;
690
691       // If we saw two dashes, we need to see a long option.
692       if (dashes == 2)
693         this->usage(_("unknown option"), argv[i]);
694
695       // Look for a short option match.  There may be more than one
696       // short option in a given argument.
697       bool done = false;
698       char* s = argv[i] + 1;
699       ++i;
700       while (*s != '\0' && !done)
701         {
702           char opt = *s;
703           int j;
704           for (j = 0; j < options_size; ++j)
705             {
706               if (options[j].short_option == opt)
707                 {
708                   if (options[j].special)
709                     {
710                       // Undo the argument skip done above.
711                       --i;
712                       i += options[j].special(argc - i, argv + i, s, this);
713                       done = true;
714                     }
715                   else
716                     {
717                       arg = NULL;
718                       if (options[j].takes_argument())
719                         {
720                           if (s[1] != '\0')
721                             {
722                               arg = s + 1;
723                               done = true;
724                             }
725                           else if (i < argc)
726                             {
727                               arg = argv[i];
728                               ++i;
729                             }
730                           else
731                             this->usage(_("missing argument"), opt);
732                         }
733                       this->apply_option(options[j], arg);
734                     }
735                   break;
736                 }
737             }
738
739           if (j >= options_size)
740             this->usage(_("unknown option"), *s);
741
742           ++s;
743         }
744     }
745
746   if (this->inputs_.in_group())
747     {
748       fprintf(stderr, _("%s: missing group end\n"), program_name);
749       this->usage();
750     }
751
752   // FIXME: We should only do this when configured in native mode.
753   this->options_.add_to_search_path_with_sysroot("/lib");
754   this->options_.add_to_search_path_with_sysroot("/usr/lib");
755
756   this->options_.add_sysroot();
757
758   // Ensure options don't contradict each other and are otherwise kosher.
759   this->normalize_options();
760 }
761
762 // Ensure options don't contradict each other and are otherwise kosher.
763
764 void
765 Command_line::normalize_options()
766 {
767   // If the user specifies both -s and -r, convert the -s as -S.
768   // -r requires us to keep externally visible symbols!
769   if (this->options_.strip_all() && this->options_.is_relocatable())
770     {
771       // Clears the strip_all() status, replacing it with strip_debug().
772       this->options_.set_strip_debug();
773     }
774
775   // FIXME: we can/should be doing a lot more sanity checking here.
776 }
777
778
779 // Apply a command line option.
780
781 void
782 Command_line::apply_option(const options::One_option& opt,
783                            const char* arg)
784 {
785   if (arg == NULL)
786     {
787       if (opt.general_noarg)
788         (this->options_.*(opt.general_noarg))();
789       else if (opt.dependent_noarg)
790         (this->position_options_.*(opt.dependent_noarg))();
791       else
792         gold_unreachable();
793     }
794   else
795     {
796       if (opt.general_arg)
797         (this->options_.*(opt.general_arg))(arg);
798       else if (opt.dependent_arg)
799         (this->position_options_.*(opt.dependent_arg))(arg);
800       else
801         gold_unreachable();
802     }
803 }
804
805 // Add an input file or library.
806
807 void
808 Command_line::add_file(const char* name, bool is_lib)
809 {
810   Input_file_argument file(name, is_lib, "", this->position_options_);
811   this->inputs_.add_file(file);
812 }
813
814 // Handle the -l option, which requires special treatment.
815
816 int
817 Command_line::process_l_option(int argc, char** argv, char* arg)
818 {
819   int ret;
820   const char* libname;
821   if (arg[1] != '\0')
822     {
823       ret = 1;
824       libname = arg + 1;
825     }
826   else if (argc > 1)
827     {
828       ret = 2;
829       libname = argv[argc + 1];
830     }
831   else
832     this->usage(_("missing argument"), arg);
833
834   this->add_file(libname, true);
835
836   return ret;
837 }
838
839 // Handle the --start-group option.
840
841 void
842 Command_line::start_group(const char* arg)
843 {
844   if (this->inputs_.in_group())
845     this->usage(_("may not nest groups"), arg);
846   this->inputs_.start_group();
847 }
848
849 // Handle the --end-group option.
850
851 void
852 Command_line::end_group(const char* arg)
853 {
854   if (!this->inputs_.in_group())
855     this->usage(_("group end without group start"), arg);
856   this->inputs_.end_group();
857 }
858
859 // Report a usage error.  */
860
861 void
862 Command_line::usage()
863 {
864   fprintf(stderr,
865           _("%s: use the --help option for usage information\n"),
866           program_name);
867   ::exit(1);
868 }
869
870 void
871 Command_line::usage(const char* msg, const char *opt)
872 {
873   fprintf(stderr,
874           _("%s: %s: %s\n"),
875           program_name, opt, msg);
876   this->usage();
877 }
878
879 void
880 Command_line::usage(const char* msg, char opt)
881 {
882   fprintf(stderr,
883           _("%s: -%c: %s\n"),
884           program_name, opt, msg);
885   this->usage();
886 }
887
888 } // End namespace gold.