diff options
Diffstat (limited to 'lib/Object')
-rw-r--r-- | lib/Object/Archive.cpp | 6 | ||||
-rw-r--r-- | lib/Object/COFFObjectFile.cpp | 36 | ||||
-rw-r--r-- | lib/Object/MachOObject.cpp | 13 | ||||
-rw-r--r-- | lib/Object/MachOObjectFile.cpp | 18 |
4 files changed, 62 insertions, 11 deletions
diff --git a/lib/Object/Archive.cpp b/lib/Object/Archive.cpp index c5f15ba..2a5951a 100644 --- a/lib/Object/Archive.cpp +++ b/lib/Object/Archive.cpp @@ -28,7 +28,7 @@ struct ArchiveMemberHeader { char UID[6]; char GID[6]; char AccessMode[8]; - char Size[10]; //< Size of data, not including header or padding. + char Size[10]; ///< Size of data, not including header or padding. char Terminator[2]; ///! Get the name without looking up long names. @@ -60,11 +60,11 @@ static const ArchiveMemberHeader *ToHeader(const char *base) { static bool isInternalMember(const ArchiveMemberHeader &amh) { - const char *internals[] = { + static const char *const internals[] = { "/", "//", "#_LLVM_SYM_TAB_#" - }; + }; StringRef name = amh.getName(); for (std::size_t i = 0; i < sizeof(internals) / sizeof(*internals); ++i) { diff --git a/lib/Object/COFFObjectFile.cpp b/lib/Object/COFFObjectFile.cpp index bd27a56..8ab54c6 100644 --- a/lib/Object/COFFObjectFile.cpp +++ b/lib/Object/COFFObjectFile.cpp @@ -622,6 +622,28 @@ error_code COFFObjectFile::getSymbolName(const coff_symbol *symbol, return object_error::success; } +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); +# ifndef NDEBUG + // Verify that the aux symbol points to a valid entry in the symbol table. + uintptr_t offset = uintptr_t(aux) - uintptr_t(base()); + if (offset < Header->PointerToSymbolTable + || offset >= Header->PointerToSymbolTable + + (Header->NumberOfSymbols * sizeof(coff_symbol))) + report_fatal_error("Aux Symbol data was outside of symbol table."); + + assert((offset - Header->PointerToSymbolTable) % sizeof(coff_symbol) + == 0 && "Aux Symbol data did not point to the beginning of a symbol"); +# endif + } + return ArrayRef<uint8_t>(aux, symbol->NumberOfAuxSymbols * sizeof(coff_symbol)); +} + error_code COFFObjectFile::getSectionName(const coff_section *Sec, StringRef &Res) const { StringRef Name; @@ -694,6 +716,20 @@ error_code COFFObjectFile::getRelocationType(DataRefImpl Rel, return object_error::success; } +const coff_section *COFFObjectFile::getCOFFSection(section_iterator &It) const { + return toSec(It->getRawDataRefImpl()); +} + +const coff_symbol *COFFObjectFile::getCOFFSymbol(symbol_iterator &It) const { + return toSymb(It->getRawDataRefImpl()); +} + +const coff_relocation *COFFObjectFile::getCOFFRelocation( + relocation_iterator &It) const { + return toRel(It->getRawDataRefImpl()); +} + + #define LLVM_COFF_SWITCH_RELOC_TYPE_NAME(enum) \ case COFF::enum: res = #enum; break; diff --git a/lib/Object/MachOObject.cpp b/lib/Object/MachOObject.cpp index b7e5cdc..00dea3f 100644 --- a/lib/Object/MachOObject.cpp +++ b/lib/Object/MachOObject.cpp @@ -357,6 +357,19 @@ void MachOObject::ReadSymbol64TableEntry(uint64_t SymbolTableOffset, ReadInMemoryStruct(*this, Buffer->getBuffer(), Offset, Res); } +template<> +void SwapStruct(macho::DataInCodeTableEntry &Value) { + SwapValue(Value.Offset); + SwapValue(Value.Length); + SwapValue(Value.Kind); +} +void MachOObject::ReadDataInCodeTableEntry(uint64_t TableOffset, + unsigned Index, + InMemoryStruct<macho::DataInCodeTableEntry> &Res) const { + uint64_t Offset = (TableOffset + + Index * sizeof(macho::DataInCodeTableEntry)); + ReadInMemoryStruct(*this, Buffer->getBuffer(), Offset, Res); +} void MachOObject::ReadULEB128s(uint64_t Index, SmallVectorImpl<uint64_t> &Out) const { diff --git a/lib/Object/MachOObjectFile.cpp b/lib/Object/MachOObjectFile.cpp index 3bcda17..d229671 100644 --- a/lib/Object/MachOObjectFile.cpp +++ b/lib/Object/MachOObjectFile.cpp @@ -598,13 +598,15 @@ error_code MachOObjectFile::isSectionZeroInit(DataRefImpl DRI, if (MachOObj->is64Bit()) { InMemoryStruct<macho::Section64> Sect; getSection64(DRI, Sect); - Result = (Sect->Flags & MachO::SectionTypeZeroFill || - Sect->Flags & MachO::SectionTypeZeroFillLarge); + unsigned SectionType = Sect->Flags & MachO::SectionFlagMaskSectionType; + Result = (SectionType == MachO::SectionTypeZeroFill || + SectionType == MachO::SectionTypeZeroFillLarge); } else { InMemoryStruct<macho::Section> Sect; getSection(DRI, Sect); - Result = (Sect->Flags & MachO::SectionTypeZeroFill || - Sect->Flags & MachO::SectionTypeZeroFillLarge); + unsigned SectionType = Sect->Flags & MachO::SectionFlagMaskSectionType; + Result = (SectionType == MachO::SectionTypeZeroFill || + SectionType == MachO::SectionTypeZeroFillLarge); } return object_error::success; @@ -786,7 +788,7 @@ error_code MachOObjectFile::getRelocationTypeName(DataRefImpl Rel, switch (Arch) { case Triple::x86: { - const char* Table[] = { + static const char *const Table[] = { "GENERIC_RELOC_VANILLA", "GENERIC_RELOC_PAIR", "GENERIC_RELOC_SECTDIFF", @@ -801,7 +803,7 @@ error_code MachOObjectFile::getRelocationTypeName(DataRefImpl Rel, break; } case Triple::x86_64: { - const char* Table[] = { + static const char *const Table[] = { "X86_64_RELOC_UNSIGNED", "X86_64_RELOC_SIGNED", "X86_64_RELOC_BRANCH", @@ -820,7 +822,7 @@ error_code MachOObjectFile::getRelocationTypeName(DataRefImpl Rel, break; } case Triple::arm: { - const char* Table[] = { + static const char *const Table[] = { "ARM_RELOC_VANILLA", "ARM_RELOC_PAIR", "ARM_RELOC_SECTDIFF", @@ -839,7 +841,7 @@ error_code MachOObjectFile::getRelocationTypeName(DataRefImpl Rel, break; } case Triple::ppc: { - const char* Table[] = { + static const char *const Table[] = { "PPC_RELOC_VANILLA", "PPC_RELOC_PAIR", "PPC_RELOC_BR14", |