Remove dependency on llvm/Support/ELF.h by using linux's elf.h.

Change-Id: Iefe66af9958641ac7f08fdc22f438d976e5b4d54
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,