Merge "Remove dependency on llvm/Support/ELF.h by using linux's elf.h."
diff --git a/compiler/elf_fixup.cc b/compiler/elf_fixup.cc
index 66c8da1..6fd4a73 100644
--- a/compiler/elf_fixup.cc
+++ b/compiler/elf_fixup.cc
@@ -16,6 +16,8 @@
#include "elf_fixup.h"
+#include <inttypes.h>
+
#include "base/logging.h"
#include "base/stringprintf.h"
#include "elf_file.h"
@@ -32,8 +34,8 @@
CHECK(elf_file.get() != nullptr) << error_msg;
// Lookup "oatdata" symbol address.
- ::llvm::ELF::Elf32_Addr oatdata_address = ElfWriter::GetOatDataAddress(elf_file.get());
- ::llvm::ELF::Elf32_Off base_address = oat_data_begin - oatdata_address;
+ Elf32_Addr oatdata_address = ElfWriter::GetOatDataAddress(elf_file.get());
+ Elf32_Off base_address = oat_data_begin - oatdata_address;
if (!FixupDynamic(*elf_file.get(), base_address)) {
LOG(WARNING) << "Failed fo fixup .dynamic in " << file->GetPath();
@@ -62,82 +64,65 @@
return true;
}
-// MIPS seems to break the rules d_val vs d_ptr even though their values are between DT_LOPROC and DT_HIPROC
-#define DT_MIPS_RLD_VERSION 0x70000001 // d_val
-#define DT_MIPS_TIME_STAMP 0x70000002 // d_val
-#define DT_MIPS_ICHECKSUM 0x70000003 // d_val
-#define DT_MIPS_IVERSION 0x70000004 // d_val
-#define DT_MIPS_FLAGS 0x70000005 // d_val
-#define DT_MIPS_BASE_ADDRESS 0x70000006 // d_ptr
-#define DT_MIPS_CONFLICT 0x70000008 // d_ptr
-#define DT_MIPS_LIBLIST 0x70000009 // d_ptr
-#define DT_MIPS_LOCAL_GOTNO 0x7000000A // d_val
-#define DT_MIPS_CONFLICTNO 0x7000000B // d_val
-#define DT_MIPS_LIBLISTNO 0x70000010 // d_val
-#define DT_MIPS_SYMTABNO 0x70000011 // d_val
-#define DT_MIPS_UNREFEXTNO 0x70000012 // d_val
-#define DT_MIPS_GOTSYM 0x70000013 // d_val
-#define DT_MIPS_HIPAGENO 0x70000014 // d_val
-#define DT_MIPS_RLD_MAP 0x70000016 // d_ptr
bool ElfFixup::FixupDynamic(ElfFile& elf_file, uintptr_t base_address) {
- for (::llvm::ELF::Elf32_Word i = 0; i < elf_file.GetDynamicNum(); i++) {
- ::llvm::ELF::Elf32_Dyn& elf_dyn = elf_file.GetDynamic(i);
- ::llvm::ELF::Elf32_Word d_tag = elf_dyn.d_tag;
+ for (Elf32_Word i = 0; i < elf_file.GetDynamicNum(); i++) {
+ Elf32_Dyn& elf_dyn = elf_file.GetDynamic(i);
+ Elf32_Word d_tag = elf_dyn.d_tag;
bool elf_dyn_needs_fixup = false;
switch (d_tag) {
// case 1: well known d_tag values that imply Elf32_Dyn.d_un contains an address in d_ptr
- case ::llvm::ELF::DT_PLTGOT:
- case ::llvm::ELF::DT_HASH:
- case ::llvm::ELF::DT_STRTAB:
- case ::llvm::ELF::DT_SYMTAB:
- case ::llvm::ELF::DT_RELA:
- case ::llvm::ELF::DT_INIT:
- case ::llvm::ELF::DT_FINI:
- case ::llvm::ELF::DT_REL:
- case ::llvm::ELF::DT_DEBUG:
- case ::llvm::ELF::DT_JMPREL: {
+ case DT_PLTGOT:
+ case DT_HASH:
+ case DT_STRTAB:
+ case DT_SYMTAB:
+ case DT_RELA:
+ case DT_INIT:
+ case DT_FINI:
+ case DT_REL:
+ case DT_DEBUG:
+ case DT_JMPREL: {
elf_dyn_needs_fixup = true;
break;
}
// d_val or ignored values
- case ::llvm::ELF::DT_NULL:
- case ::llvm::ELF::DT_NEEDED:
- case ::llvm::ELF::DT_PLTRELSZ:
- case ::llvm::ELF::DT_RELASZ:
- case ::llvm::ELF::DT_RELAENT:
- case ::llvm::ELF::DT_STRSZ:
- case ::llvm::ELF::DT_SYMENT:
- case ::llvm::ELF::DT_SONAME:
- case ::llvm::ELF::DT_RPATH:
- case ::llvm::ELF::DT_SYMBOLIC:
- case ::llvm::ELF::DT_RELSZ:
- case ::llvm::ELF::DT_RELENT:
- case ::llvm::ELF::DT_PLTREL:
- case ::llvm::ELF::DT_TEXTREL:
- case ::llvm::ELF::DT_BIND_NOW:
- case ::llvm::ELF::DT_INIT_ARRAYSZ:
- case ::llvm::ELF::DT_FINI_ARRAYSZ:
- case ::llvm::ELF::DT_RUNPATH:
- case ::llvm::ELF::DT_FLAGS: {
+ case DT_NULL:
+ case DT_NEEDED:
+ case DT_PLTRELSZ:
+ case DT_RELASZ:
+ case DT_RELAENT:
+ case DT_STRSZ:
+ case DT_SYMENT:
+ case DT_SONAME:
+ case DT_RPATH:
+ case DT_SYMBOLIC:
+ case DT_RELSZ:
+ case DT_RELENT:
+ case DT_PLTREL:
+ case DT_TEXTREL:
+ case DT_BIND_NOW:
+ case DT_INIT_ARRAYSZ:
+ case DT_FINI_ARRAYSZ:
+ case DT_RUNPATH:
+ case DT_FLAGS: {
break;
}
// boundary values that should not be used
- case ::llvm::ELF::DT_ENCODING:
- case ::llvm::ELF::DT_LOOS:
- case ::llvm::ELF::DT_HIOS:
- case ::llvm::ELF::DT_LOPROC:
- case ::llvm::ELF::DT_HIPROC: {
+ case DT_ENCODING:
+ case DT_LOOS:
+ case DT_HIOS:
+ case DT_LOPROC:
+ case DT_HIPROC: {
LOG(FATAL) << "Illegal d_tag value 0x" << std::hex << d_tag;
break;
}
default: {
// case 2: "regular" DT_* ranges where even d_tag values imply an address in d_ptr
- if ((::llvm::ELF::DT_ENCODING < d_tag && d_tag < ::llvm::ELF::DT_LOOS)
- || (::llvm::ELF::DT_LOOS < d_tag && d_tag < ::llvm::ELF::DT_HIOS)
- || (::llvm::ELF::DT_LOPROC < d_tag && d_tag < ::llvm::ELF::DT_HIPROC)) {
+ if ((DT_ENCODING < d_tag && d_tag < DT_LOOS)
+ || (DT_LOOS < d_tag && d_tag < DT_HIOS)
+ || (DT_LOPROC < d_tag && d_tag < DT_HIPROC)) {
// Special case for MIPS which breaks the regular rules between DT_LOPROC and DT_HIPROC
- if (elf_file.GetHeader().e_machine == ::llvm::ELF::EM_MIPS) {
+ if (elf_file.GetHeader().e_machine == EM_MIPS) {
switch (d_tag) {
case DT_MIPS_RLD_VERSION:
case DT_MIPS_TIME_STAMP:
@@ -189,8 +174,8 @@
}
bool ElfFixup::FixupSectionHeaders(ElfFile& elf_file, uintptr_t base_address) {
- for (::llvm::ELF::Elf32_Word i = 0; i < elf_file.GetSectionHeaderNum(); i++) {
- ::llvm::ELF::Elf32_Shdr& sh = elf_file.GetSectionHeader(i);
+ for (Elf32_Word i = 0; i < elf_file.GetSectionHeaderNum(); i++) {
+ Elf32_Shdr& sh = elf_file.GetSectionHeader(i);
// 0 implies that the section will not exist in the memory of the process
if (sh.sh_addr == 0) {
continue;
@@ -207,8 +192,8 @@
bool ElfFixup::FixupProgramHeaders(ElfFile& elf_file, uintptr_t base_address) {
// TODO: ELFObjectFile doesn't have give to Elf32_Phdr, so we do that ourselves for now.
- for (::llvm::ELF::Elf32_Word i = 0; i < elf_file.GetProgramHeaderNum(); i++) {
- ::llvm::ELF::Elf32_Phdr& ph = elf_file.GetProgramHeader(i);
+ for (Elf32_Word i = 0; i < elf_file.GetProgramHeaderNum(); i++) {
+ Elf32_Phdr& ph = elf_file.GetProgramHeader(i);
CHECK_EQ(ph.p_vaddr, ph.p_paddr) << elf_file.GetFile().GetPath() << " i=" << i;
CHECK((ph.p_align == 0) || (0 == ((ph.p_vaddr - ph.p_offset) & (ph.p_align - 1))))
<< elf_file.GetFile().GetPath() << " i=" << i;
@@ -226,16 +211,16 @@
}
bool ElfFixup::FixupSymbols(ElfFile& elf_file, uintptr_t base_address, bool dynamic) {
- ::llvm::ELF::Elf32_Word section_type = dynamic ? ::llvm::ELF::SHT_DYNSYM : ::llvm::ELF::SHT_SYMTAB;
+ Elf32_Word section_type = dynamic ? SHT_DYNSYM : SHT_SYMTAB;
// TODO: Unfortunate ELFObjectFile has protected symbol access, so use ElfFile
- ::llvm::ELF::Elf32_Shdr* symbol_section = elf_file.FindSectionByType(section_type);
+ Elf32_Shdr* symbol_section = elf_file.FindSectionByType(section_type);
if (symbol_section == NULL) {
// file is missing optional .symtab
CHECK(!dynamic) << elf_file.GetFile().GetPath();
return true;
}
for (uint32_t i = 0; i < elf_file.GetSymbolNum(*symbol_section); i++) {
- ::llvm::ELF::Elf32_Sym& symbol = elf_file.GetSymbol(section_type, i);
+ Elf32_Sym& symbol = elf_file.GetSymbol(section_type, i);
if (symbol.st_value != 0) {
if (DEBUG_FIXUP) {
LOG(INFO) << StringPrintf("In %s moving Elf32_Sym[%d] from 0x%08x to 0x%08" PRIxPTR,
@@ -249,11 +234,11 @@
}
bool ElfFixup::FixupRelocations(ElfFile& elf_file, uintptr_t base_address) {
- for (llvm::ELF::Elf32_Word i = 0; i < elf_file.GetSectionHeaderNum(); i++) {
- llvm::ELF::Elf32_Shdr& sh = elf_file.GetSectionHeader(i);
- if (sh.sh_type == llvm::ELF::SHT_REL) {
+ for (Elf32_Word i = 0; i < elf_file.GetSectionHeaderNum(); i++) {
+ Elf32_Shdr& sh = elf_file.GetSectionHeader(i);
+ if (sh.sh_type == SHT_REL) {
for (uint32_t i = 0; i < elf_file.GetRelNum(sh); i++) {
- llvm::ELF::Elf32_Rel& rel = elf_file.GetRel(sh, i);
+ Elf32_Rel& rel = elf_file.GetRel(sh, i);
if (DEBUG_FIXUP) {
LOG(INFO) << StringPrintf("In %s moving Elf32_Rel[%d] from 0x%08x to 0x%08" PRIxPTR,
elf_file.GetFile().GetPath().c_str(), i,
@@ -261,9 +246,9 @@
}
rel.r_offset += base_address;
}
- } else if (sh.sh_type == llvm::ELF::SHT_RELA) {
+ } else if (sh.sh_type == SHT_RELA) {
for (uint32_t i = 0; i < elf_file.GetRelaNum(sh); i++) {
- llvm::ELF::Elf32_Rela& rela = elf_file.GetRela(sh, i);
+ Elf32_Rela& rela = elf_file.GetRela(sh, i);
if (DEBUG_FIXUP) {
LOG(INFO) << StringPrintf("In %s moving Elf32_Rela[%d] from 0x%08x to 0x%08" PRIxPTR,
elf_file.GetFile().GetPath().c_str(), i,
diff --git a/compiler/elf_stripper.cc b/compiler/elf_stripper.cc
index 7ee8d3c..b8cc5c0 100644
--- a/compiler/elf_stripper.cc
+++ b/compiler/elf_stripper.cc
@@ -18,11 +18,10 @@
#include <vector>
-#include <llvm/Support/ELF.h>
-
#include "UniquePtr.h"
#include "base/logging.h"
#include "elf_file.h"
+#include "elf_utils.h"
#include "utils.h"
namespace art {
@@ -65,14 +64,14 @@
// - truncate rest of file
//
- std::vector<llvm::ELF::Elf32_Shdr> section_headers;
- std::vector<llvm::ELF::Elf32_Word> section_headers_original_indexes;
+ std::vector<Elf32_Shdr> section_headers;
+ std::vector<Elf32_Word> section_headers_original_indexes;
section_headers.reserve(elf_file->GetSectionHeaderNum());
- llvm::ELF::Elf32_Shdr& string_section = elf_file->GetSectionNameStringSection();
- for (llvm::ELF::Elf32_Word i = 0; i < elf_file->GetSectionHeaderNum(); i++) {
- llvm::ELF::Elf32_Shdr& sh = elf_file->GetSectionHeader(i);
+ Elf32_Shdr& string_section = elf_file->GetSectionNameStringSection();
+ for (Elf32_Word i = 0; i < elf_file->GetSectionHeaderNum(); i++) {
+ Elf32_Shdr& sh = elf_file->GetSectionHeader(i);
const char* name = elf_file->GetString(string_section, sh.sh_name);
if (name == NULL) {
CHECK_EQ(0U, i);
@@ -92,10 +91,10 @@
CHECK_EQ(section_headers.size(), section_headers_original_indexes.size());
// section 0 is the NULL section, sections start at offset of first section
- llvm::ELF::Elf32_Off offset = elf_file->GetSectionHeader(1).sh_offset;
+ Elf32_Off offset = elf_file->GetSectionHeader(1).sh_offset;
for (size_t i = 1; i < section_headers.size(); i++) {
- llvm::ELF::Elf32_Shdr& new_sh = section_headers[i];
- llvm::ELF::Elf32_Shdr& old_sh = elf_file->GetSectionHeader(section_headers_original_indexes[i]);
+ Elf32_Shdr& new_sh = section_headers[i];
+ Elf32_Shdr& old_sh = elf_file->GetSectionHeader(section_headers_original_indexes[i]);
CHECK_EQ(new_sh.sh_name, old_sh.sh_name);
if (old_sh.sh_addralign > 1) {
offset = RoundUp(offset, old_sh.sh_addralign);
@@ -113,8 +112,8 @@
offset += old_sh.sh_size;
}
- llvm::ELF::Elf32_Off shoff = offset;
- size_t section_headers_size_in_bytes = section_headers.size() * sizeof(llvm::ELF::Elf32_Shdr);
+ Elf32_Off shoff = offset;
+ size_t section_headers_size_in_bytes = section_headers.size() * sizeof(Elf32_Shdr);
memcpy(elf_file->Begin() + offset, §ion_headers[0], section_headers_size_in_bytes);
offset += section_headers_size_in_bytes;
diff --git a/compiler/elf_writer.cc b/compiler/elf_writer.cc
index 0bfe4a4..ba5f1cb 100644
--- a/compiler/elf_writer.cc
+++ b/compiler/elf_writer.cc
@@ -36,10 +36,10 @@
ElfWriter::~ElfWriter() {}
-llvm::ELF::Elf32_Addr ElfWriter::GetOatDataAddress(ElfFile* elf_file) {
- llvm::ELF::Elf32_Addr oatdata_address = elf_file->FindSymbolAddress(llvm::ELF::SHT_DYNSYM,
- "oatdata",
- false);
+Elf32_Addr ElfWriter::GetOatDataAddress(ElfFile* elf_file) {
+ Elf32_Addr oatdata_address = elf_file->FindSymbolAddress(SHT_DYNSYM,
+ "oatdata",
+ false);
CHECK_NE(0U, oatdata_address);
return oatdata_address;
}
diff --git a/compiler/elf_writer.h b/compiler/elf_writer.h
index dbc986a..99dfc56 100644
--- a/compiler/elf_writer.h
+++ b/compiler/elf_writer.h
@@ -18,14 +18,12 @@
#define ART_COMPILER_ELF_WRITER_H_
#include <stdint.h>
-
#include <cstddef>
#include <string>
#include <vector>
-#include <llvm/Support/ELF.h>
-
#include "base/macros.h"
+#include "elf_utils.h"
#include "os.h"
namespace art {
@@ -44,7 +42,7 @@
size_t& oat_data_offset);
// Returns runtime oat_data runtime address for an opened ElfFile.
- static ::llvm::ELF::Elf32_Addr GetOatDataAddress(ElfFile* elf_file);
+ static Elf32_Addr GetOatDataAddress(ElfFile* elf_file);
protected:
ElfWriter(const CompilerDriver& driver, File* elf_file);
diff --git a/compiler/elf_writer_quick.cc b/compiler/elf_writer_quick.cc
index 04342fd..3191374 100644
--- a/compiler/elf_writer_quick.cc
+++ b/compiler/elf_writer_quick.cc
@@ -20,6 +20,7 @@
#include "base/unix_file/fd_file.h"
#include "buffered_output_stream.h"
#include "driver/compiler_driver.h"
+#include "elf_utils.h"
#include "file_output_stream.h"
#include "globals.h"
#include "oat.h"
@@ -117,10 +118,10 @@
uint32_t expected_offset = 0;
// Elf32_Ehdr
- expected_offset += sizeof(llvm::ELF::Elf32_Ehdr);
+ expected_offset += sizeof(Elf32_Ehdr);
// PHDR
- uint32_t phdr_alignment = sizeof(llvm::ELF::Elf32_Word);
+ uint32_t phdr_alignment = sizeof(Elf32_Word);
uint32_t phdr_offset = expected_offset;
const uint8_t PH_PHDR = 0;
const uint8_t PH_LOAD_R__ = 1;
@@ -128,7 +129,7 @@
const uint8_t PH_LOAD_RW_ = 3;
const uint8_t PH_DYNAMIC = 4;
const uint8_t PH_NUM = 5;
- uint32_t phdr_size = sizeof(llvm::ELF::Elf32_Phdr) * PH_NUM;
+ uint32_t phdr_size = sizeof(Elf32_Phdr) * PH_NUM;
expected_offset += phdr_size;
if (debug) {
LOG(INFO) << "phdr_offset=" << phdr_offset << std::hex << " " << phdr_offset;
@@ -136,14 +137,14 @@
}
// .dynsym
- uint32_t dynsym_alignment = sizeof(llvm::ELF::Elf32_Word);
+ uint32_t dynsym_alignment = sizeof(Elf32_Word);
uint32_t dynsym_offset = expected_offset = RoundUp(expected_offset, dynsym_alignment);
const uint8_t SYM_UNDEF = 0; // aka STN_UNDEF
const uint8_t SYM_OATDATA = 1;
const uint8_t SYM_OATEXEC = 2;
const uint8_t SYM_OATLASTWORD = 3;
const uint8_t SYM_NUM = 4;
- uint32_t dynsym_size = sizeof(llvm::ELF::Elf32_Sym) * SYM_NUM;
+ uint32_t dynsym_size = sizeof(Elf32_Sym) * SYM_NUM;
expected_offset += dynsym_size;
if (debug) {
LOG(INFO) << "dynsym_offset=" << dynsym_offset << std::hex << " " << dynsym_offset;
@@ -180,13 +181,13 @@
}
// .hash
- uint32_t hash_alignment = sizeof(llvm::ELF::Elf32_Word); // Even for 64-bit
+ uint32_t hash_alignment = sizeof(Elf32_Word); // Even for 64-bit
uint32_t hash_offset = expected_offset = RoundUp(expected_offset, hash_alignment);
const uint8_t HASH_NBUCKET = 0;
const uint8_t HASH_NCHAIN = 1;
const uint8_t HASH_BUCKET0 = 2;
const uint8_t HASH_NUM = HASH_BUCKET0 + 1 + SYM_NUM;
- uint32_t hash_size = sizeof(llvm::ELF::Elf32_Word) * HASH_NUM;
+ uint32_t hash_size = sizeof(Elf32_Word) * HASH_NUM;
expected_offset += hash_size;
if (debug) {
LOG(INFO) << "hash_offset=" << hash_offset << std::hex << " " << hash_offset;
@@ -218,7 +219,7 @@
}
// .dynamic
- // alignment would naturally be sizeof(llvm::ELF::Elf32_Word), but we want this in a new segment
+ // alignment would naturally be sizeof(Elf32_Word), but we want this in a new segment
uint32_t dynamic_alignment = kPageSize;
uint32_t dynamic_offset = expected_offset = RoundUp(expected_offset, dynamic_alignment);
const uint8_t DH_SONAME = 0;
@@ -229,7 +230,7 @@
const uint8_t DH_STRSZ = 5;
const uint8_t DH_NULL = 6;
const uint8_t DH_NUM = 7;
- uint32_t dynamic_size = sizeof(llvm::ELF::Elf32_Dyn) * DH_NUM;
+ uint32_t dynamic_size = sizeof(Elf32_Dyn) * DH_NUM;
expected_offset += dynamic_size;
if (debug) {
LOG(INFO) << "dynamic_offset=" << dynamic_offset << std::hex << " " << dynamic_offset;
@@ -271,7 +272,7 @@
}
// section headers (after all sections)
- uint32_t shdr_alignment = sizeof(llvm::ELF::Elf32_Word);
+ uint32_t shdr_alignment = sizeof(Elf32_Word);
uint32_t shdr_offset = expected_offset = RoundUp(expected_offset, shdr_alignment);
const uint8_t SH_NULL = 0;
const uint8_t SH_DYNSYM = 1;
@@ -282,7 +283,7 @@
const uint8_t SH_DYNAMIC = 6;
const uint8_t SH_SHSTRTAB = 7;
const uint8_t SH_NUM = 8;
- uint32_t shdr_size = sizeof(llvm::ELF::Elf32_Shdr) * SH_NUM;
+ uint32_t shdr_size = sizeof(Elf32_Shdr) * SH_NUM;
expected_offset += shdr_size;
if (debug) {
LOG(INFO) << "shdr_offset=" << shdr_offset << std::hex << " " << shdr_offset;
@@ -292,36 +293,36 @@
// phase 2: initializing data
// Elf32_Ehdr
- llvm::ELF::Elf32_Ehdr elf_header;
+ Elf32_Ehdr elf_header;
memset(&elf_header, 0, sizeof(elf_header));
- elf_header.e_ident[llvm::ELF::EI_MAG0] = llvm::ELF::ElfMagic[0];
- elf_header.e_ident[llvm::ELF::EI_MAG1] = llvm::ELF::ElfMagic[1];
- elf_header.e_ident[llvm::ELF::EI_MAG2] = llvm::ELF::ElfMagic[2];
- elf_header.e_ident[llvm::ELF::EI_MAG3] = llvm::ELF::ElfMagic[3];
- elf_header.e_ident[llvm::ELF::EI_CLASS] = llvm::ELF::ELFCLASS32;
- elf_header.e_ident[llvm::ELF::EI_DATA] = llvm::ELF::ELFDATA2LSB;
- elf_header.e_ident[llvm::ELF::EI_VERSION] = llvm::ELF::EV_CURRENT;
- elf_header.e_ident[llvm::ELF::EI_OSABI] = llvm::ELF::ELFOSABI_LINUX;
- elf_header.e_ident[llvm::ELF::EI_ABIVERSION] = 0;
- elf_header.e_type = llvm::ELF::ET_DYN;
+ elf_header.e_ident[EI_MAG0] = ELFMAG0;
+ elf_header.e_ident[EI_MAG1] = ELFMAG1;
+ elf_header.e_ident[EI_MAG2] = ELFMAG2;
+ elf_header.e_ident[EI_MAG3] = ELFMAG3;
+ elf_header.e_ident[EI_CLASS] = ELFCLASS32;
+ elf_header.e_ident[EI_DATA] = ELFDATA2LSB;
+ elf_header.e_ident[EI_VERSION] = EV_CURRENT;
+ elf_header.e_ident[EI_OSABI] = ELFOSABI_LINUX;
+ elf_header.e_ident[EI_ABIVERSION] = 0;
+ elf_header.e_type = ET_DYN;
switch (compiler_driver_->GetInstructionSet()) {
case kThumb2: {
- elf_header.e_machine = llvm::ELF::EM_ARM;
- elf_header.e_flags = llvm::ELF::EF_ARM_EABI_VER5;
+ elf_header.e_machine = EM_ARM;
+ elf_header.e_flags = EF_ARM_EABI_VER5;
break;
}
case kX86: {
- elf_header.e_machine = llvm::ELF::EM_386;
+ elf_header.e_machine = EM_386;
elf_header.e_flags = 0;
break;
}
case kMips: {
- elf_header.e_machine = llvm::ELF::EM_MIPS;
- elf_header.e_flags = (llvm::ELF::EF_MIPS_NOREORDER |
- llvm::ELF::EF_MIPS_PIC |
- llvm::ELF::EF_MIPS_CPIC |
- llvm::ELF::EF_MIPS_ABI_O32 |
- llvm::ELF::EF_MIPS_ARCH_32R2);
+ elf_header.e_machine = EM_MIPS;
+ elf_header.e_flags = (EF_MIPS_NOREORDER |
+ EF_MIPS_PIC |
+ EF_MIPS_CPIC |
+ EF_MIPS_ABI_O32 |
+ EF_MIPS_ARCH_32R2);
break;
}
case kArm:
@@ -334,66 +335,66 @@
elf_header.e_entry = 0;
elf_header.e_phoff = phdr_offset;
elf_header.e_shoff = shdr_offset;
- elf_header.e_ehsize = sizeof(llvm::ELF::Elf32_Ehdr);
- elf_header.e_phentsize = sizeof(llvm::ELF::Elf32_Phdr);
+ elf_header.e_ehsize = sizeof(Elf32_Ehdr);
+ elf_header.e_phentsize = sizeof(Elf32_Phdr);
elf_header.e_phnum = PH_NUM;
- elf_header.e_shentsize = sizeof(llvm::ELF::Elf32_Shdr);
+ elf_header.e_shentsize = sizeof(Elf32_Shdr);
elf_header.e_shnum = SH_NUM;
elf_header.e_shstrndx = SH_SHSTRTAB;
// PHDR
- llvm::ELF::Elf32_Phdr program_headers[PH_NUM];
+ Elf32_Phdr program_headers[PH_NUM];
memset(&program_headers, 0, sizeof(program_headers));
- program_headers[PH_PHDR].p_type = llvm::ELF::PT_PHDR;
+ program_headers[PH_PHDR].p_type = PT_PHDR;
program_headers[PH_PHDR].p_offset = phdr_offset;
program_headers[PH_PHDR].p_vaddr = phdr_offset;
program_headers[PH_PHDR].p_paddr = phdr_offset;
program_headers[PH_PHDR].p_filesz = sizeof(program_headers);
program_headers[PH_PHDR].p_memsz = sizeof(program_headers);
- program_headers[PH_PHDR].p_flags = llvm::ELF::PF_R;
+ program_headers[PH_PHDR].p_flags = PF_R;
program_headers[PH_PHDR].p_align = phdr_alignment;
- program_headers[PH_LOAD_R__].p_type = llvm::ELF::PT_LOAD;
+ program_headers[PH_LOAD_R__].p_type = PT_LOAD;
program_headers[PH_LOAD_R__].p_offset = 0;
program_headers[PH_LOAD_R__].p_vaddr = 0;
program_headers[PH_LOAD_R__].p_paddr = 0;
program_headers[PH_LOAD_R__].p_filesz = oat_data_offset + oat_data_size;
program_headers[PH_LOAD_R__].p_memsz = oat_data_offset + oat_data_size;
- program_headers[PH_LOAD_R__].p_flags = llvm::ELF::PF_R;
+ program_headers[PH_LOAD_R__].p_flags = PF_R;
program_headers[PH_LOAD_R__].p_align = oat_data_alignment;
- program_headers[PH_LOAD_R_X].p_type = llvm::ELF::PT_LOAD;
+ program_headers[PH_LOAD_R_X].p_type = PT_LOAD;
program_headers[PH_LOAD_R_X].p_offset = oat_exec_offset;
program_headers[PH_LOAD_R_X].p_vaddr = oat_exec_offset;
program_headers[PH_LOAD_R_X].p_paddr = oat_exec_offset;
program_headers[PH_LOAD_R_X].p_filesz = oat_exec_size;
program_headers[PH_LOAD_R_X].p_memsz = oat_exec_size;
- program_headers[PH_LOAD_R_X].p_flags = llvm::ELF::PF_R | llvm::ELF::PF_X;
+ program_headers[PH_LOAD_R_X].p_flags = PF_R | PF_X;
program_headers[PH_LOAD_R_X].p_align = oat_exec_alignment;
// TODO: PF_W for DYNAMIC is considered processor specific, do we need it?
- program_headers[PH_LOAD_RW_].p_type = llvm::ELF::PT_LOAD;
+ program_headers[PH_LOAD_RW_].p_type = PT_LOAD;
program_headers[PH_LOAD_RW_].p_offset = dynamic_offset;
program_headers[PH_LOAD_RW_].p_vaddr = dynamic_offset;
program_headers[PH_LOAD_RW_].p_paddr = dynamic_offset;
program_headers[PH_LOAD_RW_].p_filesz = dynamic_size;
program_headers[PH_LOAD_RW_].p_memsz = dynamic_size;
- program_headers[PH_LOAD_RW_].p_flags = llvm::ELF::PF_R | llvm::ELF::PF_W;
+ program_headers[PH_LOAD_RW_].p_flags = PF_R | PF_W;
program_headers[PH_LOAD_RW_].p_align = dynamic_alignment;
// TODO: PF_W for DYNAMIC is considered processor specific, do we need it?
- program_headers[PH_DYNAMIC].p_type = llvm::ELF::PT_DYNAMIC;
+ program_headers[PH_DYNAMIC].p_type = PT_DYNAMIC;
program_headers[PH_DYNAMIC].p_offset = dynamic_offset;
program_headers[PH_DYNAMIC].p_vaddr = dynamic_offset;
program_headers[PH_DYNAMIC].p_paddr = dynamic_offset;
program_headers[PH_DYNAMIC].p_filesz = dynamic_size;
program_headers[PH_DYNAMIC].p_memsz = dynamic_size;
- program_headers[PH_DYNAMIC].p_flags = llvm::ELF::PF_R | llvm::ELF::PF_W;
+ program_headers[PH_DYNAMIC].p_flags = PF_R | PF_W;
program_headers[PH_DYNAMIC].p_align = dynamic_alignment;
// .dynsym
- llvm::ELF::Elf32_Sym dynsym[SYM_NUM];
+ Elf32_Sym dynsym[SYM_NUM];
memset(&dynsym, 0, sizeof(dynsym));
dynsym[SYM_UNDEF].st_name = 0;
@@ -406,28 +407,28 @@
dynsym[SYM_OATDATA].st_name = dynstr_oatdata_offset;
dynsym[SYM_OATDATA].st_value = oat_data_offset;
dynsym[SYM_OATDATA].st_size = oat_data_size;
- dynsym[SYM_OATDATA].setBindingAndType(llvm::ELF::STB_GLOBAL, llvm::ELF::STT_OBJECT);
- dynsym[SYM_OATDATA].st_other = llvm::ELF::STV_DEFAULT;
+ SetBindingAndType(&dynsym[SYM_OATDATA], STB_GLOBAL, STT_OBJECT);
+ dynsym[SYM_OATDATA].st_other = STV_DEFAULT;
dynsym[SYM_OATDATA].st_shndx = SH_RODATA;
dynsym[SYM_OATEXEC].st_name = dynstr_oatexec_offset;
dynsym[SYM_OATEXEC].st_value = oat_exec_offset;
dynsym[SYM_OATEXEC].st_size = oat_exec_size;
- dynsym[SYM_OATEXEC].setBindingAndType(llvm::ELF::STB_GLOBAL, llvm::ELF::STT_OBJECT);
- dynsym[SYM_OATEXEC].st_other = llvm::ELF::STV_DEFAULT;
+ SetBindingAndType(&dynsym[SYM_OATEXEC], STB_GLOBAL, STT_OBJECT);
+ dynsym[SYM_OATEXEC].st_other = STV_DEFAULT;
dynsym[SYM_OATEXEC].st_shndx = SH_TEXT;
dynsym[SYM_OATLASTWORD].st_name = dynstr_oatlastword_offset;
dynsym[SYM_OATLASTWORD].st_value = oat_exec_offset + oat_exec_size - 4;
dynsym[SYM_OATLASTWORD].st_size = 4;
- dynsym[SYM_OATLASTWORD].setBindingAndType(llvm::ELF::STB_GLOBAL, llvm::ELF::STT_OBJECT);
- dynsym[SYM_OATLASTWORD].st_other = llvm::ELF::STV_DEFAULT;
+ SetBindingAndType(&dynsym[SYM_OATLASTWORD], STB_GLOBAL, STT_OBJECT);
+ dynsym[SYM_OATLASTWORD].st_other = STV_DEFAULT;
dynsym[SYM_OATLASTWORD].st_shndx = SH_TEXT;
// .dynstr initialized above as dynstr
// .hash
- llvm::ELF::Elf32_Word hash[HASH_NUM]; // Note this is Elf32_Word even on 64-bit
+ Elf32_Word hash[HASH_NUM]; // Note this is Elf32_Word even on 64-bit
hash[HASH_NBUCKET] = 1;
hash[HASH_NCHAIN] = SYM_NUM;
hash[HASH_BUCKET0] = SYM_OATDATA;
@@ -439,38 +440,38 @@
// .rodata and .text content come from oat_contents
// .dynamic
- llvm::ELF::Elf32_Dyn dynamic_headers[DH_NUM];
+ Elf32_Dyn dynamic_headers[DH_NUM];
memset(&dynamic_headers, 0, sizeof(dynamic_headers));
- dynamic_headers[DH_SONAME].d_tag = llvm::ELF::DT_SONAME;
+ dynamic_headers[DH_SONAME].d_tag = DT_SONAME;
dynamic_headers[DH_SONAME].d_un.d_val = dynstr_soname_offset;
- dynamic_headers[DH_HASH].d_tag = llvm::ELF::DT_HASH;
+ dynamic_headers[DH_HASH].d_tag = DT_HASH;
dynamic_headers[DH_HASH].d_un.d_ptr = hash_offset;
- dynamic_headers[DH_SYMTAB].d_tag = llvm::ELF::DT_SYMTAB;
+ dynamic_headers[DH_SYMTAB].d_tag = DT_SYMTAB;
dynamic_headers[DH_SYMTAB].d_un.d_ptr = dynsym_offset;
- dynamic_headers[DH_SYMENT].d_tag = llvm::ELF::DT_SYMENT;
- dynamic_headers[DH_SYMENT].d_un.d_val = sizeof(llvm::ELF::Elf32_Sym);
+ dynamic_headers[DH_SYMENT].d_tag = DT_SYMENT;
+ dynamic_headers[DH_SYMENT].d_un.d_val = sizeof(Elf32_Sym);
- dynamic_headers[DH_STRTAB].d_tag = llvm::ELF::DT_STRTAB;
+ dynamic_headers[DH_STRTAB].d_tag = DT_STRTAB;
dynamic_headers[DH_STRTAB].d_un.d_ptr = dynstr_offset;
- dynamic_headers[DH_STRSZ].d_tag = llvm::ELF::DT_STRSZ;
+ dynamic_headers[DH_STRSZ].d_tag = DT_STRSZ;
dynamic_headers[DH_STRSZ].d_un.d_val = dynstr_size;
- dynamic_headers[DH_NULL].d_tag = llvm::ELF::DT_NULL;
+ dynamic_headers[DH_NULL].d_tag = DT_NULL;
dynamic_headers[DH_NULL].d_un.d_val = 0;
// .shstrtab initialized above as shstrtab
// section headers (after all sections)
- llvm::ELF::Elf32_Shdr section_headers[SH_NUM];
+ Elf32_Shdr section_headers[SH_NUM];
memset(§ion_headers, 0, sizeof(section_headers));
section_headers[SH_NULL].sh_name = 0;
- section_headers[SH_NULL].sh_type = llvm::ELF::SHT_NULL;
+ section_headers[SH_NULL].sh_type = SHT_NULL;
section_headers[SH_NULL].sh_flags = 0;
section_headers[SH_NULL].sh_addr = 0;
section_headers[SH_NULL].sh_offset = 0;
@@ -481,19 +482,19 @@
section_headers[SH_NULL].sh_entsize = 0;
section_headers[SH_DYNSYM].sh_name = shstrtab_dynsym_offset;
- section_headers[SH_DYNSYM].sh_type = llvm::ELF::SHT_DYNSYM;
- section_headers[SH_DYNSYM].sh_flags = llvm::ELF::SHF_ALLOC;
+ section_headers[SH_DYNSYM].sh_type = SHT_DYNSYM;
+ section_headers[SH_DYNSYM].sh_flags = SHF_ALLOC;
section_headers[SH_DYNSYM].sh_addr = dynsym_offset;
section_headers[SH_DYNSYM].sh_offset = dynsym_offset;
section_headers[SH_DYNSYM].sh_size = dynsym_size;
section_headers[SH_DYNSYM].sh_link = SH_DYNSTR;
section_headers[SH_DYNSYM].sh_info = 1; // 1 because we have not STB_LOCAL symbols
section_headers[SH_DYNSYM].sh_addralign = dynsym_alignment;
- section_headers[SH_DYNSYM].sh_entsize = sizeof(llvm::ELF::Elf32_Sym);
+ section_headers[SH_DYNSYM].sh_entsize = sizeof(Elf32_Sym);
section_headers[SH_DYNSTR].sh_name = shstrtab_dynstr_offset;
- section_headers[SH_DYNSTR].sh_type = llvm::ELF::SHT_STRTAB;
- section_headers[SH_DYNSTR].sh_flags = llvm::ELF::SHF_ALLOC;
+ section_headers[SH_DYNSTR].sh_type = SHT_STRTAB;
+ section_headers[SH_DYNSTR].sh_flags = SHF_ALLOC;
section_headers[SH_DYNSTR].sh_addr = dynstr_offset;
section_headers[SH_DYNSTR].sh_offset = dynstr_offset;
section_headers[SH_DYNSTR].sh_size = dynstr_size;
@@ -503,19 +504,19 @@
section_headers[SH_DYNSTR].sh_entsize = 0;
section_headers[SH_HASH].sh_name = shstrtab_hash_offset;
- section_headers[SH_HASH].sh_type = llvm::ELF::SHT_HASH;
- section_headers[SH_HASH].sh_flags = llvm::ELF::SHF_ALLOC;
+ section_headers[SH_HASH].sh_type = SHT_HASH;
+ section_headers[SH_HASH].sh_flags = SHF_ALLOC;
section_headers[SH_HASH].sh_addr = hash_offset;
section_headers[SH_HASH].sh_offset = hash_offset;
section_headers[SH_HASH].sh_size = hash_size;
section_headers[SH_HASH].sh_link = SH_DYNSYM;
section_headers[SH_HASH].sh_info = 0;
section_headers[SH_HASH].sh_addralign = hash_alignment;
- section_headers[SH_HASH].sh_entsize = sizeof(llvm::ELF::Elf32_Word); // This is Elf32_Word even on 64-bit
+ section_headers[SH_HASH].sh_entsize = sizeof(Elf32_Word); // This is Elf32_Word even on 64-bit
section_headers[SH_RODATA].sh_name = shstrtab_rodata_offset;
- section_headers[SH_RODATA].sh_type = llvm::ELF::SHT_PROGBITS;
- section_headers[SH_RODATA].sh_flags = llvm::ELF::SHF_ALLOC;
+ section_headers[SH_RODATA].sh_type = SHT_PROGBITS;
+ section_headers[SH_RODATA].sh_flags = SHF_ALLOC;
section_headers[SH_RODATA].sh_addr = oat_data_offset;
section_headers[SH_RODATA].sh_offset = oat_data_offset;
section_headers[SH_RODATA].sh_size = oat_data_size;
@@ -525,8 +526,8 @@
section_headers[SH_RODATA].sh_entsize = 0;
section_headers[SH_TEXT].sh_name = shstrtab_text_offset;
- section_headers[SH_TEXT].sh_type = llvm::ELF::SHT_PROGBITS;
- section_headers[SH_TEXT].sh_flags = llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_EXECINSTR;
+ section_headers[SH_TEXT].sh_type = SHT_PROGBITS;
+ section_headers[SH_TEXT].sh_flags = SHF_ALLOC | SHF_EXECINSTR;
section_headers[SH_TEXT].sh_addr = oat_exec_offset;
section_headers[SH_TEXT].sh_offset = oat_exec_offset;
section_headers[SH_TEXT].sh_size = oat_exec_size;
@@ -537,18 +538,18 @@
// TODO: SHF_WRITE for .dynamic is considered processor specific, do we need it?
section_headers[SH_DYNAMIC].sh_name = shstrtab_dynamic_offset;
- section_headers[SH_DYNAMIC].sh_type = llvm::ELF::SHT_DYNAMIC;
- section_headers[SH_DYNAMIC].sh_flags = llvm::ELF::SHF_WRITE | llvm::ELF::SHF_ALLOC;
+ section_headers[SH_DYNAMIC].sh_type = SHT_DYNAMIC;
+ section_headers[SH_DYNAMIC].sh_flags = SHF_WRITE | SHF_ALLOC;
section_headers[SH_DYNAMIC].sh_addr = dynamic_offset;
section_headers[SH_DYNAMIC].sh_offset = dynamic_offset;
section_headers[SH_DYNAMIC].sh_size = dynamic_size;
section_headers[SH_DYNAMIC].sh_link = SH_DYNSTR;
section_headers[SH_DYNAMIC].sh_info = 0;
section_headers[SH_DYNAMIC].sh_addralign = dynamic_alignment;
- section_headers[SH_DYNAMIC].sh_entsize = sizeof(llvm::ELF::Elf32_Dyn);
+ section_headers[SH_DYNAMIC].sh_entsize = sizeof(Elf32_Dyn);
section_headers[SH_SHSTRTAB].sh_name = shstrtab_shstrtab_offset;
- section_headers[SH_SHSTRTAB].sh_type = llvm::ELF::SHT_STRTAB;
+ section_headers[SH_SHSTRTAB].sh_type = SHT_STRTAB;
section_headers[SH_SHSTRTAB].sh_flags = 0;
section_headers[SH_SHSTRTAB].sh_addr = shstrtab_offset;
section_headers[SH_SHSTRTAB].sh_offset = shstrtab_offset;
diff --git a/compiler/elf_writer_test.cc b/compiler/elf_writer_test.cc
index 95e5f9f..5bad0d0 100644
--- a/compiler/elf_writer_test.cc
+++ b/compiler/elf_writer_test.cc
@@ -31,7 +31,7 @@
#define EXPECT_ELF_FILE_ADDRESS(ef, expected_value, symbol_name, build_map) \
do { \
- void* addr = reinterpret_cast<void*>(ef->FindSymbolAddress(::llvm::ELF::SHT_DYNSYM, \
+ void* addr = reinterpret_cast<void*>(ef->FindSymbolAddress(SHT_DYNSYM, \
symbol_name, \
build_map)); \
EXPECT_NE(nullptr, addr); \
diff --git a/runtime/elf_file.cc b/runtime/elf_file.cc
index 261c217..e4e58b8 100644
--- a/runtime/elf_file.cc
+++ b/runtime/elf_file.cc
@@ -72,16 +72,16 @@
return false;
}
size_t file_length = static_cast<size_t>(temp_file_length);
- if (file_length < sizeof(llvm::ELF::Elf32_Ehdr)) {
+ if (file_length < sizeof(Elf32_Ehdr)) {
*error_msg = StringPrintf("File size of %zd bytes not large enough to contain ELF header of "
- "%zd bytes: '%s'", file_length, sizeof(llvm::ELF::Elf32_Ehdr),
+ "%zd bytes: '%s'", file_length, sizeof(Elf32_Ehdr),
file_->GetPath().c_str());
return false;
}
if (program_header_only) {
// first just map ELF header to get program header size information
- size_t elf_header_size = sizeof(llvm::ELF::Elf32_Ehdr);
+ size_t elf_header_size = sizeof(Elf32_Ehdr);
if (!SetMap(MemMap::MapFile(elf_header_size, prot, flags, file_->Fd(), 0,
file_->GetPath().c_str(), error_msg),
error_msg)) {
@@ -92,7 +92,7 @@
if (file_length < program_header_size) {
*error_msg = StringPrintf("File size of %zd bytes not large enough to contain ELF program "
"header of %zd bytes: '%s'", file_length,
- sizeof(llvm::ELF::Elf32_Ehdr), file_->GetPath().c_str());
+ sizeof(Elf32_Ehdr), file_->GetPath().c_str());
return false;
}
if (!SetMap(MemMap::MapFile(program_header_size, prot, flags, file_->Fd(), 0,
@@ -119,7 +119,7 @@
section_headers_start_ = Begin() + GetHeader().e_shoff;
// Find .dynamic section info from program header
- dynamic_program_header_ = FindProgamHeaderByType(llvm::ELF::PT_DYNAMIC);
+ dynamic_program_header_ = FindProgamHeaderByType(PT_DYNAMIC);
if (dynamic_program_header_ == NULL) {
*error_msg = StringPrintf("Failed to find PT_DYNAMIC program header in ELF file: '%s'",
file_->GetPath().c_str());
@@ -127,31 +127,31 @@
}
dynamic_section_start_
- = reinterpret_cast<llvm::ELF::Elf32_Dyn*>(Begin() + GetDynamicProgramHeader().p_offset);
+ = reinterpret_cast<Elf32_Dyn*>(Begin() + GetDynamicProgramHeader().p_offset);
// Find other sections from section headers
- for (llvm::ELF::Elf32_Word i = 0; i < GetSectionHeaderNum(); i++) {
- llvm::ELF::Elf32_Shdr& section_header = GetSectionHeader(i);
+ for (Elf32_Word i = 0; i < GetSectionHeaderNum(); i++) {
+ Elf32_Shdr& section_header = GetSectionHeader(i);
byte* section_addr = Begin() + section_header.sh_offset;
switch (section_header.sh_type) {
- case llvm::ELF::SHT_SYMTAB: {
- symtab_section_start_ = reinterpret_cast<llvm::ELF::Elf32_Sym*>(section_addr);
+ case SHT_SYMTAB: {
+ symtab_section_start_ = reinterpret_cast<Elf32_Sym*>(section_addr);
break;
}
- case llvm::ELF::SHT_DYNSYM: {
- dynsym_section_start_ = reinterpret_cast<llvm::ELF::Elf32_Sym*>(section_addr);
+ case SHT_DYNSYM: {
+ dynsym_section_start_ = reinterpret_cast<Elf32_Sym*>(section_addr);
break;
}
- case llvm::ELF::SHT_STRTAB: {
+ case SHT_STRTAB: {
// TODO: base these off of sh_link from .symtab and .dynsym above
- if ((section_header.sh_flags & llvm::ELF::SHF_ALLOC) != 0) {
+ if ((section_header.sh_flags & SHF_ALLOC) != 0) {
dynstr_section_start_ = reinterpret_cast<char*>(section_addr);
} else {
strtab_section_start_ = reinterpret_cast<char*>(section_addr);
}
break;
}
- case llvm::ELF::SHT_DYNAMIC: {
+ case SHT_DYNAMIC: {
if (reinterpret_cast<byte*>(dynamic_section_start_) != section_addr) {
LOG(WARNING) << "Failed to find matching SHT_DYNAMIC for PT_DYNAMIC in "
<< file_->GetPath() << ": " << std::hex
@@ -161,8 +161,8 @@
}
break;
}
- case llvm::ELF::SHT_HASH: {
- hash_section_start_ = reinterpret_cast<llvm::ELF::Elf32_Word*>(section_addr);
+ case SHT_HASH: {
+ hash_section_start_ = reinterpret_cast<Elf32_Word*>(section_addr);
break;
}
}
@@ -187,29 +187,29 @@
CHECK(map_.get() != NULL) << file_->GetPath();
CHECK(map_->Begin() != NULL) << file_->GetPath();
- header_ = reinterpret_cast<llvm::ELF::Elf32_Ehdr*>(map_->Begin());
- if ((llvm::ELF::ElfMagic[0] != header_->e_ident[llvm::ELF::EI_MAG0])
- || (llvm::ELF::ElfMagic[1] != header_->e_ident[llvm::ELF::EI_MAG1])
- || (llvm::ELF::ElfMagic[2] != header_->e_ident[llvm::ELF::EI_MAG2])
- || (llvm::ELF::ElfMagic[3] != header_->e_ident[llvm::ELF::EI_MAG3])) {
+ header_ = reinterpret_cast<Elf32_Ehdr*>(map_->Begin());
+ if ((ELFMAG0 != header_->e_ident[EI_MAG0])
+ || (ELFMAG1 != header_->e_ident[EI_MAG1])
+ || (ELFMAG2 != header_->e_ident[EI_MAG2])
+ || (ELFMAG3 != header_->e_ident[EI_MAG3])) {
*error_msg = StringPrintf("Failed to find ELF magic in %s: %c%c%c%c",
file_->GetPath().c_str(),
- header_->e_ident[llvm::ELF::EI_MAG0],
- header_->e_ident[llvm::ELF::EI_MAG1],
- header_->e_ident[llvm::ELF::EI_MAG2],
- header_->e_ident[llvm::ELF::EI_MAG3]);
+ header_->e_ident[EI_MAG0],
+ header_->e_ident[EI_MAG1],
+ header_->e_ident[EI_MAG2],
+ header_->e_ident[EI_MAG3]);
return false;
}
// TODO: remove these static_casts from enum when using -std=gnu++0x
- CHECK_EQ(static_cast<unsigned char>(llvm::ELF::ELFCLASS32), header_->e_ident[llvm::ELF::EI_CLASS]) << file_->GetPath();
- CHECK_EQ(static_cast<unsigned char>(llvm::ELF::ELFDATA2LSB), header_->e_ident[llvm::ELF::EI_DATA]) << file_->GetPath();
- CHECK_EQ(static_cast<unsigned char>(llvm::ELF::EV_CURRENT), header_->e_ident[llvm::ELF::EI_VERSION]) << file_->GetPath();
+ CHECK_EQ(static_cast<unsigned char>(ELFCLASS32), header_->e_ident[EI_CLASS]) << file_->GetPath();
+ CHECK_EQ(static_cast<unsigned char>(ELFDATA2LSB), header_->e_ident[EI_DATA]) << file_->GetPath();
+ CHECK_EQ(static_cast<unsigned char>(EV_CURRENT), header_->e_ident[EI_VERSION]) << file_->GetPath();
// TODO: remove these static_casts from enum when using -std=gnu++0x
- CHECK_EQ(static_cast<llvm::ELF::Elf32_Half>(llvm::ELF::ET_DYN), header_->e_type) << file_->GetPath();
- CHECK_EQ(static_cast<llvm::ELF::Elf32_Word>(llvm::ELF::EV_CURRENT), header_->e_version) << file_->GetPath();
+ CHECK_EQ(static_cast<Elf32_Half>(ET_DYN), header_->e_type) << file_->GetPath();
+ CHECK_EQ(static_cast<Elf32_Word>(EV_CURRENT), header_->e_version) << file_->GetPath();
CHECK_EQ(0U, header_->e_entry) << file_->GetPath();
CHECK_NE(0U, header_->e_phoff) << file_->GetPath();
@@ -229,7 +229,7 @@
}
-llvm::ELF::Elf32_Ehdr& ElfFile::GetHeader() {
+Elf32_Ehdr& ElfFile::GetHeader() {
CHECK(header_ != NULL);
return *header_;
}
@@ -244,25 +244,25 @@
return section_headers_start_;
}
-llvm::ELF::Elf32_Phdr& ElfFile::GetDynamicProgramHeader() {
+Elf32_Phdr& ElfFile::GetDynamicProgramHeader() {
CHECK(dynamic_program_header_ != NULL);
return *dynamic_program_header_;
}
-llvm::ELF::Elf32_Dyn* ElfFile::GetDynamicSectionStart() {
+Elf32_Dyn* ElfFile::GetDynamicSectionStart() {
CHECK(dynamic_section_start_ != NULL);
return dynamic_section_start_;
}
-llvm::ELF::Elf32_Sym* ElfFile::GetSymbolSectionStart(llvm::ELF::Elf32_Word section_type) {
+Elf32_Sym* ElfFile::GetSymbolSectionStart(Elf32_Word section_type) {
CHECK(IsSymbolSectionType(section_type)) << file_->GetPath() << " " << section_type;
- llvm::ELF::Elf32_Sym* symbol_section_start;
+ Elf32_Sym* symbol_section_start;
switch (section_type) {
- case llvm::ELF::SHT_SYMTAB: {
+ case SHT_SYMTAB: {
symbol_section_start = symtab_section_start_;
break;
}
- case llvm::ELF::SHT_DYNSYM: {
+ case SHT_DYNSYM: {
symbol_section_start = dynsym_section_start_;
break;
}
@@ -275,15 +275,15 @@
return symbol_section_start;
}
-const char* ElfFile::GetStringSectionStart(llvm::ELF::Elf32_Word section_type) {
+const char* ElfFile::GetStringSectionStart(Elf32_Word section_type) {
CHECK(IsSymbolSectionType(section_type)) << file_->GetPath() << " " << section_type;
const char* string_section_start;
switch (section_type) {
- case llvm::ELF::SHT_SYMTAB: {
+ case SHT_SYMTAB: {
string_section_start = strtab_section_start_;
break;
}
- case llvm::ELF::SHT_DYNSYM: {
+ case SHT_DYNSYM: {
string_section_start = dynstr_section_start_;
break;
}
@@ -296,7 +296,7 @@
return string_section_start;
}
-const char* ElfFile::GetString(llvm::ELF::Elf32_Word section_type, llvm::ELF::Elf32_Word i) {
+const char* ElfFile::GetString(Elf32_Word section_type, Elf32_Word i) {
CHECK(IsSymbolSectionType(section_type)) << file_->GetPath() << " " << section_type;
if (i == 0) {
return NULL;
@@ -306,45 +306,45 @@
return string;
}
-llvm::ELF::Elf32_Word* ElfFile::GetHashSectionStart() {
+Elf32_Word* ElfFile::GetHashSectionStart() {
CHECK(hash_section_start_ != NULL);
return hash_section_start_;
}
-llvm::ELF::Elf32_Word ElfFile::GetHashBucketNum() {
+Elf32_Word ElfFile::GetHashBucketNum() {
return GetHashSectionStart()[0];
}
-llvm::ELF::Elf32_Word ElfFile::GetHashChainNum() {
+Elf32_Word ElfFile::GetHashChainNum() {
return GetHashSectionStart()[1];
}
-llvm::ELF::Elf32_Word ElfFile::GetHashBucket(size_t i) {
+Elf32_Word ElfFile::GetHashBucket(size_t i) {
CHECK_LT(i, GetHashBucketNum());
// 0 is nbucket, 1 is nchain
return GetHashSectionStart()[2 + i];
}
-llvm::ELF::Elf32_Word ElfFile::GetHashChain(size_t i) {
+Elf32_Word ElfFile::GetHashChain(size_t i) {
CHECK_LT(i, GetHashChainNum());
// 0 is nbucket, 1 is nchain, & chains are after buckets
return GetHashSectionStart()[2 + GetHashBucketNum() + i];
}
-llvm::ELF::Elf32_Word ElfFile::GetProgramHeaderNum() {
+Elf32_Word ElfFile::GetProgramHeaderNum() {
return GetHeader().e_phnum;
}
-llvm::ELF::Elf32_Phdr& ElfFile::GetProgramHeader(llvm::ELF::Elf32_Word i) {
+Elf32_Phdr& ElfFile::GetProgramHeader(Elf32_Word i) {
CHECK_LT(i, GetProgramHeaderNum()) << file_->GetPath();
byte* program_header = GetProgramHeadersStart() + (i * GetHeader().e_phentsize);
CHECK_LT(program_header, End()) << file_->GetPath();
- return *reinterpret_cast<llvm::ELF::Elf32_Phdr*>(program_header);
+ return *reinterpret_cast<Elf32_Phdr*>(program_header);
}
-llvm::ELF::Elf32_Phdr* ElfFile::FindProgamHeaderByType(llvm::ELF::Elf32_Word type) {
- for (llvm::ELF::Elf32_Word i = 0; i < GetProgramHeaderNum(); i++) {
- llvm::ELF::Elf32_Phdr& program_header = GetProgramHeader(i);
+Elf32_Phdr* ElfFile::FindProgamHeaderByType(Elf32_Word type) {
+ for (Elf32_Word i = 0; i < GetProgramHeaderNum(); i++) {
+ Elf32_Phdr& program_header = GetProgramHeader(i);
if (program_header.p_type == type) {
return &program_header;
}
@@ -352,26 +352,26 @@
return NULL;
}
-llvm::ELF::Elf32_Word ElfFile::GetSectionHeaderNum() {
+Elf32_Word ElfFile::GetSectionHeaderNum() {
return GetHeader().e_shnum;
}
-llvm::ELF::Elf32_Shdr& ElfFile::GetSectionHeader(llvm::ELF::Elf32_Word i) {
+Elf32_Shdr& ElfFile::GetSectionHeader(Elf32_Word i) {
// Can only access arbitrary sections when we have the whole file, not just program header.
// Even if we Load(), it doesn't bring in all the sections.
CHECK(!program_header_only_) << file_->GetPath();
CHECK_LT(i, GetSectionHeaderNum()) << file_->GetPath();
byte* section_header = GetSectionHeadersStart() + (i * GetHeader().e_shentsize);
CHECK_LT(section_header, End()) << file_->GetPath();
- return *reinterpret_cast<llvm::ELF::Elf32_Shdr*>(section_header);
+ return *reinterpret_cast<Elf32_Shdr*>(section_header);
}
-llvm::ELF::Elf32_Shdr* ElfFile::FindSectionByType(llvm::ELF::Elf32_Word type) {
+Elf32_Shdr* ElfFile::FindSectionByType(Elf32_Word type) {
// Can only access arbitrary sections when we have the whole file, not just program header.
// We could change this to switch on known types if they were detected during loading.
CHECK(!program_header_only_) << file_->GetPath();
- for (llvm::ELF::Elf32_Word i = 0; i < GetSectionHeaderNum(); i++) {
- llvm::ELF::Elf32_Shdr& section_header = GetSectionHeader(i);
+ for (Elf32_Word i = 0; i < GetSectionHeaderNum(); i++) {
+ Elf32_Shdr& section_header = GetSectionHeader(i);
if (section_header.sh_type == type) {
return §ion_header;
}
@@ -393,17 +393,17 @@
return h;
}
-llvm::ELF::Elf32_Shdr& ElfFile::GetSectionNameStringSection() {
+Elf32_Shdr& ElfFile::GetSectionNameStringSection() {
return GetSectionHeader(GetHeader().e_shstrndx);
}
byte* ElfFile::FindDynamicSymbolAddress(const std::string& symbol_name) {
- llvm::ELF::Elf32_Word hash = elfhash(symbol_name.c_str());
- llvm::ELF::Elf32_Word bucket_index = hash % GetHashBucketNum();
- llvm::ELF::Elf32_Word symbol_and_chain_index = GetHashBucket(bucket_index);
+ Elf32_Word hash = elfhash(symbol_name.c_str());
+ Elf32_Word bucket_index = hash % GetHashBucketNum();
+ Elf32_Word symbol_and_chain_index = GetHashBucket(bucket_index);
while (symbol_and_chain_index != 0 /* STN_UNDEF */) {
- llvm::ELF::Elf32_Sym& symbol = GetSymbol(llvm::ELF::SHT_DYNSYM, symbol_and_chain_index);
- const char* name = GetString(llvm::ELF::SHT_DYNSYM, symbol.st_name);
+ Elf32_Sym& symbol = GetSymbol(SHT_DYNSYM, symbol_and_chain_index);
+ const char* name = GetString(SHT_DYNSYM, symbol.st_name);
if (symbol_name == name) {
return base_address_ + symbol.st_value;
}
@@ -412,28 +412,28 @@
return NULL;
}
-bool ElfFile::IsSymbolSectionType(llvm::ELF::Elf32_Word section_type) {
- return ((section_type == llvm::ELF::SHT_SYMTAB) || (section_type == llvm::ELF::SHT_DYNSYM));
+bool ElfFile::IsSymbolSectionType(Elf32_Word section_type) {
+ return ((section_type == SHT_SYMTAB) || (section_type == SHT_DYNSYM));
}
-llvm::ELF::Elf32_Word ElfFile::GetSymbolNum(llvm::ELF::Elf32_Shdr& section_header) {
+Elf32_Word ElfFile::GetSymbolNum(Elf32_Shdr& section_header) {
CHECK(IsSymbolSectionType(section_header.sh_type)) << file_->GetPath() << " " << section_header.sh_type;
CHECK_NE(0U, section_header.sh_entsize) << file_->GetPath();
return section_header.sh_size / section_header.sh_entsize;
}
-llvm::ELF::Elf32_Sym& ElfFile::GetSymbol(llvm::ELF::Elf32_Word section_type,
- llvm::ELF::Elf32_Word i) {
+Elf32_Sym& ElfFile::GetSymbol(Elf32_Word section_type,
+ Elf32_Word i) {
return *(GetSymbolSectionStart(section_type) + i);
}
-ElfFile::SymbolTable** ElfFile::GetSymbolTable(llvm::ELF::Elf32_Word section_type) {
+ElfFile::SymbolTable** ElfFile::GetSymbolTable(Elf32_Word section_type) {
CHECK(IsSymbolSectionType(section_type)) << file_->GetPath() << " " << section_type;
switch (section_type) {
- case llvm::ELF::SHT_SYMTAB: {
+ case SHT_SYMTAB: {
return &symtab_symbol_table_;
}
- case llvm::ELF::SHT_DYNSYM: {
+ case SHT_DYNSYM: {
return &dynsym_symbol_table_;
}
default: {
@@ -443,9 +443,9 @@
}
}
-llvm::ELF::Elf32_Sym* ElfFile::FindSymbolByName(llvm::ELF::Elf32_Word section_type,
- const std::string& symbol_name,
- bool build_map) {
+Elf32_Sym* ElfFile::FindSymbolByName(Elf32_Word section_type,
+ const std::string& symbol_name,
+ bool build_map) {
CHECK(!program_header_only_) << file_->GetPath();
CHECK(IsSymbolSectionType(section_type)) << file_->GetPath() << " " << section_type;
@@ -454,13 +454,13 @@
if (*symbol_table == NULL) {
DCHECK(build_map);
*symbol_table = new SymbolTable;
- llvm::ELF::Elf32_Shdr* symbol_section = FindSectionByType(section_type);
+ Elf32_Shdr* symbol_section = FindSectionByType(section_type);
CHECK(symbol_section != NULL) << file_->GetPath();
- llvm::ELF::Elf32_Shdr& string_section = GetSectionHeader(symbol_section->sh_link);
+ Elf32_Shdr& string_section = GetSectionHeader(symbol_section->sh_link);
for (uint32_t i = 0; i < GetSymbolNum(*symbol_section); i++) {
- llvm::ELF::Elf32_Sym& symbol = GetSymbol(section_type, i);
- unsigned char type = symbol.getType();
- if (type == llvm::ELF::STT_NOTYPE) {
+ Elf32_Sym& symbol = GetSymbol(section_type, i);
+ unsigned char type = ELF32_ST_TYPE(symbol.st_info);
+ if (type == STT_NOTYPE) {
continue;
}
const char* name = GetString(string_section, symbol.st_name);
@@ -487,11 +487,11 @@
}
// Fall back to linear search
- llvm::ELF::Elf32_Shdr* symbol_section = FindSectionByType(section_type);
+ Elf32_Shdr* symbol_section = FindSectionByType(section_type);
CHECK(symbol_section != NULL) << file_->GetPath();
- llvm::ELF::Elf32_Shdr& string_section = GetSectionHeader(symbol_section->sh_link);
+ Elf32_Shdr& string_section = GetSectionHeader(symbol_section->sh_link);
for (uint32_t i = 0; i < GetSymbolNum(*symbol_section); i++) {
- llvm::ELF::Elf32_Sym& symbol = GetSymbol(section_type, i);
+ Elf32_Sym& symbol = GetSymbol(section_type, i);
const char* name = GetString(string_section, symbol.st_name);
if (name == NULL) {
continue;
@@ -503,20 +503,20 @@
return NULL;
}
-llvm::ELF::Elf32_Addr ElfFile::FindSymbolAddress(llvm::ELF::Elf32_Word section_type,
+Elf32_Addr ElfFile::FindSymbolAddress(Elf32_Word section_type,
const std::string& symbol_name,
bool build_map) {
- llvm::ELF::Elf32_Sym* symbol = FindSymbolByName(section_type, symbol_name, build_map);
+ Elf32_Sym* symbol = FindSymbolByName(section_type, symbol_name, build_map);
if (symbol == NULL) {
return 0;
}
return symbol->st_value;
}
-const char* ElfFile::GetString(llvm::ELF::Elf32_Shdr& string_section, llvm::ELF::Elf32_Word i) {
+const char* ElfFile::GetString(Elf32_Shdr& string_section, Elf32_Word i) {
CHECK(!program_header_only_) << file_->GetPath();
// TODO: remove this static_cast from enum when using -std=gnu++0x
- CHECK_EQ(static_cast<llvm::ELF::Elf32_Word>(llvm::ELF::SHT_STRTAB), string_section.sh_type) << file_->GetPath();
+ CHECK_EQ(static_cast<Elf32_Word>(SHT_STRTAB), string_section.sh_type) << file_->GetPath();
CHECK_LT(i, string_section.sh_size) << file_->GetPath();
if (i == 0) {
return NULL;
@@ -527,18 +527,18 @@
return reinterpret_cast<const char*>(string);
}
-llvm::ELF::Elf32_Word ElfFile::GetDynamicNum() {
- return GetDynamicProgramHeader().p_filesz / sizeof(llvm::ELF::Elf32_Dyn);
+Elf32_Word ElfFile::GetDynamicNum() {
+ return GetDynamicProgramHeader().p_filesz / sizeof(Elf32_Dyn);
}
-llvm::ELF::Elf32_Dyn& ElfFile::GetDynamic(llvm::ELF::Elf32_Word i) {
+Elf32_Dyn& ElfFile::GetDynamic(Elf32_Word i) {
CHECK_LT(i, GetDynamicNum()) << file_->GetPath();
return *(GetDynamicSectionStart() + i);
}
-llvm::ELF::Elf32_Word ElfFile::FindDynamicValueByType(llvm::ELF::Elf32_Sword type) {
- for (llvm::ELF::Elf32_Word i = 0; i < GetDynamicNum(); i++) {
- llvm::ELF::Elf32_Dyn& elf_dyn = GetDynamic(i);
+Elf32_Word ElfFile::FindDynamicValueByType(Elf32_Sword type) {
+ for (Elf32_Word i = 0; i < GetDynamicNum(); i++) {
+ Elf32_Dyn& elf_dyn = GetDynamic(i);
if (elf_dyn.d_tag == type) {
return elf_dyn.d_un.d_val;
}
@@ -546,54 +546,53 @@
return 0;
}
-llvm::ELF::Elf32_Rel* ElfFile::GetRelSectionStart(llvm::ELF::Elf32_Shdr& section_header) {
- CHECK(llvm::ELF::SHT_REL == section_header.sh_type) << file_->GetPath() << " " << section_header.sh_type;
- return reinterpret_cast<llvm::ELF::Elf32_Rel*>(Begin() + section_header.sh_offset);
+Elf32_Rel* ElfFile::GetRelSectionStart(Elf32_Shdr& section_header) {
+ CHECK(SHT_REL == section_header.sh_type) << file_->GetPath() << " " << section_header.sh_type;
+ return reinterpret_cast<Elf32_Rel*>(Begin() + section_header.sh_offset);
}
-llvm::ELF::Elf32_Word ElfFile::GetRelNum(llvm::ELF::Elf32_Shdr& section_header) {
- CHECK(llvm::ELF::SHT_REL == section_header.sh_type) << file_->GetPath() << " " << section_header.sh_type;
+Elf32_Word ElfFile::GetRelNum(Elf32_Shdr& section_header) {
+ CHECK(SHT_REL == section_header.sh_type) << file_->GetPath() << " " << section_header.sh_type;
CHECK_NE(0U, section_header.sh_entsize) << file_->GetPath();
return section_header.sh_size / section_header.sh_entsize;
}
-llvm::ELF::Elf32_Rel& ElfFile::GetRel(llvm::ELF::Elf32_Shdr& section_header, llvm::ELF::Elf32_Word i) {
- CHECK(llvm::ELF::SHT_REL == section_header.sh_type) << file_->GetPath() << " " << section_header.sh_type;
+Elf32_Rel& ElfFile::GetRel(Elf32_Shdr& section_header, Elf32_Word i) {
+ CHECK(SHT_REL == section_header.sh_type) << file_->GetPath() << " " << section_header.sh_type;
CHECK_LT(i, GetRelNum(section_header)) << file_->GetPath();
return *(GetRelSectionStart(section_header) + i);
}
-llvm::ELF::Elf32_Rela* ElfFile::GetRelaSectionStart(llvm::ELF::Elf32_Shdr& section_header) {
- CHECK(llvm::ELF::SHT_RELA == section_header.sh_type) << file_->GetPath() << " " << section_header.sh_type;
- return reinterpret_cast<llvm::ELF::Elf32_Rela*>(Begin() + section_header.sh_offset);
+Elf32_Rela* ElfFile::GetRelaSectionStart(Elf32_Shdr& section_header) {
+ CHECK(SHT_RELA == section_header.sh_type) << file_->GetPath() << " " << section_header.sh_type;
+ return reinterpret_cast<Elf32_Rela*>(Begin() + section_header.sh_offset);
}
-llvm::ELF::Elf32_Word ElfFile::GetRelaNum(llvm::ELF::Elf32_Shdr& section_header) {
- CHECK(llvm::ELF::SHT_RELA == section_header.sh_type) << file_->GetPath() << " " << section_header.sh_type;
+Elf32_Word ElfFile::GetRelaNum(Elf32_Shdr& section_header) {
+ CHECK(SHT_RELA == section_header.sh_type) << file_->GetPath() << " " << section_header.sh_type;
return section_header.sh_size / section_header.sh_entsize;
}
-llvm::ELF::Elf32_Rela& ElfFile::GetRela(llvm::ELF::Elf32_Shdr& section_header,
- llvm::ELF::Elf32_Word i) {
- CHECK(llvm::ELF::SHT_RELA == section_header.sh_type) << file_->GetPath() << " " << section_header.sh_type;
+Elf32_Rela& ElfFile::GetRela(Elf32_Shdr& section_header, Elf32_Word i) {
+ CHECK(SHT_RELA == section_header.sh_type) << file_->GetPath() << " " << section_header.sh_type;
CHECK_LT(i, GetRelaNum(section_header)) << file_->GetPath();
return *(GetRelaSectionStart(section_header) + i);
}
// Base on bionic phdr_table_get_load_size
size_t ElfFile::GetLoadedSize() {
- llvm::ELF::Elf32_Addr min_vaddr = 0xFFFFFFFFu;
- llvm::ELF::Elf32_Addr max_vaddr = 0x00000000u;
- for (llvm::ELF::Elf32_Word i = 0; i < GetProgramHeaderNum(); i++) {
- llvm::ELF::Elf32_Phdr& program_header = GetProgramHeader(i);
- if (program_header.p_type != llvm::ELF::PT_LOAD) {
+ Elf32_Addr min_vaddr = 0xFFFFFFFFu;
+ Elf32_Addr max_vaddr = 0x00000000u;
+ for (Elf32_Word i = 0; i < GetProgramHeaderNum(); i++) {
+ Elf32_Phdr& program_header = GetProgramHeader(i);
+ if (program_header.p_type != PT_LOAD) {
continue;
}
- llvm::ELF::Elf32_Addr begin_vaddr = program_header.p_vaddr;
+ Elf32_Addr begin_vaddr = program_header.p_vaddr;
if (begin_vaddr < min_vaddr) {
min_vaddr = begin_vaddr;
}
- llvm::ELF::Elf32_Addr end_vaddr = program_header.p_vaddr + program_header.p_memsz;
+ Elf32_Addr end_vaddr = program_header.p_vaddr + program_header.p_memsz;
if (end_vaddr > max_vaddr) {
max_vaddr = end_vaddr;
}
@@ -608,17 +607,17 @@
bool ElfFile::Load(bool executable, std::string* error_msg) {
// TODO: actually return false error
CHECK(program_header_only_) << file_->GetPath();
- for (llvm::ELF::Elf32_Word i = 0; i < GetProgramHeaderNum(); i++) {
- llvm::ELF::Elf32_Phdr& program_header = GetProgramHeader(i);
+ for (Elf32_Word i = 0; i < GetProgramHeaderNum(); i++) {
+ Elf32_Phdr& program_header = GetProgramHeader(i);
// Record .dynamic header information for later use
- if (program_header.p_type == llvm::ELF::PT_DYNAMIC) {
+ if (program_header.p_type == PT_DYNAMIC) {
dynamic_program_header_ = &program_header;
continue;
}
// Not something to load, move on.
- if (program_header.p_type != llvm::ELF::PT_LOAD) {
+ if (program_header.p_type != PT_LOAD) {
continue;
}
@@ -658,13 +657,13 @@
}
byte* p_vaddr = base_address_ + program_header.p_vaddr;
int prot = 0;
- if (executable && ((program_header.p_flags & llvm::ELF::PF_X) != 0)) {
+ if (executable && ((program_header.p_flags & PF_X) != 0)) {
prot |= PROT_EXEC;
}
- if ((program_header.p_flags & llvm::ELF::PF_W) != 0) {
+ if ((program_header.p_flags & PF_W) != 0) {
prot |= PROT_WRITE;
}
- if ((program_header.p_flags & llvm::ELF::PF_R) != 0) {
+ if ((program_header.p_flags & PF_R) != 0) {
prot |= PROT_READ;
}
int flags = MAP_FIXED;
@@ -695,24 +694,24 @@
// Now that we are done loading, .dynamic should be in memory to find .dynstr, .dynsym, .hash
dynamic_section_start_
- = reinterpret_cast<llvm::ELF::Elf32_Dyn*>(base_address_ + GetDynamicProgramHeader().p_vaddr);
- for (llvm::ELF::Elf32_Word i = 0; i < GetDynamicNum(); i++) {
- llvm::ELF::Elf32_Dyn& elf_dyn = GetDynamic(i);
+ = reinterpret_cast<Elf32_Dyn*>(base_address_ + GetDynamicProgramHeader().p_vaddr);
+ for (Elf32_Word i = 0; i < GetDynamicNum(); i++) {
+ Elf32_Dyn& elf_dyn = GetDynamic(i);
byte* d_ptr = base_address_ + elf_dyn.d_un.d_ptr;
switch (elf_dyn.d_tag) {
- case llvm::ELF::DT_HASH: {
- hash_section_start_ = reinterpret_cast<llvm::ELF::Elf32_Word*>(d_ptr);
+ case DT_HASH: {
+ hash_section_start_ = reinterpret_cast<Elf32_Word*>(d_ptr);
break;
}
- case llvm::ELF::DT_STRTAB: {
+ case DT_STRTAB: {
dynstr_section_start_ = reinterpret_cast<char*>(d_ptr);
break;
}
- case llvm::ELF::DT_SYMTAB: {
- dynsym_section_start_ = reinterpret_cast<llvm::ELF::Elf32_Sym*>(d_ptr);
+ case DT_SYMTAB: {
+ dynsym_section_start_ = reinterpret_cast<Elf32_Sym*>(d_ptr);
break;
}
- case llvm::ELF::DT_NULL: {
+ case DT_NULL: {
CHECK_EQ(GetDynamicNum(), i+1);
break;
}
diff --git a/runtime/elf_file.h b/runtime/elf_file.h
index f8c235d..baf4356 100644
--- a/runtime/elf_file.h
+++ b/runtime/elf_file.h
@@ -20,10 +20,9 @@
#include <map>
#include <vector>
-#include <llvm/Support/ELF.h>
-
#include "base/unix_file/fd_file.h"
#include "globals.h"
+#include "elf_utils.h"
#include "mem_map.h"
#include "os.h"
#include "UniquePtr.h"
@@ -56,24 +55,24 @@
return map_->Size();
}
- ::llvm::ELF::Elf32_Ehdr& GetHeader();
+ Elf32_Ehdr& GetHeader();
- ::llvm::ELF::Elf32_Word GetProgramHeaderNum();
- ::llvm::ELF::Elf32_Phdr& GetProgramHeader(::llvm::ELF::Elf32_Word);
- ::llvm::ELF::Elf32_Phdr* FindProgamHeaderByType(::llvm::ELF::Elf32_Word type);
+ Elf32_Word GetProgramHeaderNum();
+ Elf32_Phdr& GetProgramHeader(Elf32_Word);
+ Elf32_Phdr* FindProgamHeaderByType(Elf32_Word type);
- ::llvm::ELF::Elf32_Word GetSectionHeaderNum();
- ::llvm::ELF::Elf32_Shdr& GetSectionHeader(::llvm::ELF::Elf32_Word);
- ::llvm::ELF::Elf32_Shdr* FindSectionByType(::llvm::ELF::Elf32_Word type);
+ Elf32_Word GetSectionHeaderNum();
+ Elf32_Shdr& GetSectionHeader(Elf32_Word);
+ Elf32_Shdr* FindSectionByType(Elf32_Word type);
- ::llvm::ELF::Elf32_Shdr& GetSectionNameStringSection();
+ Elf32_Shdr& GetSectionNameStringSection();
// Find .dynsym using .hash for more efficient lookup than FindSymbolAddress.
byte* FindDynamicSymbolAddress(const std::string& symbol_name);
- static bool IsSymbolSectionType(::llvm::ELF::Elf32_Word section_type);
- ::llvm::ELF::Elf32_Word GetSymbolNum(::llvm::ELF::Elf32_Shdr&);
- ::llvm::ELF::Elf32_Sym& GetSymbol(::llvm::ELF::Elf32_Word section_type, ::llvm::ELF::Elf32_Word i);
+ static bool IsSymbolSectionType(Elf32_Word section_type);
+ Elf32_Word GetSymbolNum(Elf32_Shdr&);
+ Elf32_Sym& GetSymbol(Elf32_Word section_type, Elf32_Word i);
// Find symbol in specified table, returning NULL if it is not found.
//
@@ -83,32 +82,32 @@
// will be used if it was already created. Typically build_map
// should be set unless only a small number of symbols will be
// looked up.
- ::llvm::ELF::Elf32_Sym* FindSymbolByName(::llvm::ELF::Elf32_Word section_type,
+ Elf32_Sym* FindSymbolByName(Elf32_Word section_type,
const std::string& symbol_name,
bool build_map);
// Find address of symbol in specified table, returning 0 if it is
// not found. See FindSymbolByName for an explanation of build_map.
- ::llvm::ELF::Elf32_Addr FindSymbolAddress(::llvm::ELF::Elf32_Word section_type,
+ Elf32_Addr FindSymbolAddress(Elf32_Word section_type,
const std::string& symbol_name,
bool build_map);
// Lookup a string given string section and offset. Returns NULL for
// special 0 offset.
- const char* GetString(::llvm::ELF::Elf32_Shdr&, ::llvm::ELF::Elf32_Word);
+ const char* GetString(Elf32_Shdr&, Elf32_Word);
// Lookup a string by section type. Returns NULL for special 0 offset.
- const char* GetString(::llvm::ELF::Elf32_Word section_type, ::llvm::ELF::Elf32_Word);
+ const char* GetString(Elf32_Word section_type, Elf32_Word);
- ::llvm::ELF::Elf32_Word GetDynamicNum();
- ::llvm::ELF::Elf32_Dyn& GetDynamic(::llvm::ELF::Elf32_Word);
- ::llvm::ELF::Elf32_Word FindDynamicValueByType(::llvm::ELF::Elf32_Sword type);
+ Elf32_Word GetDynamicNum();
+ Elf32_Dyn& GetDynamic(Elf32_Word);
+ Elf32_Word FindDynamicValueByType(Elf32_Sword type);
- ::llvm::ELF::Elf32_Word GetRelNum(::llvm::ELF::Elf32_Shdr&);
- ::llvm::ELF::Elf32_Rel& GetRel(::llvm::ELF::Elf32_Shdr&, ::llvm::ELF::Elf32_Word);
+ Elf32_Word GetRelNum(Elf32_Shdr&);
+ Elf32_Rel& GetRel(Elf32_Shdr&, Elf32_Word);
- ::llvm::ELF::Elf32_Word GetRelaNum(::llvm::ELF::Elf32_Shdr&);
- ::llvm::ELF::Elf32_Rela& GetRela(::llvm::ELF::Elf32_Shdr&, ::llvm::ELF::Elf32_Word);
+ Elf32_Word GetRelaNum(Elf32_Shdr&);
+ Elf32_Rela& GetRela(Elf32_Shdr&, Elf32_Word);
// Returns the expected size when the file is loaded at runtime
size_t GetLoadedSize();
@@ -126,20 +125,20 @@
byte* GetProgramHeadersStart();
byte* GetSectionHeadersStart();
- ::llvm::ELF::Elf32_Phdr& GetDynamicProgramHeader();
- ::llvm::ELF::Elf32_Dyn* GetDynamicSectionStart();
- ::llvm::ELF::Elf32_Sym* GetSymbolSectionStart(::llvm::ELF::Elf32_Word section_type);
- const char* GetStringSectionStart(::llvm::ELF::Elf32_Word section_type);
- ::llvm::ELF::Elf32_Rel* GetRelSectionStart(::llvm::ELF::Elf32_Shdr&);
- ::llvm::ELF::Elf32_Rela* GetRelaSectionStart(::llvm::ELF::Elf32_Shdr&);
- ::llvm::ELF::Elf32_Word* GetHashSectionStart();
- ::llvm::ELF::Elf32_Word GetHashBucketNum();
- ::llvm::ELF::Elf32_Word GetHashChainNum();
- ::llvm::ELF::Elf32_Word GetHashBucket(size_t i);
- ::llvm::ELF::Elf32_Word GetHashChain(size_t i);
+ Elf32_Phdr& GetDynamicProgramHeader();
+ Elf32_Dyn* GetDynamicSectionStart();
+ Elf32_Sym* GetSymbolSectionStart(Elf32_Word section_type);
+ const char* GetStringSectionStart(Elf32_Word section_type);
+ Elf32_Rel* GetRelSectionStart(Elf32_Shdr&);
+ Elf32_Rela* GetRelaSectionStart(Elf32_Shdr&);
+ Elf32_Word* GetHashSectionStart();
+ Elf32_Word GetHashBucketNum();
+ Elf32_Word GetHashChainNum();
+ Elf32_Word GetHashBucket(size_t i);
+ Elf32_Word GetHashChain(size_t i);
- typedef std::map<std::string, ::llvm::ELF::Elf32_Sym*> SymbolTable;
- SymbolTable** GetSymbolTable(::llvm::ELF::Elf32_Word section_type);
+ typedef std::map<std::string, Elf32_Sym*> SymbolTable;
+ SymbolTable** GetSymbolTable(Elf32_Word section_type);
File* file_;
bool writable_;
@@ -147,7 +146,7 @@
// ELF header mapping. If program_header_only_ is false, will actually point to the entire elf file.
UniquePtr<MemMap> map_;
- ::llvm::ELF::Elf32_Ehdr* header_;
+ Elf32_Ehdr* header_;
std::vector<MemMap*> segments_;
// Pointer to start of first PT_LOAD program segment after Load() when program_header_only_ is true.
@@ -158,13 +157,13 @@
// Conditionally available values. Use accessors to ensure they exist if they are required.
byte* section_headers_start_;
- ::llvm::ELF::Elf32_Phdr* dynamic_program_header_;
- ::llvm::ELF::Elf32_Dyn* dynamic_section_start_;
- ::llvm::ELF::Elf32_Sym* symtab_section_start_;
- ::llvm::ELF::Elf32_Sym* dynsym_section_start_;
+ Elf32_Phdr* dynamic_program_header_;
+ Elf32_Dyn* dynamic_section_start_;
+ Elf32_Sym* symtab_section_start_;
+ Elf32_Sym* dynsym_section_start_;
const char* strtab_section_start_;
const char* dynstr_section_start_;
- ::llvm::ELF::Elf32_Word* hash_section_start_;
+ Elf32_Word* hash_section_start_;
SymbolTable* symtab_symbol_table_;
SymbolTable* dynsym_symbol_table_;
diff --git a/runtime/elf_utils.h b/runtime/elf_utils.h
new file mode 100644
index 0000000..acc6f46
--- /dev/null
+++ b/runtime/elf_utils.h
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ART_RUNTIME_ELF_UTILS_H_
+#define ART_RUNTIME_ELF_UTILS_H_
+
+// Include the micro-API to avoid potential macro conflicts with the
+// compiler's own elf.h file.
+#include "../../bionic/libc/kernel/uapi/linux/elf.h"
+
+// Architecture dependent flags for the ELF header.
+#define EF_ARM_EABI_VER5 0x05000000
+#define EF_MIPS_ABI_O32 0x00001000
+#define EF_MIPS_ARCH_32R2 0x70000000
+
+#define EI_ABIVERSION 8
+#define EM_ARM 40
+#define EF_MIPS_NOREORDER 1
+#define EF_MIPS_PIC 2
+#define EF_MIPS_CPIC 4
+#define STV_DEFAULT 0
+
+#define DT_BIND_NOW 24
+#define DT_INIT_ARRAY 25
+#define DT_FINI_ARRAY 26
+#define DT_INIT_ARRAYSZ 27
+#define DT_FINI_ARRAYSZ 28
+#define DT_RUNPATH 29
+#define DT_FLAGS 30
+
+/* MIPS dependent d_tag field for Elf32_Dyn. */
+#define DT_MIPS_RLD_VERSION 0x70000001 /* Runtime Linker Interface ID */
+#define DT_MIPS_TIME_STAMP 0x70000002 /* Timestamp */
+#define DT_MIPS_ICHECKSUM 0x70000003 /* Cksum of ext. str. and com. sizes */
+#define DT_MIPS_IVERSION 0x70000004 /* Version string (string tbl index) */
+#define DT_MIPS_FLAGS 0x70000005 /* Flags */
+#define DT_MIPS_BASE_ADDRESS 0x70000006 /* Segment base address */
+#define DT_MIPS_CONFLICT 0x70000008 /* Adr of .conflict section */
+#define DT_MIPS_LIBLIST 0x70000009 /* Address of .liblist section */
+#define DT_MIPS_LOCAL_GOTNO 0x7000000a /* Number of local .GOT entries */
+#define DT_MIPS_CONFLICTNO 0x7000000b /* Number of .conflict entries */
+#define DT_MIPS_LIBLISTNO 0x70000010 /* Number of .liblist entries */
+#define DT_MIPS_SYMTABNO 0x70000011 /* Number of .dynsym entries */
+#define DT_MIPS_UNREFEXTNO 0x70000012 /* First external DYNSYM */
+#define DT_MIPS_GOTSYM 0x70000013 /* First GOT entry in .dynsym */
+#define DT_MIPS_HIPAGENO 0x70000014 /* Number of GOT page table entries */
+#define DT_MIPS_RLD_MAP 0x70000016 /* Address of debug map pointer */
+
+inline void SetBindingAndType(Elf32_Sym* sym, unsigned char b, unsigned char t) {
+ sym->st_info = (b << 4) + (t & 0x0f);
+}
+
+#endif // ART_RUNTIME_ELF_UTILS_H_