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 // --rpath-link: The link time search patch for shared libraries.
80 { return this->rpath_link_; }
82 // --shared: Whether generating a shared object.
85 { return this->is_shared_; }
87 // --static: Whether doing a static link.
90 { return this->is_static_; }
93 // Don't copy this structure.
94 General_options(const General_options&);
95 General_options& operator=(const General_options&);
97 friend class Command_line;
98 friend class options::Command_line_options;
102 { this->export_dynamic_ = true; }
105 set_dynamic_linker(const char* arg)
106 { this->dynamic_linker_ = arg; }
109 add_to_search_path(const char* arg)
110 { this->search_path_.push_back(arg); }
113 set_output_file_name(const char* arg)
114 { this->output_file_name_ = arg; }
118 { this->is_relocatable_ = true; }
121 create_eh_frame_hdr()
122 { this->create_eh_frame_hdr_ = true; }
125 add_to_rpath(const char* arg)
126 { this->rpath_.push_back(arg); }
129 add_to_rpath_link(const char* arg)
130 { this->rpath_link_.push_back(arg); }
134 { this->is_shared_ = true; }
138 { this->is_static_ = true; }
144 bool export_dynamic_;
145 const char* dynamic_linker_;
146 Dir_list search_path_;
147 const char* output_file_name_;
148 bool is_relocatable_;
149 bool create_eh_frame_hdr_;
151 Dir_list rpath_link_;
156 // The current state of the position dependent options.
158 class Position_dependent_options
161 Position_dependent_options();
163 // -Bstatic: Whether we are searching for a static archive rather
164 // than a shared object.
166 do_static_search() const
167 { return this->do_static_search_; }
169 // --as-needed: Whether to add a DT_NEEDED argument only if the
170 // dynamic object is used.
173 { return this->as_needed_; }
175 // --whole-archive: Whether to include the entire contents of an
178 include_whole_archive() const
179 { return this->include_whole_archive_; }
183 { this->do_static_search_ = true; }
187 { this->do_static_search_ = false; }
191 { this->as_needed_ = true; }
195 { this->as_needed_ = false; }
199 { this->include_whole_archive_ = true; }
202 clear_whole_archive()
203 { this->include_whole_archive_ = false; }
206 bool do_static_search_;
208 bool include_whole_archive_;
211 // A single file or library argument from the command line.
213 class Input_file_argument
216 Input_file_argument()
217 : name_(), is_lib_(false), options_()
220 Input_file_argument(const char* name, bool is_lib,
221 const Position_dependent_options& options)
222 : name_(name), is_lib_(is_lib), options_(options)
227 { return this->name_.c_str(); }
229 const Position_dependent_options&
231 { return this->options_; }
235 { return this->is_lib_; }
238 // We use std::string, not const char*, here for convenience when
239 // using script files, so that we do not have to preserve the string
243 Position_dependent_options options_;
246 // A file or library, or a group, from the command line.
251 // Create a file or library argument.
252 explicit Input_argument(Input_file_argument file)
253 : is_file_(true), file_(file), group_(NULL)
256 // Create a group argument.
257 explicit Input_argument(Input_file_group* group)
258 : is_file_(false), group_(group)
261 // Return whether this is a file.
264 { return this->is_file_; }
266 // Return whether this is a group.
269 { return !this->is_file_; }
271 // Return the information about the file.
272 const Input_file_argument&
275 gold_assert(this->is_file_);
279 // Return the information about the group.
280 const Input_file_group*
283 gold_assert(!this->is_file_);
290 gold_assert(!this->is_file_);
296 Input_file_argument file_;
297 Input_file_group* group_;
300 // A group from the command line. This is a set of arguments within
301 // --start-group ... --end-group.
303 class Input_file_group
306 typedef std::vector<Input_argument> Files;
307 typedef Files::const_iterator const_iterator;
313 // Add a file to the end of the group.
315 add_file(const Input_file_argument& arg)
316 { this->files_.push_back(Input_argument(arg)); }
318 // Iterators to iterate over the group contents.
322 { return this->files_.begin(); }
326 { return this->files_.end(); }
332 // A list of files from the command line or a script.
334 class Input_arguments
337 typedef std::vector<Input_argument> Input_argument_list;
338 typedef Input_argument_list::const_iterator const_iterator;
341 : input_argument_list_(), in_group_(false)
346 add_file(const Input_file_argument& arg);
348 // Start a group (the --start-group option).
352 // End a group (the --end-group option).
356 // Return whether we are currently in a group.
359 { return this->in_group_; }
361 // Iterators to iterate over the list of input files.
365 { return this->input_argument_list_.begin(); }
369 { return this->input_argument_list_.end(); }
371 // Return whether the list is empty.
374 { return this->input_argument_list_.empty(); }
377 Input_argument_list input_argument_list_;
381 // All the information read from the command line.
386 typedef Input_arguments::const_iterator const_iterator;
390 // Process the command line options. This will exit with an
391 // appropriate error message if an unrecognized option is seen.
393 process(int argc, char** argv);
395 // Handle a -l option.
397 process_l_option(int, char**, char*);
399 // Handle a --start-group option.
401 start_group(const char* arg);
403 // Handle a --end-group option.
405 end_group(const char* arg);
407 // Get the general options.
408 const General_options&
410 { return this->options_; }
412 // Iterators to iterate over the list of input files.
416 { return this->inputs_.begin(); }
420 { return this->inputs_.end(); }
423 Command_line(const Command_line&);
424 Command_line& operator=(const Command_line&);
426 // Report usage error.
428 usage() ATTRIBUTE_NORETURN;
430 usage(const char* msg, const char* opt) ATTRIBUTE_NORETURN;
432 usage(const char* msg, char opt) ATTRIBUTE_NORETURN;
434 // Apply a command line option.
436 apply_option(const gold::options::One_option&, const char*);
440 add_file(const char* name, bool is_lib);
442 General_options options_;
443 Position_dependent_options position_options_;
444 Input_arguments inputs_;
447 } // End namespace gold.
449 #endif // !defined(GOLD_OPTIONS_H)