diff options
author | Stephen Hines <srhines@google.com> | 2014-02-11 20:01:10 -0800 |
---|---|---|
committer | Stephen Hines <srhines@google.com> | 2014-02-11 20:01:10 -0800 |
commit | ce9904c6ea8fd669978a8eefb854b330eb9828ff (patch) | |
tree | 2418ee2e96ea220977c8fb74959192036ab5b133 /lib/Object | |
parent | c27b10b198c1d9e9b51f2303994313ec2778edd7 (diff) | |
parent | dbb832b83351cec97b025b61c26536ef50c3181c (diff) | |
download | external_llvm-ce9904c6ea8fd669978a8eefb854b330eb9828ff.zip external_llvm-ce9904c6ea8fd669978a8eefb854b330eb9828ff.tar.gz external_llvm-ce9904c6ea8fd669978a8eefb854b330eb9828ff.tar.bz2 |
Merge remote-tracking branch 'upstream/release_34' into merge-20140211
Conflicts:
lib/Linker/LinkModules.cpp
lib/Support/Unix/Signals.inc
Change-Id: Ia54f291fa5dc828052d2412736e8495c1282aa64
Diffstat (limited to 'lib/Object')
-rw-r--r-- | lib/Object/Binary.cpp | 4 | ||||
-rw-r--r-- | lib/Object/CMakeLists.txt | 1 | ||||
-rw-r--r-- | lib/Object/COFFObjectFile.cpp | 308 | ||||
-rw-r--r-- | lib/Object/ELF.cpp | 714 | ||||
-rw-r--r-- | lib/Object/ELFObjectFile.cpp | 3 | ||||
-rw-r--r-- | lib/Object/ELFYAML.cpp | 1 | ||||
-rw-r--r-- | lib/Object/MachOObjectFile.cpp | 817 | ||||
-rw-r--r-- | lib/Object/MachOUniversal.cpp | 58 | ||||
-rw-r--r-- | lib/Object/ObjectFile.cpp | 2 | ||||
-rw-r--r-- | lib/Object/YAML.cpp | 1 |
10 files changed, 1341 insertions, 568 deletions
diff --git a/lib/Object/Binary.cpp b/lib/Object/Binary.cpp index fd9d3b4..de57b4c 100644 --- a/lib/Object/Binary.cpp +++ b/lib/Object/Binary.cpp @@ -91,6 +91,7 @@ error_code object::createBinary(MemoryBuffer *Source, return object_error::success; } case sys::fs::file_magic::coff_object: + case sys::fs::file_magic::coff_import_library: case sys::fs::file_magic::pecoff_executable: { OwningPtr<Binary> ret( ObjectFile::createCOFFObjectFile(scopedSource.take())); @@ -100,7 +101,8 @@ error_code object::createBinary(MemoryBuffer *Source, return object_error::success; } case sys::fs::file_magic::unknown: - case sys::fs::file_magic::bitcode: { + case sys::fs::file_magic::bitcode: + case sys::fs::file_magic::windows_resource: { // Unrecognized object file format. return object_error::invalid_file_type; } diff --git a/lib/Object/CMakeLists.txt b/lib/Object/CMakeLists.txt index 2c2cc8e..1f07cbb 100644 --- a/lib/Object/CMakeLists.txt +++ b/lib/Object/CMakeLists.txt @@ -3,6 +3,7 @@ add_llvm_library(LLVMObject Binary.cpp COFFObjectFile.cpp COFFYAML.cpp + ELF.cpp ELFObjectFile.cpp ELFYAML.cpp Error.cpp diff --git a/lib/Object/COFFObjectFile.cpp b/lib/Object/COFFObjectFile.cpp index cb029f9..3434e70 100644 --- a/lib/Object/COFFObjectFile.cpp +++ b/lib/Object/COFFObjectFile.cpp @@ -16,6 +16,9 @@ #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/ADT/Triple.h" +#include "llvm/Support/Debug.h" +#include "llvm/Support/raw_ostream.h" +#include <cctype> #include <ctype.h> @@ -111,10 +114,8 @@ error_code COFFObjectFile::getSymbolFileOffset(DataRefImpl Symb, const coff_section *Section = NULL; if (error_code ec = getSection(symb->SectionNumber, Section)) return ec; - char Type; - if (error_code ec = getSymbolNMTypeChar(Symb, Type)) - return ec; - if (Type == 'U' || Type == 'w') + + if (symb->SectionNumber == COFF::IMAGE_SYM_UNDEFINED) Result = UnknownAddressOrSize; else if (Section) Result = Section->PointerToRawData + symb->Value; @@ -129,10 +130,8 @@ error_code COFFObjectFile::getSymbolAddress(DataRefImpl Symb, const coff_section *Section = NULL; if (error_code ec = getSection(symb->SectionNumber, Section)) return ec; - char Type; - if (error_code ec = getSymbolNMTypeChar(Symb, Type)) - return ec; - if (Type == 'U' || Type == 'w') + + if (symb->SectionNumber == COFF::IMAGE_SYM_UNDEFINED) Result = UnknownAddressOrSize; else if (Section) Result = Section->VirtualAddress + symb->Value; @@ -152,12 +151,16 @@ error_code COFFObjectFile::getSymbolType(DataRefImpl Symb, if (symb->getComplexType() == COFF::IMAGE_SYM_DTYPE_FUNCTION) { Result = SymbolRef::ST_Function; } else { - char Type; - if (error_code ec = getSymbolNMTypeChar(Symb, Type)) - return ec; - if (Type == 'r' || Type == 'R') { - Result = SymbolRef::ST_Data; + uint32_t Characteristics = 0; + if (symb->SectionNumber > 0) { + const coff_section *Section = NULL; + if (error_code ec = getSection(symb->SectionNumber, Section)) + return ec; + Characteristics = Section->Characteristics; } + if (Characteristics & COFF::IMAGE_SCN_MEM_READ && + ~Characteristics & COFF::IMAGE_SCN_MEM_WRITE) // Read only. + Result = SymbolRef::ST_Data; } } return object_error::success; @@ -196,10 +199,8 @@ error_code COFFObjectFile::getSymbolSize(DataRefImpl Symb, const coff_section *Section = NULL; if (error_code ec = getSection(symb->SectionNumber, Section)) return ec; - char Type; - if (error_code ec = getSymbolNMTypeChar(Symb, Type)) - return ec; - if (Type == 'U' || Type == 'w') + + if (symb->SectionNumber == COFF::IMAGE_SYM_UNDEFINED) Result = UnknownAddressOrSize; else if (Section) Result = Section->SizeOfRawData - symb->Value; @@ -208,74 +209,6 @@ error_code COFFObjectFile::getSymbolSize(DataRefImpl Symb, return object_error::success; } -error_code COFFObjectFile::getSymbolNMTypeChar(DataRefImpl Symb, - char &Result) const { - const coff_symbol *symb = toSymb(Symb); - StringRef name; - if (error_code ec = getSymbolName(Symb, name)) - return ec; - char ret = StringSwitch<char>(name) - .StartsWith(".debug", 'N') - .StartsWith(".sxdata", 'N') - .Default('?'); - - if (ret != '?') { - Result = ret; - return object_error::success; - } - - uint32_t Characteristics = 0; - if (symb->SectionNumber > 0) { - const coff_section *Section = NULL; - if (error_code ec = getSection(symb->SectionNumber, Section)) - return ec; - Characteristics = Section->Characteristics; - } - - switch (symb->SectionNumber) { - case COFF::IMAGE_SYM_UNDEFINED: - // Check storage classes. - if (symb->StorageClass == COFF::IMAGE_SYM_CLASS_WEAK_EXTERNAL) { - Result = 'w'; - return object_error::success; // Don't do ::toupper. - } else if (symb->Value != 0) // Check for common symbols. - ret = 'c'; - else - ret = 'u'; - break; - case COFF::IMAGE_SYM_ABSOLUTE: - ret = 'a'; - break; - case COFF::IMAGE_SYM_DEBUG: - ret = 'n'; - break; - default: - // Check section type. - if (Characteristics & COFF::IMAGE_SCN_CNT_CODE) - ret = 't'; - else if ( Characteristics & COFF::IMAGE_SCN_MEM_READ - && ~Characteristics & COFF::IMAGE_SCN_MEM_WRITE) // Read only. - ret = 'r'; - else if (Characteristics & COFF::IMAGE_SCN_CNT_INITIALIZED_DATA) - ret = 'd'; - else if (Characteristics & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA) - ret = 'b'; - else if (Characteristics & COFF::IMAGE_SCN_LNK_INFO) - ret = 'i'; - - // Check for section symbol. - else if ( symb->StorageClass == COFF::IMAGE_SYM_CLASS_STATIC - && symb->Value == 0) - ret = 's'; - } - - if (symb->StorageClass == COFF::IMAGE_SYM_CLASS_EXTERNAL) - ret = ::toupper(static_cast<unsigned char>(ret)); - - Result = ret; - return object_error::success; -} - error_code COFFObjectFile::getSymbolSection(DataRefImpl Symb, section_iterator &Result) const { const coff_symbol *symb = toSymb(Symb); @@ -406,7 +339,7 @@ error_code COFFObjectFile::sectionContainsSymbol(DataRefImpl Sec, return object_error::success; } -relocation_iterator COFFObjectFile::getSectionRelBegin(DataRefImpl Sec) const { +relocation_iterator COFFObjectFile::section_rel_begin(DataRefImpl Sec) const { const coff_section *sec = toSec(Sec); DataRefImpl ret; if (sec->NumberOfRelocations == 0) @@ -417,7 +350,7 @@ relocation_iterator COFFObjectFile::getSectionRelBegin(DataRefImpl Sec) const { return relocation_iterator(RelocationRef(ret, this)); } -relocation_iterator COFFObjectFile::getSectionRelEnd(DataRefImpl Sec) const { +relocation_iterator COFFObjectFile::section_rel_end(DataRefImpl Sec) const { const coff_section *sec = toSec(Sec); DataRefImpl ret; if (sec->NumberOfRelocations == 0) @@ -431,6 +364,94 @@ relocation_iterator COFFObjectFile::getSectionRelEnd(DataRefImpl Sec) const { return relocation_iterator(RelocationRef(ret, this)); } +// Initialize the pointer to the symbol table. +error_code COFFObjectFile::initSymbolTablePtr() { + if (error_code ec = getObject( + SymbolTable, Data, base() + COFFHeader->PointerToSymbolTable, + COFFHeader->NumberOfSymbols * sizeof(coff_symbol))) + return ec; + + // Find string table. The first four byte of the string table contains the + // total size of the string table, including the size field itself. If the + // string table is empty, the value of the first four byte would be 4. + const uint8_t *StringTableAddr = + base() + COFFHeader->PointerToSymbolTable + + COFFHeader->NumberOfSymbols * sizeof(coff_symbol); + const ulittle32_t *StringTableSizePtr; + if (error_code ec = getObject(StringTableSizePtr, Data, StringTableAddr)) + return ec; + StringTableSize = *StringTableSizePtr; + if (error_code ec = + getObject(StringTable, Data, StringTableAddr, StringTableSize)) + return ec; + + // Check that the string table is null terminated if has any in it. + if (StringTableSize < 4 || + (StringTableSize > 4 && StringTable[StringTableSize - 1] != 0)) + return object_error::parse_failed; + return object_error::success; +} + +// Returns the file offset for the given RVA. +error_code COFFObjectFile::getRvaPtr(uint32_t Rva, uintptr_t &Res) const { + error_code ec; + for (section_iterator i = begin_sections(), e = end_sections(); i != e; + i.increment(ec)) { + if (ec) + return ec; + const coff_section *Section = getCOFFSection(i); + uint32_t SectionStart = Section->VirtualAddress; + uint32_t SectionEnd = Section->VirtualAddress + Section->VirtualSize; + if (SectionStart <= Rva && Rva < SectionEnd) { + uint32_t Offset = Rva - SectionStart; + Res = uintptr_t(base()) + Section->PointerToRawData + Offset; + return object_error::success; + } + } + return object_error::parse_failed; +} + +// Returns hint and name fields, assuming \p Rva is pointing to a Hint/Name +// table entry. +error_code COFFObjectFile:: +getHintName(uint32_t Rva, uint16_t &Hint, StringRef &Name) const { + uintptr_t IntPtr = 0; + if (error_code ec = getRvaPtr(Rva, IntPtr)) + return ec; + const uint8_t *Ptr = reinterpret_cast<const uint8_t *>(IntPtr); + Hint = *reinterpret_cast<const ulittle16_t *>(Ptr); + Name = StringRef(reinterpret_cast<const char *>(Ptr + 2)); + return object_error::success; +} + +// Find the import table. +error_code COFFObjectFile::initImportTablePtr() { + // First, we get the RVA of the import table. If the file lacks a pointer to + // the import table, do nothing. + const data_directory *DataEntry; + if (getDataDirectory(COFF::IMPORT_TABLE, DataEntry)) + return object_error::success; + + // Do nothing if the pointer to import table is NULL. + if (DataEntry->RelativeVirtualAddress == 0) + return object_error::success; + + uint32_t ImportTableRva = DataEntry->RelativeVirtualAddress; + NumberOfImportDirectory = DataEntry->Size / + sizeof(import_directory_table_entry); + + // Find the section that contains the RVA. This is needed because the RVA is + // the import table's memory address which is different from its file offset. + uintptr_t IntPtr = 0; + if (error_code ec = getRvaPtr(ImportTableRva, IntPtr)) + return ec; + ImportDirectory = reinterpret_cast< + const import_directory_table_entry *>(IntPtr); + + // It's an error if there's no section containing the Import Table RVA. + return object_error::parse_failed; +} + COFFObjectFile::COFFObjectFile(MemoryBuffer *Object, error_code &ec) : ObjectFile(Binary::ID_COFF, Object) , COFFHeader(0) @@ -439,7 +460,9 @@ COFFObjectFile::COFFObjectFile(MemoryBuffer *Object, error_code &ec) , SectionTable(0) , SymbolTable(0) , StringTable(0) - , StringTableSize(0) { + , StringTableSize(0) + , ImportDirectory(0) + , NumberOfImportDirectory(0) { // Check that we at least have enough room for a header. if (!checkSize(Data, ec, sizeof(coff_file_header))) return; @@ -486,49 +509,33 @@ COFFObjectFile::COFFObjectFile(MemoryBuffer *Object, error_code &ec) CurPtr += COFFHeader->SizeOfOptionalHeader; } - if ((ec = getObject(SectionTable, Data, base() + CurPtr, - COFFHeader->NumberOfSections * sizeof(coff_section)))) - return; - - if (COFFHeader->PointerToSymbolTable != 0) { - if ((ec = getObject(SymbolTable, Data, - base() + COFFHeader->PointerToSymbolTable, - COFFHeader->NumberOfSymbols * sizeof(coff_symbol)))) + if (!COFFHeader->isImportLibrary()) + if ((ec = getObject(SectionTable, Data, base() + CurPtr, + COFFHeader->NumberOfSections * sizeof(coff_section)))) return; - // Find string table. The first four byte of the string table contains the - // total size of the string table, including the size field itself. If the - // string table is empty, the value of the first four byte would be 4. - const uint8_t *StringTableAddr = base() + COFFHeader->PointerToSymbolTable - + COFFHeader->NumberOfSymbols * sizeof(coff_symbol); - const ulittle32_t *StringTableSizePtr; - if ((ec = getObject(StringTableSizePtr, Data, StringTableAddr))) - return; - StringTableSize = *StringTableSizePtr; - if ((ec = getObject(StringTable, Data, StringTableAddr, StringTableSize))) + // Initialize the pointer to the symbol table. + if (COFFHeader->PointerToSymbolTable != 0) + if ((ec = initSymbolTablePtr())) return; - // Check that the string table is null terminated if has any in it. - if (StringTableSize < 4 - || (StringTableSize > 4 && StringTable[StringTableSize - 1] != 0)) { - ec = object_error::parse_failed; - return; - } - } + // Initialize the pointer to the beginning of the import table. + if ((ec = initImportTablePtr())) + return; ec = object_error::success; } symbol_iterator COFFObjectFile::begin_symbols() const { DataRefImpl ret; - ret.p = reinterpret_cast<intptr_t>(SymbolTable); + ret.p = reinterpret_cast<uintptr_t>(SymbolTable); return symbol_iterator(SymbolRef(ret, this)); } symbol_iterator COFFObjectFile::end_symbols() const { // The symbol table ends where the string table begins. DataRefImpl ret; - ret.p = reinterpret_cast<intptr_t>(StringTable); + ret.p = reinterpret_cast<uintptr_t>(StringTable); return symbol_iterator(SymbolRef(ret, this)); } @@ -557,16 +564,34 @@ StringRef COFFObjectFile::getLoadName() const { return ""; } +import_directory_iterator COFFObjectFile::import_directory_begin() const { + DataRefImpl Imp; + Imp.p = reinterpret_cast<uintptr_t>(ImportDirectory); + return import_directory_iterator(ImportDirectoryEntryRef(Imp, this)); +} + +import_directory_iterator COFFObjectFile::import_directory_end() const { + DataRefImpl Imp; + if (ImportDirectory) { + Imp.p = reinterpret_cast<uintptr_t>( + ImportDirectory + (NumberOfImportDirectory - 1)); + } else { + Imp.p = 0; + } + return import_directory_iterator(ImportDirectoryEntryRef(Imp, this)); +} section_iterator COFFObjectFile::begin_sections() const { DataRefImpl ret; - ret.p = reinterpret_cast<intptr_t>(SectionTable); + ret.p = reinterpret_cast<uintptr_t>(SectionTable); return section_iterator(SectionRef(ret, this)); } section_iterator COFFObjectFile::end_sections() const { DataRefImpl ret; - ret.p = reinterpret_cast<intptr_t>(SectionTable + COFFHeader->NumberOfSections); + int numSections = COFFHeader->isImportLibrary() + ? 0 : COFFHeader->NumberOfSections; + ret.p = reinterpret_cast<uintptr_t>(SectionTable + numSections); return section_iterator(SectionRef(ret, this)); } @@ -678,7 +703,7 @@ error_code COFFObjectFile::getSymbolName(const coff_symbol *symbol, ArrayRef<uint8_t> COFFObjectFile::getSymbolAuxData( const coff_symbol *symbol) const { const uint8_t *aux = NULL; - + if ( symbol->NumberOfAuxSymbols > 0 ) { // AUX data comes immediately after the symbol in COFF aux = reinterpret_cast<const uint8_t *>(symbol + 1); @@ -779,7 +804,6 @@ const coff_relocation *COFFObjectFile::getCOFFRelocation( return toRel(It->getRawDataRefImpl()); } - #define LLVM_COFF_SWITCH_RELOC_TYPE_NAME(enum) \ case COFF::enum: res = #enum; break; @@ -860,6 +884,52 @@ error_code COFFObjectFile::getLibraryPath(DataRefImpl LibData, report_fatal_error("getLibraryPath not implemented in COFFObjectFile"); } +bool ImportDirectoryEntryRef:: +operator==(const ImportDirectoryEntryRef &Other) const { + return ImportDirectoryPimpl == Other.ImportDirectoryPimpl; +} + +static const import_directory_table_entry *toImportEntry(DataRefImpl Imp) { + return reinterpret_cast<const import_directory_table_entry *>(Imp.p); +} + +error_code +ImportDirectoryEntryRef::getNext(ImportDirectoryEntryRef &Result) const { + const import_directory_table_entry *Dir = toImportEntry(ImportDirectoryPimpl); + Dir += 1; + DataRefImpl Next; + Next.p = reinterpret_cast<uintptr_t>(Dir); + Result = ImportDirectoryEntryRef(Next, OwningObject); + return object_error::success; +} + +error_code ImportDirectoryEntryRef:: +getImportTableEntry(const import_directory_table_entry *&Result) const { + Result = toImportEntry(ImportDirectoryPimpl); + return object_error::success; +} + +error_code ImportDirectoryEntryRef::getName(StringRef &Result) const { + const import_directory_table_entry *Dir = toImportEntry(ImportDirectoryPimpl); + uintptr_t IntPtr = 0; + if (error_code ec = OwningObject->getRvaPtr(Dir->NameRVA, IntPtr)) + return ec; + const char *Ptr = reinterpret_cast<const char *>(IntPtr); + Result = StringRef(Ptr); + return object_error::success; +} + +error_code ImportDirectoryEntryRef::getImportLookupEntry( + const import_lookup_table_entry32 *&Result) const { + const import_directory_table_entry *Dir = toImportEntry(ImportDirectoryPimpl); + uintptr_t IntPtr = 0; + if (error_code ec = OwningObject->getRvaPtr( + Dir->ImportLookupTableRVA, IntPtr)) + return ec; + Result = reinterpret_cast<const import_lookup_table_entry32 *>(IntPtr); + return object_error::success; +} + namespace llvm { ObjectFile *ObjectFile::createCOFFObjectFile(MemoryBuffer *Object) { diff --git a/lib/Object/ELF.cpp b/lib/Object/ELF.cpp new file mode 100644 index 0000000..7c80d41 --- /dev/null +++ b/lib/Object/ELF.cpp @@ -0,0 +1,714 @@ +//===- ELF.cpp - ELF object file implementation -----------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/Object/ELF.h" + +namespace llvm { +namespace object { + +#define LLVM_ELF_SWITCH_RELOC_TYPE_NAME(enum) \ + case ELF::enum: \ + return #enum; \ + +StringRef getELFRelocationTypeName(uint32_t Machine, uint32_t Type) { + switch (Machine) { + case ELF::EM_X86_64: + switch (Type) { + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_NONE); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_64); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_PC32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_GOT32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_PLT32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_COPY); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_GLOB_DAT); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_JUMP_SLOT); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_RELATIVE); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_GOTPCREL); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_32S); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_PC16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_8); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_PC8); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_DTPMOD64); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_DTPOFF64); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_TPOFF64); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_TLSGD); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_TLSLD); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_DTPOFF32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_GOTTPOFF); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_TPOFF32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_PC64); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_GOTOFF64); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_GOTPC32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_GOT64); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_GOTPCREL64); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_GOTPC64); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_GOTPLT64); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_PLTOFF64); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_SIZE32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_SIZE64); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_GOTPC32_TLSDESC); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_TLSDESC_CALL); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_TLSDESC); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_X86_64_IRELATIVE); + default: + break; + } + break; + case ELF::EM_386: + switch (Type) { + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_NONE); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_PC32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_GOT32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_PLT32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_COPY); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_GLOB_DAT); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_JUMP_SLOT); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_RELATIVE); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_GOTOFF); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_GOTPC); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_32PLT); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_TLS_TPOFF); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_TLS_IE); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_TLS_GOTIE); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_TLS_LE); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_TLS_GD); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_TLS_LDM); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_PC16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_8); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_PC8); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_TLS_GD_32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_TLS_GD_PUSH); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_TLS_GD_CALL); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_TLS_GD_POP); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_TLS_LDM_32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_TLS_LDM_PUSH); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_TLS_LDM_CALL); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_TLS_LDM_POP); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_TLS_LDO_32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_TLS_IE_32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_TLS_LE_32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_TLS_DTPMOD32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_TLS_DTPOFF32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_TLS_TPOFF32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_TLS_GOTDESC); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_TLS_DESC_CALL); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_TLS_DESC); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_386_IRELATIVE); + default: + break; + } + break; + case ELF::EM_MIPS: + switch (Type) { + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_NONE); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_REL32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_26); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_HI16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_LO16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_GPREL16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_LITERAL); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_GOT16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_PC16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_CALL16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_GPREL32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_SHIFT5); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_SHIFT6); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_64); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_GOT_DISP); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_GOT_PAGE); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_GOT_OFST); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_GOT_HI16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_GOT_LO16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_SUB); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_INSERT_A); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_INSERT_B); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_DELETE); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_HIGHER); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_HIGHEST); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_CALL_HI16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_CALL_LO16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_SCN_DISP); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_REL16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_ADD_IMMEDIATE); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_PJUMP); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_RELGOT); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_JALR); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_TLS_DTPMOD32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_TLS_DTPREL32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_TLS_DTPMOD64); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_TLS_DTPREL64); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_TLS_GD); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_TLS_LDM); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_TLS_DTPREL_HI16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_TLS_DTPREL_LO16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_TLS_GOTTPREL); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_TLS_TPREL32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_TLS_TPREL64); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_TLS_TPREL_HI16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_TLS_TPREL_LO16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_GLOB_DAT); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_COPY); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_JUMP_SLOT); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MICROMIPS_26_S1); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MICROMIPS_HI16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MICROMIPS_LO16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MICROMIPS_GOT16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MICROMIPS_PC16_S1); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MICROMIPS_CALL16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MICROMIPS_GOT_DISP); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MICROMIPS_GOT_PAGE); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MICROMIPS_GOT_OFST); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MICROMIPS_TLS_DTPREL_HI16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MICROMIPS_TLS_DTPREL_LO16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MICROMIPS_TLS_TPREL_HI16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MICROMIPS_TLS_TPREL_LO16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MIPS_NUM); + default: + break; + } + break; + case ELF::EM_AARCH64: + switch (Type) { + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_NONE); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_ABS64); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_ABS32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_ABS16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_PREL64); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_PREL32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_PREL16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_MOVW_UABS_G0); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_MOVW_UABS_G0_NC); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_MOVW_UABS_G1); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_MOVW_UABS_G1_NC); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_MOVW_UABS_G2); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_MOVW_UABS_G2_NC); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_MOVW_UABS_G3); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_MOVW_SABS_G0); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_MOVW_SABS_G1); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_MOVW_SABS_G2); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_LD_PREL_LO19); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_ADR_PREL_LO21); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_ADR_PREL_PG_HI21); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_ADD_ABS_LO12_NC); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_LDST8_ABS_LO12_NC); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TSTBR14); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_CONDBR19); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_JUMP26); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_CALL26); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_LDST16_ABS_LO12_NC); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_LDST32_ABS_LO12_NC); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_LDST64_ABS_LO12_NC); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_LDST128_ABS_LO12_NC); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_ADR_GOT_PAGE); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_LD64_GOT_LO12_NC); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLD_MOVW_DTPREL_G2); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLD_MOVW_DTPREL_G1); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLD_MOVW_DTPREL_G1_NC); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLD_MOVW_DTPREL_G0); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLD_MOVW_DTPREL_G0_NC); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLD_ADD_DTPREL_HI12); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLD_ADD_DTPREL_LO12); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLD_ADD_DTPREL_LO12_NC); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLD_LDST8_DTPREL_LO12); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLD_LDST16_DTPREL_LO12); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLD_LDST32_DTPREL_LO12); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLD_LDST64_DTPREL_LO12); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSIE_MOVW_GOTTPREL_G1); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSIE_LD_GOTTPREL_PREL19); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLE_MOVW_TPREL_G2); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLE_MOVW_TPREL_G1); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLE_MOVW_TPREL_G1_NC); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLE_MOVW_TPREL_G0); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLE_MOVW_TPREL_G0_NC); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLE_ADD_TPREL_HI12); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLE_ADD_TPREL_LO12); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLE_ADD_TPREL_LO12_NC); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLE_LDST8_TPREL_LO12); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLE_LDST8_TPREL_LO12_NC); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLE_LDST16_TPREL_LO12); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLE_LDST16_TPREL_LO12_NC); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLE_LDST32_TPREL_LO12); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLE_LDST32_TPREL_LO12_NC); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLE_LDST64_TPREL_LO12); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSLE_LDST64_TPREL_LO12_NC); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSDESC_ADR_PAGE); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSDESC_LD64_LO12_NC); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSDESC_ADD_LO12_NC); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_AARCH64_TLSDESC_CALL); + default: + break; + } + break; + case ELF::EM_ARM: + switch (Type) { + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_NONE); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_PC24); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_ABS32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_REL32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_LDR_PC_G0); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_ABS16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_ABS12); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_THM_ABS5); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_ABS8); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_SBREL32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_THM_CALL); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_THM_PC8); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_BREL_ADJ); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_TLS_DESC); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_THM_SWI8); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_XPC25); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_THM_XPC22); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_TLS_DTPMOD32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_TLS_DTPOFF32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_TLS_TPOFF32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_COPY); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_GLOB_DAT); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_JUMP_SLOT); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_RELATIVE); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_GOTOFF32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_BASE_PREL); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_GOT_BREL); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_PLT32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_CALL); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_JUMP24); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_THM_JUMP24); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_BASE_ABS); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_ALU_PCREL_7_0); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_ALU_PCREL_15_8); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_ALU_PCREL_23_15); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_LDR_SBREL_11_0_NC); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_ALU_SBREL_19_12_NC); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_ALU_SBREL_27_20_CK); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_TARGET1); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_SBREL31); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_V4BX); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_TARGET2); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_PREL31); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_MOVW_ABS_NC); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_MOVT_ABS); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_MOVW_PREL_NC); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_MOVT_PREL); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_THM_MOVW_ABS_NC); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_THM_MOVT_ABS); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_THM_MOVW_PREL_NC); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_THM_MOVT_PREL); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_THM_JUMP19); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_THM_JUMP6); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_THM_ALU_PREL_11_0); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_THM_PC12); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_ABS32_NOI); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_REL32_NOI); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_ALU_PC_G0_NC); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_ALU_PC_G0); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_ALU_PC_G1_NC); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_ALU_PC_G1); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_ALU_PC_G2); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_LDR_PC_G1); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_LDR_PC_G2); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_LDRS_PC_G0); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_LDRS_PC_G1); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_LDRS_PC_G2); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_LDC_PC_G0); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_LDC_PC_G1); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_LDC_PC_G2); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_ALU_SB_G0_NC); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_ALU_SB_G0); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_ALU_SB_G1_NC); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_ALU_SB_G1); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_ALU_SB_G2); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_LDR_SB_G0); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_LDR_SB_G1); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_LDR_SB_G2); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_LDRS_SB_G0); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_LDRS_SB_G1); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_LDRS_SB_G2); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_LDC_SB_G0); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_LDC_SB_G1); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_LDC_SB_G2); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_MOVW_BREL_NC); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_MOVT_BREL); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_MOVW_BREL); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_THM_MOVW_BREL_NC); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_THM_MOVT_BREL); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_THM_MOVW_BREL); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_TLS_GOTDESC); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_TLS_CALL); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_TLS_DESCSEQ); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_THM_TLS_CALL); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_PLT32_ABS); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_GOT_ABS); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_GOT_PREL); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_GOT_BREL12); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_GOTOFF12); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_GOTRELAX); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_GNU_VTENTRY); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_GNU_VTINHERIT); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_THM_JUMP11); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_THM_JUMP8); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_TLS_GD32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_TLS_LDM32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_TLS_LDO32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_TLS_IE32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_TLS_LE32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_TLS_LDO12); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_TLS_LE12); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_TLS_IE12GP); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_PRIVATE_0); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_PRIVATE_1); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_PRIVATE_2); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_PRIVATE_3); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_PRIVATE_4); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_PRIVATE_5); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_PRIVATE_6); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_PRIVATE_7); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_PRIVATE_8); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_PRIVATE_9); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_PRIVATE_10); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_PRIVATE_11); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_PRIVATE_12); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_PRIVATE_13); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_PRIVATE_14); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_PRIVATE_15); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_ME_TOO); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_THM_TLS_DESCSEQ16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_ARM_THM_TLS_DESCSEQ32); + default: + break; + } + break; + case ELF::EM_HEXAGON: + switch (Type) { + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_NONE); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_B22_PCREL); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_B15_PCREL); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_B7_PCREL); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_LO16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_HI16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_8); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_GPREL16_0); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_GPREL16_1); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_GPREL16_2); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_GPREL16_3); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_HL16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_B13_PCREL); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_B9_PCREL); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_B32_PCREL_X); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_32_6_X); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_B22_PCREL_X); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_B15_PCREL_X); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_B13_PCREL_X); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_B9_PCREL_X); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_B7_PCREL_X); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_16_X); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_12_X); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_11_X); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_10_X); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_9_X); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_8_X); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_7_X); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_6_X); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_32_PCREL); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_COPY); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_GLOB_DAT); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_JMP_SLOT); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_RELATIVE); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_PLT_B22_PCREL); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_GOTREL_LO16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_GOTREL_HI16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_GOTREL_32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_GOT_LO16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_GOT_HI16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_GOT_32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_GOT_16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_DTPMOD_32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_DTPREL_LO16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_DTPREL_HI16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_DTPREL_32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_DTPREL_16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_GD_PLT_B22_PCREL); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_GD_GOT_LO16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_GD_GOT_HI16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_GD_GOT_32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_GD_GOT_16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_IE_LO16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_IE_HI16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_IE_32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_IE_GOT_LO16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_IE_GOT_HI16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_IE_GOT_32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_IE_GOT_16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_TPREL_LO16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_TPREL_HI16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_TPREL_32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_TPREL_16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_6_PCREL_X); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_GOTREL_32_6_X); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_GOTREL_16_X); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_GOTREL_11_X); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_GOT_32_6_X); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_GOT_16_X); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_GOT_11_X); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_DTPREL_32_6_X); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_DTPREL_16_X); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_DTPREL_11_X); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_GD_GOT_32_6_X); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_GD_GOT_16_X); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_GD_GOT_11_X); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_IE_32_6_X); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_IE_16_X); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_IE_GOT_32_6_X); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_IE_GOT_16_X); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_IE_GOT_11_X); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_TPREL_32_6_X); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_TPREL_16_X); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_HEX_TPREL_11_X); + default: + break; + } + break; + case ELF::EM_PPC: + switch (Type) { + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_NONE); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_ADDR32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_ADDR24); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_ADDR16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_ADDR16_LO); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_ADDR16_HI); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_ADDR16_HA); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_ADDR14); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_ADDR14_BRTAKEN); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_ADDR14_BRNTAKEN); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_REL24); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_REL14); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_REL14_BRTAKEN); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_REL14_BRNTAKEN); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_GOT16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_GOT16_LO); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_GOT16_HI); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_GOT16_HA); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_REL32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_TLS); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_DTPMOD32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_TPREL16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_TPREL16_LO); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_TPREL16_HI); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_TPREL16_HA); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_TPREL32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_DTPREL16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_DTPREL16_LO); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_DTPREL16_HI); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_DTPREL16_HA); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_DTPREL32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_GOT_TLSGD16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_GOT_TLSGD16_LO); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_GOT_TLSGD16_HI); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_GOT_TLSGD16_HA); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_GOT_TLSLD16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_GOT_TLSLD16_LO); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_GOT_TLSLD16_HI); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_GOT_TLSLD16_HA); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_GOT_TPREL16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_GOT_TPREL16_LO); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_GOT_TPREL16_HI); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_GOT_TPREL16_HA); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_GOT_DTPREL16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_GOT_DTPREL16_LO); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_GOT_DTPREL16_HI); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_GOT_DTPREL16_HA); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_TLSGD); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_TLSLD); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_REL16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_REL16_LO); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_REL16_HI); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC_REL16_HA); + default: + break; + } + break; + case ELF::EM_PPC64: + switch (Type) { + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_NONE); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_ADDR32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_ADDR24); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_ADDR16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_ADDR16_LO); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_ADDR16_HI); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_ADDR16_HA); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_ADDR14); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_ADDR14_BRTAKEN); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_ADDR14_BRNTAKEN); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_REL24); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_REL14); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_REL14_BRTAKEN); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_REL14_BRNTAKEN); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_GOT16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_GOT16_LO); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_GOT16_HI); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_GOT16_HA); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_REL32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_ADDR64); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_ADDR16_HIGHER); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_ADDR16_HIGHERA); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_ADDR16_HIGHEST); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_ADDR16_HIGHESTA); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_REL64); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_TOC16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_TOC16_LO); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_TOC16_HI); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_TOC16_HA); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_TOC); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_ADDR16_DS); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_ADDR16_LO_DS); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_GOT16_DS); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_GOT16_LO_DS); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_TOC16_DS); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_TOC16_LO_DS); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_TLS); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_DTPMOD64); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_TPREL16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_TPREL16_LO); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_TPREL16_HI); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_TPREL16_HA); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_TPREL64); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_DTPREL16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_DTPREL16_LO); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_DTPREL16_HI); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_DTPREL16_HA); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_DTPREL64); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_GOT_TLSGD16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_GOT_TLSGD16_LO); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_GOT_TLSGD16_HI); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_GOT_TLSGD16_HA); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_GOT_TLSLD16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_GOT_TLSLD16_LO); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_GOT_TLSLD16_HI); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_GOT_TLSLD16_HA); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_GOT_TPREL16_DS); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_GOT_TPREL16_LO_DS); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_GOT_TPREL16_HI); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_GOT_TPREL16_HA); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_GOT_DTPREL16_DS); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_GOT_DTPREL16_LO_DS); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_GOT_DTPREL16_HI); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_GOT_DTPREL16_HA); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_TPREL16_DS); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_TPREL16_LO_DS); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_TPREL16_HIGHER); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_TPREL16_HIGHERA); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_TPREL16_HIGHEST); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_TPREL16_HIGHESTA); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_DTPREL16_DS); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_DTPREL16_LO_DS); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_DTPREL16_HIGHER); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_DTPREL16_HIGHERA); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_DTPREL16_HIGHEST); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_DTPREL16_HIGHESTA); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_TLSGD); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_TLSLD); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_REL16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_REL16_LO); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_REL16_HI); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_PPC64_REL16_HA); + default: + break; + } + break; + case ELF::EM_S390: + switch (Type) { + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_NONE); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_8); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_12); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_PC32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_GOT12); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_GOT32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_PLT32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_COPY); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_GLOB_DAT); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_JMP_SLOT); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_RELATIVE); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_GOTOFF); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_GOTPC); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_GOT16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_PC16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_PC16DBL); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_PLT16DBL); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_PC32DBL); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_PLT32DBL); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_GOTPCDBL); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_64); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_PC64); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_GOT64); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_PLT64); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_GOTENT); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_GOTOFF16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_GOTOFF64); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_GOTPLT12); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_GOTPLT16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_GOTPLT32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_GOTPLT64); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_GOTPLTENT); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_PLTOFF16); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_PLTOFF32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_PLTOFF64); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_TLS_LOAD); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_TLS_GDCALL); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_TLS_LDCALL); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_TLS_GD32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_TLS_GD64); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_TLS_GOTIE12); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_TLS_GOTIE32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_TLS_GOTIE64); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_TLS_LDM32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_TLS_LDM64); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_TLS_IE32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_TLS_IE64); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_TLS_IEENT); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_TLS_LE32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_TLS_LE64); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_TLS_LDO32); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_TLS_LDO64); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_TLS_DTPMOD); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_TLS_DTPOFF); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_TLS_TPOFF); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_20); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_GOT20); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_GOTPLT20); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_TLS_GOTIE20); + LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_390_IRELATIVE); + default: + break; + } + break; + default: + break; + } + return "Unknown"; +} + +#undef LLVM_ELF_SWITCH_RELOC_TYPE_NAME + +} // end namespace object +} // end namespace llvm diff --git a/lib/Object/ELFObjectFile.cpp b/lib/Object/ELFObjectFile.cpp index a6c128e..20b7307 100644 --- a/lib/Object/ELFObjectFile.cpp +++ b/lib/Object/ELFObjectFile.cpp @@ -11,13 +11,12 @@ // //===----------------------------------------------------------------------===// -#include "llvm/Object/ELF.h" +#include "llvm/Object/ELFObjectFile.h" #include "llvm/Support/MathExtras.h" #include <ctype.h> namespace llvm { - using namespace object; // Creates an in-memory object-file by default: createELFObjectFile(Buffer) diff --git a/lib/Object/ELFYAML.cpp b/lib/Object/ELFYAML.cpp index e530d3d..2f35cf9 100644 --- a/lib/Object/ELFYAML.cpp +++ b/lib/Object/ELFYAML.cpp @@ -266,6 +266,7 @@ void ScalarBitSetTraits<ELFYAML::ELF_SHF>::bitset(IO &IO, #define BCase(X) IO.bitSetCase(Value, #X, ELF::X); BCase(SHF_WRITE) BCase(SHF_ALLOC) + BCase(SHF_EXCLUDE) BCase(SHF_EXECINSTR) BCase(SHF_MERGE) BCase(SHF_STRINGS) diff --git a/lib/Object/MachOObjectFile.cpp b/lib/Object/MachOObjectFile.cpp index 5d0399e..d2cb8bd 100644 --- a/lib/Object/MachOObjectFile.cpp +++ b/lib/Object/MachOObjectFile.cpp @@ -14,11 +14,11 @@ #include "llvm/Object/MachO.h" #include "llvm/ADT/Triple.h" -#include "llvm/Object/MachOFormat.h" #include "llvm/Support/DataExtractor.h" #include "llvm/Support/Format.h" #include "llvm/Support/Host.h" #include "llvm/Support/MemoryBuffer.h" +#include "llvm/Support/raw_ostream.h" #include <cctype> #include <cstring> #include <limits> @@ -29,16 +29,16 @@ using namespace object; namespace llvm { namespace object { -struct SymbolTableEntryBase { - uint32_t StringIndex; - uint8_t Type; - uint8_t SectionIndex; - uint16_t Flags; +struct nlist_base { + uint32_t n_strx; + uint8_t n_type; + uint8_t n_sect; + uint16_t n_desc; }; -struct SectionBase { - char Name[16]; - char SegmentName[16]; +struct section_base { + char sectname[16]; + char segname[16]; }; template<typename T> @@ -50,167 +50,174 @@ template<typename T> static void SwapStruct(T &Value); template<> -void SwapStruct(macho::RelocationEntry &H) { - SwapValue(H.Word0); - SwapValue(H.Word1); +void SwapStruct(MachO::any_relocation_info &H) { + SwapValue(H.r_word0); + SwapValue(H.r_word1); } template<> -void SwapStruct(macho::LoadCommand &L) { - SwapValue(L.Type); - SwapValue(L.Size); +void SwapStruct(MachO::load_command &L) { + SwapValue(L.cmd); + SwapValue(L.cmdsize); } template<> -void SwapStruct(SymbolTableEntryBase &S) { - SwapValue(S.StringIndex); - SwapValue(S.Flags); +void SwapStruct(nlist_base &S) { + SwapValue(S.n_strx); + SwapValue(S.n_desc); } template<> -void SwapStruct(macho::Section &S) { - SwapValue(S.Address); - SwapValue(S.Size); - SwapValue(S.Offset); - SwapValue(S.Align); - SwapValue(S.RelocationTableOffset); - SwapValue(S.NumRelocationTableEntries); - SwapValue(S.Flags); - SwapValue(S.Reserved1); - SwapValue(S.Reserved2); +void SwapStruct(MachO::section &S) { + SwapValue(S.addr); + SwapValue(S.size); + SwapValue(S.offset); + SwapValue(S.align); + SwapValue(S.reloff); + SwapValue(S.nreloc); + SwapValue(S.flags); + SwapValue(S.reserved1); + SwapValue(S.reserved2); } template<> -void SwapStruct(macho::Section64 &S) { - SwapValue(S.Address); - SwapValue(S.Size); - SwapValue(S.Offset); - SwapValue(S.Align); - SwapValue(S.RelocationTableOffset); - SwapValue(S.NumRelocationTableEntries); - SwapValue(S.Flags); - SwapValue(S.Reserved1); - SwapValue(S.Reserved2); - SwapValue(S.Reserved3); +void SwapStruct(MachO::section_64 &S) { + SwapValue(S.addr); + SwapValue(S.size); + SwapValue(S.offset); + SwapValue(S.align); + SwapValue(S.reloff); + SwapValue(S.nreloc); + SwapValue(S.flags); + SwapValue(S.reserved1); + SwapValue(S.reserved2); + SwapValue(S.reserved3); } template<> -void SwapStruct(macho::SymbolTableEntry &S) { - SwapValue(S.StringIndex); - SwapValue(S.Flags); - SwapValue(S.Value); +void SwapStruct(MachO::nlist &S) { + SwapValue(S.n_strx); + SwapValue(S.n_desc); + SwapValue(S.n_value); } template<> -void SwapStruct(macho::Symbol64TableEntry &S) { - SwapValue(S.StringIndex); - SwapValue(S.Flags); - SwapValue(S.Value); +void SwapStruct(MachO::nlist_64 &S) { + SwapValue(S.n_strx); + SwapValue(S.n_desc); + SwapValue(S.n_value); } template<> -void SwapStruct(macho::Header &H) { - SwapValue(H.Magic); - SwapValue(H.CPUType); - SwapValue(H.CPUSubtype); - SwapValue(H.FileType); - SwapValue(H.NumLoadCommands); - SwapValue(H.SizeOfLoadCommands); - SwapValue(H.Flags); +void SwapStruct(MachO::mach_header &H) { + SwapValue(H.magic); + SwapValue(H.cputype); + SwapValue(H.cpusubtype); + SwapValue(H.filetype); + SwapValue(H.ncmds); + SwapValue(H.sizeofcmds); + SwapValue(H.flags); } template<> -void SwapStruct(macho::Header64Ext &E) { - SwapValue(E.Reserved); +void SwapStruct(MachO::mach_header_64 &H) { + SwapValue(H.magic); + SwapValue(H.cputype); + SwapValue(H.cpusubtype); + SwapValue(H.filetype); + SwapValue(H.ncmds); + SwapValue(H.sizeofcmds); + SwapValue(H.flags); + SwapValue(H.reserved); } template<> -void SwapStruct(macho::SymtabLoadCommand &C) { - SwapValue(C.Type); - SwapValue(C.Size); - SwapValue(C.SymbolTableOffset); - SwapValue(C.NumSymbolTableEntries); - SwapValue(C.StringTableOffset); - SwapValue(C.StringTableSize); +void SwapStruct(MachO::symtab_command &C) { + SwapValue(C.cmd); + SwapValue(C.cmdsize); + SwapValue(C.symoff); + SwapValue(C.nsyms); + SwapValue(C.stroff); + SwapValue(C.strsize); } template<> -void SwapStruct(macho::DysymtabLoadCommand &C) { - SwapValue(C.Type); - SwapValue(C.Size); - SwapValue(C.LocalSymbolsIndex); - SwapValue(C.NumLocalSymbols); - SwapValue(C.ExternalSymbolsIndex); - SwapValue(C.NumExternalSymbols); - SwapValue(C.UndefinedSymbolsIndex); - SwapValue(C.NumUndefinedSymbols); - SwapValue(C.TOCOffset); - SwapValue(C.NumTOCEntries); - SwapValue(C.ModuleTableOffset); - SwapValue(C.NumModuleTableEntries); - SwapValue(C.ReferenceSymbolTableOffset); - SwapValue(C.NumReferencedSymbolTableEntries); - SwapValue(C.IndirectSymbolTableOffset); - SwapValue(C.NumIndirectSymbolTableEntries); - SwapValue(C.ExternalRelocationTableOffset); - SwapValue(C.NumExternalRelocationTableEntries); - SwapValue(C.LocalRelocationTableOffset); - SwapValue(C.NumLocalRelocationTableEntries); +void SwapStruct(MachO::dysymtab_command &C) { + SwapValue(C.cmd); + SwapValue(C.cmdsize); + SwapValue(C.ilocalsym); + SwapValue(C.nlocalsym); + SwapValue(C.iextdefsym); + SwapValue(C.nextdefsym); + SwapValue(C.iundefsym); + SwapValue(C.nundefsym); + SwapValue(C.tocoff); + SwapValue(C.ntoc); + SwapValue(C.modtaboff); + SwapValue(C.nmodtab); + SwapValue(C.extrefsymoff); + SwapValue(C.nextrefsyms); + SwapValue(C.indirectsymoff); + SwapValue(C.nindirectsyms); + SwapValue(C.extreloff); + SwapValue(C.nextrel); + SwapValue(C.locreloff); + SwapValue(C.nlocrel); } template<> -void SwapStruct(macho::LinkeditDataLoadCommand &C) { - SwapValue(C.Type); - SwapValue(C.Size); - SwapValue(C.DataOffset); - SwapValue(C.DataSize); +void SwapStruct(MachO::linkedit_data_command &C) { + SwapValue(C.cmd); + SwapValue(C.cmdsize); + SwapValue(C.dataoff); + SwapValue(C.datasize); } template<> -void SwapStruct(macho::SegmentLoadCommand &C) { - SwapValue(C.Type); - SwapValue(C.Size); - SwapValue(C.VMAddress); - SwapValue(C.VMSize); - SwapValue(C.FileOffset); - SwapValue(C.FileSize); - SwapValue(C.MaxVMProtection); - SwapValue(C.InitialVMProtection); - SwapValue(C.NumSections); - SwapValue(C.Flags); +void SwapStruct(MachO::segment_command &C) { + SwapValue(C.cmd); + SwapValue(C.cmdsize); + SwapValue(C.vmaddr); + SwapValue(C.vmsize); + SwapValue(C.fileoff); + SwapValue(C.filesize); + SwapValue(C.maxprot); + SwapValue(C.initprot); + SwapValue(C.nsects); + SwapValue(C.flags); } template<> -void SwapStruct(macho::Segment64LoadCommand &C) { - SwapValue(C.Type); - SwapValue(C.Size); - SwapValue(C.VMAddress); - SwapValue(C.VMSize); - SwapValue(C.FileOffset); - SwapValue(C.FileSize); - SwapValue(C.MaxVMProtection); - SwapValue(C.InitialVMProtection); - SwapValue(C.NumSections); - SwapValue(C.Flags); +void SwapStruct(MachO::segment_command_64 &C) { + SwapValue(C.cmd); + SwapValue(C.cmdsize); + SwapValue(C.vmaddr); + SwapValue(C.vmsize); + SwapValue(C.fileoff); + SwapValue(C.filesize); + SwapValue(C.maxprot); + SwapValue(C.initprot); + SwapValue(C.nsects); + SwapValue(C.flags); } template<> -void SwapStruct(macho::IndirectSymbolTableEntry &C) { - SwapValue(C.Index); +void SwapStruct(uint32_t &C) { + SwapValue(C); } template<> -void SwapStruct(macho::LinkerOptionsLoadCommand &C) { - SwapValue(C.Type); - SwapValue(C.Size); - SwapValue(C.Count); +void SwapStruct(MachO::linker_options_command &C) { + SwapValue(C.cmd); + SwapValue(C.cmdsize); + SwapValue(C.count); } template<> -void SwapStruct(macho::DataInCodeTableEntry &C) { - SwapValue(C.Offset); - SwapValue(C.Length); - SwapValue(C.Kind); +void SwapStruct(MachO::data_in_code_entry &C) { + SwapValue(C.offset); + SwapValue(C.length); + SwapValue(C.kind); } template<typename T> @@ -226,11 +233,11 @@ static uint32_t getSegmentLoadCommandNumSections(const MachOObjectFile *O, const MachOObjectFile::LoadCommandInfo &L) { if (O->is64Bit()) { - macho::Segment64LoadCommand S = O->getSegment64LoadCommand(L); - return S.NumSections; + MachO::segment_command_64 S = O->getSegment64LoadCommand(L); + return S.nsects; } - macho::SegmentLoadCommand S = O->getSegmentLoadCommand(L); - return S.NumSections; + MachO::segment_command S = O->getSegmentLoadCommand(L); + return S.nsects; } static const char * @@ -239,10 +246,10 @@ getSectionPtr(const MachOObjectFile *O, MachOObjectFile::LoadCommandInfo L, uintptr_t CommandAddr = reinterpret_cast<uintptr_t>(L.Ptr); bool Is64 = O->is64Bit(); - unsigned SegmentLoadSize = Is64 ? sizeof(macho::Segment64LoadCommand) : - sizeof(macho::SegmentLoadCommand); - unsigned SectionSize = Is64 ? sizeof(macho::Section64) : - sizeof(macho::Section); + unsigned SegmentLoadSize = Is64 ? sizeof(MachO::segment_command_64) : + sizeof(MachO::segment_command); + unsigned SectionSize = Is64 ? sizeof(MachO::section_64) : + sizeof(MachO::section); uintptr_t SectionAddr = CommandAddr + SegmentLoadSize + Sec * SectionSize; return reinterpret_cast<const char*>(SectionAddr); @@ -252,10 +259,10 @@ static const char *getPtr(const MachOObjectFile *O, size_t Offset) { return O->getData().substr(Offset, 1).data(); } -static SymbolTableEntryBase +static nlist_base getSymbolTableEntryBase(const MachOObjectFile *O, DataRefImpl DRI) { const char *P = reinterpret_cast<const char *>(DRI.p); - return getStruct<SymbolTableEntryBase>(O, P); + return getStruct<nlist_base>(O, P); } static StringRef parseSegmentOrSectionName(const char *P) { @@ -283,11 +290,11 @@ static void advanceTo(T &it, size_t Val) { } static unsigned getCPUType(const MachOObjectFile *O) { - return O->getHeader().CPUType; + return O->getHeader().cputype; } static void printRelocationTargetName(const MachOObjectFile *O, - const macho::RelocationEntry &RE, + const MachO::any_relocation_info &RE, raw_string_ostream &fmt) { bool IsScattered = O->isRelocationScattered(RE); @@ -355,59 +362,61 @@ static void printRelocationTargetName(const MachOObjectFile *O, fmt << S; } -static uint32_t getPlainRelocationAddress(const macho::RelocationEntry &RE) { - return RE.Word0; +static uint32_t +getPlainRelocationAddress(const MachO::any_relocation_info &RE) { + return RE.r_word0; } static unsigned -getScatteredRelocationAddress(const macho::RelocationEntry &RE) { - return RE.Word0 & 0xffffff; +getScatteredRelocationAddress(const MachO::any_relocation_info &RE) { + return RE.r_word0 & 0xffffff; } static bool getPlainRelocationPCRel(const MachOObjectFile *O, - const macho::RelocationEntry &RE) { + const MachO::any_relocation_info &RE) { if (O->isLittleEndian()) - return (RE.Word1 >> 24) & 1; - return (RE.Word1 >> 7) & 1; + return (RE.r_word1 >> 24) & 1; + return (RE.r_word1 >> 7) & 1; } static bool getScatteredRelocationPCRel(const MachOObjectFile *O, - const macho::RelocationEntry &RE) { - return (RE.Word0 >> 30) & 1; + const MachO::any_relocation_info &RE) { + return (RE.r_word0 >> 30) & 1; } static unsigned getPlainRelocationLength(const MachOObjectFile *O, - const macho::RelocationEntry &RE) { + const MachO::any_relocation_info &RE) { if (O->isLittleEndian()) - return (RE.Word1 >> 25) & 3; - return (RE.Word1 >> 5) & 3; + return (RE.r_word1 >> 25) & 3; + return (RE.r_word1 >> 5) & 3; } static unsigned -getScatteredRelocationLength(const macho::RelocationEntry &RE) { - return (RE.Word0 >> 28) & 3; +getScatteredRelocationLength(const MachO::any_relocation_info &RE) { + return (RE.r_word0 >> 28) & 3; } static unsigned getPlainRelocationType(const MachOObjectFile *O, - const macho::RelocationEntry &RE) { + const MachO::any_relocation_info &RE) { if (O->isLittleEndian()) - return RE.Word1 >> 28; - return RE.Word1 & 0xf; + return RE.r_word1 >> 28; + return RE.r_word1 & 0xf; } -static unsigned getScatteredRelocationType(const macho::RelocationEntry &RE) { - return (RE.Word0 >> 24) & 0xf; +static unsigned +getScatteredRelocationType(const MachO::any_relocation_info &RE) { + return (RE.r_word0 >> 24) & 0xf; } static uint32_t getSectionFlags(const MachOObjectFile *O, DataRefImpl Sec) { if (O->is64Bit()) { - macho::Section64 Sect = O->getSection64(Sec); - return Sect.Flags; + MachO::section_64 Sect = O->getSection64(Sec); + return Sect.flags; } - macho::Section Sect = O->getSection(Sec); - return Sect.Flags; + MachO::section Sect = O->getSection(Sec); + return Sect.flags; } MachOObjectFile::MachOObjectFile(MemoryBuffer *Object, @@ -415,22 +424,22 @@ MachOObjectFile::MachOObjectFile(MemoryBuffer *Object, error_code &ec) : ObjectFile(getMachOType(IsLittleEndian, Is64bits), Object), SymtabLoadCmd(NULL), DysymtabLoadCmd(NULL), DataInCodeLoadCmd(NULL) { - uint32_t LoadCommandCount = this->getHeader().NumLoadCommands; - macho::LoadCommandType SegmentLoadType = is64Bit() ? - macho::LCT_Segment64 : macho::LCT_Segment; + uint32_t LoadCommandCount = this->getHeader().ncmds; + MachO::LoadCommandType SegmentLoadType = is64Bit() ? + MachO::LC_SEGMENT_64 : MachO::LC_SEGMENT; MachOObjectFile::LoadCommandInfo Load = getFirstLoadCommandInfo(); for (unsigned I = 0; ; ++I) { - if (Load.C.Type == macho::LCT_Symtab) { + if (Load.C.cmd == MachO::LC_SYMTAB) { assert(!SymtabLoadCmd && "Multiple symbol tables"); SymtabLoadCmd = Load.Ptr; - } else if (Load.C.Type == macho::LCT_Dysymtab) { + } else if (Load.C.cmd == MachO::LC_DYSYMTAB) { assert(!DysymtabLoadCmd && "Multiple dynamic symbol tables"); DysymtabLoadCmd = Load.Ptr; - } else if (Load.C.Type == macho::LCT_DataInCode) { + } else if (Load.C.cmd == MachO::LC_DATA_IN_CODE) { assert(!DataInCodeLoadCmd && "Multiple data in code tables"); DataInCodeLoadCmd = Load.Ptr; - } else if (Load.C.Type == SegmentLoadType) { + } else if (Load.C.cmd == SegmentLoadType) { uint32_t NumSections = getSegmentLoadCommandNumSections(this, Load); for (unsigned J = 0; J < NumSections; ++J) { const char *Sec = getSectionPtr(this, Load, J); @@ -448,8 +457,8 @@ MachOObjectFile::MachOObjectFile(MemoryBuffer *Object, error_code MachOObjectFile::getSymbolNext(DataRefImpl Symb, SymbolRef &Res) const { unsigned SymbolTableEntrySize = is64Bit() ? - sizeof(macho::Symbol64TableEntry) : - sizeof(macho::SymbolTableEntry); + sizeof(MachO::nlist_64) : + sizeof(MachO::nlist); Symb.p += SymbolTableEntrySize; Res = SymbolRef(Symb, this); return object_error::success; @@ -458,8 +467,8 @@ error_code MachOObjectFile::getSymbolNext(DataRefImpl Symb, error_code MachOObjectFile::getSymbolName(DataRefImpl Symb, StringRef &Res) const { StringRef StringTable = getStringTableData(); - SymbolTableEntryBase Entry = getSymbolTableEntryBase(this, Symb); - const char *Start = &StringTable.data()[Entry.StringIndex]; + nlist_base Entry = getSymbolTableEntryBase(this, Symb); + const char *Start = &StringTable.data()[Entry.n_strx]; Res = StringRef(Start); return object_error::success; } @@ -467,11 +476,11 @@ error_code MachOObjectFile::getSymbolName(DataRefImpl Symb, error_code MachOObjectFile::getSymbolAddress(DataRefImpl Symb, uint64_t &Res) const { if (is64Bit()) { - macho::Symbol64TableEntry Entry = getSymbol64TableEntry(Symb); - Res = Entry.Value; + MachO::nlist_64 Entry = getSymbol64TableEntry(Symb); + Res = Entry.n_value; } else { - macho::SymbolTableEntry Entry = getSymbolTableEntry(Symb); - Res = Entry.Value; + MachO::nlist Entry = getSymbolTableEntry(Symb); + Res = Entry.n_value; } return object_error::success; } @@ -479,18 +488,18 @@ error_code MachOObjectFile::getSymbolAddress(DataRefImpl Symb, error_code MachOObjectFile::getSymbolFileOffset(DataRefImpl Symb, uint64_t &Res) const { - SymbolTableEntryBase Entry = getSymbolTableEntryBase(this, Symb); + nlist_base Entry = getSymbolTableEntryBase(this, Symb); getSymbolAddress(Symb, Res); - if (Entry.SectionIndex) { + if (Entry.n_sect) { uint64_t Delta; DataRefImpl SecRel; - SecRel.d.a = Entry.SectionIndex-1; + SecRel.d.a = Entry.n_sect-1; if (is64Bit()) { - macho::Section64 Sec = getSection64(SecRel); - Delta = Sec.Offset - Sec.Address; + MachO::section_64 Sec = getSection64(SecRel); + Delta = Sec.offset - Sec.addr; } else { - macho::Section Sec = getSection(SecRel); - Delta = Sec.Offset - Sec.Address; + MachO::section Sec = getSection(SecRel); + Delta = Sec.offset - Sec.addr; } Res += Delta; @@ -504,8 +513,8 @@ error_code MachOObjectFile::getSymbolAlignment(DataRefImpl DRI, uint32_t flags; this->getSymbolFlags(DRI, flags); if (flags & SymbolRef::SF_Common) { - SymbolTableEntryBase Entry = getSymbolTableEntryBase(this, DRI); - Result = 1 << MachO::GET_COMM_ALIGN(Entry.Flags); + nlist_base Entry = getSymbolTableEntryBase(this, DRI); + Result = 1 << MachO::GET_COMM_ALIGN(Entry.n_desc); } else { Result = 0; } @@ -518,13 +527,13 @@ error_code MachOObjectFile::getSymbolSize(DataRefImpl DRI, uint64_t EndOffset = 0; uint8_t SectionIndex; - SymbolTableEntryBase Entry = getSymbolTableEntryBase(this, DRI); + nlist_base Entry = getSymbolTableEntryBase(this, DRI); uint64_t Value; getSymbolAddress(DRI, Value); BeginOffset = Value; - SectionIndex = Entry.SectionIndex; + SectionIndex = Entry.n_sect; if (!SectionIndex) { uint32_t flags = SymbolRef::SF_None; this->getSymbolFlags(DRI, flags); @@ -542,7 +551,7 @@ error_code MachOObjectFile::getSymbolSize(DataRefImpl DRI, DataRefImpl DRI = I->getRawDataRefImpl(); Entry = getSymbolTableEntryBase(this, DRI); getSymbolAddress(DRI, Value); - if (Entry.SectionIndex == SectionIndex && Value > BeginOffset) + if (Entry.n_sect == SectionIndex && Value > BeginOffset) if (!EndOffset || Value < EndOffset) EndOffset = Value; } @@ -560,73 +569,47 @@ error_code MachOObjectFile::getSymbolSize(DataRefImpl DRI, error_code MachOObjectFile::getSymbolType(DataRefImpl Symb, SymbolRef::Type &Res) const { - SymbolTableEntryBase Entry = getSymbolTableEntryBase(this, Symb); - uint8_t n_type = Entry.Type; + nlist_base Entry = getSymbolTableEntryBase(this, Symb); + uint8_t n_type = Entry.n_type; Res = SymbolRef::ST_Other; // If this is a STAB debugging symbol, we can do nothing more. - if (n_type & MachO::NlistMaskStab) { + if (n_type & MachO::N_STAB) { Res = SymbolRef::ST_Debug; return object_error::success; } - switch (n_type & MachO::NlistMaskType) { - case MachO::NListTypeUndefined : + switch (n_type & MachO::N_TYPE) { + case MachO::N_UNDF : Res = SymbolRef::ST_Unknown; break; - case MachO::NListTypeSection : + case MachO::N_SECT : Res = SymbolRef::ST_Function; break; } return object_error::success; } -error_code MachOObjectFile::getSymbolNMTypeChar(DataRefImpl Symb, - char &Res) const { - SymbolTableEntryBase Entry = getSymbolTableEntryBase(this, Symb); - uint8_t Type = Entry.Type; - uint16_t Flags = Entry.Flags; - - char Char; - switch (Type & macho::STF_TypeMask) { - case macho::STT_Undefined: - Char = 'u'; - break; - case macho::STT_Absolute: - case macho::STT_Section: - Char = 's'; - break; - default: - Char = '?'; - break; - } - - if (Flags & (macho::STF_External | macho::STF_PrivateExtern)) - Char = toupper(static_cast<unsigned char>(Char)); - Res = Char; - return object_error::success; -} - error_code MachOObjectFile::getSymbolFlags(DataRefImpl DRI, uint32_t &Result) const { - SymbolTableEntryBase Entry = getSymbolTableEntryBase(this, DRI); + nlist_base Entry = getSymbolTableEntryBase(this, DRI); - uint8_t MachOType = Entry.Type; - uint16_t MachOFlags = Entry.Flags; + uint8_t MachOType = Entry.n_type; + uint16_t MachOFlags = Entry.n_desc; // TODO: Correctly set SF_ThreadLocal Result = SymbolRef::SF_None; - if ((MachOType & MachO::NlistMaskType) == MachO::NListTypeUndefined) + if ((MachOType & MachO::N_TYPE) == MachO::N_UNDF) Result |= SymbolRef::SF_Undefined; - if (MachOFlags & macho::STF_StabsEntryMask) + if (MachOType & MachO::N_STAB) Result |= SymbolRef::SF_FormatSpecific; - if (MachOType & MachO::NlistMaskExternal) { + if (MachOType & MachO::N_EXT) { Result |= SymbolRef::SF_Global; - if ((MachOType & MachO::NlistMaskType) == MachO::NListTypeUndefined) { + if ((MachOType & MachO::N_TYPE) == MachO::N_UNDF) { uint64_t Value; getSymbolAddress(DRI, Value); if (Value) @@ -634,10 +617,10 @@ error_code MachOObjectFile::getSymbolFlags(DataRefImpl DRI, } } - if (MachOFlags & (MachO::NListDescWeakRef | MachO::NListDescWeakDef)) + if (MachOFlags & (MachO::N_WEAK_REF | MachO::N_WEAK_DEF)) Result |= SymbolRef::SF_Weak; - if ((MachOType & MachO::NlistMaskType) == MachO::NListTypeAbsolute) + if ((MachOType & MachO::N_TYPE) == MachO::N_ABS) Result |= SymbolRef::SF_Absolute; return object_error::success; @@ -646,8 +629,8 @@ error_code MachOObjectFile::getSymbolFlags(DataRefImpl DRI, error_code MachOObjectFile::getSymbolSection(DataRefImpl Symb, section_iterator &Res) const { - SymbolTableEntryBase Entry = getSymbolTableEntryBase(this, Symb); - uint8_t index = Entry.SectionIndex; + nlist_base Entry = getSymbolTableEntryBase(this, Symb); + uint8_t index = Entry.n_sect; if (index == 0) { Res = end_sections(); @@ -682,11 +665,11 @@ MachOObjectFile::getSectionName(DataRefImpl Sec, StringRef &Result) const { error_code MachOObjectFile::getSectionAddress(DataRefImpl Sec, uint64_t &Res) const { if (is64Bit()) { - macho::Section64 Sect = getSection64(Sec); - Res = Sect.Address; + MachO::section_64 Sect = getSection64(Sec); + Res = Sect.addr; } else { - macho::Section Sect = getSection(Sec); - Res = Sect.Address; + MachO::section Sect = getSection(Sec); + Res = Sect.addr; } return object_error::success; } @@ -694,11 +677,11 @@ MachOObjectFile::getSectionAddress(DataRefImpl Sec, uint64_t &Res) const { error_code MachOObjectFile::getSectionSize(DataRefImpl Sec, uint64_t &Res) const { if (is64Bit()) { - macho::Section64 Sect = getSection64(Sec); - Res = Sect.Size; + MachO::section_64 Sect = getSection64(Sec); + Res = Sect.size; } else { - macho::Section Sect = getSection(Sec); - Res = Sect.Size; + MachO::section Sect = getSection(Sec); + Res = Sect.size; } return object_error::success; @@ -710,13 +693,13 @@ MachOObjectFile::getSectionContents(DataRefImpl Sec, StringRef &Res) const { uint64_t Size; if (is64Bit()) { - macho::Section64 Sect = getSection64(Sec); - Offset = Sect.Offset; - Size = Sect.Size; + MachO::section_64 Sect = getSection64(Sec); + Offset = Sect.offset; + Size = Sect.size; } else { - macho::Section Sect =getSection(Sec); - Offset = Sect.Offset; - Size = Sect.Size; + MachO::section Sect = getSection(Sec); + Offset = Sect.offset; + Size = Sect.size; } Res = this->getData().substr(Offset, Size); @@ -727,11 +710,11 @@ error_code MachOObjectFile::getSectionAlignment(DataRefImpl Sec, uint64_t &Res) const { uint32_t Align; if (is64Bit()) { - macho::Section64 Sect = getSection64(Sec); - Align = Sect.Align; + MachO::section_64 Sect = getSection64(Sec); + Align = Sect.align; } else { - macho::Section Sect = getSection(Sec); - Align = Sect.Align; + MachO::section Sect = getSection(Sec); + Align = Sect.align; } Res = uint64_t(1) << Align; @@ -741,7 +724,7 @@ MachOObjectFile::getSectionAlignment(DataRefImpl Sec, uint64_t &Res) const { error_code MachOObjectFile::isSectionText(DataRefImpl Sec, bool &Res) const { uint32_t Flags = getSectionFlags(this, Sec); - Res = Flags & macho::SF_PureInstructions; + Res = Flags & MachO::S_ATTR_PURE_INSTRUCTIONS; return object_error::success; } @@ -775,9 +758,9 @@ error_code MachOObjectFile::isSectionVirtual(DataRefImpl Sec, error_code MachOObjectFile::isSectionZeroInit(DataRefImpl Sec, bool &Res) const { uint32_t Flags = getSectionFlags(this, Sec); - unsigned SectionType = Flags & MachO::SectionFlagMaskSectionType; - Res = SectionType == MachO::SectionTypeZeroFill || - SectionType == MachO::SectionTypeZeroFillLarge; + unsigned SectionType = Flags & MachO::SECTION_TYPE; + Res = SectionType == MachO::S_ZEROFILL || + SectionType == MachO::S_GB_ZEROFILL; return object_error::success; } @@ -814,14 +797,14 @@ MachOObjectFile::sectionContainsSymbol(DataRefImpl Sec, DataRefImpl Symb, return object_error::success; } -relocation_iterator MachOObjectFile::getSectionRelBegin(DataRefImpl Sec) const { +relocation_iterator MachOObjectFile::section_rel_begin(DataRefImpl Sec) const { uint32_t Offset; if (is64Bit()) { - macho::Section64 Sect = getSection64(Sec); - Offset = Sect.RelocationTableOffset; + MachO::section_64 Sect = getSection64(Sec); + Offset = Sect.reloff; } else { - macho::Section Sect = getSection(Sec); - Offset = Sect.RelocationTableOffset; + MachO::section Sect = getSection(Sec); + Offset = Sect.reloff; } DataRefImpl Ret; @@ -830,21 +813,21 @@ relocation_iterator MachOObjectFile::getSectionRelBegin(DataRefImpl Sec) const { } relocation_iterator -MachOObjectFile::getSectionRelEnd(DataRefImpl Sec) const { +MachOObjectFile::section_rel_end(DataRefImpl Sec) const { uint32_t Offset; uint32_t Num; if (is64Bit()) { - macho::Section64 Sect = getSection64(Sec); - Offset = Sect.RelocationTableOffset; - Num = Sect.NumRelocationTableEntries; + MachO::section_64 Sect = getSection64(Sec); + Offset = Sect.reloff; + Num = Sect.nreloc; } else { - macho::Section Sect = getSection(Sec); - Offset = Sect.RelocationTableOffset; - Num = Sect.NumRelocationTableEntries; + MachO::section Sect = getSection(Sec); + Offset = Sect.reloff; + Num = Sect.nreloc; } - const macho::RelocationEntry *P = - reinterpret_cast<const macho::RelocationEntry*>(getPtr(this, Offset)); + const MachO::any_relocation_info *P = + reinterpret_cast<const MachO::any_relocation_info *>(getPtr(this, Offset)); DataRefImpl Ret; Ret.p = reinterpret_cast<uintptr_t>(P + Num); @@ -853,8 +836,8 @@ MachOObjectFile::getSectionRelEnd(DataRefImpl Sec) const { error_code MachOObjectFile::getRelocationNext(DataRefImpl Rel, RelocationRef &Res) const { - const macho::RelocationEntry *P = - reinterpret_cast<const macho::RelocationEntry *>(Rel.p); + const MachO::any_relocation_info *P = + reinterpret_cast<const MachO::any_relocation_info *>(Rel.p); Rel.p = reinterpret_cast<uintptr_t>(P + 1); Res = RelocationRef(Rel, this); return object_error::success; @@ -867,24 +850,24 @@ MachOObjectFile::getRelocationAddress(DataRefImpl Rel, uint64_t &Res) const { error_code MachOObjectFile::getRelocationOffset(DataRefImpl Rel, uint64_t &Res) const { - macho::RelocationEntry RE = getRelocation(Rel); + MachO::any_relocation_info RE = getRelocation(Rel); Res = getAnyRelocationAddress(RE); return object_error::success; } symbol_iterator MachOObjectFile::getRelocationSymbol(DataRefImpl Rel) const { - macho::RelocationEntry RE = getRelocation(Rel); + MachO::any_relocation_info RE = getRelocation(Rel); uint32_t SymbolIdx = getPlainRelocationSymbolNum(RE); bool isExtern = getPlainRelocationExternal(RE); if (!isExtern) return end_symbols(); - macho::SymtabLoadCommand S = getSymtabLoadCommand(); + MachO::symtab_command S = getSymtabLoadCommand(); unsigned SymbolTableEntrySize = is64Bit() ? - sizeof(macho::Symbol64TableEntry) : - sizeof(macho::SymbolTableEntry); - uint64_t Offset = S.SymbolTableOffset + SymbolIdx * SymbolTableEntrySize; + sizeof(MachO::nlist_64) : + sizeof(MachO::nlist); + uint64_t Offset = S.symoff + SymbolIdx * SymbolTableEntrySize; DataRefImpl Sym; Sym.p = reinterpret_cast<uintptr_t>(getPtr(this, Offset)); return symbol_iterator(SymbolRef(Sym, this)); @@ -892,7 +875,7 @@ MachOObjectFile::getRelocationSymbol(DataRefImpl Rel) const { error_code MachOObjectFile::getRelocationType(DataRefImpl Rel, uint64_t &Res) const { - macho::RelocationEntry RE = getRelocation(Rel); + MachO::any_relocation_info RE = getRelocation(Rel); Res = getAnyRelocationType(RE); return object_error::success; } @@ -993,7 +976,7 @@ MachOObjectFile::getRelocationTypeName(DataRefImpl Rel, error_code MachOObjectFile::getRelocationValueString(DataRefImpl Rel, SmallVectorImpl<char> &Result) const { - macho::RelocationEntry RE = getRelocation(Rel); + MachO::any_relocation_info RE = getRelocation(Rel); unsigned Arch = this->getArch(); @@ -1010,47 +993,47 @@ MachOObjectFile::getRelocationValueString(DataRefImpl Rel, bool isPCRel = getAnyRelocationPCRel(RE); switch (Type) { - case macho::RIT_X86_64_GOTLoad: // X86_64_RELOC_GOT_LOAD - case macho::RIT_X86_64_GOT: { // X86_64_RELOC_GOT + case MachO::X86_64_RELOC_GOT_LOAD: + case MachO::X86_64_RELOC_GOT: { printRelocationTargetName(this, RE, fmt); fmt << "@GOT"; if (isPCRel) fmt << "PCREL"; break; } - case macho::RIT_X86_64_Subtractor: { // X86_64_RELOC_SUBTRACTOR + case MachO::X86_64_RELOC_SUBTRACTOR: { DataRefImpl RelNext = Rel; RelNext.d.a++; - macho::RelocationEntry RENext = getRelocation(RelNext); + MachO::any_relocation_info RENext = getRelocation(RelNext); - // X86_64_SUBTRACTOR must be followed by a relocation of type + // X86_64_RELOC_SUBTRACTOR must be followed by a relocation of type // X86_64_RELOC_UNSIGNED. // NOTE: Scattered relocations don't exist on x86_64. unsigned RType = getAnyRelocationType(RENext); - if (RType != 0) + if (RType != MachO::X86_64_RELOC_UNSIGNED) report_fatal_error("Expected X86_64_RELOC_UNSIGNED after " "X86_64_RELOC_SUBTRACTOR."); - // The X86_64_RELOC_UNSIGNED contains the minuend symbol, - // X86_64_SUBTRACTOR contains to the subtrahend. + // The X86_64_RELOC_UNSIGNED contains the minuend symbol; + // X86_64_RELOC_SUBTRACTOR contains the subtrahend. printRelocationTargetName(this, RENext, fmt); fmt << "-"; printRelocationTargetName(this, RE, fmt); break; } - case macho::RIT_X86_64_TLV: + case MachO::X86_64_RELOC_TLV: printRelocationTargetName(this, RE, fmt); fmt << "@TLV"; if (isPCRel) fmt << "P"; break; - case macho::RIT_X86_64_Signed1: // X86_64_RELOC_SIGNED1 + case MachO::X86_64_RELOC_SIGNED_1: printRelocationTargetName(this, RE, fmt); fmt << "-1"; break; - case macho::RIT_X86_64_Signed2: // X86_64_RELOC_SIGNED2 + case MachO::X86_64_RELOC_SIGNED_2: printRelocationTargetName(this, RE, fmt); fmt << "-2"; break; - case macho::RIT_X86_64_Signed4: // X86_64_RELOC_SIGNED4 + case MachO::X86_64_RELOC_SIGNED_4: printRelocationTargetName(this, RE, fmt); fmt << "-4"; break; @@ -1059,21 +1042,22 @@ MachOObjectFile::getRelocationValueString(DataRefImpl Rel, break; } // X86 and ARM share some relocation types in common. - } else if (Arch == Triple::x86 || Arch == Triple::arm) { + } else if (Arch == Triple::x86 || Arch == Triple::arm || + Arch == Triple::ppc) { // Generic relocation types... switch (Type) { - case macho::RIT_Pair: // GENERIC_RELOC_PAIR - prints no info + case MachO::GENERIC_RELOC_PAIR: // prints no info return object_error::success; - case macho::RIT_Difference: { // GENERIC_RELOC_SECTDIFF + case MachO::GENERIC_RELOC_SECTDIFF: { DataRefImpl RelNext = Rel; RelNext.d.a++; - macho::RelocationEntry RENext = getRelocation(RelNext); + MachO::any_relocation_info RENext = getRelocation(RelNext); // X86 sect diff's must be followed by a relocation of type // GENERIC_RELOC_PAIR. unsigned RType = getAnyRelocationType(RENext); - if (RType != 1) + if (RType != MachO::GENERIC_RELOC_PAIR) report_fatal_error("Expected GENERIC_RELOC_PAIR after " "GENERIC_RELOC_SECTDIFF."); @@ -1084,19 +1068,17 @@ MachOObjectFile::getRelocationValueString(DataRefImpl Rel, } } - if (Arch == Triple::x86) { - // All X86 relocations that need special printing were already - // handled in the generic code. + if (Arch == Triple::x86 || Arch == Triple::ppc) { switch (Type) { - case macho::RIT_Generic_LocalDifference:{// GENERIC_RELOC_LOCAL_SECTDIFF + case MachO::GENERIC_RELOC_LOCAL_SECTDIFF: { DataRefImpl RelNext = Rel; RelNext.d.a++; - macho::RelocationEntry RENext = getRelocation(RelNext); + MachO::any_relocation_info RENext = getRelocation(RelNext); // X86 sect diff's must be followed by a relocation of type // GENERIC_RELOC_PAIR. unsigned RType = getAnyRelocationType(RENext); - if (RType != 1) + if (RType != MachO::GENERIC_RELOC_PAIR) report_fatal_error("Expected GENERIC_RELOC_PAIR after " "GENERIC_RELOC_LOCAL_SECTDIFF."); @@ -1105,7 +1087,7 @@ MachOObjectFile::getRelocationValueString(DataRefImpl Rel, printRelocationTargetName(this, RENext, fmt); break; } - case macho::RIT_Generic_TLV: { + case MachO::GENERIC_RELOC_TLV: { printRelocationTargetName(this, RE, fmt); fmt << "@TLV"; if (IsPCRel) fmt << "P"; @@ -1116,8 +1098,8 @@ MachOObjectFile::getRelocationValueString(DataRefImpl Rel, } } else { // ARM-specific relocations switch (Type) { - case macho::RIT_ARM_Half: // ARM_RELOC_HALF - case macho::RIT_ARM_HalfDifference: { // ARM_RELOC_HALF_SECTDIFF + case MachO::ARM_RELOC_HALF: + case MachO::ARM_RELOC_HALF_SECTDIFF: { // Half relocations steal a bit from the length field to encode // whether this is an upper16 or a lower16 relocation. bool isUpper = getAnyRelocationLength(RE) >> 1; @@ -1130,14 +1112,14 @@ MachOObjectFile::getRelocationValueString(DataRefImpl Rel, DataRefImpl RelNext = Rel; RelNext.d.a++; - macho::RelocationEntry RENext = getRelocation(RelNext); + MachO::any_relocation_info RENext = getRelocation(RelNext); // ARM half relocs must be followed by a relocation of type // ARM_RELOC_PAIR. unsigned RType = getAnyRelocationType(RENext); - if (RType != 1) + if (RType != MachO::ARM_RELOC_PAIR) report_fatal_error("Expected ARM_RELOC_PAIR after " - "GENERIC_RELOC_HALF"); + "ARM_RELOC_HALF"); // NOTE: The half of the target virtual address is stashed in the // address field of the secondary relocation, but we can't reverse @@ -1146,7 +1128,7 @@ MachOObjectFile::getRelocationValueString(DataRefImpl Rel, // ARM_RELOC_HALF_SECTDIFF encodes the second section in the // symbol/section pointer of the follow-on relocation. - if (Type == macho::RIT_ARM_HalfDifference) { + if (Type == MachO::ARM_RELOC_HALF_SECTDIFF) { fmt << "-"; printRelocationTargetName(this, RENext, fmt); } @@ -1177,17 +1159,17 @@ MachOObjectFile::getRelocationHidden(DataRefImpl Rel, bool &Result) const { // On arches that use the generic relocations, GENERIC_RELOC_PAIR // is always hidden. - if (Arch == Triple::x86 || Arch == Triple::arm) { - if (Type == macho::RIT_Pair) Result = true; + if (Arch == Triple::x86 || Arch == Triple::arm || Arch == Triple::ppc) { + if (Type == MachO::GENERIC_RELOC_PAIR) Result = true; } else if (Arch == Triple::x86_64) { // On x86_64, X86_64_RELOC_UNSIGNED is hidden only when it follows // an X86_64_RELOC_SUBTRACTOR. - if (Type == macho::RIT_X86_64_Unsigned && Rel.d.a > 0) { + if (Type == MachO::X86_64_RELOC_UNSIGNED && Rel.d.a > 0) { DataRefImpl RelPrev = Rel; RelPrev.d.a--; uint64_t PrevType; getRelocationType(RelPrev, PrevType); - if (PrevType == macho::RIT_X86_64_Subtractor) + if (PrevType == MachO::X86_64_RELOC_SUBTRACTOR) Result = true; } } @@ -1210,8 +1192,8 @@ symbol_iterator MachOObjectFile::begin_symbols() const { if (!SymtabLoadCmd) return symbol_iterator(SymbolRef(DRI, this)); - macho::SymtabLoadCommand Symtab = getSymtabLoadCommand(); - DRI.p = reinterpret_cast<uintptr_t>(getPtr(this, Symtab.SymbolTableOffset)); + MachO::symtab_command Symtab = getSymtabLoadCommand(); + DRI.p = reinterpret_cast<uintptr_t>(getPtr(this, Symtab.symoff)); return symbol_iterator(SymbolRef(DRI, this)); } @@ -1220,12 +1202,12 @@ symbol_iterator MachOObjectFile::end_symbols() const { if (!SymtabLoadCmd) return symbol_iterator(SymbolRef(DRI, this)); - macho::SymtabLoadCommand Symtab = getSymtabLoadCommand(); + MachO::symtab_command Symtab = getSymtabLoadCommand(); unsigned SymbolTableEntrySize = is64Bit() ? - sizeof(macho::Symbol64TableEntry) : - sizeof(macho::SymbolTableEntry); - unsigned Offset = Symtab.SymbolTableOffset + - Symtab.NumSymbolTableEntries * SymbolTableEntrySize; + sizeof(MachO::nlist_64) : + sizeof(MachO::nlist); + unsigned Offset = Symtab.symoff + + Symtab.nsyms * SymbolTableEntrySize; DRI.p = reinterpret_cast<uintptr_t>(getPtr(this, Offset)); return symbol_iterator(SymbolRef(DRI, this)); } @@ -1269,28 +1251,28 @@ StringRef MachOObjectFile::getFileFormatName() const { unsigned CPUType = getCPUType(this); if (!is64Bit()) { switch (CPUType) { - case llvm::MachO::CPUTypeI386: + case llvm::MachO::CPU_TYPE_I386: return "Mach-O 32-bit i386"; - case llvm::MachO::CPUTypeARM: + case llvm::MachO::CPU_TYPE_ARM: return "Mach-O arm"; - case llvm::MachO::CPUTypePowerPC: + case llvm::MachO::CPU_TYPE_POWERPC: return "Mach-O 32-bit ppc"; default: - assert((CPUType & llvm::MachO::CPUArchABI64) == 0 && + assert((CPUType & llvm::MachO::CPU_ARCH_ABI64) == 0 && "64-bit object file when we're not 64-bit?"); return "Mach-O 32-bit unknown"; } } // Make sure the cpu type has the correct mask. - assert((CPUType & llvm::MachO::CPUArchABI64) - == llvm::MachO::CPUArchABI64 && + assert((CPUType & llvm::MachO::CPU_ARCH_ABI64) + == llvm::MachO::CPU_ARCH_ABI64 && "32-bit object file when we're 64-bit?"); switch (CPUType) { - case llvm::MachO::CPUTypeX86_64: + case llvm::MachO::CPU_TYPE_X86_64: return "Mach-O 64-bit x86-64"; - case llvm::MachO::CPUTypePowerPC64: + case llvm::MachO::CPU_TYPE_POWERPC64: return "Mach-O 64-bit ppc64"; default: return "Mach-O 64-bit unknown"; @@ -1299,15 +1281,15 @@ StringRef MachOObjectFile::getFileFormatName() const { Triple::ArchType MachOObjectFile::getArch(uint32_t CPUType) { switch (CPUType) { - case llvm::MachO::CPUTypeI386: + case llvm::MachO::CPU_TYPE_I386: return Triple::x86; - case llvm::MachO::CPUTypeX86_64: + case llvm::MachO::CPU_TYPE_X86_64: return Triple::x86_64; - case llvm::MachO::CPUTypeARM: + case llvm::MachO::CPU_TYPE_ARM: return Triple::arm; - case llvm::MachO::CPUTypePowerPC: + case llvm::MachO::CPU_TYPE_POWERPC: return Triple::ppc; - case llvm::MachO::CPUTypePowerPC64: + case llvm::MachO::CPU_TYPE_POWERPC64: return Triple::ppc64; default: return Triple::UnknownArch; @@ -1323,16 +1305,16 @@ StringRef MachOObjectFile::getLoadName() const { report_fatal_error("get_load_name() unimplemented in MachOObjectFile"); } -relocation_iterator MachOObjectFile::getSectionRelBegin(unsigned Index) const { +relocation_iterator MachOObjectFile::section_rel_begin(unsigned Index) const { DataRefImpl DRI; DRI.d.a = Index; - return getSectionRelBegin(DRI); + return section_rel_begin(DRI); } -relocation_iterator MachOObjectFile::getSectionRelEnd(unsigned Index) const { +relocation_iterator MachOObjectFile::section_rel_end(unsigned Index) const { DataRefImpl DRI; DRI.d.a = Index; - return getSectionRelEnd(DRI); + return section_rel_end(DRI); } dice_iterator MachOObjectFile::begin_dices() const { @@ -1340,8 +1322,8 @@ dice_iterator MachOObjectFile::begin_dices() const { if (!DataInCodeLoadCmd) return dice_iterator(DiceRef(DRI, this)); - macho::LinkeditDataLoadCommand DicLC = getDataInCodeLoadCommand(); - DRI.p = reinterpret_cast<uintptr_t>(getPtr(this, DicLC.DataOffset)); + MachO::linkedit_data_command DicLC = getDataInCodeLoadCommand(); + DRI.p = reinterpret_cast<uintptr_t>(getPtr(this, DicLC.dataoff)); return dice_iterator(DiceRef(DRI, this)); } @@ -1350,8 +1332,8 @@ dice_iterator MachOObjectFile::end_dices() const { if (!DataInCodeLoadCmd) return dice_iterator(DiceRef(DRI, this)); - macho::LinkeditDataLoadCommand DicLC = getDataInCodeLoadCommand(); - unsigned Offset = DicLC.DataOffset + DicLC.DataSize; + MachO::linkedit_data_command DicLC = getDataInCodeLoadCommand(); + unsigned Offset = DicLC.dataoff + DicLC.datasize; DRI.p = reinterpret_cast<uintptr_t>(getPtr(this, Offset)); return dice_iterator(DiceRef(DRI, this)); } @@ -1364,80 +1346,82 @@ MachOObjectFile::getSectionFinalSegmentName(DataRefImpl Sec) const { ArrayRef<char> MachOObjectFile::getSectionRawName(DataRefImpl Sec) const { - const SectionBase *Base = - reinterpret_cast<const SectionBase*>(Sections[Sec.d.a]); - return ArrayRef<char>(Base->Name); + const section_base *Base = + reinterpret_cast<const section_base *>(Sections[Sec.d.a]); + return ArrayRef<char>(Base->sectname); } ArrayRef<char> MachOObjectFile::getSectionRawFinalSegmentName(DataRefImpl Sec) const { - const SectionBase *Base = - reinterpret_cast<const SectionBase*>(Sections[Sec.d.a]); - return ArrayRef<char>(Base->SegmentName); + const section_base *Base = + reinterpret_cast<const section_base *>(Sections[Sec.d.a]); + return ArrayRef<char>(Base->segname); } bool -MachOObjectFile::isRelocationScattered(const macho::RelocationEntry &RE) +MachOObjectFile::isRelocationScattered(const MachO::any_relocation_info &RE) const { - if (getCPUType(this) == llvm::MachO::CPUTypeX86_64) + if (getCPUType(this) == MachO::CPU_TYPE_X86_64) return false; - return getPlainRelocationAddress(RE) & macho::RF_Scattered; + return getPlainRelocationAddress(RE) & MachO::R_SCATTERED; } unsigned MachOObjectFile::getPlainRelocationSymbolNum( - const macho::RelocationEntry &RE) const { + const MachO::any_relocation_info &RE) const { if (isLittleEndian()) - return RE.Word1 & 0xffffff; - return RE.Word1 >> 8; + return RE.r_word1 & 0xffffff; + return RE.r_word1 >> 8; } bool MachOObjectFile::getPlainRelocationExternal( - const macho::RelocationEntry &RE) const { + const MachO::any_relocation_info &RE) const { if (isLittleEndian()) - return (RE.Word1 >> 27) & 1; - return (RE.Word1 >> 4) & 1; + return (RE.r_word1 >> 27) & 1; + return (RE.r_word1 >> 4) & 1; } bool MachOObjectFile::getScatteredRelocationScattered( - const macho::RelocationEntry &RE) const { - return RE.Word0 >> 31; + const MachO::any_relocation_info &RE) const { + return RE.r_word0 >> 31; } uint32_t MachOObjectFile::getScatteredRelocationValue( - const macho::RelocationEntry &RE) const { - return RE.Word1; + const MachO::any_relocation_info &RE) const { + return RE.r_word1; } unsigned MachOObjectFile::getAnyRelocationAddress( - const macho::RelocationEntry &RE) const { + const MachO::any_relocation_info &RE) const { if (isRelocationScattered(RE)) return getScatteredRelocationAddress(RE); return getPlainRelocationAddress(RE); } -unsigned -MachOObjectFile::getAnyRelocationPCRel(const macho::RelocationEntry &RE) const { +unsigned MachOObjectFile::getAnyRelocationPCRel( + const MachO::any_relocation_info &RE) const { if (isRelocationScattered(RE)) return getScatteredRelocationPCRel(this, RE); return getPlainRelocationPCRel(this, RE); } unsigned MachOObjectFile::getAnyRelocationLength( - const macho::RelocationEntry &RE) const { + const MachO::any_relocation_info &RE) const { if (isRelocationScattered(RE)) return getScatteredRelocationLength(RE); return getPlainRelocationLength(this, RE); } unsigned -MachOObjectFile::getAnyRelocationType(const macho::RelocationEntry &RE) const { +MachOObjectFile::getAnyRelocationType( + const MachO::any_relocation_info &RE) const { if (isRelocationScattered(RE)) return getScatteredRelocationType(RE); return getPlainRelocationType(this, RE); } SectionRef -MachOObjectFile::getRelocationSection(const macho::RelocationEntry &RE) const { +MachOObjectFile::getRelocationSection( + const MachO::any_relocation_info &RE) const { if (isRelocationScattered(RE) || getPlainRelocationExternal(RE)) return *end_sections(); unsigned SecNum = getPlainRelocationSymbolNum(RE) - 1; @@ -1450,133 +1434,132 @@ MachOObjectFile::LoadCommandInfo MachOObjectFile::getFirstLoadCommandInfo() const { MachOObjectFile::LoadCommandInfo Load; - unsigned HeaderSize = is64Bit() ? macho::Header64Size : macho::Header32Size; + unsigned HeaderSize = is64Bit() ? sizeof(MachO::mach_header_64) : + sizeof(MachO::mach_header); Load.Ptr = getPtr(this, HeaderSize); - Load.C = getStruct<macho::LoadCommand>(this, Load.Ptr); + Load.C = getStruct<MachO::load_command>(this, Load.Ptr); return Load; } MachOObjectFile::LoadCommandInfo MachOObjectFile::getNextLoadCommandInfo(const LoadCommandInfo &L) const { MachOObjectFile::LoadCommandInfo Next; - Next.Ptr = L.Ptr + L.C.Size; - Next.C = getStruct<macho::LoadCommand>(this, Next.Ptr); + Next.Ptr = L.Ptr + L.C.cmdsize; + Next.C = getStruct<MachO::load_command>(this, Next.Ptr); return Next; } -macho::Section MachOObjectFile::getSection(DataRefImpl DRI) const { - return getStruct<macho::Section>(this, Sections[DRI.d.a]); +MachO::section MachOObjectFile::getSection(DataRefImpl DRI) const { + return getStruct<MachO::section>(this, Sections[DRI.d.a]); } -macho::Section64 MachOObjectFile::getSection64(DataRefImpl DRI) const { - return getStruct<macho::Section64>(this, Sections[DRI.d.a]); +MachO::section_64 MachOObjectFile::getSection64(DataRefImpl DRI) const { + return getStruct<MachO::section_64>(this, Sections[DRI.d.a]); } -macho::Section MachOObjectFile::getSection(const LoadCommandInfo &L, +MachO::section MachOObjectFile::getSection(const LoadCommandInfo &L, unsigned Index) const { const char *Sec = getSectionPtr(this, L, Index); - return getStruct<macho::Section>(this, Sec); + return getStruct<MachO::section>(this, Sec); } -macho::Section64 MachOObjectFile::getSection64(const LoadCommandInfo &L, - unsigned Index) const { +MachO::section_64 MachOObjectFile::getSection64(const LoadCommandInfo &L, + unsigned Index) const { const char *Sec = getSectionPtr(this, L, Index); - return getStruct<macho::Section64>(this, Sec); + return getStruct<MachO::section_64>(this, Sec); } -macho::SymbolTableEntry +MachO::nlist MachOObjectFile::getSymbolTableEntry(DataRefImpl DRI) const { const char *P = reinterpret_cast<const char *>(DRI.p); - return getStruct<macho::SymbolTableEntry>(this, P); + return getStruct<MachO::nlist>(this, P); } -macho::Symbol64TableEntry +MachO::nlist_64 MachOObjectFile::getSymbol64TableEntry(DataRefImpl DRI) const { const char *P = reinterpret_cast<const char *>(DRI.p); - return getStruct<macho::Symbol64TableEntry>(this, P); + return getStruct<MachO::nlist_64>(this, P); } -macho::LinkeditDataLoadCommand MachOObjectFile::getLinkeditDataLoadCommand( - const MachOObjectFile::LoadCommandInfo &L) const { - return getStruct<macho::LinkeditDataLoadCommand>(this, L.Ptr); +MachO::linkedit_data_command +MachOObjectFile::getLinkeditDataLoadCommand(const LoadCommandInfo &L) const { + return getStruct<MachO::linkedit_data_command>(this, L.Ptr); } -macho::SegmentLoadCommand +MachO::segment_command MachOObjectFile::getSegmentLoadCommand(const LoadCommandInfo &L) const { - return getStruct<macho::SegmentLoadCommand>(this, L.Ptr); + return getStruct<MachO::segment_command>(this, L.Ptr); } -macho::Segment64LoadCommand +MachO::segment_command_64 MachOObjectFile::getSegment64LoadCommand(const LoadCommandInfo &L) const { - return getStruct<macho::Segment64LoadCommand>(this, L.Ptr); + return getStruct<MachO::segment_command_64>(this, L.Ptr); } -macho::LinkerOptionsLoadCommand +MachO::linker_options_command MachOObjectFile::getLinkerOptionsLoadCommand(const LoadCommandInfo &L) const { - return getStruct<macho::LinkerOptionsLoadCommand>(this, L.Ptr); + return getStruct<MachO::linker_options_command>(this, L.Ptr); } -macho::RelocationEntry +MachO::any_relocation_info MachOObjectFile::getRelocation(DataRefImpl Rel) const { const char *P = reinterpret_cast<const char *>(Rel.p); - return getStruct<macho::RelocationEntry>(this, P); + return getStruct<MachO::any_relocation_info>(this, P); } -macho::DataInCodeTableEntry +MachO::data_in_code_entry MachOObjectFile::getDice(DataRefImpl Rel) const { const char *P = reinterpret_cast<const char *>(Rel.p); - return getStruct<macho::DataInCodeTableEntry>(this, P); + return getStruct<MachO::data_in_code_entry>(this, P); } -macho::Header MachOObjectFile::getHeader() const { - return getStruct<macho::Header>(this, getPtr(this, 0)); +MachO::mach_header MachOObjectFile::getHeader() const { + return getStruct<MachO::mach_header>(this, getPtr(this, 0)); } -macho::Header64Ext MachOObjectFile::getHeader64Ext() const { - return - getStruct<macho::Header64Ext>(this, getPtr(this, sizeof(macho::Header))); +MachO::mach_header_64 MachOObjectFile::getHeader64() const { + return getStruct<MachO::mach_header_64>(this, getPtr(this, 0)); } -macho::IndirectSymbolTableEntry MachOObjectFile::getIndirectSymbolTableEntry( - const macho::DysymtabLoadCommand &DLC, - unsigned Index) const { - uint64_t Offset = DLC.IndirectSymbolTableOffset + - Index * sizeof(macho::IndirectSymbolTableEntry); - return getStruct<macho::IndirectSymbolTableEntry>(this, getPtr(this, Offset)); +uint32_t MachOObjectFile::getIndirectSymbolTableEntry( + const MachO::dysymtab_command &DLC, + unsigned Index) const { + uint64_t Offset = DLC.indirectsymoff + Index * sizeof(uint32_t); + return getStruct<uint32_t>(this, getPtr(this, Offset)); } -macho::DataInCodeTableEntry +MachO::data_in_code_entry MachOObjectFile::getDataInCodeTableEntry(uint32_t DataOffset, unsigned Index) const { - uint64_t Offset = DataOffset + Index * sizeof(macho::DataInCodeTableEntry); - return getStruct<macho::DataInCodeTableEntry>(this, getPtr(this, Offset)); + uint64_t Offset = DataOffset + Index * sizeof(MachO::data_in_code_entry); + return getStruct<MachO::data_in_code_entry>(this, getPtr(this, Offset)); } -macho::SymtabLoadCommand MachOObjectFile::getSymtabLoadCommand() const { - return getStruct<macho::SymtabLoadCommand>(this, SymtabLoadCmd); +MachO::symtab_command MachOObjectFile::getSymtabLoadCommand() const { + return getStruct<MachO::symtab_command>(this, SymtabLoadCmd); } -macho::DysymtabLoadCommand MachOObjectFile::getDysymtabLoadCommand() const { - return getStruct<macho::DysymtabLoadCommand>(this, DysymtabLoadCmd); +MachO::dysymtab_command MachOObjectFile::getDysymtabLoadCommand() const { + return getStruct<MachO::dysymtab_command>(this, DysymtabLoadCmd); } -macho::LinkeditDataLoadCommand +MachO::linkedit_data_command MachOObjectFile::getDataInCodeLoadCommand() const { if (DataInCodeLoadCmd) - return getStruct<macho::LinkeditDataLoadCommand>(this, DataInCodeLoadCmd); + return getStruct<MachO::linkedit_data_command>(this, DataInCodeLoadCmd); // If there is no DataInCodeLoadCmd return a load command with zero'ed fields. - macho::LinkeditDataLoadCommand Cmd; - Cmd.Type = macho::LCT_DataInCode; - Cmd.Size = macho::LinkeditLoadCommandSize; - Cmd.DataOffset = 0; - Cmd.DataSize = 0; + MachO::linkedit_data_command Cmd; + Cmd.cmd = MachO::LC_DATA_IN_CODE; + Cmd.cmdsize = sizeof(MachO::linkedit_data_command); + Cmd.dataoff = 0; + Cmd.datasize = 0; return Cmd; } StringRef MachOObjectFile::getStringTableData() const { - macho::SymtabLoadCommand S = getSymtabLoadCommand(); - return getData().substr(S.StringTableOffset, S.StringTableSize); + MachO::symtab_command S = getSymtabLoadCommand(); + return getData().substr(S.stroff, S.strsize); } bool MachOObjectFile::is64Bit() const { diff --git a/lib/Object/MachOUniversal.cpp b/lib/Object/MachOUniversal.cpp index b76f10e..75160af 100644 --- a/lib/Object/MachOUniversal.cpp +++ b/lib/Object/MachOUniversal.cpp @@ -31,18 +31,18 @@ template<typename T> static void SwapStruct(T &Value); template<> -void SwapStruct(macho::FatHeader &H) { - SwapValue(H.Magic); - SwapValue(H.NumFatArch); +void SwapStruct(MachO::fat_header &H) { + SwapValue(H.magic); + SwapValue(H.nfat_arch); } template<> -void SwapStruct(macho::FatArchHeader &H) { - SwapValue(H.CPUType); - SwapValue(H.CPUSubtype); - SwapValue(H.Offset); - SwapValue(H.Size); - SwapValue(H.Align); +void SwapStruct(MachO::fat_arch &H) { + SwapValue(H.cputype); + SwapValue(H.cpusubtype); + SwapValue(H.offset); + SwapValue(H.size); + SwapValue(H.align); } template<typename T> @@ -63,10 +63,10 @@ MachOUniversalBinary::ObjectForArch::ObjectForArch( } else { // Parse object header. StringRef ParentData = Parent->getData(); - const char *HeaderPos = ParentData.begin() + macho::FatHeaderSize + - Index * macho::FatArchHeaderSize; - Header = getUniversalBinaryStruct<macho::FatArchHeader>(HeaderPos); - if (ParentData.size() < Header.Offset + Header.Size) { + const char *HeaderPos = ParentData.begin() + sizeof(MachO::fat_header) + + Index * sizeof(MachO::fat_arch); + Header = getUniversalBinaryStruct<MachO::fat_arch>(HeaderPos); + if (ParentData.size() < Header.offset + Header.size) { clear(); } } @@ -76,10 +76,10 @@ error_code MachOUniversalBinary::ObjectForArch::getAsObjectFile( OwningPtr<ObjectFile> &Result) const { if (Parent) { StringRef ParentData = Parent->getData(); - StringRef ObjectData = ParentData.substr(Header.Offset, Header.Size); + StringRef ObjectData = ParentData.substr(Header.offset, Header.size); std::string ObjectName = Parent->getFileName().str() + ":" + - Triple::getArchTypeName(MachOObjectFile::getArch(Header.CPUType)); + Triple::getArchTypeName(MachOObjectFile::getArch(Header.cputype)); MemoryBuffer *ObjBuffer = MemoryBuffer::getMemBuffer( ObjectData, ObjectName, false); if (ObjectFile *Obj = ObjectFile::createMachOObjectFile(ObjBuffer)) { @@ -96,31 +96,31 @@ MachOUniversalBinary::MachOUniversalBinary(MemoryBuffer *Source, error_code &ec) : Binary(Binary::ID_MachOUniversalBinary, Source), NumberOfObjects(0) { - if (Source->getBufferSize() < macho::FatHeaderSize) { + if (Source->getBufferSize() < sizeof(MachO::fat_header)) { ec = object_error::invalid_file_type; return; } // Check for magic value and sufficient header size. StringRef Buf = getData(); - macho::FatHeader H = getUniversalBinaryStruct<macho::FatHeader>(Buf.begin()); - NumberOfObjects = H.NumFatArch; - uint32_t MinSize = macho::FatHeaderSize + - macho::FatArchHeaderSize * NumberOfObjects; - if (H.Magic != macho::HM_Universal || Buf.size() < MinSize) { + MachO::fat_header H= getUniversalBinaryStruct<MachO::fat_header>(Buf.begin()); + NumberOfObjects = H.nfat_arch; + uint32_t MinSize = sizeof(MachO::fat_header) + + sizeof(MachO::fat_arch) * NumberOfObjects; + if (H.magic != MachO::FAT_MAGIC || Buf.size() < MinSize) { ec = object_error::parse_failed; return; } ec = object_error::success; } -static bool getCTMForArch(Triple::ArchType Arch, mach::CPUTypeMachine &CTM) { +static bool getCTMForArch(Triple::ArchType Arch, MachO::CPUType &CTM) { switch (Arch) { - case Triple::x86: CTM = mach::CTM_i386; return true; - case Triple::x86_64: CTM = mach::CTM_x86_64; return true; - case Triple::arm: CTM = mach::CTM_ARM; return true; - case Triple::sparc: CTM = mach::CTM_SPARC; return true; - case Triple::ppc: CTM = mach::CTM_PowerPC; return true; - case Triple::ppc64: CTM = mach::CTM_PowerPC64; return true; + case Triple::x86: CTM = MachO::CPU_TYPE_I386; return true; + case Triple::x86_64: CTM = MachO::CPU_TYPE_X86_64; return true; + case Triple::arm: CTM = MachO::CPU_TYPE_ARM; return true; + case Triple::sparc: CTM = MachO::CPU_TYPE_SPARC; return true; + case Triple::ppc: CTM = MachO::CPU_TYPE_POWERPC; return true; + case Triple::ppc64: CTM = MachO::CPU_TYPE_POWERPC64; return true; default: return false; } } @@ -128,7 +128,7 @@ static bool getCTMForArch(Triple::ArchType Arch, mach::CPUTypeMachine &CTM) { error_code MachOUniversalBinary::getObjectForArch(Triple::ArchType Arch, OwningPtr<ObjectFile> &Result) const { - mach::CPUTypeMachine CTM; + MachO::CPUType CTM; if (!getCTMForArch(Arch, CTM)) return object_error::arch_not_found; for (object_iterator I = begin_objects(), E = end_objects(); I != E; ++I) { diff --git a/lib/Object/ObjectFile.cpp b/lib/Object/ObjectFile.cpp index 1d1dafd..0e626d6 100644 --- a/lib/Object/ObjectFile.cpp +++ b/lib/Object/ObjectFile.cpp @@ -49,6 +49,7 @@ ObjectFile *ObjectFile::createObjectFile(MemoryBuffer *Object) { case sys::fs::file_magic::bitcode: case sys::fs::file_magic::archive: case sys::fs::file_magic::macho_universal_binary: + case sys::fs::file_magic::windows_resource: delete Object; return 0; case sys::fs::file_magic::elf_relocatable: @@ -68,6 +69,7 @@ ObjectFile *ObjectFile::createObjectFile(MemoryBuffer *Object) { case sys::fs::file_magic::macho_dsym_companion: return createMachOObjectFile(Object); case sys::fs::file_magic::coff_object: + case sys::fs::file_magic::coff_import_library: case sys::fs::file_magic::pecoff_executable: return createCOFFObjectFile(Object); } diff --git a/lib/Object/YAML.cpp b/lib/Object/YAML.cpp index 21bacb8..c527bde 100644 --- a/lib/Object/YAML.cpp +++ b/lib/Object/YAML.cpp @@ -15,6 +15,7 @@ #include "llvm/Object/YAML.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Support/raw_ostream.h" +#include <cctype> using namespace llvm; using namespace object::yaml; |