#include <string>
#include <vector>
+#include "elfcpp.h"
#include "script.h"
namespace gold
class Command_line;
class Input_file_group;
class Position_dependent_options;
+class Target;
namespace options
{
// This is the usual constructor.
Search_directory(const char* name, bool put_in_sysroot)
: name_(name), put_in_sysroot_(put_in_sysroot), is_in_sysroot_(false)
- { gold_assert(!this->name_.empty()); }
+ {
+ if (this->name_.empty())
+ this->name_ = ".";
+ }
// This is called if we have a sysroot. The sysroot is prefixed to
// any entries for which put_in_sysroot_ is true. is_in_sysroot_ is
class General_options
{
public:
+ enum Object_format
+ {
+ // Ordinary ELF.
+ OBJECT_FORMAT_ELF,
+ // Straight binary format.
+ OBJECT_FORMAT_BINARY
+ };
+
General_options(Script_options*);
// -e: set entry address.
output_file_name() const
{ return this->output_file_name_; }
+ // --oformat: Output format.
+ Object_format
+ output_format() const
+ { return this->output_format_; }
+
+ // Return the default target.
+ Target*
+ default_target() const;
+
// -r: Whether we are doing a relocatable link.
bool
is_relocatable() const
version_script() const
{ return *this->script_options_->version_script_info(); }
+ // -Tbss: The address of the BSS segment
+ uint64_t
+ bss_segment_address() const
+ { return this->bss_segment_address_; }
+
+ // Whether -Tbss was used.
+ bool
+ user_set_bss_segment_address() const
+ { return this->bss_segment_address_ != -1U; }
+
+ // -Tdata: The address of the data segment
+ uint64_t
+ data_segment_address() const
+ { return this->data_segment_address_; }
+
+ // Whether -Tdata was used.
+ bool
+ user_set_data_segment_address() const
+ { return this->data_segment_address_ != -1U; }
+
// -Ttext: The address of the .text section
uint64_t
text_segment_address() const
set_output_file_name(const char* arg)
{ this->output_file_name_ = arg; }
+ void
+ set_output_format(const char*);
+
void
set_relocatable()
{ this->is_relocatable_ = true; }
{ this->sysroot_ = arg; }
void
- set_text_segment_address(const char* arg)
+ set_segment_address(const char* name, const char* arg, uint64_t* val)
{
char* endptr;
- this->text_segment_address_ = strtoull(arg, &endptr, 0);
- if (*endptr != '\0'
- || this->text_segment_address_ == -1U)
- gold_fatal(_("invalid argument to -Ttext: %s"), arg);
+ *val = strtoull(arg, &endptr, 0);
+ if (*endptr != '\0' || *val == -1U)
+ gold_fatal(_("invalid argument to %s: %s"), name, arg);
}
+ void
+ set_bss_segment_address(const char* arg)
+ { this->set_segment_address("-Tbss", arg, &this->bss_segment_address_); }
+
+ void
+ set_data_segment_address(const char* arg)
+ { this->set_segment_address("-Tdata", arg, &this->data_segment_address_); }
+
+ void
+ set_text_segment_address(const char* arg)
+ { this->set_segment_address("-Ttext", arg, &this->text_segment_address_); }
+
int
parse_thread_count(const char* arg)
{
Dir_list search_path_;
int optimization_level_;
const char* output_file_name_;
+ Object_format output_format_;
+ const char* output_format_string_;
bool is_relocatable_;
Strip strip_;
bool allow_shlib_undefined_;
bool is_static_;
bool print_stats_;
std::string sysroot_;
+ uint64_t bss_segment_address_;
+ uint64_t data_segment_address_;
uint64_t text_segment_address_;
bool threads_;
int thread_count_initial_;
class Position_dependent_options
{
public:
+ typedef General_options::Object_format Object_format;
+
Position_dependent_options();
// -Bdynamic/-Bstatic: Whether we are searching for a static archive
include_whole_archive() const
{ return this->include_whole_archive_; }
+ // --format: The format of the input file.
+ Object_format
+ input_format() const
+ { return this->input_format_; }
+
void
set_static_search()
{ this->do_static_search_ = true; }
clear_whole_archive()
{ this->include_whole_archive_ = false; }
+ void
+ set_input_format(const char*);
+
private:
bool do_static_search_;
bool as_needed_;
bool include_whole_archive_;
+ Object_format input_format_;
};
// A single file or library argument from the command line.
// extra_search_path: an extra directory to look for the file, prior
// to checking the normal library search path. If this is "",
// then no extra directory is added.
+ // just_symbols: whether this file only defines symbols.
// options: The position dependent options at this point in the
// command line, such as --whole-archive.
Input_file_argument()
- : name_(), is_lib_(false), extra_search_path_(""), options_()
+ : name_(), is_lib_(false), extra_search_path_(""), just_symbols_(false),
+ options_()
{ }
Input_file_argument(const char* name, bool is_lib,
const char* extra_search_path,
+ bool just_symbols,
const Position_dependent_options& options)
: name_(name), is_lib_(is_lib), extra_search_path_(extra_search_path),
- options_(options)
+ just_symbols_(just_symbols), options_(options)
{ }
const char*
: this->extra_search_path_.c_str());
}
+ // Return whether we should only read symbols from this file.
+ bool
+ just_symbols() const
+ { return this->just_symbols_; }
+
// Return whether this file may require a search using the -L
// options.
bool
std::string name_;
bool is_lib_;
std::string extra_search_path_;
+ bool just_symbols_;
Position_dependent_options options_;
};
int
process_l_option(int, char**, char*, bool);
+ // Handle a -R option when it means --rpath.
+ void
+ add_to_rpath(const char* arg)
+ { this->options_.add_to_rpath(arg); }
+
+ // Add a file for which we just read the symbols.
+ void
+ add_just_symbols_file(const char* arg)
+ {
+ this->inputs_.add_file(Input_file_argument(arg, false, "", true,
+ this->position_options_));
+ }
+
// Handle a --start-group option.
void
start_group(const char* arg);