From f44281335e8fe5192d121c33e917f6c58a825001 Mon Sep 17 00:00:00 2001 From: Haowei Wu Date: Mon, 10 Aug 2020 21:30:01 -0700 Subject: [PATCH] Revert "Move ELFObjHandler to TextAPI library" This reverts commit e6f8ba12e6ea97cbf4374b70e78309c2d859ca1c due to build failures. --- lib/TextAPI/CMakeLists.txt | 3 +- tools/llvm-elfabi/CMakeLists.txt | 1 + .../llvm-elfabi}/ELFObjHandler.cpp | 51 ++++++++++--------- .../ELF => tools/llvm-elfabi}/ELFObjHandler.h | 6 +-- tools/llvm-elfabi/llvm-elfabi.cpp | 4 +- 5 files changed, 34 insertions(+), 31 deletions(-) rename {lib/TextAPI/ELF => tools/llvm-elfabi}/ELFObjHandler.cpp (91%) rename {include/llvm/TextAPI/ELF => tools/llvm-elfabi}/ELFObjHandler.h (87%) diff --git a/lib/TextAPI/CMakeLists.txt b/lib/TextAPI/CMakeLists.txt index ed3cd4ee480..36528f0995d 100644 --- a/lib/TextAPI/CMakeLists.txt +++ b/lib/TextAPI/CMakeLists.txt @@ -1,5 +1,4 @@ add_llvm_component_library(LLVMTextAPI - ELF/ELFObjHandler.cpp ELF/ELFStub.cpp ELF/TBEHandler.cpp MachO/Architecture.cpp @@ -14,6 +13,6 @@ add_llvm_component_library(LLVMTextAPI ADDITIONAL_HEADER_DIRS "${LLVM_MAIN_INCLUDE_DIR}/llvm/TextAPI" - "${LLVM_MAIN_INCLUDE_DIR}/llvm/TextAPI/ELF" + "${LLVM_MAIN_INCLUDE_DIR}/llvm/TextAPI/Elf" "${LLVM_MAIN_INCLUDE_DIR}/llvm/TextAPI/MachO" ) diff --git a/tools/llvm-elfabi/CMakeLists.txt b/tools/llvm-elfabi/CMakeLists.txt index bd4875f0be4..bd3ec851887 100644 --- a/tools/llvm-elfabi/CMakeLists.txt +++ b/tools/llvm-elfabi/CMakeLists.txt @@ -5,6 +5,7 @@ set(LLVM_LINK_COMPONENTS ) add_llvm_tool(llvm-elfabi + ELFObjHandler.cpp ErrorCollector.cpp llvm-elfabi.cpp ) diff --git a/lib/TextAPI/ELF/ELFObjHandler.cpp b/tools/llvm-elfabi/ELFObjHandler.cpp similarity index 91% rename from lib/TextAPI/ELF/ELFObjHandler.cpp rename to tools/llvm-elfabi/ELFObjHandler.cpp index f43fbf99ba9..124fffbb9cf 100644 --- a/lib/TextAPI/ELF/ELFObjHandler.cpp +++ b/tools/llvm-elfabi/ELFObjHandler.cpp @@ -6,7 +6,7 @@ // //===-----------------------------------------------------------------------===/ -#include "llvm/TextAPI/ELF/ELFObjHandler.h" +#include "ELFObjHandler.h" #include "llvm/Object/Binary.h" #include "llvm/Object/ELFObjectFile.h" #include "llvm/Object/ELFTypes.h" @@ -128,17 +128,19 @@ static Error populateDynamic(DynamicEntries &Dyn, "Couldn't locate dynamic symbol table (no DT_SYMTAB entry)"); } if (Dyn.SONameOffset.hasValue() && *Dyn.SONameOffset >= Dyn.StrSize) { - return createStringError(object_error::parse_failed, - "DT_SONAME string offset (0x%016" PRIx64 - ") outside of dynamic string table", - *Dyn.SONameOffset); + return createStringError( + object_error::parse_failed, + "DT_SONAME string offset (0x%016" PRIx64 + ") outside of dynamic string table", + *Dyn.SONameOffset); } for (uint64_t Offset : Dyn.NeededLibNames) { if (Offset >= Dyn.StrSize) { - return createStringError(object_error::parse_failed, - "DT_NEEDED string offset (0x%016" PRIx64 - ") outside of dynamic string table", - Offset); + return createStringError( + object_error::parse_failed, + "DT_NEEDED string offset (0x%016" PRIx64 + ") outside of dynamic string table", + Offset); } } @@ -210,16 +212,16 @@ static Expected getNumSyms(DynamicEntries &Dyn, static ELFSymbolType convertInfoToType(uint8_t Info) { Info = Info & 0xf; switch (Info) { - case ELF::STT_NOTYPE: - return ELFSymbolType::NoType; - case ELF::STT_OBJECT: - return ELFSymbolType::Object; - case ELF::STT_FUNC: - return ELFSymbolType::Func; - case ELF::STT_TLS: - return ELFSymbolType::TLS; - default: - return ELFSymbolType::Unknown; + case ELF::STT_NOTYPE: + return ELFSymbolType::NoType; + case ELF::STT_OBJECT: + return ELFSymbolType::Object; + case ELF::STT_FUNC: + return ELFSymbolType::Func; + case ELF::STT_TLS: + return ELFSymbolType::TLS; + default: + return ELFSymbolType::Unknown; } } @@ -257,8 +259,8 @@ static ELFSymbol createELFSym(StringRef SymName, /// @param DynStr StringRef to the dynamic string table. template static Error populateSymbols(ELFStub &TargetStub, - const typename ELFT::SymRange DynSym, - StringRef DynStr) { + const typename ELFT::SymRange DynSym, + StringRef DynStr) { // Skips the first symbol since it's the NULL symbol. for (auto RawSym : DynSym.drop_front(1)) { // If a symbol does not have global or weak binding, ignore it. @@ -309,7 +311,7 @@ buildStub(const ELFObjectFile &ElfObj) { if (Error Err = populateDynamic(DynEnt, *DynTable)) return std::move(Err); - // Get pointer to in-memory location of .dynstr section. + // Get pointer to in-memory location of .dynstr section. Expected DynStrPtr = ElfFile->toMappedAddr(DynEnt.StrTabAddr); if (!DynStrPtr) @@ -353,8 +355,9 @@ buildStub(const ELFObjectFile &ElfObj) { if (!DynSymPtr) return appendToError(DynSymPtr.takeError(), "when locating .dynsym section contents"); - Elf_Sym_Range DynSyms = ArrayRef( - reinterpret_cast(*DynSymPtr), *SymCount); + Elf_Sym_Range DynSyms = + ArrayRef(reinterpret_cast(*DynSymPtr), + *SymCount); Error SymReadError = populateSymbols(*DestStub, DynSyms, DynStr); if (SymReadError) return appendToError(std::move(SymReadError), diff --git a/include/llvm/TextAPI/ELF/ELFObjHandler.h b/tools/llvm-elfabi/ELFObjHandler.h similarity index 87% rename from include/llvm/TextAPI/ELF/ELFObjHandler.h rename to tools/llvm-elfabi/ELFObjHandler.h index 5abed3af9f4..97f0d68f4d4 100644 --- a/include/llvm/TextAPI/ELF/ELFObjHandler.h +++ b/tools/llvm-elfabi/ELFObjHandler.h @@ -10,8 +10,8 @@ /// //===-----------------------------------------------------------------------===/ -#ifndef LLVM_TEXTAPI_ELF_ELFOBJHANDLER_H -#define LLVM_TEXTAPI_ELF_ELFOBJHANDLER_H +#ifndef LLVM_TOOLS_ELFABI_ELFOBJHANDLER_H +#define LLVM_TOOLS_ELFABI_ELFOBJHANDLER_H #include "llvm/Object/ELFObjectFile.h" #include "llvm/Object/ELFTypes.h" @@ -29,4 +29,4 @@ Expected> readELFFile(MemoryBufferRef Buf); } // end namespace elfabi } // end namespace llvm -#endif // LLVM_TEXTAPI_ELF_ELFOBJHANDLER_H +#endif // LLVM_TOOLS_ELFABI_ELFOBJHANDLER_H diff --git a/tools/llvm-elfabi/llvm-elfabi.cpp b/tools/llvm-elfabi/llvm-elfabi.cpp index e70df2697d1..044b5f77c6d 100644 --- a/tools/llvm-elfabi/llvm-elfabi.cpp +++ b/tools/llvm-elfabi/llvm-elfabi.cpp @@ -6,15 +6,15 @@ // //===-----------------------------------------------------------------------===/ +#include "ELFObjHandler.h" #include "ErrorCollector.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Errc.h" #include "llvm/Support/FileOutputBuffer.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Path.h" -#include "llvm/Support/WithColor.h" #include "llvm/Support/raw_ostream.h" -#include "llvm/TextAPI/ELF/ELFObjHandler.h" +#include "llvm/Support/WithColor.h" #include "llvm/TextAPI/ELF/TBEHandler.h" #include