diff --git a/llvm/tools/llvm-elfabi/ELFObjHandler.h b/llvm/include/llvm/TextAPI/ELF/ELFObjHandler.h rename from llvm/tools/llvm-elfabi/ELFObjHandler.h rename to llvm/include/llvm/TextAPI/ELF/ELFObjHandler.h --- a/llvm/tools/llvm-elfabi/ELFObjHandler.h +++ b/llvm/include/llvm/TextAPI/ELF/ELFObjHandler.h @@ -10,8 +10,8 @@ /// //===-----------------------------------------------------------------------===/ -#ifndef LLVM_TOOLS_ELFABI_ELFOBJHANDLER_H -#define LLVM_TOOLS_ELFABI_ELFOBJHANDLER_H +#ifndef LLVM_TEXTAPI_ELFOBJHANDLER_H +#define LLVM_TEXTAPI_ELFOBJHANDLER_H #include "llvm/Object/ELFObjectFile.h" #include "llvm/Object/ELFTypes.h" @@ -29,4 +29,4 @@ } // end namespace elfabi } // end namespace llvm -#endif // LLVM_TOOLS_ELFABI_ELFOBJHANDLER_H +#endif // LLVM_TEXTAPI_ELFOBJHANDLER_H diff --git a/llvm/lib/TextAPI/CMakeLists.txt b/llvm/lib/TextAPI/CMakeLists.txt --- a/llvm/lib/TextAPI/CMakeLists.txt +++ b/llvm/lib/TextAPI/CMakeLists.txt @@ -1,4 +1,5 @@ add_llvm_component_library(LLVMTextAPI + ELF/ELFObjHandler.cpp ELF/ELFStub.cpp ELF/TBEHandler.cpp MachO/Architecture.cpp @@ -13,6 +14,6 @@ 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/llvm/tools/llvm-elfabi/ELFObjHandler.cpp b/llvm/lib/TextAPI/ELF/ELFObjHandler.cpp rename from llvm/tools/llvm-elfabi/ELFObjHandler.cpp rename to llvm/lib/TextAPI/ELF/ELFObjHandler.cpp --- a/llvm/tools/llvm-elfabi/ELFObjHandler.cpp +++ b/llvm/lib/TextAPI/ELF/ELFObjHandler.cpp @@ -6,7 +6,7 @@ // //===-----------------------------------------------------------------------===/ -#include "ELFObjHandler.h" +#include "llvm/TextAPI/ELF/ELFObjHandler.h" #include "llvm/Object/Binary.h" #include "llvm/Object/ELFObjectFile.h" #include "llvm/Object/ELFTypes.h" @@ -128,19 +128,17 @@ "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); } } @@ -212,16 +210,16 @@ 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; } } @@ -259,8 +257,8 @@ /// @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. @@ -311,7 +309,7 @@ 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) @@ -355,9 +353,8 @@ 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/llvm/tools/llvm-elfabi/CMakeLists.txt b/llvm/tools/llvm-elfabi/CMakeLists.txt --- a/llvm/tools/llvm-elfabi/CMakeLists.txt +++ b/llvm/tools/llvm-elfabi/CMakeLists.txt @@ -5,7 +5,6 @@ ) add_llvm_tool(llvm-elfabi - ELFObjHandler.cpp ErrorCollector.cpp llvm-elfabi.cpp ) diff --git a/llvm/tools/llvm-elfabi/llvm-elfabi.cpp b/llvm/tools/llvm-elfabi/llvm-elfabi.cpp --- a/llvm/tools/llvm-elfabi/llvm-elfabi.cpp +++ b/llvm/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/raw_ostream.h" #include "llvm/Support/WithColor.h" +#include "llvm/Support/raw_ostream.h" +#include "llvm/TextAPI/ELF/ELFObjHandler.h" #include "llvm/TextAPI/ELF/TBEHandler.h" #include