15 changed files with 849 additions and 39 deletions
@ -0,0 +1,356 @@ |
|||
// binary.cc -- binary input files for gold
|
|||
|
|||
// Copyright 2008 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 <cerrno> |
|||
#include <cstring> |
|||
#include "safe-ctype.h" |
|||
|
|||
#include "elfcpp.h" |
|||
#include "stringpool.h" |
|||
#include "fileread.h" |
|||
#include "output.h" |
|||
#include "binary.h" |
|||
|
|||
// Support for reading binary files as input. These become blobs in
|
|||
// the final output. These files are treated as though they have a
|
|||
// single .data section and define three symbols:
|
|||
// _binary_FILENAME_start, _binary_FILENAME_end, _binary_FILENAME_end.
|
|||
// The FILENAME is the name of the input file, with any
|
|||
// non-alphanumeric character changed to an underscore.
|
|||
|
|||
// We implement this by creating an ELF file in memory.
|
|||
|
|||
namespace gold |
|||
{ |
|||
|
|||
// class Binary_to_elf.
|
|||
|
|||
Binary_to_elf::Binary_to_elf(elfcpp::EM machine, int size, bool big_endian, |
|||
const std::string& filename) |
|||
: elf_machine_(machine), size_(size), big_endian_(big_endian), |
|||
filename_(filename), data_(NULL), filesize_(0) |
|||
{ |
|||
} |
|||
|
|||
Binary_to_elf::~Binary_to_elf() |
|||
{ |
|||
if (this->data_ != NULL) |
|||
delete[] this->data_; |
|||
} |
|||
|
|||
// Given FILENAME, create a buffer which looks like an ELF file with
|
|||
// the contents of FILENAME as the contents of the only section. The
|
|||
// TASK parameters is mainly for debugging, and records who holds
|
|||
// locks.
|
|||
|
|||
bool |
|||
Binary_to_elf::convert(const Task* task) |
|||
{ |
|||
if (this->size_ == 32) |
|||
{ |
|||
if (!this->big_endian_) |
|||
{ |
|||
#ifdef HAVE_TARGET_32_LITTLE |
|||
return this->sized_convert<32, false>(task); |
|||
#else |
|||
gold_unreachable(); |
|||
#endif |
|||
} |
|||
else |
|||
{ |
|||
#ifdef HAVE_TARGET_32_BIG |
|||
return this->sized_convert<32, true>(task); |
|||
#else |
|||
gold_unreachable(); |
|||
#endif |
|||
} |
|||
} |
|||
else if (this->size_ == 64) |
|||
{ |
|||
if (!this->big_endian_) |
|||
{ |
|||
#ifdef HAVE_TARGET_64_LITTLE |
|||
return this->sized_convert<64, false>(task); |
|||
#else |
|||
gold_unreachable(); |
|||
#endif |
|||
} |
|||
else |
|||
{ |
|||
#ifdef HAVE_TARGET_64_BIG |
|||
return this->sized_convert<64, true>(task); |
|||
#else |
|||
gold_unreachable(); |
|||
#endif |
|||
} |
|||
} |
|||
else |
|||
gold_unreachable(); |
|||
} |
|||
|
|||
// We are going to create:
|
|||
// * The ELF file header.
|
|||
// * Five sections: null section, .data, .symtab, .strtab, .shstrtab
|
|||
// * The contents of the file.
|
|||
// * Four symbols: null, begin, end, size.
|
|||
// * Three symbol names.
|
|||
// * Four section names.
|
|||
|
|||
template<int size, bool big_endian> |
|||
bool |
|||
Binary_to_elf::sized_convert(const Task* task) |
|||
{ |
|||
// Read the input file.
|
|||
|
|||
File_read f; |
|||
if (!f.open(task, this->filename_)) |
|||
{ |
|||
gold_error(_("cannot open %s: %s:"), this->filename_.c_str(), |
|||
strerror(errno)); |
|||
return false; |
|||
} |
|||
|
|||
section_size_type filesize = convert_to_section_size_type(f.filesize()); |
|||
const unsigned char* fileview = f.get_view(0, filesize, false); |
|||
|
|||
unsigned int align; |
|||
if (size == 32) |
|||
align = 4; |
|||
else if (size == 64) |
|||
align = 8; |
|||
else |
|||
gold_unreachable(); |
|||
section_size_type aligned_filesize = align_address(filesize, align); |
|||
|
|||
// Build the stringpool for the symbol table.
|
|||
|
|||
std::string mangled_name = this->filename_; |
|||
for (std::string::iterator p = mangled_name.begin(); |
|||
p != mangled_name.end(); |
|||
++p) |
|||
if (!ISALNUM(*p)) |
|||
*p = '_'; |
|||
mangled_name = "_binary_" + mangled_name; |
|||
std::string start_symbol_name = mangled_name + "_start"; |
|||
std::string end_symbol_name = mangled_name + "_end"; |
|||
std::string size_symbol_name = mangled_name + "_size"; |
|||
|
|||
Stringpool strtab; |
|||
strtab.add(start_symbol_name.c_str(), false, NULL); |
|||
strtab.add(end_symbol_name.c_str(), false, NULL); |
|||
strtab.add(size_symbol_name.c_str(), false, NULL); |
|||
strtab.set_string_offsets(); |
|||
|
|||
// Build the stringpool for the section name table.
|
|||
|
|||
Stringpool shstrtab; |
|||
shstrtab.add(".data", false, NULL); |
|||
shstrtab.add(".symtab", false, NULL); |
|||
shstrtab.add(".strtab", false, NULL); |
|||
shstrtab.add(".shstrtab", false, NULL); |
|||
shstrtab.set_string_offsets(); |
|||
|
|||
// Work out the size of the generated file, and the offsets of the
|
|||
// various sections, and allocate a buffer.
|
|||
|
|||
const int sym_size = elfcpp::Elf_sizes<size>::sym_size; |
|||
|
|||
size_t output_size = (elfcpp::Elf_sizes<size>::ehdr_size |
|||
+ 5 * elfcpp::Elf_sizes<size>::shdr_size); |
|||
size_t data_offset = output_size; |
|||
output_size += aligned_filesize; |
|||
size_t symtab_offset = output_size; |
|||
output_size += 4 * sym_size; |
|||
size_t strtab_offset = output_size; |
|||
output_size += strtab.get_strtab_size(); |
|||
size_t shstrtab_offset = output_size; |
|||
output_size += shstrtab.get_strtab_size(); |
|||
|
|||
unsigned char* buffer = new unsigned char[output_size]; |
|||
|
|||
// Write out the data.
|
|||
|
|||
unsigned char* pout = buffer; |
|||
|
|||
this->write_file_header<size, big_endian>(&pout); |
|||
|
|||
this->write_section_header<size, big_endian>("", &shstrtab, elfcpp::SHT_NULL, |
|||
0, 0, 0, 0, 0, |
|||
0, 0, &pout); |
|||
// Having the section be named ".data" and having it be writable is
|
|||
// because th GNU linker does it that way, and existing linker
|
|||
// script expect it.
|
|||
this->write_section_header<size, big_endian>(".data", &shstrtab, |
|||
elfcpp::SHT_PROGBITS, |
|||
(elfcpp::SHF_ALLOC |
|||
| elfcpp::SHF_WRITE), |
|||
data_offset, |
|||
filesize, 0, 0, |
|||
align, 0, &pout); |
|||
this->write_section_header<size, big_endian>(".symtab", &shstrtab, |
|||
elfcpp::SHT_SYMTAB, |
|||
0, symtab_offset, 4 * sym_size, |
|||
3, 1, align, sym_size, &pout); |
|||
this->write_section_header<size, big_endian>(".strtab", &shstrtab, |
|||
elfcpp::SHT_STRTAB, |
|||
0, strtab_offset, |
|||
strtab.get_strtab_size(), |
|||
0, 0, 1, 0, &pout); |
|||
this->write_section_header<size, big_endian>(".shstrtab", &shstrtab, |
|||
elfcpp::SHT_STRTAB, |
|||
0, shstrtab_offset, |
|||
shstrtab.get_strtab_size(), |
|||
0, 0, 1, 0, &pout); |
|||
|
|||
memcpy(pout, fileview, filesize); |
|||
pout += filesize; |
|||
memset(pout, 0, aligned_filesize - filesize); |
|||
pout += aligned_filesize - filesize; |
|||
|
|||
this->write_symbol<size, big_endian>("", &strtab, 0, 0, &pout); |
|||
this->write_symbol<size, big_endian>(start_symbol_name, &strtab, 0, 1, |
|||
&pout); |
|||
this->write_symbol<size, big_endian>(end_symbol_name, &strtab, filesize, 1, |
|||
&pout); |
|||
this->write_symbol<size, big_endian>(size_symbol_name, &strtab, filesize, |
|||
elfcpp::SHN_ABS, &pout); |
|||
|
|||
strtab.write_to_buffer(pout, strtab.get_strtab_size()); |
|||
pout += strtab.get_strtab_size(); |
|||
|
|||
shstrtab.write_to_buffer(pout, shstrtab.get_strtab_size()); |
|||
pout += shstrtab.get_strtab_size(); |
|||
|
|||
gold_assert(static_cast<size_t>(pout - buffer) == output_size); |
|||
|
|||
this->data_ = buffer; |
|||
this->filesize_ = output_size; |
|||
|
|||
f.unlock(task); |
|||
|
|||
return true; |
|||
} |
|||
|
|||
// Write out the file header.
|
|||
|
|||
template<int size, bool big_endian> |
|||
void |
|||
Binary_to_elf::write_file_header(unsigned char** ppout) |
|||
{ |
|||
elfcpp::Ehdr_write<size, big_endian> oehdr(*ppout); |
|||
|
|||
unsigned char e_ident[elfcpp::EI_NIDENT]; |
|||
memset(e_ident, 0, elfcpp::EI_NIDENT); |
|||
e_ident[elfcpp::EI_MAG0] = elfcpp::ELFMAG0; |
|||
e_ident[elfcpp::EI_MAG1] = elfcpp::ELFMAG1; |
|||
e_ident[elfcpp::EI_MAG2] = elfcpp::ELFMAG2; |
|||
e_ident[elfcpp::EI_MAG3] = elfcpp::ELFMAG3; |
|||
if (size == 32) |
|||
e_ident[elfcpp::EI_CLASS] = elfcpp::ELFCLASS32; |
|||
else if (size == 64) |
|||
e_ident[elfcpp::EI_CLASS] = elfcpp::ELFCLASS64; |
|||
else |
|||
gold_unreachable(); |
|||
e_ident[elfcpp::EI_DATA] = (big_endian |
|||
? elfcpp::ELFDATA2MSB |
|||
: elfcpp::ELFDATA2LSB); |
|||
e_ident[elfcpp::EI_VERSION] = elfcpp::EV_CURRENT; |
|||
oehdr.put_e_ident(e_ident); |
|||
|
|||
oehdr.put_e_type(elfcpp::ET_REL); |
|||
oehdr.put_e_machine(this->elf_machine_); |
|||
oehdr.put_e_version(elfcpp::EV_CURRENT); |
|||
oehdr.put_e_entry(0); |
|||
oehdr.put_e_phoff(0); |
|||
oehdr.put_e_shoff(elfcpp::Elf_sizes<size>::ehdr_size); |
|||
oehdr.put_e_flags(0); |
|||
oehdr.put_e_ehsize(elfcpp::Elf_sizes<size>::ehdr_size); |
|||
oehdr.put_e_phentsize(0); |
|||
oehdr.put_e_phnum(0); |
|||
oehdr.put_e_shentsize(elfcpp::Elf_sizes<size>::shdr_size); |
|||
oehdr.put_e_shnum(5); |
|||
oehdr.put_e_shstrndx(4); |
|||
|
|||
*ppout += elfcpp::Elf_sizes<size>::ehdr_size; |
|||
} |
|||
|
|||
// Write out a section header.
|
|||
|
|||
template<int size, bool big_endian> |
|||
void |
|||
Binary_to_elf::write_section_header( |
|||
const char* name, |
|||
const Stringpool* shstrtab, |
|||
elfcpp::SHT type, |
|||
unsigned int flags, |
|||
section_size_type offset, |
|||
section_size_type section_size, |
|||
unsigned int link, |
|||
unsigned int info, |
|||
unsigned int addralign, |
|||
unsigned int entsize, |
|||
unsigned char** ppout) |
|||
{ |
|||
elfcpp::Shdr_write<size, big_endian> oshdr(*ppout); |
|||
|
|||
oshdr.put_sh_name(*name == '\0' ? 0 : shstrtab->get_offset(name)); |
|||
oshdr.put_sh_type(type); |
|||
oshdr.put_sh_flags(flags); |
|||
oshdr.put_sh_addr(0); |
|||
oshdr.put_sh_offset(offset); |
|||
oshdr.put_sh_size(section_size); |
|||
oshdr.put_sh_link(link); |
|||
oshdr.put_sh_info(info); |
|||
oshdr.put_sh_addralign(addralign); |
|||
oshdr.put_sh_entsize(entsize); |
|||
|
|||
*ppout += elfcpp::Elf_sizes<size>::shdr_size; |
|||
} |
|||
|
|||
// Write out a symbol.
|
|||
|
|||
template<int size, bool big_endian> |
|||
void |
|||
Binary_to_elf::write_symbol( |
|||
const std::string& name, |
|||
const Stringpool* strtab, |
|||
section_size_type value, |
|||
unsigned int shndx, |
|||
unsigned char** ppout) |
|||
{ |
|||
unsigned char* pout = *ppout; |
|||
|
|||
elfcpp::Sym_write<size, big_endian> osym(pout); |
|||
osym.put_st_name(name.empty() ? 0 : strtab->get_offset(name.c_str())); |
|||
osym.put_st_value(value); |
|||
osym.put_st_size(0); |
|||
osym.put_st_info(name.empty() ? elfcpp::STB_LOCAL : elfcpp::STB_GLOBAL, |
|||
elfcpp::STT_NOTYPE); |
|||
osym.put_st_other(elfcpp::STV_DEFAULT, 0); |
|||
osym.put_st_shndx(shndx); |
|||
|
|||
*ppout += elfcpp::Elf_sizes<size>::sym_size; |
|||
} |
|||
|
|||
} // End namespace gold.
|
|||
@ -0,0 +1,116 @@ |
|||
// binary.h -- binary input files for gold -*- C++ -*-
|
|||
|
|||
// Copyright 2008 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.
|
|||
|
|||
// Support binary input files by making them look like an ELF file.
|
|||
|
|||
#ifndef GOLD_BINARY_H |
|||
#define GOLD_BINARY_H |
|||
|
|||
#include <string> |
|||
|
|||
#include "elfcpp.h" |
|||
|
|||
namespace gold |
|||
{ |
|||
|
|||
class Task; |
|||
|
|||
template<typename Stringpool_char> |
|||
class Stringpool_template; |
|||
|
|||
// This class takes a file name and creates a buffer which looks like
|
|||
// an ELF file read into memory.
|
|||
|
|||
class Binary_to_elf |
|||
{ |
|||
public: |
|||
Binary_to_elf(elfcpp::EM machine, int size, bool big_endian, |
|||
const std::string& filename); |
|||
|
|||
~Binary_to_elf(); |
|||
|
|||
// Read contents and create an ELF buffer. Return true if this
|
|||
// succeeds, false otherwise.
|
|||
bool |
|||
convert(const Task*); |
|||
|
|||
// Return a pointer to the contents of the ELF file.
|
|||
const unsigned char* |
|||
converted_data() const |
|||
{ return this->data_; } |
|||
|
|||
// Return a pointer to the contents of the ELF file and let the
|
|||
// caller take charge of it. It was allocated using new[].
|
|||
unsigned char* |
|||
converted_data_leak() |
|||
{ |
|||
unsigned char* ret = this->data_; |
|||
this->data_ = NULL; |
|||
return ret; |
|||
} |
|||
|
|||
// Return the size of the ELF file.
|
|||
size_t |
|||
converted_size() const |
|||
{ return this->filesize_; } |
|||
|
|||
private: |
|||
Binary_to_elf(const Binary_to_elf&); |
|||
Binary_to_elf& operator=(const Binary_to_elf&); |
|||
|
|||
template<int size, bool big_endian> |
|||
bool |
|||
sized_convert(const Task*); |
|||
|
|||
template<int size, bool big_endian> |
|||
void |
|||
write_file_header(unsigned char**); |
|||
|
|||
template<int size, bool big_endian> |
|||
void |
|||
write_section_header(const char*, const Stringpool_template<char>*, |
|||
elfcpp::SHT, unsigned int, section_size_type, |
|||
section_size_type, unsigned int, unsigned int, |
|||
unsigned int, unsigned int, unsigned char**); |
|||
|
|||
template<int size, bool big_endian> |
|||
void |
|||
write_symbol(const std::string&, const Stringpool_template<char>*, |
|||
section_size_type, unsigned int, unsigned char**); |
|||
|
|||
// The ELF machine code of the file to create.
|
|||
elfcpp::EM elf_machine_; |
|||
// The size of the file to create, 32 or 64.
|
|||
int size_; |
|||
// Whether to create a big endian file.
|
|||
bool big_endian_; |
|||
// The name of the file to read.
|
|||
std::string filename_; |
|||
// The ELF file data, allocated by new [].
|
|||
unsigned char* data_; |
|||
// The ELF file size.
|
|||
section_size_type filesize_; |
|||
}; |
|||
|
|||
} // End namespace gold.
|
|||
|
|||
#endif // !defined(GOLD_BINARY_H)
|
|||
@ -0,0 +1 @@ |
|||
This file is used for the binary test. |
|||
@ -0,0 +1,46 @@ |
|||
// binary_test.cc -- test --format binary for gold
|
|||
|
|||
// Copyright 2008 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.
|
|||
|
|||
// This program is linked with a small text file named binary.txt
|
|||
// using --formatbinary.
|
|||
|
|||
#include <cassert> |
|||
#include <cstddef> |
|||
#include <cstring> |
|||
#include <stdint.h> |
|||
|
|||
extern char _binary_binary_txt_start[]; |
|||
extern char _binary_binary_txt_end[]; |
|||
extern char _binary_binary_txt_size[]; |
|||
|
|||
int |
|||
main(int, char**) |
|||
{ |
|||
int size = reinterpret_cast<uintptr_t>(_binary_binary_txt_size); |
|||
assert(size == _binary_binary_txt_end - _binary_binary_txt_start); |
|||
|
|||
const char* const txt = "This file is used for the binary test.\n"; |
|||
assert(strncmp(txt, _binary_binary_txt_start, size) == 0); |
|||
assert(static_cast<size_t>(size) == strlen(txt)); |
|||
|
|||
return 0; |
|||
} |
|||
@ -0,0 +1,147 @@ |
|||
// binary_unittest.cc -- test Binary_to_elf
|
|||
|
|||
// Copyright 2008 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 <unistd.h> |
|||
#include <sys/types.h> |
|||
#include <sys/stat.h> |
|||
#include <fcntl.h> |
|||
|
|||
#include "elfcpp.h" |
|||
#include "parameters.h" |
|||
#include "errors.h" |
|||
#include "options.h" |
|||
#include "binary.h" |
|||
#include "object.h" |
|||
|
|||
#include "test.h" |
|||
#include "testfile.h" |
|||
|
|||
namespace gold_testsuite |
|||
{ |
|||
|
|||
using namespace gold; |
|||
|
|||
template<int size, bool big_endian> |
|||
bool |
|||
Sized_binary_test(Target* target) |
|||
{ |
|||
// We need a pretend Task.
|
|||
const Task* task = reinterpret_cast<const Task*>(-1); |
|||
|
|||
// Use the executable itself as the binary data.
|
|||
struct stat st; |
|||
CHECK(::stat(gold::program_name, &st) == 0); |
|||
int o = ::open(gold::program_name, O_RDONLY); |
|||
CHECK(o >= 0); |
|||
unsigned char* filedata = new unsigned char[st.st_size]; |
|||
CHECK(::read(o, filedata, st.st_size) == st.st_size); |
|||
CHECK(::close(o) == 0); |
|||
|
|||
Binary_to_elf binary(static_cast<elfcpp::EM>(0xffff), size, big_endian, |
|||
gold::program_name); |
|||
|
|||
CHECK(binary.convert(task)); |
|||
|
|||
Input_file input_file(task, "test.o", binary.converted_data(), |
|||
binary.converted_size()); |
|||
Object* object = make_elf_object("test.o", &input_file, 0, |
|||
binary.converted_data(), |
|||
binary.converted_size()); |
|||
CHECK(object != NULL); |
|||
if (object == NULL) |
|||
return false; |
|||
|
|||
CHECK(!object->is_dynamic()); |
|||
CHECK(object->target() == target); |
|||
CHECK(object->shnum() == 5); |
|||
CHECK(object->section_name(1) == ".data"); |
|||
CHECK(object->section_flags(1) == elfcpp::SHF_ALLOC | elfcpp::SHF_WRITE); |
|||
section_size_type len; |
|||
const unsigned char* contents = object->section_contents(1, &len, false); |
|||
CHECK(len == st.st_size); |
|||
CHECK(memcmp(filedata, contents, len) == 0); |
|||
|
|||
// Force the symbols to be read internally, so that
|
|||
// symbol_section_and_value will work.
|
|||
Read_symbols_data sd; |
|||
object->read_symbols(&sd); |
|||
delete sd.section_headers; |
|||
delete sd.section_names; |
|||
delete sd.symbols; |
|||
delete sd.symbol_names; |
|||
|
|||
Sized_relobj<size, big_endian>* relobj = |
|||
static_cast<Sized_relobj<size, big_endian>*>(object); |
|||
typename Sized_relobj<size, big_endian>::Address value; |
|||
CHECK(relobj->symbol_section_and_value(0, &value) == 0); |
|||
CHECK(value == 0); |
|||
CHECK(relobj->symbol_section_and_value(1, &value) == 1); |
|||
CHECK(value == 0); |
|||
CHECK(relobj->symbol_section_and_value(2, &value) == 1); |
|||
CHECK(static_cast<off_t>(value) == st.st_size); |
|||
CHECK(relobj->symbol_section_and_value(3, &value) == elfcpp::SHN_ABS); |
|||
CHECK(static_cast<off_t>(value) == st.st_size); |
|||
|
|||
object->unlock(task); |
|||
return true; |
|||
} |
|||
|
|||
bool |
|||
Binary_test(Test_report*) |
|||
{ |
|||
Errors errors(gold::program_name); |
|||
initialize_parameters(&errors); |
|||
|
|||
Script_options script_options; |
|||
General_options options(&script_options); |
|||
set_parameters_from_options(&options); |
|||
|
|||
int fail = 0; |
|||
|
|||
#ifdef HAVE_TARGET_32_LITTLE |
|||
if (!Sized_binary_test<32, false>(target_test_pointer_32_little)) |
|||
++fail; |
|||
#endif |
|||
|
|||
#ifdef HAVE_TARGET_32_BIG |
|||
if (!Sized_binary_test<32, true>(target_test_pointer_32_big)) |
|||
++fail; |
|||
#endif |
|||
|
|||
#ifdef HAVE_TARGET_64_LITTLE |
|||
if (!Sized_binary_test<64, false>(target_test_pointer_64_little)) |
|||
++fail; |
|||
#endif |
|||
|
|||
#ifdef HAVE_TARGET_64_BIG |
|||
if (!Sized_binary_test<64, true>(target_test_pointer_64_big)) |
|||
++fail; |
|||
#endif |
|||
|
|||
return fail == 0; |
|||
} |
|||
|
|||
Register_test binary_register("Binary", Binary_test); |
|||
|
|||
} // End namespace gold_testsuite.
|
|||
Loading…
Reference in new issue