mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-12-03 04:12:10 +08:00
6fa2a40bf4
info; adjust display of GOT entries. * incremental.cc (Sized_incremental_binary::setup_readers): Allocate vector of input objects; remove file_status_. (Sized_incremental_binary::do_reserve_layout): Remove file_status_. (Sized_incremental_binary::do_process_got_plt): Adjust calls to got_plt reader; call target hooks to reserve GOT entries. (Output_section_incremental_inputs::set_final_data_size): Adjust size of input file info header and GOT info entry. (Output_section_incremental_inputs::write_info_blocks): Write dynamic relocation info. (Got_plt_view_info::got_descriptor): Remove. (Got_plt_view_info::sym_index): New data member. (Got_plt_view_info::input_index): New data member. (Local_got_offset_visitor::visit): Write input file index. (Global_got_offset_visitor::visit): Write 0 for input file index. (Global_symbol_visitor_got_plt::operator()): Replace got_descriptor with sym_index and input_index. (Output_section_incremental_inputs::write_got_plt): Adjust size of incremental info GOT entry; replace got_descriptor with input_index. (Sized_relobj_incr::Sized_relobj_incr): Adjust initializers; record map from input file index to object. (Sized_relobj_incr::do_layout): Replace direct data member reference with accessor function. (Sized_relobj_incr::do_for_all_local_got_entries): Move to base class. * incremental.h (Incremental_input_entry_reader::get_symbol_offset): Adjust size of input file info header. (Incremental_input_entry_reader::get_first_dyn_reloc): New function. (Incremental_input_entry_reader::get_dyn_reloc_count): New function. (Incremental_input_entry_reader::get_input_section): Adjust size of input file info header. (Incremental_got_plt_reader::Incremental_got_plt_reader): Adjust size of incremental info GOT entry. (Incremental_got_plt_reader::get_got_desc): Remove. (Incremental_got_plt_reader::get_got_symndx): New function. (Incremental_got_plt_reader::get_got_input_index): New function. (Sized_incremental_binary::Sized_incremental_binary): Remove file_status_; add input_objects_. (Sized_incremental_binary::~Sized_incremental_binary): Remove. (Sized_incremental_binary::set_file_is_unchanged): Remove. (Sized_incremental_binary::file_is_unchanged): Remove. (Sized_incremental_binary::set_input_object): New function. (Sized_incremental_binary::input_object): New function. (Sized_incremental_binary::file_status_): Remove. (Sized_incremental_binary::input_objects_): New data member. (Sized_relobj_incr): Rename Sized_incr_relobj to this; adjust all references. (Sized_relobj_incr::invalid_address): Move to base class. (Sized_relobj_incr::is_output_section_offset_invalid): Move to base class. (Sized_relobj_incr::do_output_section_offset): Likewise. (Sized_relobj_incr::do_for_all_local_got_entries): Likewise. (Sized_relobj_incr::section_offsets_): Likewise. * object.cc (Sized_relobj::do_for_all_local_got_entries): New function. (Sized_relobj_file::Sized_relobj_file): Remove local_got_offsets_. (Sized_relobj_file::layout_section): Replace refs to section_offsets_ with accessor function. (Sized_relobj_file::do_layout): Likewise. (Sized_relobj_file::do_layout_deferred_sections): Likewise. (Sized_relobj_file::do_for_all_local_got_entries): Move to base class. (Sized_relobj_file::compute_final_local_value): Replace refs to section_offsets_ with accessor function. (Sized_relobj_file::do_finalize_local_symbols): Likewise. * object.h (Relobj::Relobj): Initialize new data members. (Relobj::add_dyn_reloc): New function. (Relobj::first_dyn_reloc): New function. (Relobj::dyn_reloc_count): New function. (Relobj::first_dyn_reloc_): New data member. (Relobj::dyn_reloc_count_): New data member. (Sized_relobj): Rename Sized_relobj_base to this; adjust all references. (Sized_relobj::Address): New typedef. (Sized_relobj::invalid_address): Move here from child class. (Sized_relobj::Sized_relobj): Initialize new data members. (Sized_relobj::sized_relobj): New function. (Sized_relobj::is_output_section_offset_invalid): Move here from child class. (Sized_relobj::get_output_section_offset): Likewise. (Sized_relobj::local_has_got_offset): Likewise. (Sized_relobj::local_got_offset): Likewise. (Sized_relobj::set_local_got_offset): Likewise. (Sized_relobj::do_for_all_local_got_entries): Likewise. (Sized_relobj::clear_got_offsets): New function. (Sized_relobj::section_offsets): Move here from child class. (Sized_relobj::do_output_section_offset): Likewise. (Sized_relobj::do_set_section_offset): Likewise. (Sized_relobj::Local_got_offsets): Likewise. (Sized_relobj::local_got_offsets_): Likewise. (Sized_relobj::section_offsets_): Likewise. (Sized_relobj_file): Rename Sized_relobj to this; adjust all references. (Sized_relobj_file::is_output_section_offset_invalid): Move to base class. (Sized_relobj_file::sized_relobj): New function (Sized_relobj_file::local_has_got_offset): Move to base class. (Sized_relobj_file::local_got_offset): Likewise. (Sized_relobj_file::set_local_got_offset): Likewise. (Sized_relobj_file::get_output_section_offset): Likewise. (Sized_relobj_file::do_for_all_local_got_entries): Likewise. (Sized_relobj_file::do_output_section_offset): Likewise. (Sized_relobj_file::do_set_section_offset): Likewise. (Sized_relobj_file::Local_got_offsets): Likewise. (Sized_relobj_file::local_got_offsets_): Likewise. (Sized_relobj_file::section_offsets_): Likewise. * output.cc (Output_reloc::Output_reloc): Adjust type of relobj (all constructors). (set_needs_dynsym_index): Convert relobj to derived class pointer. (Output_reloc::get_symbol_index): Likewise. (Output_reloc::local_section_offset): Likewise. (Output_reloc::get_address): Likewise. (Output_reloc::symbol_value): Likewise. (Output_data_got::reserve_slot): Move to class definition. (Output_data_got::reserve_local): New function. (Output_data_got::reserve_slot_for_global): Remove. (Output_data_got::reserve_global): New function. * output.h (Output_reloc::Output_reloc): Adjust type of relobj (all constructors, two instantiations). (Output_reloc::get_relobj): New function (two instantiations). (Output_reloc::u1_.relobj, Output_reloc::u2_.relobj): Adjust type. (Output_data_reloc_base::add): Convert relobj to derived class pointer. (Output_data_reloc::add_global): Adjust type of relobj. (Output_data_reloc::add_global_relative): Likewise. (Output_data_reloc::add_symbolless_global_addend): Likewise. (Output_data_reloc::add_local): Likewise. (Output_data_reloc::add_local_relative): Likewise. (Output_data_reloc::add_symbolless_local_addend): Likewise. (Output_data_reloc::add_local_section): Likewise. (Output_data_reloc::add_output_section): Likewise. (Output_data_reloc::add_absolute): Likewise. (Output_data_reloc::add_target_specific): Likewise. (Output_data_got::reserve_slot): Move definition here. (Output_data_got::reserve_local): New function. (Output_data_got::reserve_global): New function. * reloc.cc (Sized_relobj_file::do_read_relocs): Replace refs to section_offsets_ with accessor function. (Sized_relobj_file::write_sections): Likewise. (Sized_relobj_file::do_relocate_sections): Likewise. * target.h (Sized_target::reserve_local_got_entry): New function. (Sized_target::reserve_global_got_entry): New function. * x86_64.cc (Target_x86_64::reserve_local_got_entry): New function. (Target_x86_64::reserve_global_got_entry): New function. (Target_x86_64::init_got_plt_for_update): Create rela_dyn section.
204 lines
5.9 KiB
C++
204 lines
5.9 KiB
C++
// target.cc
|
|
|
|
// Copyright 2009, 2010 Free Software Foundation, Inc.
|
|
// Written by Doug Kwan <dougkwan@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 "elfcpp.h"
|
|
#include "dynobj.h"
|
|
#include "symtab.h"
|
|
#include "output.h"
|
|
#include "target.h"
|
|
|
|
namespace gold
|
|
{
|
|
|
|
// Return whether NAME is a local label name. This is used to implement the
|
|
// --discard-locals options and can be overridden by child classes to
|
|
// implement system-specific behaviour. The logic here is the same as that
|
|
// in _bfd_elf_is_local_label_name().
|
|
|
|
bool
|
|
Target::do_is_local_label_name(const char* name) const
|
|
{
|
|
// Normal local symbols start with ``.L''.
|
|
if (name[0] == '.' && name[1] == 'L')
|
|
return true;
|
|
|
|
// At least some SVR4 compilers (e.g., UnixWare 2.1 cc) generate
|
|
// DWARF debugging symbols starting with ``..''.
|
|
if (name[0] == '.' && name[1] == '.')
|
|
return true;
|
|
|
|
// gcc will sometimes generate symbols beginning with ``_.L_'' when
|
|
// emitting DWARF debugging output. I suspect this is actually a
|
|
// small bug in gcc (it calls ASM_OUTPUT_LABEL when it should call
|
|
// ASM_GENERATE_INTERNAL_LABEL, and this causes the leading
|
|
// underscore to be emitted on some ELF targets). For ease of use,
|
|
// we treat such symbols as local.
|
|
if (name[0] == '_' && name[1] == '.' && name[2] == 'L' && name[3] == '_')
|
|
return true;
|
|
|
|
return false;
|
|
}
|
|
|
|
// Implementations of methods Target::do_make_elf_object are almost identical
|
|
// except for the address sizes and endianities. So we extract this
|
|
// into a template.
|
|
|
|
template<int size, bool big_endian>
|
|
inline Object*
|
|
Target::do_make_elf_object_implementation(
|
|
const std::string& name,
|
|
Input_file* input_file,
|
|
off_t offset,
|
|
const elfcpp::Ehdr<size, big_endian>& ehdr)
|
|
{
|
|
int et = ehdr.get_e_type();
|
|
if (et == elfcpp::ET_REL)
|
|
{
|
|
Sized_relobj_file<size, big_endian>* obj =
|
|
new Sized_relobj_file<size, big_endian>(name, input_file, offset, ehdr);
|
|
obj->setup();
|
|
return obj;
|
|
}
|
|
else if (et == elfcpp::ET_DYN)
|
|
{
|
|
Sized_dynobj<size, big_endian>* obj =
|
|
new Sized_dynobj<size, big_endian>(name, input_file, offset, ehdr);
|
|
obj->setup();
|
|
return obj;
|
|
}
|
|
else
|
|
{
|
|
gold_error(_("%s: unsupported ELF file type %d"),
|
|
name.c_str(), et);
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
// Make an ELF object called NAME by reading INPUT_FILE at OFFSET. EHDR
|
|
// is the ELF header of the object. There are four versions of this
|
|
// for different address sizes and endianities.
|
|
|
|
#ifdef HAVE_TARGET_32_LITTLE
|
|
Object*
|
|
Target::do_make_elf_object(const std::string& name, Input_file* input_file,
|
|
off_t offset, const elfcpp::Ehdr<32, false>& ehdr)
|
|
{
|
|
return this->do_make_elf_object_implementation<32, false>(name, input_file,
|
|
offset, ehdr);
|
|
}
|
|
#endif
|
|
|
|
#ifdef HAVE_TARGET_32_BIG
|
|
Object*
|
|
Target::do_make_elf_object(const std::string& name, Input_file* input_file,
|
|
off_t offset, const elfcpp::Ehdr<32, true>& ehdr)
|
|
{
|
|
return this->do_make_elf_object_implementation<32, true>(name, input_file,
|
|
offset, ehdr);
|
|
}
|
|
#endif
|
|
|
|
#ifdef HAVE_TARGET_64_LITTLE
|
|
Object*
|
|
Target::do_make_elf_object(const std::string& name, Input_file* input_file,
|
|
off_t offset, const elfcpp::Ehdr<64, false>& ehdr)
|
|
{
|
|
return this->do_make_elf_object_implementation<64, false>(name, input_file,
|
|
offset, ehdr);
|
|
}
|
|
#endif
|
|
|
|
#ifdef HAVE_TARGET_64_BIG
|
|
Object*
|
|
Target::do_make_elf_object(const std::string& name, Input_file* input_file,
|
|
off_t offset, const elfcpp::Ehdr<64, true>& ehdr)
|
|
{
|
|
return this->do_make_elf_object_implementation<64, true>(name, input_file,
|
|
offset, ehdr);
|
|
}
|
|
#endif
|
|
|
|
Output_section*
|
|
Target::do_make_output_section(const char* name, elfcpp::Elf_Word type,
|
|
elfcpp::Elf_Xword flags)
|
|
{
|
|
return new Output_section(name, type, flags);
|
|
}
|
|
|
|
// Default for whether a reloc is a call to a non-split function is
|
|
// whether the symbol is a function.
|
|
|
|
bool
|
|
Target::do_is_call_to_non_split(const Symbol* sym, unsigned int) const
|
|
{
|
|
return sym->type() == elfcpp::STT_FUNC;
|
|
}
|
|
|
|
// Default conversion for -fsplit-stack is to give an error.
|
|
|
|
void
|
|
Target::do_calls_non_split(Relobj* object, unsigned int, section_offset_type,
|
|
section_size_type, unsigned char*, section_size_type,
|
|
std::string*, std::string*) const
|
|
{
|
|
static bool warned;
|
|
if (!warned)
|
|
{
|
|
gold_error(_("linker does not include stack split support "
|
|
"required by %s"),
|
|
object->name().c_str());
|
|
warned = true;
|
|
}
|
|
}
|
|
|
|
// Return whether BYTES/LEN matches VIEW/VIEW_SIZE at OFFSET.
|
|
|
|
bool
|
|
Target::match_view(const unsigned char* view, section_size_type view_size,
|
|
section_offset_type offset, const char* bytes,
|
|
size_t len) const
|
|
{
|
|
if (offset + len > view_size)
|
|
return false;
|
|
return memcmp(view + offset, bytes, len) == 0;
|
|
}
|
|
|
|
// Set the contents of a VIEW/VIEW_SIZE to nops starting at OFFSET
|
|
// for LEN bytes.
|
|
|
|
void
|
|
Target::set_view_to_nop(unsigned char* view, section_size_type view_size,
|
|
section_offset_type offset, size_t len) const
|
|
{
|
|
gold_assert(offset >= 0 && offset + len <= view_size);
|
|
if (!this->has_code_fill())
|
|
memset(view + offset, 0, len);
|
|
else
|
|
{
|
|
std::string fill = this->code_fill(len);
|
|
memcpy(view + offset, fill.data(), len);
|
|
}
|
|
}
|
|
|
|
} // End namespace gold.
|