old-cross-binutils/gold/target.cc
Doug Kwan c0a6286595 2009-10-09 Doug Kwan <dougkwan@google.com>
* layout.cc (Layout::make_output_section): Call target hook to make
	ordinary output section.
	(Layout::finalize): Adjust parameter list of call the
	Target::may_relax().
	* layout.h (class Layout::section_list): New method.
	* merge.h (Output_merge_base::entsize): Change visibility to public.
	(Output_merge_base::is_string, Output_merge_base::do_is_string):
	New methods.
	(Output_merge_string::do_is_string): New method.
	* object.cc (Sized_relobj::do_setup): renamed from
	Sized_relobj::set_up.
	* object.h (Sized_relobj::adjust_shndx,
	Sized_relobj::initializ_input_to_output_maps,
	Sized_relobj::free_input_to_output_maps): Change visibilities to
	protected.
	(Sized_relobj::setup): Virtualize.
	(Sized_relobj::do_setup): New method declaration.
	(Sized_relobj::invalidate_section_offset,
	Sized_relobj::do_invalidate_section_offset): New method decfinitions.
	(Sized_relobj::elf_file, Sized_relobj::local_values): New methods.
	* options.cc (parse_int): New function.
	* options.h (parse_int): New declaration.
	(DEFINE_int): New macro.
	(stub_group_size): New option.
	* output.cc (Output_section::Output_section): Initialize memebers
	merge_section_map_, merge_section_by_properties_map_,
	relaxed_input_section_map_, is_relaxed_input_section_map_valid_.
	(Output_section::add_input_section): Handled deferred code-fill
	generation and remove an old comment.
	(Output_section::add_relaxed_input_section): New method definition.
	(Output_section::add_merge_input_section): Use merge section by
	properties map to speed to search.  Update merge section maps
	as appropriate.
	(Output_section::build_relaxation_map): New method definition.
	(Output_section::convert_input_sections_in_list_to_relaxed_sections):
	Same.
	(Output_section::relax_input_section): Renamed to
	Output_section::convert_input_sections_to_relaxed_sections and change
	interface to take a vector of pointers to relaxed sections.
	(Output_section::find_merge_section,
	Output_section::find_relaxed_input_section): New method definitions.
	(Output_section::is_input_address_mapped,
	Output_section::output_offset, Output_section::output_address):
	Use output section data maps to speed up searching.
	(Output_section::find_starting_output_address): Add comments.
	(Output_section::do_write,
	Output_section::write_to_postprocessing_buffer): Do code-fill
	generation as appropriate.
	(Output_section::get_input_sections): Invalidate relaxed input section
	map.
	(Output_section::restore_states): Adjust type of checkpoint .
	Invalidate relaxed input section map.
	* output.h (Output_merge_base): New class declaration.
	(Input_section_specifier): New class defintion.
	(class Output_relaxed_input_section) Change base class to
	Output_section_data_build.
	(Output_relaxed_input_section::Output_relaxed_input_section): Adjust
	base class initializer.
	(Output_section::add_relaxed_input_section): New method declaration.
	(Output_section::Input_section): Change visibility to protected.
     	(Output_section::Input_section::relobj,
	Output_section::Input_section::shndx): Handle relaxed input sections.
	Output_section::input_sections) Change visibility to protected.  Also
	define overload to return a non-const pointer.
	(Output_section::Merge_section_properties): New class defintion.
	(Output_section::Merge_section_by_properties_map,
	Output_section::Output_section_data_by_input_section_map,
	Output_section::Relaxation_map): New types.
	(Output_section::relax_input_section): Rename method to
	Output_section::convert_input_sections_to_relaxed_sections and change
	interface to take a vector of relaxed section pointers.
	(Output_section::find_merge_section,
	Output_section::find_relaxed_input_section,
	Output_section::build_relaxation_map,
	Output_section::convert_input_sections_in_list_to_relaxed_sections):
	New method declarations.
	(Output_section::merge_section_map_
	Output_section::merge_section_by_properties_map_,
	Output_section::relaxed_input_section_map_,
	Output_section::is_relaxed_input_section_map_valid_,
	Output_section::generate_code_fills_at_write_): New data members.
	* script-sections.cc
	(Output_section_element_input::set_section_addresses): Call
	current_data_size and addralign methods of relaxed input sections.
	(Orphan_output_section::set_section_addresses): Call current_data_size
	and addralign methods of relaxed input sections.
	* symtab.cc (Symbol_table::compute_final_value): Extract template
	from the body of Symbol_table::sized_finalize_symbol.
	(Symbol_table::sized_finalized_symbol): Call
	Symbol_table::compute_final_value.
	* symtab.h (Symbol_table::Compute_final_value_status): New enum type.
	(Symbol_table::compute_final_value): New templated method declaration.
	* target.cc (Target::do_make_output_section): New method defintion.
	* target.h (Target::make_output_section): New method declaration.
	(Target::relax): Add more parameters for input objects, symbol table
	and layout.  Adjust call to do_relax.
	(Target::do_make_output_section): New method declaration.
	(Target::do_relax): Add parameters for input objects, symbol table
	and layout.
2009-10-09 23:18:19 +00:00

193 lines
5.6 KiB
C++

// target.cc
// Copyright 2009 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 "target.h"
#include "dynobj.h"
#include "output.h"
#include "elfcpp.h"
namespace gold
{
// Return whether NAME is a local label name. This is used to implement the
// --discard-locals options and can be overriden by children 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<size, big_endian>* obj =
new Sized_relobj<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 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.