mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-12-09 04:21:49 +08:00
2e702c99c5
* configure: Regenerate. gold/ * nacl.cc: New file. * nacl.h: New file. * Makefile.am (CCFILES, HFILES): Add them. * Makefile.in: Regenerate. * i386.cc (Output_data_plt_i386_nacl): New class. (Output_data_plt_i386_nacl_exec): New class. (Output_data_plt_i386_nacl_dyn): New class. (Target_i386_nacl): New class. (Target_selector_i386_nacl): New class. (target_selector_i386): Use it instead of Target_selector_i386. * x86_64.cc (Output_data_plt_x86_64_nacl): New class. (Target_x86_64_nacl): New class. (Target_selector_x86_64_nacl): New class. (target_selector_x86_64, target_selector_x32): Use it instead of Target_selector_x86_64. * arm.cc (Output_data_plt_arm_nacl): New class. (Target_arm_nacl): New class. (Target_selector_arm_nacl): New class. (target_selector_arm, target_selector_armbe): Use it instead of Target_selector_arm. * target-select.cc (select_target): Take new Input_file* and off_t arguments, pass them on to recognize method of selector. * object.cc (make_elf_sized_object): Update caller. * parameters.cc (parameters_force_valid_target): Likewise. * incremental.cc (make_sized_incremental_binary): Likewise. * target-select.h: Update decl. (Target_selector::recognize): Take new Input_file* argument, pass it on to do_recognize. (Target_selector::do_recognize): Take new Input_file* argument. * freebsd.h (Target_selector_freebsd::do_recognize): Likewise. * powerpc.cc (Target_selector_powerpc::do_recognize): Likewise. * sparc.cc (Target_selector_sparc::do_recognize): Likewise. * testsuite/testfile.cc (Target_selector::do_recognize): Likewise. * target.h (Target::Target_info): New members isolate_execinstr and rosegment_gap. (Target::isolate_execinstr, Target::rosegment_gap): New methods. * arm.cc (Target_arm::arm_info): Update initializer. * i386.cc (Target_i386::i386_info): Likewise. * powerpc.cc (Target_powerpc::powerpc_info): Likewise. * sparc.cc (Target_sparc::sparc_info): Likewise. * x86_64.cc (Target_x86_64::x86_64_info): Likewise. * testsuite/testfile.cc (Target_test::test_target_info): Likewise. * layout.cc (Layout::attach_allocated_section_to_segment): Take new const Target* argument. If target->isolate_execinstr(), act like --rosegment. (Layout::find_first_load_seg): Take new const Target* argument; if target->isolate_execinstr(), reject PF_X segments. (Layout::relaxation_loop_body): Update caller. (Layout::set_segment_offsets): If target->isolate_execinstr(), reset file offset to zero when we hit LOAD_SEG, and then do a second loop over the segments before LOAD_SEG to reassign offsets after addresses have been determined. Handle target->rosegment_gap(). (Layout::attach_section_to_segment): Take new const Target* argument; pass it to attach_allocated_section_to_segment. (Layout::make_output_section): Update caller. (Layout::attach_sections_to_segments): Take new const Target* argument; pass it to attach_section_to_segment. * gold.cc (queue_middle_tasks): Update caller. * layout.h (Layout): Update method decls with new arguments. * arm.cc (Target_arm::Target_arm): Take optional argument for the Target_info pointer to use. (Target_arm::do_make_data_plt): New virtual method. (Target_arm::make_data_plt): New method that calls it. (Target_arm::make_plt_entry): Use it. (Output_data_plt_arm::Output_data_plt_arm): Take additional argument for the section alignment. (Output_data_plt_arm::do_first_plt_entry_offset): New abstract virtual method. (Output_data_plt_arm::first_plt_entry_offset): Call it. (Output_data_plt_arm::do_get_plt_entry_size): New abstract virtual method. (Output_data_plt_arm::get_plt_entry_size): Call it. (Output_data_plt_arm::do_fill_plt_entry): New abstract virtual method. (Output_data_plt_arm::fill_plt_entry): New method that calls it. (Output_data_plt_arm::do_fill_first_plt_entry): New abstract virtual method. (Output_data_plt_arm::fill_first_plt_entry): New method that calls it. (Output_data_plt_arm::set_final_data_size): Use get_plt_entry_size method instead of sizeof(plt_entry). (Output_data_plt_arm::add_entry): Likewise. Use first_plt_entry_offset method instead of sizeof(first_plt_entry). (Target_arm::first_plt_entry_offset): Call method on this->plt_ rather than static method. (Target_arm::plt_entry_size): Likewise. (Output_data_plt_arm::first_plt_entry, Output_data_plt_arm::plt_entry): Move to ... (Output_data_plt_arm_standard): ... here, new class. (Output_data_plt_arm::do_write): Move guts of PLT filling to... (Output_data_plt_arm_standard::do_fill_first_plt_entry): ... here ... (Output_data_plt_arm_standard::do_fill_plt_entry): ... and here. * x86_64.cc (Output_data_plt_x86_64::Output_data_plt_x86_64): Take additional argument for the PLT entry size. (Output_data_plt_x86_64::get_tlsdesc_plt_offset): Use get_plt_entry_size method rather than plt_entry_size variable. (Output_data_plt_x86_64::reserve_slot): Likewise. (Output_data_plt_x86_64::do_adjust_output_section): Likewise. (Output_data_plt_x86_64::add_entry): Likewise. (Output_data_plt_x86_64::add_local_ifunc_entry): Likewise. (Output_data_plt_x86_64::address_for_global): Likewise. (Output_data_plt_x86_64::address_for_local): Likewise. (Output_data_plt_x86_64::set_final_data_size): Likewise. (Output_data_plt_x86_64::first_plt_entry_offset): Likewise. Make method non-static. (Output_data_plt_x86_64::do_get_plt_entry_size): New abstract virtual method. (Output_data_plt_x86_64::get_plt_entry_size): Just call that. (Output_data_plt_x86_64::do_add_eh_frame): New abstract virtual method. (Output_data_plt_x86_64::add_eh_frame): New method to call it. (Output_data_plt_x86_64::do_fill_first_plt_entry): New abstract virtual method. (Output_data_plt_x86_64::fill_first_plt_entry): New method to call it. (Output_data_plt_x86_64::do_fill_plt_entry): New abstract virtual method. (Output_data_plt_x86_64::fill_plt_entry): New method to call it. (Output_data_plt_x86_64::do_fill_tlsdesc_entry): New abstract virtual method. (Output_data_plt_x86_64::fill_tlsdesc_entry): New method to call it. (Output_data_plt_x86_64::plt_entry_size) (Output_data_plt_x86_64::first_plt_entry) (Output_data_plt_x86_64::plt_entry) (Output_data_plt_x86_64::tlsdesc_plt_entry) (Output_data_plt_x86_64::plt_eh_frame_fde_size) (Output_data_plt_x86_64::plt_eh_frame_fde): Move to ... (Output_data_plt_x86_64_standard): ... here, new class. (Target_x86_64::Target_x86_64): Take optional argument for the Target_info pointer to use. (Target_x86_64::do_make_data_plt): New virtual method. (Target_x86_64::make_data_plt): New method to call it. (Target_x86_64::init_got_plt_for_update): Use that. Call this->plt_->add_eh_frame method here. (Output_data_plt_x86_64::init): Don't do add_eh_frame_for_plt here. (Target_x86_64::first_plt_entry_offset): Call method on this->plt_ rather than static method. (Target_x86_64::plt_entry_size): Likewise. (Output_data_plt_x86_64::do_write): Use get_plt_entry_size method rather than plt_entry_size variable. Move guts of PLT filling to... (Output_data_plt_x86_64_standard::do_fill_first_plt_entry): ... here ... (Output_data_plt_x86_64_standard::do_fill_plt_entry): ... and here ... (Output_data_plt_x86_64_standard::do_fill_tlsdesc_entry): ... and here. * i386.cc (Output_data_plt_i386::Output_data_plt_i386): Take additional argument for the section alignment. Don't do add_eh_frame_for_plt here. (Output_data_plt_i386::first_plt_entry_offset): Make the method non-static. Use get_plt_entry_size method rather than plt_entry_size variable. (Output_data_plt_i386::do_get_plt_entry_size): New abstract virtual method. (Output_data_plt_i386::get_plt_entry_size): Call it. (Output_data_plt_i386::do_add_eh_frame): New abstract virtual method. (Output_data_plt_i386::add_eh_frame): New method to call it. (Output_data_plt_i386::do_fill_first_plt_entry): New abstract virtual method. (Output_data_plt_i386::fill_first_plt_entry): New method to call it. (Output_data_plt_i386::do_fill_plt_entry): New abstract virtual method. (Output_data_plt_i386::fill_plt_entry): New method to call it. (Output_data_plt_i386::set_final_data_size): Use get_plt_entry_size method instead of plt_entry_size. (Output_data_plt_i386::plt_entry_size) (Output_data_plt_i386::plt_eh_frame_fde_size) (Output_data_plt_i386::plt_eh_frame_fde): Move to ... (Output_data_plt_i386_standard): ... here, new class. (Output_data_plt_i386_exec): New class. (Output_data_plt_i386::exec_first_plt_entry): Move to ... (Output_data_plt_i386_exec::first_plt_entry): ... here. (Output_data_plt_i386::exec_plt_entry): Move to ... (Output_data_plt_i386_exec::plt_entry): ... here. (Output_data_plt_i386_dyn): New class. (Output_data_plt_i386::first_plt_entry): Move to ... (Output_data_plt_i386_dyn::first_plt_entry): ... here. (Output_data_plt_i386::dyn_plt_entry): Move to ... (Output_data_plt_i386_dyn::plt_entry): ... here. (Target_i386::Target_i386): Take optional argument for the Target_info pointer to use. (Target_i386::do_make_data_plt): New virtual method. (Target_i386::make_data_plt): New method to call it. (Target_i386::make_plt_section): Use that. Call this->plt_->add_eh_frame method here. (Output_data_plt_i386::add_entry): Use get_plt_entry_size method rather than plt_entry_size variable. (Output_data_plt_i386::add_local_ifunc_entry): Likewise. (Output_data_plt_i386::address_for_local): Likewise. (Output_data_plt_i386::do_write): Likewise. Move guts of PLT filling to... (Output_data_plt_i386_exec::do_fill_first_plt_entry): ... here ... (Output_data_plt_i386_exec::do_fill_plt_entry): ... and here ... (Output_data_plt_i386_dyn::do_fill_first_plt_entry): ... and here ... (Output_data_plt_i386_dyn::do_fill_plt_entry): ... and here. Change-Id: Id24b95600489835ff5e860a39c147203d4380c2b
381 lines
9.4 KiB
C++
381 lines
9.4 KiB
C++
// parameters.cc -- general parameters for a link using gold
|
|
|
|
// Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012
|
|
// Free Software Foundation, Inc.
|
|
// Written by Ian Lance Taylor <iant@google.com>.
|
|
|
|
// This file is part of gold.
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation; either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with this program; if not, write to the Free Software
|
|
// Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
|
|
// MA 02110-1301, USA.
|
|
|
|
#include "gold.h"
|
|
|
|
#include "debug.h"
|
|
#include "options.h"
|
|
#include "target.h"
|
|
#include "target-select.h"
|
|
|
|
namespace gold
|
|
{
|
|
|
|
// Our local version of the variable, which is not const.
|
|
|
|
static Parameters static_parameters;
|
|
|
|
// The global variable.
|
|
|
|
const Parameters* parameters = &static_parameters;
|
|
|
|
// A helper class to set the target once.
|
|
|
|
class Set_parameters_target_once : public Once
|
|
{
|
|
public:
|
|
Set_parameters_target_once(Parameters* parameters)
|
|
: parameters_(parameters)
|
|
{ }
|
|
|
|
protected:
|
|
void
|
|
do_run_once(void* arg)
|
|
{ this->parameters_->set_target_once(static_cast<Target*>(arg)); }
|
|
|
|
private:
|
|
Parameters* parameters_;
|
|
};
|
|
|
|
// We only need one Set_parameters_target_once.
|
|
|
|
static
|
|
Set_parameters_target_once set_parameters_target_once(&static_parameters);
|
|
|
|
// Class Parameters.
|
|
|
|
Parameters::Parameters()
|
|
: errors_(NULL), timer_(NULL), options_(NULL), target_(NULL),
|
|
doing_static_link_valid_(false), doing_static_link_(false),
|
|
debug_(0), incremental_mode_(General_options::INCREMENTAL_OFF),
|
|
set_parameters_target_once_(&set_parameters_target_once)
|
|
{
|
|
}
|
|
|
|
void
|
|
Parameters::set_errors(Errors* errors)
|
|
{
|
|
gold_assert(this->errors_ == NULL);
|
|
this->errors_ = errors;
|
|
}
|
|
|
|
void
|
|
Parameters::set_timer(Timer* timer)
|
|
{
|
|
gold_assert(this->timer_ == NULL);
|
|
this->timer_ = timer;
|
|
}
|
|
|
|
void
|
|
Parameters::set_options(const General_options* options)
|
|
{
|
|
gold_assert(!this->options_valid());
|
|
this->options_ = options;
|
|
// For speed, we convert the options() debug var from a string to an
|
|
// enum (from debug.h).
|
|
this->debug_ = debug_string_to_enum(this->options().debug());
|
|
// Set incremental_mode_ based on the value of the --incremental option.
|
|
// We copy the mode into parameters because it can change based on inputs.
|
|
this->incremental_mode_ = this->options().incremental_mode();
|
|
// If --verbose is set, it acts as "--debug=files".
|
|
if (options->verbose())
|
|
this->debug_ |= DEBUG_FILES;
|
|
if (this->target_valid())
|
|
this->check_target_endianness();
|
|
}
|
|
|
|
void
|
|
Parameters::set_doing_static_link(bool doing_static_link)
|
|
{
|
|
gold_assert(!this->doing_static_link_valid_);
|
|
this->doing_static_link_ = doing_static_link;
|
|
this->doing_static_link_valid_ = true;
|
|
}
|
|
|
|
void
|
|
Parameters::set_target(Target* target)
|
|
{
|
|
this->set_parameters_target_once_->run_once(static_cast<void*>(target));
|
|
gold_assert(target == this->target_);
|
|
}
|
|
|
|
// This is called at most once.
|
|
|
|
void
|
|
Parameters::set_target_once(Target* target)
|
|
{
|
|
gold_assert(this->target_ == NULL);
|
|
this->target_ = target;
|
|
if (this->options_valid())
|
|
this->check_target_endianness();
|
|
}
|
|
|
|
// Clear the target, for testing.
|
|
|
|
void
|
|
Parameters::clear_target()
|
|
{
|
|
this->target_ = NULL;
|
|
// We need a new Set_parameters_target_once so that we can set the
|
|
// target again.
|
|
this->set_parameters_target_once_ = new Set_parameters_target_once(this);
|
|
}
|
|
|
|
// Return whether TARGET is compatible with the target we are using.
|
|
|
|
bool
|
|
Parameters::is_compatible_target(const Target* target) const
|
|
{
|
|
if (this->target_ == NULL)
|
|
return true;
|
|
return target == this->target_;
|
|
}
|
|
|
|
Parameters::Target_size_endianness
|
|
Parameters::size_and_endianness() const
|
|
{
|
|
if (this->target().get_size() == 32)
|
|
{
|
|
if (!this->target().is_big_endian())
|
|
{
|
|
#ifdef HAVE_TARGET_32_LITTLE
|
|
return TARGET_32_LITTLE;
|
|
#else
|
|
gold_unreachable();
|
|
#endif
|
|
}
|
|
else
|
|
{
|
|
#ifdef HAVE_TARGET_32_BIG
|
|
return TARGET_32_BIG;
|
|
#else
|
|
gold_unreachable();
|
|
#endif
|
|
}
|
|
}
|
|
else if (parameters->target().get_size() == 64)
|
|
{
|
|
if (!parameters->target().is_big_endian())
|
|
{
|
|
#ifdef HAVE_TARGET_64_LITTLE
|
|
return TARGET_64_LITTLE;
|
|
#else
|
|
gold_unreachable();
|
|
#endif
|
|
}
|
|
else
|
|
{
|
|
#ifdef HAVE_TARGET_64_BIG
|
|
return TARGET_64_BIG;
|
|
#else
|
|
gold_unreachable();
|
|
#endif
|
|
}
|
|
}
|
|
else
|
|
gold_unreachable();
|
|
}
|
|
|
|
// If output endianness is specified in command line, check that it does
|
|
// not conflict with the target.
|
|
|
|
void
|
|
Parameters::check_target_endianness()
|
|
{
|
|
General_options::Endianness endianness = this->options().endianness();
|
|
if (endianness != General_options::ENDIANNESS_NOT_SET)
|
|
{
|
|
bool big_endian;
|
|
if (endianness == General_options::ENDIANNESS_BIG)
|
|
big_endian = true;
|
|
else
|
|
{
|
|
gold_assert(endianness == General_options::ENDIANNESS_LITTLE);
|
|
big_endian = false;;
|
|
}
|
|
|
|
if (this->target().is_big_endian() != big_endian)
|
|
gold_error(_("input file does not match -EB/EL option"));
|
|
}
|
|
}
|
|
|
|
// Return the name of the entry symbol.
|
|
|
|
const char*
|
|
Parameters::entry() const
|
|
{
|
|
const char* ret = this->options().entry();
|
|
if (ret == NULL)
|
|
{
|
|
// FIXME: Need to support target specific entry symbol.
|
|
ret = "_start";
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
// Set the incremental linking mode to INCREMENTAL_FULL. Used when
|
|
// the linker determines that an incremental update is not possible.
|
|
// Returns false if the incremental mode was INCREMENTAL_UPDATE,
|
|
// indicating that the linker should exit if an update is not possible.
|
|
|
|
bool
|
|
Parameters::set_incremental_full()
|
|
{
|
|
gold_assert(this->incremental_mode_ != General_options::INCREMENTAL_OFF);
|
|
if (this->incremental_mode_ == General_options::INCREMENTAL_UPDATE)
|
|
return false;
|
|
this->incremental_mode_ = General_options::INCREMENTAL_FULL;
|
|
return true;
|
|
}
|
|
|
|
// Return true if we need to prepare incremental linking information.
|
|
|
|
bool
|
|
Parameters::incremental() const
|
|
{
|
|
return this->incremental_mode_ != General_options::INCREMENTAL_OFF;
|
|
}
|
|
|
|
// Return true if we are doing a full incremental link.
|
|
|
|
bool
|
|
Parameters::incremental_full() const
|
|
{
|
|
return this->incremental_mode_ == General_options::INCREMENTAL_FULL;
|
|
}
|
|
|
|
// Return true if we are doing an incremental update.
|
|
|
|
bool
|
|
Parameters::incremental_update() const
|
|
{
|
|
return (this->incremental_mode_ == General_options::INCREMENTAL_UPDATE
|
|
|| this->incremental_mode_ == General_options::INCREMENTAL_AUTO);
|
|
}
|
|
|
|
void
|
|
set_parameters_errors(Errors* errors)
|
|
{ static_parameters.set_errors(errors); }
|
|
|
|
void
|
|
set_parameters_timer(Timer* timer)
|
|
{ static_parameters.set_timer(timer); }
|
|
|
|
void
|
|
set_parameters_options(const General_options* options)
|
|
{ static_parameters.set_options(options); }
|
|
|
|
void
|
|
set_parameters_target(Target* target)
|
|
{
|
|
static_parameters.set_target(target);
|
|
target->select_as_default_target();
|
|
}
|
|
|
|
void
|
|
set_parameters_doing_static_link(bool doing_static_link)
|
|
{ static_parameters.set_doing_static_link(doing_static_link); }
|
|
|
|
// Set the incremental linking mode to INCREMENTAL_FULL. Used when
|
|
// the linker determines that an incremental update is not possible.
|
|
// Returns false if the incremental mode was INCREMENTAL_UPDATE,
|
|
// indicating that the linker should exit if an update is not possible.
|
|
bool
|
|
set_parameters_incremental_full()
|
|
{ return static_parameters.set_incremental_full(); }
|
|
|
|
// Force the target to be valid by using the default. Use the
|
|
// --oformat option is set; this supports the x86_64 kernel build,
|
|
// which converts a binary file to an object file using -r --format
|
|
// binary --oformat elf32-i386 foo.o. Otherwise use the configured
|
|
// default.
|
|
|
|
void
|
|
parameters_force_valid_target()
|
|
{
|
|
if (parameters->target_valid())
|
|
return;
|
|
|
|
gold_assert(parameters->options_valid());
|
|
if (parameters->options().user_set_oformat())
|
|
{
|
|
const char* bfd_name = parameters->options().oformat();
|
|
Target* target = select_target_by_bfd_name(bfd_name);
|
|
if (target != NULL)
|
|
{
|
|
set_parameters_target(target);
|
|
return;
|
|
}
|
|
|
|
gold_error(_("unrecognized output format %s"), bfd_name);
|
|
}
|
|
|
|
if (parameters->options().user_set_m())
|
|
{
|
|
const char* emulation = parameters->options().m();
|
|
Target* target = select_target_by_emulation(emulation);
|
|
if (target != NULL)
|
|
{
|
|
set_parameters_target(target);
|
|
return;
|
|
}
|
|
|
|
gold_error(_("unrecognized emulation %s"), emulation);
|
|
}
|
|
|
|
// The GOLD_DEFAULT_xx macros are defined by the configure script.
|
|
bool is_big_endian;
|
|
General_options::Endianness endianness = parameters->options().endianness();
|
|
if (endianness == General_options::ENDIANNESS_BIG)
|
|
is_big_endian = true;
|
|
else if (endianness == General_options::ENDIANNESS_LITTLE)
|
|
is_big_endian = false;
|
|
else
|
|
is_big_endian = GOLD_DEFAULT_BIG_ENDIAN;
|
|
|
|
Target* target = select_target(NULL, 0,
|
|
elfcpp::GOLD_DEFAULT_MACHINE,
|
|
GOLD_DEFAULT_SIZE,
|
|
is_big_endian,
|
|
elfcpp::GOLD_DEFAULT_OSABI,
|
|
0);
|
|
|
|
if (target == NULL)
|
|
{
|
|
gold_assert(is_big_endian != GOLD_DEFAULT_BIG_ENDIAN);
|
|
gold_fatal(_("no supported target for -EB/-EL option"));
|
|
}
|
|
|
|
set_parameters_target(target);
|
|
}
|
|
|
|
// Clear the current target, for testing.
|
|
|
|
void
|
|
parameters_clear_target()
|
|
{
|
|
static_parameters.clear_target();
|
|
}
|
|
|
|
} // End namespace gold.
|