diff options
author | Ian Lance Taylor <ian@airs.com> | 2009-10-09 16:40:51 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@airs.com> | 2009-10-09 16:40:51 +0000 |
commit | c549a6949c8cbbbeafa79ab903b172bbc5f2b8ea (patch) | |
tree | d7881e3b7056774b661607d3d3ae9e56e3a14ebf /gold/object.cc | |
parent | e322137b9b864508a8b8f378ebb331589812ed18 (diff) | |
download | gdb-c549a6949c8cbbbeafa79ab903b172bbc5f2b8ea.zip gdb-c549a6949c8cbbbeafa79ab903b172bbc5f2b8ea.tar.gz gdb-c549a6949c8cbbbeafa79ab903b172bbc5f2b8ea.tar.bz2 |
elfcpp/:
* elfcpp_file.h: Fix header guard. Include <cstdio>.
(class Elf_recognizer): New class, code from gold/object.cc.
(Elf_file::find_section_by_type): New method.
gold/:
* incremental.cc: Include <cstdarg> and "target-select.h".
(vexplain_no_incremental): New function.
(explain_no_incremental): New function.
(Incremental_binary::error): New method.
(Sized_incremental_binary::do_find_incremental_inputs_section): New
method.
(make_sized_incremental_binary): New function.
(open_incremental_binary): New function.
(can_incrementally_link_file): Add checks if output is ELF and has
inputs section.
* incremental.h: Include "elfcpp_file.h" and "output.h".
(Incremental_binary): New class.
(Sized_incremental_binary): New class.
(open_incremental_binary): Declare.
* object.cc (is_elf_object): Use
elfcpp::Elf_recognizer::is_elf_file.
(make_elf_object): Use elfcpp::Elf_recognizer::is_valid_header.
* output.h (Output_file::filesize): New method.
Diffstat (limited to 'gold/object.cc')
-rw-r--r-- | gold/object.cc | 74 |
1 files changed, 12 insertions, 62 deletions
diff --git a/gold/object.cc b/gold/object.cc index 5ac7878..b8d9eb8 100644 --- a/gold/object.cc +++ b/gold/object.cc @@ -2281,7 +2281,7 @@ is_elf_object(Input_file* input_file, off_t offset, const unsigned char** start, int *read_size) { off_t filesize = input_file->file().filesize(); - int want = elfcpp::Elf_sizes<64>::ehdr_size; + int want = elfcpp::Elf_recognizer::max_header_size; if (filesize - offset < want) want = filesize - offset; @@ -2290,15 +2290,7 @@ is_elf_object(Input_file* input_file, off_t offset, *start = p; *read_size = want; - if (want < 4) - return false; - - static unsigned char elfmagic[4] = - { - elfcpp::ELFMAG0, elfcpp::ELFMAG1, - elfcpp::ELFMAG2, elfcpp::ELFMAG3 - }; - return memcmp(p, elfmagic, 4) == 0; + return elfcpp::Elf_recognizer::is_elf_file(p, want); } // Read an ELF file and return the appropriate instance of Object. @@ -2311,57 +2303,18 @@ make_elf_object(const std::string& name, Input_file* input_file, off_t offset, if (punconfigured != NULL) *punconfigured = false; - if (bytes < elfcpp::EI_NIDENT) - { - gold_error(_("%s: ELF file too short"), name.c_str()); - return NULL; - } - - int v = p[elfcpp::EI_VERSION]; - if (v != elfcpp::EV_CURRENT) - { - if (v == elfcpp::EV_NONE) - gold_error(_("%s: invalid ELF version 0"), name.c_str()); - else - gold_error(_("%s: unsupported ELF version %d"), name.c_str(), v); - return NULL; - } - - int c = p[elfcpp::EI_CLASS]; - if (c == elfcpp::ELFCLASSNONE) + std::string error; + bool big_endian; + int size; + if (!elfcpp::Elf_recognizer::is_valid_header(p, bytes, &size, + &big_endian, &error)) { - gold_error(_("%s: invalid ELF class 0"), name.c_str()); - return NULL; - } - else if (c != elfcpp::ELFCLASS32 - && c != elfcpp::ELFCLASS64) - { - gold_error(_("%s: unsupported ELF class %d"), name.c_str(), c); + gold_error(_("%s: %s"), name.c_str(), error.c_str()); return NULL; } - int d = p[elfcpp::EI_DATA]; - if (d == elfcpp::ELFDATANONE) + if (size == 32) { - gold_error(_("%s: invalid ELF data encoding"), name.c_str()); - return NULL; - } - else if (d != elfcpp::ELFDATA2LSB - && d != elfcpp::ELFDATA2MSB) - { - gold_error(_("%s: unsupported ELF data encoding %d"), name.c_str(), d); - return NULL; - } - - bool big_endian = d == elfcpp::ELFDATA2MSB; - - if (c == elfcpp::ELFCLASS32) - { - if (bytes < elfcpp::Elf_sizes<32>::ehdr_size) - { - gold_error(_("%s: ELF file too short"), name.c_str()); - return NULL; - } if (big_endian) { #ifdef HAVE_TARGET_32_BIG @@ -2395,13 +2348,8 @@ make_elf_object(const std::string& name, Input_file* input_file, off_t offset, #endif } } - else + else if (size == 64) { - if (bytes < elfcpp::Elf_sizes<64>::ehdr_size) - { - gold_error(_("%s: ELF file too short"), name.c_str()); - return NULL; - } if (big_endian) { #ifdef HAVE_TARGET_64_BIG @@ -2435,6 +2383,8 @@ make_elf_object(const std::string& name, Input_file* input_file, off_t offset, #endif } } + else + gold_unreachable(); } // Instantiate the templates we need. |