1 // options.h -- handle command line options for gold -*- C++ -*-
4 // Holds everything we get from the command line.
5 // General_options (from Command_line::options())
6 // Options which are not position dependent.
7 // Input_argument (from Command_line::inputs())
8 // The list of input files, including -l options.
9 // Position_dependent_options (from Input_argument::options())
10 // Position dependent options which apply to this argument.
12 #ifndef GOLD_OPTIONS_H
13 #define GOLD_OPTIONS_H
23 class Input_file_group
;
27 class Command_line_options
;
30 } // End namespace gold::options.
32 // The position independent options which apply to the whole link.
33 // There are a lot of them.
40 // -E: export dynamic symbols.
42 export_dynamic() const
43 { return this->export_dynamic_
; }
45 // -I: dynamic linker name.
47 dynamic_linker() const
48 { return this->dynamic_linker_
; }
50 // -L: Library search path.
51 typedef std::vector
<const char*> Dir_list
;
55 { return this->search_path_
; }
57 // -o: Output file name.
59 output_file_name() const
60 { return this->output_file_name_
; }
62 // -r: Whether we are doing a relocatable link.
64 is_relocatable() const
65 { return this->is_relocatable_
; }
67 // --eh-frame-hdr: Whether to generate an exception frame header.
69 create_eh_frame_hdr() const
70 { return this->create_eh_frame_hdr_
; }
72 // --rpath: The runtime search path.
75 { return this->rpath_
; }
77 // --shared: Whether generating a shared object.
80 { return this->is_shared_
; }
82 // --static: Whether doing a static link.
85 { return this->is_static_
; }
88 // Don't copy this structure.
89 General_options(const General_options
&);
90 General_options
& operator=(const General_options
&);
92 friend class Command_line
;
93 friend class options::Command_line_options
;
97 { this->export_dynamic_
= true; }
100 set_dynamic_linker(const char* arg
)
101 { this->dynamic_linker_
= arg
; }
104 add_to_search_path(const char* arg
)
105 { this->search_path_
.push_back(arg
); }
108 set_output_file_name(const char* arg
)
109 { this->output_file_name_
= arg
; }
113 { this->is_relocatable_
= true; }
116 create_eh_frame_hdr()
117 { this->create_eh_frame_hdr_
= true; }
120 add_to_rpath(const char* arg
)
121 { this->rpath_
.push_back(arg
); }
125 { this->is_shared_
= true; }
129 { this->is_static_
= true; }
135 bool export_dynamic_
;
136 const char* dynamic_linker_
;
137 Dir_list search_path_
;
138 const char* output_file_name_
;
139 bool is_relocatable_
;
140 bool create_eh_frame_hdr_
;
146 // The current state of the position dependent options.
148 class Position_dependent_options
151 Position_dependent_options();
153 // -Bstatic: Whether we are searching for a static archive rather
154 // than a shared object.
156 do_static_search() const
157 { return this->do_static_search_
; }
159 // --as-needed: Whether to add a DT_NEEDED argument only if the
160 // dynamic object is used.
163 { return this->as_needed_
; }
165 // --whole-archive: Whether to include the entire contents of an
168 include_whole_archive() const
169 { return this->include_whole_archive_
; }
173 { this->do_static_search_
= true; }
177 { this->do_static_search_
= false; }
181 { this->as_needed_
= true; }
185 { this->as_needed_
= false; }
189 { this->include_whole_archive_
= true; }
192 clear_whole_archive()
193 { this->include_whole_archive_
= false; }
196 bool do_static_search_
;
198 bool include_whole_archive_
;
201 // A single file or library argument from the command line.
203 class Input_file_argument
206 Input_file_argument()
207 : name_(), is_lib_(false), options_()
210 Input_file_argument(const char* name
, bool is_lib
,
211 const Position_dependent_options
& options
)
212 : name_(name
), is_lib_(is_lib
), options_(options
)
217 { return this->name_
.c_str(); }
219 const Position_dependent_options
&
221 { return this->options_
; }
225 { return this->is_lib_
; }
228 // We use std::string, not const char*, here for convenience when
229 // using script files, so that we do not have to preserve the string
233 Position_dependent_options options_
;
236 // A file or library, or a group, from the command line.
241 // Create a file or library argument.
242 explicit Input_argument(Input_file_argument file
)
243 : is_file_(true), file_(file
), group_(NULL
)
246 // Create a group argument.
247 explicit Input_argument(Input_file_group
* group
)
248 : is_file_(false), group_(group
)
251 // Return whether this is a file.
254 { return this->is_file_
; }
256 // Return whether this is a group.
259 { return !this->is_file_
; }
261 // Return the information about the file.
262 const Input_file_argument
&
265 gold_assert(this->is_file_
);
269 // Return the information about the group.
270 const Input_file_group
*
273 gold_assert(!this->is_file_
);
280 gold_assert(!this->is_file_
);
286 Input_file_argument file_
;
287 Input_file_group
* group_
;
290 // A group from the command line. This is a set of arguments within
291 // --start-group ... --end-group.
293 class Input_file_group
296 typedef std::vector
<Input_argument
> Files
;
297 typedef Files::const_iterator const_iterator
;
303 // Add a file to the end of the group.
305 add_file(const Input_file_argument
& arg
)
306 { this->files_
.push_back(Input_argument(arg
)); }
308 // Iterators to iterate over the group contents.
312 { return this->files_
.begin(); }
316 { return this->files_
.end(); }
322 // A list of files from the command line or a script.
324 class Input_arguments
327 typedef std::vector
<Input_argument
> Input_argument_list
;
328 typedef Input_argument_list::const_iterator const_iterator
;
331 : input_argument_list_(), in_group_(false)
336 add_file(const Input_file_argument
& arg
);
338 // Start a group (the --start-group option).
342 // End a group (the --end-group option).
346 // Return whether we are currently in a group.
349 { return this->in_group_
; }
351 // Iterators to iterate over the list of input files.
355 { return this->input_argument_list_
.begin(); }
359 { return this->input_argument_list_
.end(); }
361 // Return whether the list is empty.
364 { return this->input_argument_list_
.empty(); }
367 Input_argument_list input_argument_list_
;
371 // All the information read from the command line.
376 typedef Input_arguments::const_iterator const_iterator
;
380 // Process the command line options. This will exit with an
381 // appropriate error message if an unrecognized option is seen.
383 process(int argc
, char** argv
);
385 // Handle a -l option.
387 process_l_option(int, char**, char*);
389 // Handle a --start-group option.
391 start_group(const char* arg
);
393 // Handle a --end-group option.
395 end_group(const char* arg
);
397 // Get the general options.
398 const General_options
&
400 { return this->options_
; }
402 // Iterators to iterate over the list of input files.
406 { return this->inputs_
.begin(); }
410 { return this->inputs_
.end(); }
413 Command_line(const Command_line
&);
414 Command_line
& operator=(const Command_line
&);
416 // Report usage error.
418 usage() ATTRIBUTE_NORETURN
;
420 usage(const char* msg
, const char* opt
) ATTRIBUTE_NORETURN
;
422 usage(const char* msg
, char opt
) ATTRIBUTE_NORETURN
;
424 // Apply a command line option.
426 apply_option(const gold::options::One_option
&, const char*);
430 add_file(const char* name
, bool is_lib
);
432 General_options options_
;
433 Position_dependent_options position_options_
;
434 Input_arguments inputs_
;
437 } // End namespace gold.
439 #endif // !defined(GOLD_OPTIONS_H)