2006-08-05 07:10:59 +08:00
|
|
|
// options.h -- handle command line options for gold -*- C++ -*-
|
|
|
|
|
|
|
|
// Command_line
|
|
|
|
// Holds everything we get from the command line.
|
|
|
|
// General_options (from Command_line::options())
|
|
|
|
// Options which are not position dependent.
|
|
|
|
// Input_argument (from Command_line::inputs())
|
|
|
|
// The list of input files, including -l options.
|
|
|
|
// Position_dependent_options (from Input_argument::options())
|
|
|
|
// Position dependent options which apply to this argument.
|
|
|
|
|
|
|
|
#ifndef GOLD_OPTIONS_H
|
|
|
|
#define GOLD_OPTIONS_H
|
|
|
|
|
|
|
|
#include <list>
|
2006-09-30 03:58:17 +08:00
|
|
|
#include <string>
|
2006-10-21 04:40:49 +08:00
|
|
|
#include <vector>
|
2006-08-05 07:10:59 +08:00
|
|
|
|
|
|
|
namespace gold
|
|
|
|
{
|
|
|
|
|
|
|
|
class Command_line;
|
2006-11-04 02:26:11 +08:00
|
|
|
class Input_file_group;
|
2006-08-05 07:10:59 +08:00
|
|
|
|
|
|
|
namespace options {
|
|
|
|
|
|
|
|
class Command_line_options;
|
|
|
|
struct One_option;
|
|
|
|
|
|
|
|
} // End namespace gold::options.
|
|
|
|
|
|
|
|
// The position independent options which apply to the whole link.
|
|
|
|
// There are a lot of them.
|
|
|
|
|
|
|
|
class General_options
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
General_options();
|
|
|
|
|
2007-08-22 13:06:38 +08:00
|
|
|
// -E: export dynamic symbols.
|
|
|
|
bool
|
|
|
|
export_dynamic() const
|
|
|
|
{ return this->export_dynamic_; }
|
|
|
|
|
2006-11-15 03:21:05 +08:00
|
|
|
// -I: dynamic linker name.
|
|
|
|
const char*
|
|
|
|
dynamic_linker() const
|
|
|
|
{ return this->dynamic_linker_; }
|
|
|
|
|
2006-08-05 07:10:59 +08:00
|
|
|
// -L: Library search path.
|
2007-08-22 04:37:32 +08:00
|
|
|
typedef std::vector<const char*> Dir_list;
|
2006-08-05 07:10:59 +08:00
|
|
|
|
|
|
|
const Dir_list&
|
|
|
|
search_path() const
|
|
|
|
{ return this->search_path_; }
|
|
|
|
|
2006-09-30 03:58:17 +08:00
|
|
|
// -o: Output file name.
|
|
|
|
const char*
|
|
|
|
output_file_name() const
|
|
|
|
{ return this->output_file_name_; }
|
|
|
|
|
2006-08-05 07:10:59 +08:00
|
|
|
// -r: Whether we are doing a relocatable link.
|
|
|
|
bool
|
|
|
|
is_relocatable() const
|
|
|
|
{ return this->is_relocatable_; }
|
|
|
|
|
2007-08-23 01:07:36 +08:00
|
|
|
// --eh-frame-hdr: Whether to generate an exception frame header.
|
|
|
|
bool
|
|
|
|
create_eh_frame_hdr() const
|
|
|
|
{ return this->create_eh_frame_hdr_; }
|
|
|
|
|
2007-08-22 04:37:32 +08:00
|
|
|
// --rpath: The runtime search path.
|
|
|
|
const Dir_list&
|
|
|
|
rpath() const
|
|
|
|
{ return this->rpath_; }
|
|
|
|
|
2007-09-07 07:37:53 +08:00
|
|
|
// --rpath-link: The link time search patch for shared libraries.
|
|
|
|
const Dir_list&
|
|
|
|
rpath_link() const
|
|
|
|
{ return this->rpath_link_; }
|
|
|
|
|
2006-10-21 04:40:49 +08:00
|
|
|
// --shared: Whether generating a shared object.
|
|
|
|
bool
|
|
|
|
is_shared() const
|
|
|
|
{ return this->is_shared_; }
|
|
|
|
|
2006-08-05 07:10:59 +08:00
|
|
|
// --static: Whether doing a static link.
|
|
|
|
bool
|
|
|
|
is_static() const
|
|
|
|
{ return this->is_static_; }
|
|
|
|
|
|
|
|
private:
|
2006-11-15 03:21:05 +08:00
|
|
|
// Don't copy this structure.
|
|
|
|
General_options(const General_options&);
|
|
|
|
General_options& operator=(const General_options&);
|
|
|
|
|
2006-08-05 07:10:59 +08:00
|
|
|
friend class Command_line;
|
|
|
|
friend class options::Command_line_options;
|
|
|
|
|
2007-08-22 13:06:38 +08:00
|
|
|
void
|
|
|
|
set_export_dynamic()
|
|
|
|
{ this->export_dynamic_ = true; }
|
|
|
|
|
2006-11-15 03:21:05 +08:00
|
|
|
void
|
|
|
|
set_dynamic_linker(const char* arg)
|
|
|
|
{ this->dynamic_linker_ = arg; }
|
|
|
|
|
2006-08-05 07:10:59 +08:00
|
|
|
void
|
|
|
|
add_to_search_path(const char* arg)
|
|
|
|
{ this->search_path_.push_back(arg); }
|
|
|
|
|
2006-09-30 03:58:17 +08:00
|
|
|
void
|
|
|
|
set_output_file_name(const char* arg)
|
|
|
|
{ this->output_file_name_ = arg; }
|
|
|
|
|
2006-08-05 07:10:59 +08:00
|
|
|
void
|
|
|
|
set_relocatable()
|
|
|
|
{ this->is_relocatable_ = true; }
|
|
|
|
|
2007-08-23 01:07:36 +08:00
|
|
|
void
|
|
|
|
create_eh_frame_hdr()
|
|
|
|
{ this->create_eh_frame_hdr_ = true; }
|
|
|
|
|
2007-08-22 04:37:32 +08:00
|
|
|
void
|
|
|
|
add_to_rpath(const char* arg)
|
|
|
|
{ this->rpath_.push_back(arg); }
|
|
|
|
|
2007-09-07 07:37:53 +08:00
|
|
|
void
|
|
|
|
add_to_rpath_link(const char* arg)
|
|
|
|
{ this->rpath_link_.push_back(arg); }
|
|
|
|
|
2006-10-21 04:40:49 +08:00
|
|
|
void
|
|
|
|
set_shared()
|
|
|
|
{ this->is_shared_ = true; }
|
|
|
|
|
2006-08-05 07:10:59 +08:00
|
|
|
void
|
|
|
|
set_static()
|
|
|
|
{ this->is_static_ = true; }
|
|
|
|
|
2006-11-04 02:48:03 +08:00
|
|
|
void
|
|
|
|
ignore(const char*)
|
|
|
|
{ }
|
|
|
|
|
2007-08-22 13:06:38 +08:00
|
|
|
bool export_dynamic_;
|
2006-11-15 03:21:05 +08:00
|
|
|
const char* dynamic_linker_;
|
2006-08-05 07:10:59 +08:00
|
|
|
Dir_list search_path_;
|
2006-09-30 03:58:17 +08:00
|
|
|
const char* output_file_name_;
|
2006-08-05 07:10:59 +08:00
|
|
|
bool is_relocatable_;
|
2007-08-23 01:07:36 +08:00
|
|
|
bool create_eh_frame_hdr_;
|
2007-08-22 04:37:32 +08:00
|
|
|
Dir_list rpath_;
|
2007-09-07 07:37:53 +08:00
|
|
|
Dir_list rpath_link_;
|
2006-10-21 04:40:49 +08:00
|
|
|
bool is_shared_;
|
2006-08-05 07:10:59 +08:00
|
|
|
bool is_static_;
|
|
|
|
};
|
|
|
|
|
|
|
|
// The current state of the position dependent options.
|
|
|
|
|
|
|
|
class Position_dependent_options
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Position_dependent_options();
|
|
|
|
|
|
|
|
// -Bstatic: Whether we are searching for a static archive rather
|
2006-11-15 03:21:05 +08:00
|
|
|
// than a shared object.
|
2006-08-05 07:10:59 +08:00
|
|
|
bool
|
2006-11-15 03:21:05 +08:00
|
|
|
do_static_search() const
|
2006-08-05 07:10:59 +08:00
|
|
|
{ return this->do_static_search_; }
|
|
|
|
|
2006-11-15 03:21:05 +08:00
|
|
|
// --as-needed: Whether to add a DT_NEEDED argument only if the
|
|
|
|
// dynamic object is used.
|
|
|
|
bool
|
|
|
|
as_needed() const
|
|
|
|
{ return this->as_needed_; }
|
2006-08-05 07:10:59 +08:00
|
|
|
|
2007-08-22 07:37:56 +08:00
|
|
|
// --whole-archive: Whether to include the entire contents of an
|
|
|
|
// --archive.
|
|
|
|
bool
|
|
|
|
include_whole_archive() const
|
|
|
|
{ return this->include_whole_archive_; }
|
|
|
|
|
2006-08-05 07:10:59 +08:00
|
|
|
void
|
|
|
|
set_static_search()
|
|
|
|
{ this->do_static_search_ = true; }
|
|
|
|
|
|
|
|
void
|
|
|
|
set_dynamic_search()
|
|
|
|
{ this->do_static_search_ = false; }
|
|
|
|
|
2006-11-15 03:21:05 +08:00
|
|
|
void
|
|
|
|
set_as_needed()
|
|
|
|
{ this->as_needed_ = true; }
|
|
|
|
|
|
|
|
void
|
|
|
|
clear_as_needed()
|
|
|
|
{ this->as_needed_ = false; }
|
|
|
|
|
2007-08-22 07:37:56 +08:00
|
|
|
void
|
|
|
|
set_whole_archive()
|
|
|
|
{ this->include_whole_archive_ = true; }
|
|
|
|
|
|
|
|
void
|
|
|
|
clear_whole_archive()
|
|
|
|
{ this->include_whole_archive_ = false; }
|
|
|
|
|
2006-11-15 03:21:05 +08:00
|
|
|
private:
|
2006-08-05 07:10:59 +08:00
|
|
|
bool do_static_search_;
|
2006-11-15 03:21:05 +08:00
|
|
|
bool as_needed_;
|
2007-08-22 07:37:56 +08:00
|
|
|
bool include_whole_archive_;
|
2006-08-05 07:10:59 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// A single file or library argument from the command line.
|
|
|
|
|
2006-11-04 02:26:11 +08:00
|
|
|
class Input_file_argument
|
2006-08-05 07:10:59 +08:00
|
|
|
{
|
|
|
|
public:
|
2006-11-04 02:26:11 +08:00
|
|
|
Input_file_argument()
|
2006-11-15 03:21:05 +08:00
|
|
|
: name_(), is_lib_(false), options_()
|
2006-11-04 02:26:11 +08:00
|
|
|
{ }
|
|
|
|
|
|
|
|
Input_file_argument(const char* name, bool is_lib,
|
|
|
|
const Position_dependent_options& options)
|
2006-09-30 03:58:17 +08:00
|
|
|
: name_(name), is_lib_(is_lib), options_(options)
|
2006-08-05 07:10:59 +08:00
|
|
|
{ }
|
|
|
|
|
|
|
|
const char*
|
|
|
|
name() const
|
2006-11-15 03:21:05 +08:00
|
|
|
{ return this->name_.c_str(); }
|
2006-08-05 07:10:59 +08:00
|
|
|
|
|
|
|
const Position_dependent_options&
|
|
|
|
options() const
|
|
|
|
{ return this->options_; }
|
|
|
|
|
|
|
|
bool
|
|
|
|
is_lib() const
|
2006-09-30 03:58:17 +08:00
|
|
|
{ return this->is_lib_; }
|
2006-08-05 07:10:59 +08:00
|
|
|
|
|
|
|
private:
|
2006-11-15 03:21:05 +08:00
|
|
|
// We use std::string, not const char*, here for convenience when
|
|
|
|
// using script files, so that we do not have to preserve the string
|
|
|
|
// in that case.
|
|
|
|
std::string name_;
|
2006-09-30 03:58:17 +08:00
|
|
|
bool is_lib_;
|
2006-08-05 07:10:59 +08:00
|
|
|
Position_dependent_options options_;
|
|
|
|
};
|
|
|
|
|
2006-11-04 02:26:11 +08:00
|
|
|
// A file or library, or a group, from the command line.
|
|
|
|
|
|
|
|
class Input_argument
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// Create a file or library argument.
|
|
|
|
explicit Input_argument(Input_file_argument file)
|
|
|
|
: is_file_(true), file_(file), group_(NULL)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
// Create a group argument.
|
|
|
|
explicit Input_argument(Input_file_group* group)
|
|
|
|
: is_file_(false), group_(group)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
// Return whether this is a file.
|
|
|
|
bool
|
|
|
|
is_file() const
|
|
|
|
{ return this->is_file_; }
|
|
|
|
|
|
|
|
// Return whether this is a group.
|
|
|
|
bool
|
|
|
|
is_group() const
|
|
|
|
{ return !this->is_file_; }
|
|
|
|
|
|
|
|
// Return the information about the file.
|
|
|
|
const Input_file_argument&
|
|
|
|
file() const
|
|
|
|
{
|
2006-11-30 01:56:40 +08:00
|
|
|
gold_assert(this->is_file_);
|
2006-11-04 02:26:11 +08:00
|
|
|
return this->file_;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the information about the group.
|
|
|
|
const Input_file_group*
|
|
|
|
group() const
|
|
|
|
{
|
2006-11-30 01:56:40 +08:00
|
|
|
gold_assert(!this->is_file_);
|
2006-11-04 02:26:11 +08:00
|
|
|
return this->group_;
|
|
|
|
}
|
|
|
|
|
|
|
|
Input_file_group*
|
|
|
|
group()
|
|
|
|
{
|
2006-11-30 01:56:40 +08:00
|
|
|
gold_assert(!this->is_file_);
|
2006-11-04 02:26:11 +08:00
|
|
|
return this->group_;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool is_file_;
|
|
|
|
Input_file_argument file_;
|
|
|
|
Input_file_group* group_;
|
|
|
|
};
|
|
|
|
|
|
|
|
// A group from the command line. This is a set of arguments within
|
|
|
|
// --start-group ... --end-group.
|
|
|
|
|
|
|
|
class Input_file_group
|
2006-10-21 04:40:49 +08:00
|
|
|
{
|
2006-11-04 02:26:11 +08:00
|
|
|
public:
|
|
|
|
typedef std::vector<Input_argument> Files;
|
|
|
|
typedef Files::const_iterator const_iterator;
|
|
|
|
|
|
|
|
Input_file_group()
|
|
|
|
: files_()
|
|
|
|
{ }
|
|
|
|
|
|
|
|
// Add a file to the end of the group.
|
|
|
|
void
|
|
|
|
add_file(const Input_file_argument& arg)
|
|
|
|
{ this->files_.push_back(Input_argument(arg)); }
|
|
|
|
|
|
|
|
// Iterators to iterate over the group contents.
|
|
|
|
|
|
|
|
const_iterator
|
|
|
|
begin() const
|
|
|
|
{ return this->files_.begin(); }
|
|
|
|
|
|
|
|
const_iterator
|
|
|
|
end() const
|
|
|
|
{ return this->files_.end(); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
Files files_;
|
2006-10-21 04:40:49 +08:00
|
|
|
};
|
|
|
|
|
2006-11-15 03:21:05 +08:00
|
|
|
// A list of files from the command line or a script.
|
|
|
|
|
|
|
|
class Input_arguments
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef std::vector<Input_argument> Input_argument_list;
|
|
|
|
typedef Input_argument_list::const_iterator const_iterator;
|
|
|
|
|
|
|
|
Input_arguments()
|
|
|
|
: input_argument_list_(), in_group_(false)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
// Add a file.
|
|
|
|
void
|
|
|
|
add_file(const Input_file_argument& arg);
|
|
|
|
|
|
|
|
// Start a group (the --start-group option).
|
|
|
|
void
|
|
|
|
start_group();
|
|
|
|
|
|
|
|
// End a group (the --end-group option).
|
|
|
|
void
|
|
|
|
end_group();
|
|
|
|
|
|
|
|
// Return whether we are currently in a group.
|
|
|
|
bool
|
|
|
|
in_group() const
|
|
|
|
{ return this->in_group_; }
|
|
|
|
|
|
|
|
// Iterators to iterate over the list of input files.
|
|
|
|
|
|
|
|
const_iterator
|
|
|
|
begin() const
|
|
|
|
{ return this->input_argument_list_.begin(); }
|
|
|
|
|
|
|
|
const_iterator
|
|
|
|
end() const
|
|
|
|
{ return this->input_argument_list_.end(); }
|
|
|
|
|
|
|
|
// Return whether the list is empty.
|
|
|
|
bool
|
|
|
|
empty() const
|
|
|
|
{ return this->input_argument_list_.empty(); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
Input_argument_list input_argument_list_;
|
|
|
|
bool in_group_;
|
|
|
|
};
|
|
|
|
|
2006-08-05 07:10:59 +08:00
|
|
|
// All the information read from the command line.
|
|
|
|
|
|
|
|
class Command_line
|
|
|
|
{
|
|
|
|
public:
|
2006-11-04 02:26:11 +08:00
|
|
|
typedef Input_arguments::const_iterator const_iterator;
|
|
|
|
|
2006-08-05 07:10:59 +08:00
|
|
|
Command_line();
|
|
|
|
|
|
|
|
// Process the command line options. This will exit with an
|
|
|
|
// appropriate error message if an unrecognized option is seen.
|
|
|
|
void
|
|
|
|
process(int argc, char** argv);
|
|
|
|
|
2006-09-30 03:58:17 +08:00
|
|
|
// Handle a -l option.
|
|
|
|
int
|
|
|
|
process_l_option(int, char**, char*);
|
|
|
|
|
2006-11-04 02:26:11 +08:00
|
|
|
// Handle a --start-group option.
|
|
|
|
void
|
|
|
|
start_group(const char* arg);
|
|
|
|
|
|
|
|
// Handle a --end-group option.
|
|
|
|
void
|
|
|
|
end_group(const char* arg);
|
|
|
|
|
2006-09-30 03:58:17 +08:00
|
|
|
// Get the general options.
|
2006-08-05 07:10:59 +08:00
|
|
|
const General_options&
|
|
|
|
options() const
|
|
|
|
{ return this->options_; }
|
|
|
|
|
2006-11-04 02:26:11 +08:00
|
|
|
// Iterators to iterate over the list of input files.
|
|
|
|
|
|
|
|
const_iterator
|
|
|
|
begin() const
|
|
|
|
{ return this->inputs_.begin(); }
|
|
|
|
|
|
|
|
const_iterator
|
|
|
|
end() const
|
|
|
|
{ return this->inputs_.end(); }
|
2006-08-05 07:10:59 +08:00
|
|
|
|
|
|
|
private:
|
2006-11-04 02:26:11 +08:00
|
|
|
Command_line(const Command_line&);
|
|
|
|
Command_line& operator=(const Command_line&);
|
|
|
|
|
|
|
|
// Report usage error.
|
|
|
|
void
|
|
|
|
usage() ATTRIBUTE_NORETURN;
|
|
|
|
void
|
|
|
|
usage(const char* msg, const char* opt) ATTRIBUTE_NORETURN;
|
|
|
|
void
|
|
|
|
usage(const char* msg, char opt) ATTRIBUTE_NORETURN;
|
|
|
|
|
|
|
|
// Apply a command line option.
|
|
|
|
void
|
|
|
|
apply_option(const gold::options::One_option&, const char*);
|
|
|
|
|
|
|
|
// Add a file.
|
|
|
|
void
|
|
|
|
add_file(const char* name, bool is_lib);
|
2006-08-05 07:10:59 +08:00
|
|
|
|
|
|
|
General_options options_;
|
|
|
|
Position_dependent_options position_options_;
|
2006-11-04 02:26:11 +08:00
|
|
|
Input_arguments inputs_;
|
2006-08-05 07:10:59 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // End namespace gold.
|
|
|
|
|
|
|
|
#endif // !defined(GOLD_OPTIONS_H)
|