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 // --rpath: The runtime search path.
70 { return this->rpath_
; }
72 // --shared: Whether generating a shared object.
75 { return this->is_shared_
; }
77 // --static: Whether doing a static link.
80 { return this->is_static_
; }
83 // Don't copy this structure.
84 General_options(const General_options
&);
85 General_options
& operator=(const General_options
&);
87 friend class Command_line
;
88 friend class options::Command_line_options
;
92 { this->export_dynamic_
= true; }
95 set_dynamic_linker(const char* arg
)
96 { this->dynamic_linker_
= arg
; }
99 add_to_search_path(const char* arg
)
100 { this->search_path_
.push_back(arg
); }
103 set_output_file_name(const char* arg
)
104 { this->output_file_name_
= arg
; }
108 { this->is_relocatable_
= true; }
111 add_to_rpath(const char* arg
)
112 { this->rpath_
.push_back(arg
); }
116 { this->is_shared_
= true; }
120 { this->is_static_
= true; }
126 bool export_dynamic_
;
127 const char* dynamic_linker_
;
128 Dir_list search_path_
;
129 const char* output_file_name_
;
130 bool is_relocatable_
;
136 // The current state of the position dependent options.
138 class Position_dependent_options
141 Position_dependent_options();
143 // -Bstatic: Whether we are searching for a static archive rather
144 // than a shared object.
146 do_static_search() const
147 { return this->do_static_search_
; }
149 // --as-needed: Whether to add a DT_NEEDED argument only if the
150 // dynamic object is used.
153 { return this->as_needed_
; }
155 // --whole-archive: Whether to include the entire contents of an
158 include_whole_archive() const
159 { return this->include_whole_archive_
; }
163 { this->do_static_search_
= true; }
167 { this->do_static_search_
= false; }
171 { this->as_needed_
= true; }
175 { this->as_needed_
= false; }
179 { this->include_whole_archive_
= true; }
182 clear_whole_archive()
183 { this->include_whole_archive_
= false; }
186 bool do_static_search_
;
188 bool include_whole_archive_
;
191 // A single file or library argument from the command line.
193 class Input_file_argument
196 Input_file_argument()
197 : name_(), is_lib_(false), options_()
200 Input_file_argument(const char* name
, bool is_lib
,
201 const Position_dependent_options
& options
)
202 : name_(name
), is_lib_(is_lib
), options_(options
)
207 { return this->name_
.c_str(); }
209 const Position_dependent_options
&
211 { return this->options_
; }
215 { return this->is_lib_
; }
218 // We use std::string, not const char*, here for convenience when
219 // using script files, so that we do not have to preserve the string
223 Position_dependent_options options_
;
226 // A file or library, or a group, from the command line.
231 // Create a file or library argument.
232 explicit Input_argument(Input_file_argument file
)
233 : is_file_(true), file_(file
), group_(NULL
)
236 // Create a group argument.
237 explicit Input_argument(Input_file_group
* group
)
238 : is_file_(false), group_(group
)
241 // Return whether this is a file.
244 { return this->is_file_
; }
246 // Return whether this is a group.
249 { return !this->is_file_
; }
251 // Return the information about the file.
252 const Input_file_argument
&
255 gold_assert(this->is_file_
);
259 // Return the information about the group.
260 const Input_file_group
*
263 gold_assert(!this->is_file_
);
270 gold_assert(!this->is_file_
);
276 Input_file_argument file_
;
277 Input_file_group
* group_
;
280 // A group from the command line. This is a set of arguments within
281 // --start-group ... --end-group.
283 class Input_file_group
286 typedef std::vector
<Input_argument
> Files
;
287 typedef Files::const_iterator const_iterator
;
293 // Add a file to the end of the group.
295 add_file(const Input_file_argument
& arg
)
296 { this->files_
.push_back(Input_argument(arg
)); }
298 // Iterators to iterate over the group contents.
302 { return this->files_
.begin(); }
306 { return this->files_
.end(); }
312 // A list of files from the command line or a script.
314 class Input_arguments
317 typedef std::vector
<Input_argument
> Input_argument_list
;
318 typedef Input_argument_list::const_iterator const_iterator
;
321 : input_argument_list_(), in_group_(false)
326 add_file(const Input_file_argument
& arg
);
328 // Start a group (the --start-group option).
332 // End a group (the --end-group option).
336 // Return whether we are currently in a group.
339 { return this->in_group_
; }
341 // Iterators to iterate over the list of input files.
345 { return this->input_argument_list_
.begin(); }
349 { return this->input_argument_list_
.end(); }
351 // Return whether the list is empty.
354 { return this->input_argument_list_
.empty(); }
357 Input_argument_list input_argument_list_
;
361 // All the information read from the command line.
366 typedef Input_arguments::const_iterator const_iterator
;
370 // Process the command line options. This will exit with an
371 // appropriate error message if an unrecognized option is seen.
373 process(int argc
, char** argv
);
375 // Handle a -l option.
377 process_l_option(int, char**, char*);
379 // Handle a --start-group option.
381 start_group(const char* arg
);
383 // Handle a --end-group option.
385 end_group(const char* arg
);
387 // Get the general options.
388 const General_options
&
390 { return this->options_
; }
392 // Iterators to iterate over the list of input files.
396 { return this->inputs_
.begin(); }
400 { return this->inputs_
.end(); }
403 Command_line(const Command_line
&);
404 Command_line
& operator=(const Command_line
&);
406 // Report usage error.
408 usage() ATTRIBUTE_NORETURN
;
410 usage(const char* msg
, const char* opt
) ATTRIBUTE_NORETURN
;
412 usage(const char* msg
, char opt
) ATTRIBUTE_NORETURN
;
414 // Apply a command line option.
416 apply_option(const gold::options::One_option
&, const char*);
420 add_file(const char* name
, bool is_lib
);
422 General_options options_
;
423 Position_dependent_options position_options_
;
424 Input_arguments inputs_
;
427 } // End namespace gold.
429 #endif // !defined(GOLD_OPTIONS_H)