diff options
author | Doug Kwan <dougkwan@google.com> | 2009-08-18 23:49:29 +0000 |
---|---|---|
committer | Doug Kwan <dougkwan@google.com> | 2009-08-18 23:49:29 +0000 |
commit | f733487b048b9822fb648be60633061d610b40f3 (patch) | |
tree | 4df42b83ffd58eecbf028b2b8ed33ebb487843b5 /gold/target.cc | |
parent | 688805f3b82d345b056810e08842224bfea3a879 (diff) | |
download | gdb-f733487b048b9822fb648be60633061d610b40f3.zip gdb-f733487b048b9822fb648be60633061d610b40f3.tar.gz gdb-f733487b048b9822fb648be60633061d610b40f3.tar.bz2 |
2009-08-18 Doug Kwan <dougkwan@google.com>
* dynobj.cc (Sized_dynobj::setup): Take a Target object instead of
an elcpp::Ehdr as parameter. Adjust call to set_target.
* dynobj.h (Sized_dynobj::setup): Take a Target object instead of
an elfcpp::Ehdr as parameter.
* object.cc (Object::set_target): Remove the version that looks up
a target and sets it.
(Sized_relobj::setup): Take a Target object instead of
an elfcpp::Ehdr as parameter. Adjust call to set_target.
(make_elf_sized_object): Find target and ask target to
make an ELF object.
* object.h: (Object::set_target): Remove the version that looks up
a target and sets it.
(Sized_relobj::setup): Take a Target object instead of
an elfcpp:Ehdr as parameter.
* target.cc: Include dynobj.h.
(Target::do_make_elf_object_implementation): New.
(Target::do_make_elf_object): New.
* target.h (Target::make_elf_object): New template declaration.
(Target::do_make_elf_object): New method declarations.
(Target::do_make_elf_object_implementation): New template declaration.
Diffstat (limited to 'gold/target.cc')
-rw-r--r-- | gold/target.cc | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/gold/target.cc b/gold/target.cc index b6844d0..2dca98a 100644 --- a/gold/target.cc +++ b/gold/target.cc @@ -22,6 +22,7 @@ #include "gold.h" #include "target.h" +#include "dynobj.h" namespace gold { @@ -55,4 +56,83 @@ Target::do_is_local_label_name (const char* name) const 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(this); + 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(this); + 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 + } // End namespace gold. |