summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas Geoffray <ngeoffray@google.com>2014-09-02 08:12:09 +0000
committerNicolas Geoffray <ngeoffray@google.com>2014-09-02 08:12:09 +0000
commitf9b87b1eece0e03578c4d1b627f1d5e8691a539a (patch)
tree451b94c30f4b9a25e40600d6993fc1069efa0689
parent7eebd95bddc7c6866ba29010d28b4f8251b43242 (diff)
downloadart-f9b87b1eece0e03578c4d1b627f1d5e8691a539a.zip
art-f9b87b1eece0e03578c4d1b627f1d5e8691a539a.tar.gz
art-f9b87b1eece0e03578c4d1b627f1d5e8691a539a.tar.bz2
Revert "Revert "ART: Prepare for ELF64.""
Fix was commited in "Fix frame size issue with 64-bit" This reverts commit 7eebd95bddc7c6866ba29010d28b4f8251b43242. Change-Id: I799b7fcab14ae24471d2f9d6d3a5e5cedd4aa7b8
-rw-r--r--compiler/dex/quick/quick_compiler.cc4
-rw-r--r--compiler/elf_writer_quick.cc338
-rw-r--r--compiler/elf_writer_quick.h103
3 files changed, 274 insertions, 171 deletions
diff --git a/compiler/dex/quick/quick_compiler.cc b/compiler/dex/quick/quick_compiler.cc
index 49c16cb..2c5f79c 100644
--- a/compiler/dex/quick/quick_compiler.cc
+++ b/compiler/dex/quick/quick_compiler.cc
@@ -608,8 +608,8 @@ bool QuickCompiler::WriteElf(art::File* file,
const std::vector<const art::DexFile*>& dex_files,
const std::string& android_root,
bool is_host) const {
- return art::ElfWriterQuick::Create(file, oat_writer, dex_files, android_root, is_host,
- *GetCompilerDriver());
+ return art::ElfWriterQuick32::Create(file, oat_writer, dex_files, android_root, is_host,
+ *GetCompilerDriver());
}
Backend* QuickCompiler::GetCodeGenerator(CompilationUnit* cu, void* compilation_unit) const {
diff --git a/compiler/elf_writer_quick.cc b/compiler/elf_writer_quick.cc
index e45eb61..0216900 100644
--- a/compiler/elf_writer_quick.cc
+++ b/compiler/elf_writer_quick.cc
@@ -34,7 +34,8 @@
namespace art {
-static constexpr Elf32_Word NextOffset(const Elf32_Shdr& cur, const Elf32_Shdr& prev) {
+template <typename Elf_Word, typename Elf_Shdr>
+static constexpr Elf_Word NextOffset(const Elf_Shdr& cur, const Elf_Shdr& prev) {
return RoundUp(prev.sh_size + prev.sh_offset, cur.sh_addralign);
}
@@ -78,22 +79,26 @@ static void PushHalf(std::vector<uint8_t>* buf, int data) {
buf->push_back((data >> 8) & 0xff);
}
-bool ElfWriterQuick::ElfBuilder::Init() {
+template <typename Elf_Word, typename Elf_Sword, typename Elf_Addr,
+ typename Elf_Dyn, typename Elf_Sym, typename Elf_Ehdr,
+ typename Elf_Phdr, typename Elf_Shdr>
+bool ElfWriterQuick<Elf_Word, Elf_Sword, Elf_Addr, Elf_Dyn,
+ Elf_Sym, Elf_Ehdr, Elf_Phdr, Elf_Shdr>::ElfBuilder::Init() {
// The basic layout of the elf file. Order may be different in final output.
// +-------------------------+
- // | Elf32_Ehdr |
+ // | Elf_Ehdr |
// +-------------------------+
- // | Elf32_Phdr PHDR |
- // | Elf32_Phdr LOAD R | .dynsym .dynstr .hash .rodata
- // | Elf32_Phdr LOAD R X | .text
- // | Elf32_Phdr LOAD RW | .dynamic
- // | Elf32_Phdr DYNAMIC | .dynamic
+ // | Elf_Phdr PHDR |
+ // | Elf_Phdr LOAD R | .dynsym .dynstr .hash .rodata
+ // | Elf_Phdr LOAD R X | .text
+ // | Elf_Phdr LOAD RW | .dynamic
+ // | Elf_Phdr DYNAMIC | .dynamic
// +-------------------------+
// | .dynsym |
- // | Elf32_Sym STN_UNDEF |
- // | Elf32_Sym oatdata |
- // | Elf32_Sym oatexec |
- // | Elf32_Sym oatlastword |
+ // | Elf_Sym STN_UNDEF |
+ // | Elf_Sym oatdata |
+ // | Elf_Sym oatexec |
+ // | Elf_Sym oatlastword |
// +-------------------------+
// | .dynstr |
// | \0 |
@@ -103,14 +108,14 @@ bool ElfWriterQuick::ElfBuilder::Init() {
// | boot.oat\0 |
// +-------------------------+
// | .hash |
- // | Elf32_Word nbucket = b |
- // | Elf32_Word nchain = c |
- // | Elf32_Word bucket[0] |
+ // | Elf_Word nbucket = b |
+ // | Elf_Word nchain = c |
+ // | Elf_Word bucket[0] |
// | ... |
- // | Elf32_Word bucket[b - 1]|
- // | Elf32_Word chain[0] |
+ // | Elf_Word bucket[b - 1] |
+ // | Elf_Word chain[0] |
// | ... |
- // | Elf32_Word chain[c - 1] |
+ // | Elf_Word chain[c - 1] |
// +-------------------------+
// | .rodata |
// | oatdata..oatexec-4 |
@@ -119,13 +124,13 @@ bool ElfWriterQuick::ElfBuilder::Init() {
// | oatexec..oatlastword |
// +-------------------------+
// | .dynamic |
- // | Elf32_Dyn DT_SONAME |
- // | Elf32_Dyn DT_HASH |
- // | Elf32_Dyn DT_SYMTAB |
- // | Elf32_Dyn DT_SYMENT |
- // | Elf32_Dyn DT_STRTAB |
- // | Elf32_Dyn DT_STRSZ |
- // | Elf32_Dyn DT_NULL |
+ // | Elf_Dyn DT_SONAME |
+ // | Elf_Dyn DT_HASH |
+ // | Elf_Dyn DT_SYMTAB |
+ // | Elf_Dyn DT_SYMENT |
+ // | Elf_Dyn DT_STRTAB |
+ // | Elf_Dyn DT_STRSZ |
+ // | Elf_Dyn DT_NULL |
// +-------------------------+ (Optional)
// | .strtab | (Optional)
// | program symbol names | (Optional)
@@ -160,19 +165,19 @@ bool ElfWriterQuick::ElfBuilder::Init() {
// +-------------------------+ (Optional)
// | .debug_str | (Optional)
// +-------------------------+ (Optional)
- // | Elf32_Shdr NULL |
- // | Elf32_Shdr .dynsym |
- // | Elf32_Shdr .dynstr |
- // | Elf32_Shdr .hash |
- // | Elf32_Shdr .text |
- // | Elf32_Shdr .rodata |
- // | Elf32_Shdr .dynamic |
- // | Elf32_Shdr .shstrtab |
- // | Elf32_Shdr .debug_info | (Optional)
- // | Elf32_Shdr .debug_abbrev| (Optional)
- // | Elf32_Shdr .eh_frame | (Optional)
- // | Elf32_Shdr .debug_line | (Optional)
- // | Elf32_Shdr .debug_str | (Optional)
+ // | Elf_Shdr NULL |
+ // | Elf_Shdr .dynsym |
+ // | Elf_Shdr .dynstr |
+ // | Elf_Shdr .hash |
+ // | Elf_Shdr .text |
+ // | Elf_Shdr .rodata |
+ // | Elf_Shdr .dynamic |
+ // | Elf_Shdr .shstrtab |
+ // | Elf_Shdr .debug_info | (Optional)
+ // | Elf_Shdr .debug_abbrev | (Optional)
+ // | Elf_Shdr .eh_frame | (Optional)
+ // | Elf_Shdr .debug_line | (Optional)
+ // | Elf_Shdr .debug_str | (Optional)
// +-------------------------+
if (fatal_error_) {
@@ -193,7 +198,7 @@ bool ElfWriterQuick::ElfBuilder::Init() {
program_headers_[PH_PHDR].p_filesz = sizeof(program_headers_);
program_headers_[PH_PHDR].p_memsz = sizeof(program_headers_);
program_headers_[PH_PHDR].p_flags = PF_R;
- program_headers_[PH_PHDR].p_align = sizeof(Elf32_Word);
+ program_headers_[PH_PHDR].p_align = sizeof(Elf_Word);
program_headers_[PH_LOAD_R__].p_type = PT_LOAD;
program_headers_[PH_LOAD_R__].p_offset = 0;
@@ -274,53 +279,58 @@ bool ElfWriterQuick::ElfBuilder::Init() {
hash_ = dynsym_builder_.GenerateHashContents();
if (debug_logging_) {
- LOG(INFO) << ".hash size (bytes)=" << hash_.size() * sizeof(Elf32_Word)
- << std::hex << " " << hash_.size() * sizeof(Elf32_Word);
+ LOG(INFO) << ".hash size (bytes)=" << hash_.size() * sizeof(Elf_Word)
+ << std::hex << " " << hash_.size() * sizeof(Elf_Word);
}
- Elf32_Word base_offset = sizeof(Elf32_Ehdr) + sizeof(program_headers_);
+ Elf_Word base_offset = sizeof(Elf_Ehdr) + sizeof(program_headers_);
// Get the layout in the sections.
//
// Get the layout of the dynsym section.
dynsym_builder_.section_.sh_offset = RoundUp(base_offset, dynsym_builder_.section_.sh_addralign);
dynsym_builder_.section_.sh_addr = dynsym_builder_.section_.sh_offset;
- dynsym_builder_.section_.sh_size = dynsym_builder_.GetSize() * sizeof(Elf32_Sym);
+ dynsym_builder_.section_.sh_size = dynsym_builder_.GetSize() * sizeof(Elf_Sym);
dynsym_builder_.section_.sh_link = dynsym_builder_.GetLink();
// Get the layout of the dynstr section.
- dynsym_builder_.strtab_.section_.sh_offset = NextOffset(dynsym_builder_.strtab_.section_,
- dynsym_builder_.section_);
+ dynsym_builder_.strtab_.section_.sh_offset = NextOffset<Elf_Word, Elf_Shdr>
+ (dynsym_builder_.strtab_.section_,
+ dynsym_builder_.section_);
dynsym_builder_.strtab_.section_.sh_addr = dynsym_builder_.strtab_.section_.sh_offset;
dynsym_builder_.strtab_.section_.sh_size = dynstr_.size();
dynsym_builder_.strtab_.section_.sh_link = dynsym_builder_.strtab_.GetLink();
// Get the layout of the hash section
- hash_builder_.section_.sh_offset = NextOffset(hash_builder_.section_,
- dynsym_builder_.strtab_.section_);
+ hash_builder_.section_.sh_offset = NextOffset<Elf_Word, Elf_Shdr>
+ (hash_builder_.section_,
+ dynsym_builder_.strtab_.section_);
hash_builder_.section_.sh_addr = hash_builder_.section_.sh_offset;
- hash_builder_.section_.sh_size = hash_.size() * sizeof(Elf32_Word);
+ hash_builder_.section_.sh_size = hash_.size() * sizeof(Elf_Word);
hash_builder_.section_.sh_link = hash_builder_.GetLink();
// Get the layout of the rodata section.
- rodata_builder_.section_.sh_offset = NextOffset(rodata_builder_.section_,
- hash_builder_.section_);
+ rodata_builder_.section_.sh_offset = NextOffset<Elf_Word, Elf_Shdr>
+ (rodata_builder_.section_,
+ hash_builder_.section_);
rodata_builder_.section_.sh_addr = rodata_builder_.section_.sh_offset;
rodata_builder_.section_.sh_size = rodata_builder_.size_;
rodata_builder_.section_.sh_link = rodata_builder_.GetLink();
// Get the layout of the text section.
- text_builder_.section_.sh_offset = NextOffset(text_builder_.section_, rodata_builder_.section_);
+ text_builder_.section_.sh_offset = NextOffset<Elf_Word, Elf_Shdr>
+ (text_builder_.section_, rodata_builder_.section_);
text_builder_.section_.sh_addr = text_builder_.section_.sh_offset;
text_builder_.section_.sh_size = text_builder_.size_;
text_builder_.section_.sh_link = text_builder_.GetLink();
CHECK_ALIGNED(rodata_builder_.section_.sh_offset + rodata_builder_.section_.sh_size, kPageSize);
// Get the layout of the dynamic section.
- dynamic_builder_.section_.sh_offset = NextOffset(dynamic_builder_.section_,
- text_builder_.section_);
+ dynamic_builder_.section_.sh_offset = NextOffset<Elf_Word, Elf_Shdr>
+ (dynamic_builder_.section_,
+ text_builder_.section_);
dynamic_builder_.section_.sh_addr = dynamic_builder_.section_.sh_offset;
- dynamic_builder_.section_.sh_size = dynamic_builder_.GetSize() * sizeof(Elf32_Dyn);
+ dynamic_builder_.section_.sh_size = dynamic_builder_.GetSize() * sizeof(Elf_Dyn);
dynamic_builder_.section_.sh_link = dynamic_builder_.GetLink();
if (debug_logging_) {
@@ -341,9 +351,13 @@ bool ElfWriterQuick::ElfBuilder::Init() {
return true;
}
-bool ElfWriterQuick::ElfBuilder::Write() {
+template <typename Elf_Word, typename Elf_Sword, typename Elf_Addr,
+ typename Elf_Dyn, typename Elf_Sym, typename Elf_Ehdr,
+ typename Elf_Phdr, typename Elf_Shdr>
+bool ElfWriterQuick<Elf_Word, Elf_Sword, Elf_Addr, Elf_Dyn,
+ Elf_Sym, Elf_Ehdr, Elf_Phdr, Elf_Shdr>::ElfBuilder::Write() {
std::vector<ElfFilePiece> pieces;
- Elf32_Shdr prev = dynamic_builder_.section_;
+ Elf_Shdr prev = dynamic_builder_.section_;
std::string strtab;
if (IncludingDebugSymbols()) {
@@ -389,16 +403,18 @@ bool ElfWriterQuick::ElfBuilder::Write() {
if (IncludingDebugSymbols()) {
// Get the layout of the symtab section.
- symtab_builder_.section_.sh_offset = NextOffset(symtab_builder_.section_,
- dynamic_builder_.section_);
+ symtab_builder_.section_.sh_offset = NextOffset<Elf_Word, Elf_Shdr>
+ (symtab_builder_.section_,
+ dynamic_builder_.section_);
symtab_builder_.section_.sh_addr = 0;
// Add to leave space for the null symbol.
- symtab_builder_.section_.sh_size = symtab_builder_.GetSize() * sizeof(Elf32_Sym);
+ symtab_builder_.section_.sh_size = symtab_builder_.GetSize() * sizeof(Elf_Sym);
symtab_builder_.section_.sh_link = symtab_builder_.GetLink();
// Get the layout of the dynstr section.
- symtab_builder_.strtab_.section_.sh_offset = NextOffset(symtab_builder_.strtab_.section_,
- symtab_builder_.section_);
+ symtab_builder_.strtab_.section_.sh_offset = NextOffset<Elf_Word, Elf_Shdr>
+ (symtab_builder_.strtab_.section_,
+ symtab_builder_.section_);
symtab_builder_.strtab_.section_.sh_addr = 0;
symtab_builder_.strtab_.section_.sh_size = strtab.size();
symtab_builder_.strtab_.section_.sh_link = symtab_builder_.strtab_.GetLink();
@@ -415,7 +431,7 @@ bool ElfWriterQuick::ElfBuilder::Write() {
// Get the layout of the extra sections. (This will deal with the debug
// sections if they are there)
for (auto it = other_builders_.begin(); it != other_builders_.end(); ++it) {
- it->section_.sh_offset = NextOffset(it->section_, prev);
+ it->section_.sh_offset = NextOffset<Elf_Word, Elf_Shdr>(it->section_, prev);
it->section_.sh_addr = 0;
it->section_.sh_size = it->GetBuffer()->size();
it->section_.sh_link = it->GetLink();
@@ -429,7 +445,8 @@ bool ElfWriterQuick::ElfBuilder::Write() {
}
// Get the layout of the shstrtab section
- shstrtab_builder_.section_.sh_offset = NextOffset(shstrtab_builder_.section_, prev);
+ shstrtab_builder_.section_.sh_offset = NextOffset<Elf_Word, Elf_Shdr>
+ (shstrtab_builder_.section_, prev);
shstrtab_builder_.section_.sh_addr = 0;
shstrtab_builder_.section_.sh_size = shstrtab_.size();
shstrtab_builder_.section_.sh_link = shstrtab_builder_.GetLink();
@@ -439,34 +456,34 @@ bool ElfWriterQuick::ElfBuilder::Write() {
}
// The section list comes after come after.
- Elf32_Word sections_offset = RoundUp(
+ Elf_Word sections_offset = RoundUp(
shstrtab_builder_.section_.sh_offset + shstrtab_builder_.section_.sh_size,
- sizeof(Elf32_Word));
+ sizeof(Elf_Word));
// Setup the actual symbol arrays.
- std::vector<Elf32_Sym> dynsym = dynsym_builder_.GenerateSymtab();
- CHECK_EQ(dynsym.size() * sizeof(Elf32_Sym), dynsym_builder_.section_.sh_size);
- std::vector<Elf32_Sym> symtab;
+ std::vector<Elf_Sym> dynsym = dynsym_builder_.GenerateSymtab();
+ CHECK_EQ(dynsym.size() * sizeof(Elf_Sym), dynsym_builder_.section_.sh_size);
+ std::vector<Elf_Sym> symtab;
if (IncludingDebugSymbols()) {
symtab = symtab_builder_.GenerateSymtab();
- CHECK_EQ(symtab.size() * sizeof(Elf32_Sym), symtab_builder_.section_.sh_size);
+ CHECK_EQ(symtab.size() * sizeof(Elf_Sym), symtab_builder_.section_.sh_size);
}
// Setup the dynamic section.
// This will add the 2 values we cannot know until now time, namely the size
// and the soname_offset.
- std::vector<Elf32_Dyn> dynamic = dynamic_builder_.GetDynamics(dynstr_.size(),
+ std::vector<Elf_Dyn> dynamic = dynamic_builder_.GetDynamics(dynstr_.size(),
dynstr_soname_offset_);
- CHECK_EQ(dynamic.size() * sizeof(Elf32_Dyn), dynamic_builder_.section_.sh_size);
+ CHECK_EQ(dynamic.size() * sizeof(Elf_Dyn), dynamic_builder_.section_.sh_size);
// Finish setup of the program headers now that we know the layout of the
// whole file.
- Elf32_Word load_r_size = rodata_builder_.section_.sh_offset + rodata_builder_.section_.sh_size;
+ Elf_Word load_r_size = rodata_builder_.section_.sh_offset + rodata_builder_.section_.sh_size;
program_headers_[PH_LOAD_R__].p_filesz = load_r_size;
program_headers_[PH_LOAD_R__].p_memsz = load_r_size;
program_headers_[PH_LOAD_R__].p_align = rodata_builder_.section_.sh_addralign;
- Elf32_Word load_rx_size = text_builder_.section_.sh_size;
+ Elf_Word load_rx_size = text_builder_.section_.sh_size;
program_headers_[PH_LOAD_R_X].p_offset = text_builder_.section_.sh_offset;
program_headers_[PH_LOAD_R_X].p_vaddr = text_builder_.section_.sh_offset;
program_headers_[PH_LOAD_R_X].p_paddr = text_builder_.section_.sh_offset;
@@ -502,18 +519,18 @@ bool ElfWriterQuick::ElfBuilder::Write() {
pieces.push_back(ElfFilePiece(".dynamic", dynamic_builder_.section_.sh_offset,
dynamic.data(), dynamic_builder_.section_.sh_size));
pieces.push_back(ElfFilePiece(".dynsym", dynsym_builder_.section_.sh_offset,
- dynsym.data(), dynsym.size() * sizeof(Elf32_Sym)));
+ dynsym.data(), dynsym.size() * sizeof(Elf_Sym)));
pieces.push_back(ElfFilePiece(".dynstr", dynsym_builder_.strtab_.section_.sh_offset,
dynstr_.c_str(), dynstr_.size()));
pieces.push_back(ElfFilePiece(".hash", hash_builder_.section_.sh_offset,
- hash_.data(), hash_.size() * sizeof(Elf32_Word)));
+ hash_.data(), hash_.size() * sizeof(Elf_Word)));
pieces.push_back(ElfFilePiece(".rodata", rodata_builder_.section_.sh_offset,
nullptr, rodata_builder_.section_.sh_size));
pieces.push_back(ElfFilePiece(".text", text_builder_.section_.sh_offset,
nullptr, text_builder_.section_.sh_size));
if (IncludingDebugSymbols()) {
pieces.push_back(ElfFilePiece(".symtab", symtab_builder_.section_.sh_offset,
- symtab.data(), symtab.size() * sizeof(Elf32_Sym)));
+ symtab.data(), symtab.size() * sizeof(Elf_Sym)));
pieces.push_back(ElfFilePiece(".strtab", symtab_builder_.strtab_.section_.sh_offset,
strtab.c_str(), strtab.size()));
}
@@ -522,9 +539,9 @@ bool ElfWriterQuick::ElfBuilder::Write() {
for (uint32_t i = 0; i < section_ptrs_.size(); ++i) {
// Just add all the sections in induvidually since they are all over the
// place on the heap/stack.
- Elf32_Word cur_off = sections_offset + i * sizeof(Elf32_Shdr);
+ Elf_Word cur_off = sections_offset + i * sizeof(Elf_Shdr);
pieces.push_back(ElfFilePiece("section table piece", cur_off,
- section_ptrs_[i], sizeof(Elf32_Shdr)));
+ section_ptrs_[i], sizeof(Elf_Shdr)));
}
if (!WriteOutFile(pieces)) {
@@ -532,7 +549,7 @@ bool ElfWriterQuick::ElfBuilder::Write() {
return false;
}
// write out the actual oat file data.
- Elf32_Word oat_data_offset = rodata_builder_.section_.sh_offset;
+ Elf_Word oat_data_offset = rodata_builder_.section_.sh_offset;
if (static_cast<off_t>(oat_data_offset) != lseek(elf_file_->Fd(), oat_data_offset, SEEK_SET)) {
PLOG(ERROR) << "Failed to seek to .rodata offset " << oat_data_offset
<< " for " << elf_file_->GetPath();
@@ -548,7 +565,11 @@ bool ElfWriterQuick::ElfBuilder::Write() {
return true;
}
-bool ElfWriterQuick::ElfBuilder::WriteOutFile(const std::vector<ElfFilePiece>& pieces) {
+template <typename Elf_Word, typename Elf_Sword, typename Elf_Addr,
+ typename Elf_Dyn, typename Elf_Sym, typename Elf_Ehdr,
+ typename Elf_Phdr, typename Elf_Shdr>
+bool ElfWriterQuick<Elf_Word, Elf_Sword, Elf_Addr, Elf_Dyn,
+ Elf_Sym, Elf_Ehdr, Elf_Phdr, Elf_Shdr>::ElfBuilder::WriteOutFile(const std::vector<ElfFilePiece>& pieces) {
// TODO It would be nice if this checked for overlap.
for (auto it = pieces.begin(); it != pieces.end(); ++it) {
if (it->data_) {
@@ -566,14 +587,22 @@ bool ElfWriterQuick::ElfBuilder::WriteOutFile(const std::vector<ElfFilePiece>& p
return true;
}
-void ElfWriterQuick::ElfBuilder::SetupDynamic() {
+template <typename Elf_Word, typename Elf_Sword, typename Elf_Addr,
+ typename Elf_Dyn, typename Elf_Sym, typename Elf_Ehdr,
+ typename Elf_Phdr, typename Elf_Shdr>
+void ElfWriterQuick<Elf_Word, Elf_Sword, Elf_Addr, Elf_Dyn,
+ Elf_Sym, Elf_Ehdr, Elf_Phdr, Elf_Shdr>::ElfBuilder::SetupDynamic() {
dynamic_builder_.AddDynamicTag(DT_HASH, 0, &hash_builder_);
dynamic_builder_.AddDynamicTag(DT_STRTAB, 0, &dynsym_builder_.strtab_);
dynamic_builder_.AddDynamicTag(DT_SYMTAB, 0, &dynsym_builder_);
- dynamic_builder_.AddDynamicTag(DT_SYMENT, sizeof(Elf32_Sym));
+ dynamic_builder_.AddDynamicTag(DT_SYMENT, sizeof(Elf_Sym));
}
-void ElfWriterQuick::ElfBuilder::SetupRequiredSymbols() {
+template <typename Elf_Word, typename Elf_Sword, typename Elf_Addr,
+ typename Elf_Dyn, typename Elf_Sym, typename Elf_Ehdr,
+ typename Elf_Phdr, typename Elf_Shdr>
+void ElfWriterQuick<Elf_Word, Elf_Sword, Elf_Addr, Elf_Dyn,
+ Elf_Sym, Elf_Ehdr, Elf_Phdr, Elf_Shdr>::ElfBuilder::SetupRequiredSymbols() {
dynsym_builder_.AddSymbol("oatdata", &rodata_builder_, 0, true,
rodata_builder_.size_, STB_GLOBAL, STT_OBJECT);
dynsym_builder_.AddSymbol("oatexec", &text_builder_, 0, true,
@@ -582,14 +611,22 @@ void ElfWriterQuick::ElfBuilder::SetupRequiredSymbols() {
true, 4, STB_GLOBAL, STT_OBJECT);
}
-void ElfWriterQuick::ElfDynamicBuilder::AddDynamicTag(Elf32_Sword tag, Elf32_Word d_un) {
+template <typename Elf_Word, typename Elf_Sword, typename Elf_Addr,
+ typename Elf_Dyn, typename Elf_Sym, typename Elf_Ehdr,
+ typename Elf_Phdr, typename Elf_Shdr>
+void ElfWriterQuick<Elf_Word, Elf_Sword, Elf_Addr, Elf_Dyn,
+ Elf_Sym, Elf_Ehdr, Elf_Phdr, Elf_Shdr>::ElfDynamicBuilder::AddDynamicTag(Elf_Sword tag, Elf_Word d_un) {
if (tag == DT_NULL) {
return;
}
dynamics_.push_back({nullptr, tag, d_un});
}
-void ElfWriterQuick::ElfDynamicBuilder::AddDynamicTag(Elf32_Sword tag, Elf32_Word d_un,
+template <typename Elf_Word, typename Elf_Sword, typename Elf_Addr,
+ typename Elf_Dyn, typename Elf_Sym, typename Elf_Ehdr,
+ typename Elf_Phdr, typename Elf_Shdr>
+void ElfWriterQuick<Elf_Word, Elf_Sword, Elf_Addr, Elf_Dyn,
+ Elf_Sym, Elf_Ehdr, Elf_Phdr, Elf_Shdr>::ElfDynamicBuilder::AddDynamicTag(Elf_Sword tag, Elf_Word d_un,
ElfSectionBuilder* section) {
if (tag == DT_NULL) {
return;
@@ -597,9 +634,13 @@ void ElfWriterQuick::ElfDynamicBuilder::AddDynamicTag(Elf32_Sword tag, Elf32_Wor
dynamics_.push_back({section, tag, d_un});
}
-std::vector<Elf32_Dyn> ElfWriterQuick::ElfDynamicBuilder::GetDynamics(Elf32_Word strsz,
- Elf32_Word soname) {
- std::vector<Elf32_Dyn> ret;
+template <typename Elf_Word, typename Elf_Sword, typename Elf_Addr,
+ typename Elf_Dyn, typename Elf_Sym, typename Elf_Ehdr,
+ typename Elf_Phdr, typename Elf_Shdr>
+std::vector<Elf_Dyn> ElfWriterQuick<Elf_Word, Elf_Sword, Elf_Addr, Elf_Dyn,
+ Elf_Sym, Elf_Ehdr, Elf_Phdr, Elf_Shdr>::ElfDynamicBuilder::GetDynamics(Elf_Word strsz,
+ Elf_Word soname) {
+ std::vector<Elf_Dyn> ret;
for (auto it = dynamics_.cbegin(); it != dynamics_.cend(); ++it) {
if (it->section_) {
// We are adding an address relative to a section.
@@ -615,15 +656,19 @@ std::vector<Elf32_Dyn> ElfWriterQuick::ElfDynamicBuilder::GetDynamics(Elf32_Word
return ret;
}
-std::vector<Elf32_Sym> ElfWriterQuick::ElfSymtabBuilder::GenerateSymtab() {
- std::vector<Elf32_Sym> ret;
- Elf32_Sym undef_sym;
+template <typename Elf_Word, typename Elf_Sword, typename Elf_Addr,
+ typename Elf_Dyn, typename Elf_Sym, typename Elf_Ehdr,
+ typename Elf_Phdr, typename Elf_Shdr>
+std::vector<Elf_Sym> ElfWriterQuick<Elf_Word, Elf_Sword, Elf_Addr, Elf_Dyn,
+ Elf_Sym, Elf_Ehdr, Elf_Phdr, Elf_Shdr>::ElfSymtabBuilder::GenerateSymtab() {
+ std::vector<Elf_Sym> ret;
+ Elf_Sym undef_sym;
memset(&undef_sym, 0, sizeof(undef_sym));
undef_sym.st_shndx = SHN_UNDEF;
ret.push_back(undef_sym);
for (auto it = symbols_.cbegin(); it != symbols_.cend(); ++it) {
- Elf32_Sym sym;
+ Elf_Sym sym;
memset(&sym, 0, sizeof(sym));
sym.st_name = it->name_idx_;
if (it->is_relative_) {
@@ -641,7 +686,11 @@ std::vector<Elf32_Sym> ElfWriterQuick::ElfSymtabBuilder::GenerateSymtab() {
return ret;
}
-std::string ElfWriterQuick::ElfSymtabBuilder::GenerateStrtab() {
+template <typename Elf_Word, typename Elf_Sword, typename Elf_Addr,
+ typename Elf_Dyn, typename Elf_Sym, typename Elf_Ehdr,
+ typename Elf_Phdr, typename Elf_Shdr>
+std::string ElfWriterQuick<Elf_Word, Elf_Sword, Elf_Addr, Elf_Dyn,
+ Elf_Sym, Elf_Ehdr, Elf_Phdr, Elf_Shdr>::ElfSymtabBuilder::GenerateStrtab() {
std::string tab;
tab += '\0';
for (auto it = symbols_.begin(); it != symbols_.end(); ++it) {
@@ -653,7 +702,11 @@ std::string ElfWriterQuick::ElfSymtabBuilder::GenerateStrtab() {
return tab;
}
-void ElfWriterQuick::ElfBuilder::AssignSectionStr(
+template <typename Elf_Word, typename Elf_Sword, typename Elf_Addr,
+ typename Elf_Dyn, typename Elf_Sym, typename Elf_Ehdr,
+ typename Elf_Phdr, typename Elf_Shdr>
+void ElfWriterQuick<Elf_Word, Elf_Sword, Elf_Addr, Elf_Dyn,
+ Elf_Sym, Elf_Ehdr, Elf_Phdr, Elf_Shdr>::ElfBuilder::AssignSectionStr(
ElfSectionBuilder* builder, std::string* strtab) {
builder->section_.sh_name = strtab->size();
*strtab += builder->name_;
@@ -678,8 +731,11 @@ static unsigned elfhash(const char *_name) {
return h;
}
-
-std::vector<Elf32_Word> ElfWriterQuick::ElfSymtabBuilder::GenerateHashContents() {
+template <typename Elf_Word, typename Elf_Sword, typename Elf_Addr,
+ typename Elf_Dyn, typename Elf_Sym, typename Elf_Ehdr,
+ typename Elf_Phdr, typename Elf_Shdr>
+std::vector<Elf_Word> ElfWriterQuick<Elf_Word, Elf_Sword, Elf_Addr, Elf_Dyn,
+ Elf_Sym, Elf_Ehdr, Elf_Phdr, Elf_Shdr>::ElfSymtabBuilder::GenerateHashContents() {
// Here is how The ELF hash table works.
// There are 3 arrays to worry about.
// * The symbol table where the symbol information is.
@@ -713,8 +769,8 @@ std::vector<Elf32_Word> ElfWriterQuick::ElfSymtabBuilder::GenerateHashContents()
// Select number of buckets.
// This is essentially arbitrary.
- Elf32_Word nbuckets;
- Elf32_Word chain_size = GetSize();
+ Elf_Word nbuckets;
+ Elf_Word chain_size = GetSize();
if (symbols_.size() < 8) {
nbuckets = 2;
} else if (symbols_.size() < 32) {
@@ -725,22 +781,22 @@ std::vector<Elf32_Word> ElfWriterQuick::ElfSymtabBuilder::GenerateHashContents()
// Have about 32 ids per bucket.
nbuckets = RoundUp(symbols_.size()/32, 2);
}
- std::vector<Elf32_Word> hash;
+ std::vector<Elf_Word> hash;
hash.push_back(nbuckets);
hash.push_back(chain_size);
uint32_t bucket_offset = hash.size();
uint32_t chain_offset = bucket_offset + nbuckets;
hash.resize(hash.size() + nbuckets + chain_size, 0);
- Elf32_Word* buckets = hash.data() + bucket_offset;
- Elf32_Word* chain = hash.data() + chain_offset;
+ Elf_Word* buckets = hash.data() + bucket_offset;
+ Elf_Word* chain = hash.data() + chain_offset;
// Set up the actual hash table.
- for (Elf32_Word i = 0; i < symbols_.size(); i++) {
+ for (Elf_Word i = 0; i < symbols_.size(); i++) {
// Add 1 since we need to have the null symbol that is not in the symbols
// list.
- Elf32_Word index = i + 1;
- Elf32_Word hash_val = static_cast<Elf32_Word>(elfhash(symbols_[i].name_.c_str())) % nbuckets;
+ Elf_Word index = i + 1;
+ Elf_Word hash_val = static_cast<Elf_Word>(elfhash(symbols_[i].name_.c_str())) % nbuckets;
if (buckets[hash_val] == 0) {
buckets[hash_val] = index;
} else {
@@ -754,14 +810,18 @@ std::vector<Elf32_Word> ElfWriterQuick::ElfSymtabBuilder::GenerateHashContents()
// Check for loops. Works because if this is non-empty then there must be
// another cell which already contains the same symbol index as this one,
// which means some symbol has more then one name, which isn't allowed.
- CHECK_EQ(chain[index], static_cast<Elf32_Word>(0));
+ CHECK_EQ(chain[index], static_cast<Elf_Word>(0));
}
}
return hash;
}
-void ElfWriterQuick::ElfBuilder::SetupEhdr() {
+template <typename Elf_Word, typename Elf_Sword, typename Elf_Addr,
+ typename Elf_Dyn, typename Elf_Sym, typename Elf_Ehdr,
+ typename Elf_Phdr, typename Elf_Shdr>
+void ElfWriterQuick<Elf_Word, Elf_Sword, Elf_Addr, Elf_Dyn,
+ Elf_Sym, Elf_Ehdr, Elf_Phdr, Elf_Shdr>::ElfBuilder::SetupEhdr() {
memset(&elf_header_, 0, sizeof(elf_header_));
elf_header_.e_ident[EI_MAG0] = ELFMAG0;
elf_header_.e_ident[EI_MAG1] = ELFMAG1;
@@ -775,13 +835,17 @@ void ElfWriterQuick::ElfBuilder::SetupEhdr() {
elf_header_.e_type = ET_DYN;
elf_header_.e_version = 1;
elf_header_.e_entry = 0;
- elf_header_.e_ehsize = sizeof(Elf32_Ehdr);
- elf_header_.e_phentsize = sizeof(Elf32_Phdr);
- elf_header_.e_shentsize = sizeof(Elf32_Shdr);
- elf_header_.e_phoff = sizeof(Elf32_Ehdr);
+ elf_header_.e_ehsize = sizeof(Elf_Ehdr);
+ elf_header_.e_phentsize = sizeof(Elf_Phdr);
+ elf_header_.e_shentsize = sizeof(Elf_Shdr);
+ elf_header_.e_phoff = sizeof(Elf_Ehdr);
}
-void ElfWriterQuick::ElfBuilder::SetISA(InstructionSet isa) {
+template <typename Elf_Word, typename Elf_Sword, typename Elf_Addr,
+ typename Elf_Dyn, typename Elf_Sym, typename Elf_Ehdr,
+ typename Elf_Phdr, typename Elf_Shdr>
+void ElfWriterQuick<Elf_Word, Elf_Sword, Elf_Addr, Elf_Dyn,
+ Elf_Sym, Elf_Ehdr, Elf_Phdr, Elf_Shdr>::ElfBuilder::SetISA(InstructionSet isa) {
switch (isa) {
case kArm:
// Fall through.
@@ -822,16 +886,24 @@ void ElfWriterQuick::ElfBuilder::SetISA(InstructionSet isa) {
}
}
-void ElfWriterQuick::ElfSymtabBuilder::AddSymbol(
- const std::string& name, const ElfSectionBuilder* section, Elf32_Addr addr,
- bool is_relative, Elf32_Word size, uint8_t binding, uint8_t type, uint8_t other) {
+template <typename Elf_Word, typename Elf_Sword, typename Elf_Addr,
+ typename Elf_Dyn, typename Elf_Sym, typename Elf_Ehdr,
+ typename Elf_Phdr, typename Elf_Shdr>
+void ElfWriterQuick<Elf_Word, Elf_Sword, Elf_Addr, Elf_Dyn,
+ Elf_Sym, Elf_Ehdr, Elf_Phdr, Elf_Shdr>::ElfSymtabBuilder::AddSymbol(
+ const std::string& name, const ElfSectionBuilder* section, Elf_Addr addr,
+ bool is_relative, Elf_Word size, uint8_t binding, uint8_t type, uint8_t other) {
CHECK(section);
ElfSymtabBuilder::ElfSymbolState state {name, section, addr, size, is_relative,
MakeStInfo(binding, type), other, 0};
symbols_.push_back(state);
}
-bool ElfWriterQuick::Create(File* elf_file,
+template <typename Elf_Word, typename Elf_Sword, typename Elf_Addr,
+ typename Elf_Dyn, typename Elf_Sym, typename Elf_Ehdr,
+ typename Elf_Phdr, typename Elf_Shdr>
+bool ElfWriterQuick<Elf_Word, Elf_Sword, Elf_Addr, Elf_Dyn,
+ Elf_Sym, Elf_Ehdr, Elf_Phdr, Elf_Shdr>::Create(File* elf_file,
OatWriter* oat_writer,
const std::vector<const DexFile*>& dex_files,
const std::string& android_root,
@@ -841,9 +913,13 @@ bool ElfWriterQuick::Create(File* elf_file,
return elf_writer.Write(oat_writer, dex_files, android_root, is_host);
}
-// Add patch information to this section. Each patch is a Elf32_Word that
+template <typename Elf_Word, typename Elf_Sword, typename Elf_Addr,
+ typename Elf_Dyn, typename Elf_Sym, typename Elf_Ehdr,
+ typename Elf_Phdr, typename Elf_Shdr>
+// Add patch information to this section. Each patch is a Elf_Word that
// identifies an offset from the start of the text section
-void ElfWriterQuick::ReservePatchSpace(std::vector<uint8_t>* buffer, bool debug) {
+void ElfWriterQuick<Elf_Word, Elf_Sword, Elf_Addr, Elf_Dyn,
+ Elf_Sym, Elf_Ehdr, Elf_Phdr, Elf_Shdr>::ReservePatchSpace(std::vector<uint8_t>* buffer, bool debug) {
size_t size =
compiler_driver_->GetCodeToPatch().size() +
compiler_driver_->GetMethodsToPatch().size() +
@@ -970,13 +1046,17 @@ std::vector<uint8_t>* ConstructCIEFrame(InstructionSet isa) {
}
}
-bool ElfWriterQuick::Write(OatWriter* oat_writer,
+template <typename Elf_Word, typename Elf_Sword, typename Elf_Addr,
+ typename Elf_Dyn, typename Elf_Sym, typename Elf_Ehdr,
+ typename Elf_Phdr, typename Elf_Shdr>
+bool ElfWriterQuick<Elf_Word, Elf_Sword, Elf_Addr, Elf_Dyn,
+ Elf_Sym, Elf_Ehdr, Elf_Phdr, Elf_Shdr>::Write(OatWriter* oat_writer,
const std::vector<const DexFile*>& dex_files_unused,
const std::string& android_root_unused,
bool is_host_unused) {
constexpr bool debug = false;
const OatHeader& oat_header = oat_writer->GetOatHeader();
- Elf32_Word oat_data_size = oat_header.GetExecutableOffset();
+ Elf_Word oat_data_size = oat_header.GetExecutableOffset();
uint32_t oat_exec_size = oat_writer->GetSize() - oat_data_size;
ElfBuilder builder(oat_writer, elf_file_, compiler_driver_->GetInstructionSet(), 0,
@@ -1002,11 +1082,15 @@ bool ElfWriterQuick::Write(OatWriter* oat_writer,
return builder.Write();
}
-void ElfWriterQuick::WriteDebugSymbols(ElfBuilder* builder, OatWriter* oat_writer) {
+template <typename Elf_Word, typename Elf_Sword, typename Elf_Addr,
+ typename Elf_Dyn, typename Elf_Sym, typename Elf_Ehdr,
+ typename Elf_Phdr, typename Elf_Shdr>
+void ElfWriterQuick<Elf_Word, Elf_Sword, Elf_Addr, Elf_Dyn,
+ Elf_Sym, Elf_Ehdr, Elf_Phdr, Elf_Shdr>::WriteDebugSymbols(ElfBuilder* builder, OatWriter* oat_writer) {
std::unique_ptr<std::vector<uint8_t>> cfi_info(
ConstructCIEFrame(compiler_driver_->GetInstructionSet()));
- Elf32_Addr text_section_address = builder->text_builder_.section_.sh_addr;
+ Elf_Addr text_section_address = builder->text_builder_.section_.sh_addr;
// Iterate over the compiled methods.
const std::vector<OatWriter::DebugInfo>& method_info = oat_writer->GetCFIMethodInfo();
@@ -1259,7 +1343,11 @@ static void GetLineInfoForJava(const uint8_t* dbgstream, const SrcMap& pc2dex,
}
}
-void ElfWriterQuick::FillInCFIInformation(OatWriter* oat_writer,
+template <typename Elf_Word, typename Elf_Sword, typename Elf_Addr,
+ typename Elf_Dyn, typename Elf_Sym, typename Elf_Ehdr,
+ typename Elf_Phdr, typename Elf_Shdr>
+void ElfWriterQuick<Elf_Word, Elf_Sword, Elf_Addr, Elf_Dyn,
+ Elf_Sym, Elf_Ehdr, Elf_Phdr, Elf_Shdr>::FillInCFIInformation(OatWriter* oat_writer,
std::vector<uint8_t>* dbg_info,
std::vector<uint8_t>* dbg_abbrev,
std::vector<uint8_t>* dbg_str,
@@ -1492,4 +1580,10 @@ void ElfWriterQuick::FillInCFIInformation(OatWriter* oat_writer,
UpdateWord(dbg_info, cunit_length, dbg_info->size() - cunit_length - 4);
}
+// Explicit instantiations
+template class ElfWriterQuick<Elf32_Word, Elf32_Sword, Elf32_Addr, Elf32_Dyn,
+ Elf32_Sym, Elf32_Ehdr, Elf32_Phdr, Elf32_Shdr>;
+template class ElfWriterQuick<Elf64_Word, Elf64_Sword, Elf64_Addr, Elf64_Dyn,
+ Elf64_Sym, Elf64_Ehdr, Elf64_Phdr, Elf64_Shdr>;
+
} // namespace art
diff --git a/compiler/elf_writer_quick.h b/compiler/elf_writer_quick.h
index c7ef872..890528e 100644
--- a/compiler/elf_writer_quick.h
+++ b/compiler/elf_writer_quick.h
@@ -23,6 +23,9 @@
namespace art {
+template <typename Elf_Word, typename Elf_Sword, typename Elf_Addr,
+ typename Elf_Dyn, typename Elf_Sym, typename Elf_Ehdr,
+ typename Elf_Phdr, typename Elf_Shdr>
class ElfWriterQuick FINAL : public ElfWriter {
public:
// Write an ELF file. Returns true on success, false on failure.
@@ -53,9 +56,9 @@ class ElfWriterQuick FINAL : public ElfWriter {
class ElfSectionBuilder {
public:
- ElfSectionBuilder(const std::string& sec_name, Elf32_Word type, Elf32_Word flags,
- const ElfSectionBuilder *link, Elf32_Word info, Elf32_Word align,
- Elf32_Word entsize)
+ ElfSectionBuilder(const std::string& sec_name, Elf_Word type, Elf_Word flags,
+ const ElfSectionBuilder *link, Elf_Word info, Elf_Word align,
+ Elf_Word entsize)
: name_(sec_name), link_(link) {
memset(&section_, 0, sizeof(section_));
section_.sh_type = type;
@@ -67,14 +70,14 @@ class ElfWriterQuick FINAL : public ElfWriter {
virtual ~ElfSectionBuilder() {}
- Elf32_Shdr section_;
- Elf32_Word section_index_ = 0;
+ Elf_Shdr section_;
+ Elf_Word section_index_ = 0;
protected:
const std::string name_;
const ElfSectionBuilder* link_;
- Elf32_Word GetLink() {
+ Elf_Word GetLink() {
return (link_) ? link_->section_index_ : 0;
}
@@ -84,22 +87,22 @@ class ElfWriterQuick FINAL : public ElfWriter {
class ElfDynamicBuilder : public ElfSectionBuilder {
public:
- void AddDynamicTag(Elf32_Sword tag, Elf32_Word d_un);
- void AddDynamicTag(Elf32_Sword tag, Elf32_Word offset, ElfSectionBuilder* section);
+ void AddDynamicTag(Elf_Sword tag, Elf_Word d_un);
+ void AddDynamicTag(Elf_Sword tag, Elf_Word offset, ElfSectionBuilder* section);
ElfDynamicBuilder(const std::string& sec_name, ElfSectionBuilder *link)
: ElfSectionBuilder(sec_name, SHT_DYNAMIC, SHF_ALLOC | SHF_ALLOC, link,
- 0, kPageSize, sizeof(Elf32_Dyn)) {}
+ 0, kPageSize, sizeof(Elf_Dyn)) {}
~ElfDynamicBuilder() {}
protected:
struct ElfDynamicState {
ElfSectionBuilder* section_;
- Elf32_Sword tag_;
- Elf32_Word off_;
+ Elf_Sword tag_;
+ Elf_Word off_;
};
std::vector<ElfDynamicState> dynamics_;
- Elf32_Word GetSize() {
+ Elf_Word GetSize() {
// Add 1 for the DT_NULL, 1 for DT_STRSZ, and 1 for DT_SONAME. All of
// these must be added when we actually put the file together because
// their values are very dependent on state.
@@ -110,7 +113,7 @@ class ElfWriterQuick FINAL : public ElfWriter {
// table and soname_off should be the offset of the soname in .dynstr.
// Since niether can be found prior to final layout we will wait until here
// to add them.
- std::vector<Elf32_Dyn> GetDynamics(Elf32_Word strsz, Elf32_Word soname_off);
+ std::vector<Elf_Dyn> GetDynamics(Elf_Word strsz, Elf_Word soname_off);
private:
friend class ElfBuilder;
@@ -118,9 +121,9 @@ class ElfWriterQuick FINAL : public ElfWriter {
class ElfRawSectionBuilder : public ElfSectionBuilder {
public:
- ElfRawSectionBuilder(const std::string& sec_name, Elf32_Word type, Elf32_Word flags,
- const ElfSectionBuilder* link, Elf32_Word info, Elf32_Word align,
- Elf32_Word entsize)
+ ElfRawSectionBuilder(const std::string& sec_name, Elf_Word type, Elf_Word flags,
+ const ElfSectionBuilder* link, Elf_Word info, Elf_Word align,
+ Elf_Word entsize)
: ElfSectionBuilder(sec_name, type, flags, link, info, align, entsize) {}
~ElfRawSectionBuilder() {}
std::vector<uint8_t>* GetBuffer() { return &buf_; }
@@ -135,17 +138,17 @@ class ElfWriterQuick FINAL : public ElfWriter {
class ElfOatSectionBuilder : public ElfSectionBuilder {
public:
- ElfOatSectionBuilder(const std::string& sec_name, Elf32_Word size, Elf32_Word offset,
- Elf32_Word type, Elf32_Word flags)
+ ElfOatSectionBuilder(const std::string& sec_name, Elf_Word size, Elf_Word offset,
+ Elf_Word type, Elf_Word flags)
: ElfSectionBuilder(sec_name, type, flags, NULL, 0, kPageSize, 0),
offset_(offset), size_(size) {}
~ElfOatSectionBuilder() {}
protected:
// Offset of the content within the file.
- Elf32_Word offset_;
+ Elf_Word offset_;
// Size of the content within the file.
- Elf32_Word size_;
+ Elf_Word size_;
private:
friend class ElfBuilder;
@@ -157,27 +160,27 @@ class ElfWriterQuick FINAL : public ElfWriter {
// 'relative_addr' within the given section and has the given attributes.
void AddSymbol(const std::string& name,
const ElfSectionBuilder* section,
- Elf32_Addr addr,
+ Elf_Addr addr,
bool is_relative,
- Elf32_Word size,
+ Elf_Word size,
uint8_t binding,
uint8_t type,
uint8_t other = 0);
- ElfSymtabBuilder(const std::string& sec_name, Elf32_Word type,
- const std::string& str_name, Elf32_Word str_type, bool alloc)
+ ElfSymtabBuilder(const std::string& sec_name, Elf_Word type,
+ const std::string& str_name, Elf_Word str_type, bool alloc)
: ElfSectionBuilder(sec_name, type, ((alloc) ? SHF_ALLOC : 0U), &strtab_, 0,
- sizeof(Elf32_Word), sizeof(Elf32_Sym)),
+ sizeof(Elf_Word), sizeof(Elf_Sym)),
str_name_(str_name), str_type_(str_type),
strtab_(str_name, str_type, ((alloc) ? SHF_ALLOC : 0U), NULL, 0, 1, 1) {}
~ElfSymtabBuilder() {}
protected:
- std::vector<Elf32_Word> GenerateHashContents();
+ std::vector<Elf_Word> GenerateHashContents();
std::string GenerateStrtab();
- std::vector<Elf32_Sym> GenerateSymtab();
+ std::vector<Elf_Sym> GenerateSymtab();
- Elf32_Word GetSize() {
+ Elf_Word GetSize() {
// 1 is for the implicit NULL symbol.
return symbols_.size() + 1;
}
@@ -185,18 +188,18 @@ class ElfWriterQuick FINAL : public ElfWriter {
struct ElfSymbolState {
const std::string name_;
const ElfSectionBuilder* section_;
- Elf32_Addr addr_;
- Elf32_Word size_;
+ Elf_Addr addr_;
+ Elf_Word size_;
bool is_relative_;
uint8_t info_;
uint8_t other_;
// Used during Write() to temporarially hold name index in the strtab.
- Elf32_Word name_idx_;
+ Elf_Word name_idx_;
};
// Information for the strsym for dynstr sections.
const std::string str_name_;
- Elf32_Word str_type_;
+ Elf_Word str_type_;
// The symbols in the same order they will be in the symbol table.
std::vector<ElfSymbolState> symbols_;
ElfSectionBuilder strtab_;
@@ -210,10 +213,10 @@ class ElfWriterQuick FINAL : public ElfWriter {
ElfBuilder(OatWriter* oat_writer,
File* elf_file,
InstructionSet isa,
- Elf32_Word rodata_relative_offset,
- Elf32_Word rodata_size,
- Elf32_Word text_relative_offset,
- Elf32_Word text_size,
+ Elf_Word rodata_relative_offset,
+ Elf_Word rodata_size,
+ Elf_Word text_relative_offset,
+ Elf_Word text_size,
const bool add_symbols,
bool debug = false)
: oat_writer_(oat_writer),
@@ -227,7 +230,7 @@ class ElfWriterQuick FINAL : public ElfWriter {
dynsym_builder_(".dynsym", SHT_DYNSYM, ".dynstr", SHT_STRTAB, true),
symtab_builder_(".symtab", SHT_SYMTAB, ".strtab", SHT_STRTAB, false),
hash_builder_(".hash", SHT_HASH, SHF_ALLOC, &dynsym_builder_, 0,
- sizeof(Elf32_Word), sizeof(Elf32_Word)),
+ sizeof(Elf_Word), sizeof(Elf_Word)),
dynamic_builder_(".dynamic", &dynsym_builder_),
shstrtab_builder_(".shstrtab", SHT_STRTAB, 0, NULL, 0, 1, 1) {
SetupEhdr();
@@ -255,7 +258,7 @@ class ElfWriterQuick FINAL : public ElfWriter {
bool fatal_error_ = false;
// What phdr is.
- static const uint32_t PHDR_OFFSET = sizeof(Elf32_Ehdr);
+ static const uint32_t PHDR_OFFSET = sizeof(Elf_Ehdr);
enum : uint8_t {
PH_PHDR = 0,
PH_LOAD_R__ = 1,
@@ -264,18 +267,18 @@ class ElfWriterQuick FINAL : public ElfWriter {
PH_DYNAMIC = 4,
PH_NUM = 5,
};
- static const uint32_t PHDR_SIZE = sizeof(Elf32_Phdr) * PH_NUM;
- Elf32_Phdr program_headers_[PH_NUM];
+ static const uint32_t PHDR_SIZE = sizeof(Elf_Phdr) * PH_NUM;
+ Elf_Phdr program_headers_[PH_NUM];
- Elf32_Ehdr elf_header_;
+ Elf_Ehdr elf_header_;
- Elf32_Shdr null_hdr_;
+ Elf_Shdr null_hdr_;
std::string shstrtab_;
uint32_t section_index_;
std::string dynstr_;
uint32_t dynstr_soname_offset_;
- std::vector<Elf32_Shdr*> section_ptrs_;
- std::vector<Elf32_Word> hash_;
+ std::vector<Elf_Shdr*> section_ptrs_;
+ std::vector<Elf_Word> hash_;
public:
ElfOatSectionBuilder text_builder_;
@@ -312,14 +315,14 @@ class ElfWriterQuick FINAL : public ElfWriter {
void SetupRequiredSymbols();
void AssignSectionStr(ElfSectionBuilder *builder, std::string* strtab);
struct ElfFilePiece {
- ElfFilePiece(const std::string& name, Elf32_Word offset, const void* data, Elf32_Word size)
+ ElfFilePiece(const std::string& name, Elf_Word offset, const void* data, Elf_Word size)
: dbg_name_(name), offset_(offset), data_(data), size_(size) {}
~ElfFilePiece() {}
const std::string& dbg_name_;
- Elf32_Word offset_;
+ Elf_Word offset_;
const void *data_;
- Elf32_Word size_;
+ Elf_Word size_;
static bool Compare(ElfFilePiece a, ElfFilePiece b) {
return a.offset_ < b.offset_;
}
@@ -344,6 +347,12 @@ class ElfWriterQuick FINAL : public ElfWriter {
DISALLOW_IMPLICIT_CONSTRUCTORS(ElfWriterQuick);
};
+// Explicitly instantiated in elf_writer_quick.cc
+typedef ElfWriterQuick<Elf32_Word, Elf32_Sword, Elf32_Addr, Elf32_Dyn,
+ Elf32_Sym, Elf32_Ehdr, Elf32_Phdr, Elf32_Shdr> ElfWriterQuick32;
+typedef ElfWriterQuick<Elf64_Word, Elf64_Sword, Elf64_Addr, Elf64_Dyn,
+ Elf64_Sym, Elf64_Ehdr, Elf64_Phdr, Elf64_Shdr> ElfWriterQuick64;
+
} // namespace art
#endif // ART_COMPILER_ELF_WRITER_QUICK_H_