diff --git a/llvm/tools/llvm-elfabi/ELFObjHandler.h b/llvm/include/llvm/InterfaceStub/ELFObjHandler.h rename from llvm/tools/llvm-elfabi/ELFObjHandler.h rename to llvm/include/llvm/InterfaceStub/ELFObjHandler.h --- a/llvm/tools/llvm-elfabi/ELFObjHandler.h +++ b/llvm/include/llvm/InterfaceStub/ELFObjHandler.h @@ -13,9 +13,9 @@ #ifndef LLVM_TOOLS_ELFABI_ELFOBJHANDLER_H #define LLVM_TOOLS_ELFABI_ELFOBJHANDLER_H +#include "llvm/InterfaceStub/ELFStub.h" #include "llvm/Object/ELFObjectFile.h" #include "llvm/Object/ELFTypes.h" -#include "llvm/TextAPI/ELF/ELFStub.h" namespace llvm { diff --git a/llvm/include/llvm/TextAPI/ELF/ELFStub.h b/llvm/include/llvm/InterfaceStub/ELFStub.h rename from llvm/include/llvm/TextAPI/ELF/ELFStub.h rename to llvm/include/llvm/InterfaceStub/ELFStub.h --- a/llvm/include/llvm/TextAPI/ELF/ELFStub.h +++ b/llvm/include/llvm/InterfaceStub/ELFStub.h @@ -16,8 +16,8 @@ #include "llvm/BinaryFormat/ELF.h" #include "llvm/Support/VersionTuple.h" -#include #include +#include namespace llvm { namespace elfabi { @@ -42,15 +42,13 @@ bool Undefined; bool Weak; Optional Warning; - bool operator<(const ELFSymbol &RHS) const { - return Name < RHS.Name; - } + bool operator<(const ELFSymbol &RHS) const { return Name < RHS.Name; } }; // A cumulative representation of ELF stubs. // Both textual and binary stubs will read into and write from this object. class ELFStub { -// TODO: Add support for symbol versioning. + // TODO: Add support for symbol versioning. public: VersionTuple TbeVersion; Optional SoName; diff --git a/llvm/include/llvm/TextAPI/ELF/TBEHandler.h b/llvm/include/llvm/InterfaceStub/TBEHandler.h rename from llvm/include/llvm/TextAPI/ELF/TBEHandler.h rename to llvm/include/llvm/InterfaceStub/TBEHandler.h --- a/llvm/include/llvm/TextAPI/ELF/TBEHandler.h +++ b/llvm/include/llvm/InterfaceStub/TBEHandler.h @@ -15,8 +15,8 @@ #ifndef LLVM_TEXTAPI_ELF_TBEHANDLER_H #define LLVM_TEXTAPI_ELF_TBEHANDLER_H -#include "llvm/Support/VersionTuple.h" #include "llvm/Support/Error.h" +#include "llvm/Support/VersionTuple.h" #include namespace llvm { diff --git a/llvm/lib/CMakeLists.txt b/llvm/lib/CMakeLists.txt --- a/llvm/lib/CMakeLists.txt +++ b/llvm/lib/CMakeLists.txt @@ -3,6 +3,7 @@ add_subdirectory(IR) add_subdirectory(FuzzMutate) +add_subdirectory(InterfaceStub) add_subdirectory(IRReader) add_subdirectory(CodeGen) add_subdirectory(BinaryFormat) diff --git a/llvm/lib/InterfaceStub/CMakeLists.txt b/llvm/lib/InterfaceStub/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/llvm/lib/InterfaceStub/CMakeLists.txt @@ -0,0 +1,8 @@ +add_llvm_component_library(LLVMInterfaceStub + ELFObjHandler.cpp + ELFStub.cpp + TBEHandler.cpp + + ADDITIONAL_HEADER_DIRS + "${LLVM_MAIN_INCLUDE_DIR}/llvm/InterfaceStub" +) diff --git a/llvm/tools/llvm-elfabi/ELFObjHandler.cpp b/llvm/lib/InterfaceStub/ELFObjHandler.cpp rename from llvm/tools/llvm-elfabi/ELFObjHandler.cpp rename to llvm/lib/InterfaceStub/ELFObjHandler.cpp --- a/llvm/tools/llvm-elfabi/ELFObjHandler.cpp +++ b/llvm/lib/InterfaceStub/ELFObjHandler.cpp @@ -6,14 +6,14 @@ // //===-----------------------------------------------------------------------===/ -#include "ELFObjHandler.h" +#include "llvm/InterfaceStub/ELFObjHandler.h" +#include "llvm/InterfaceStub/ELFStub.h" #include "llvm/Object/Binary.h" #include "llvm/Object/ELFObjectFile.h" #include "llvm/Object/ELFTypes.h" #include "llvm/Support/Errc.h" #include "llvm/Support/Error.h" #include "llvm/Support/MemoryBuffer.h" -#include "llvm/TextAPI/ELF/ELFStub.h" using llvm::MemoryBufferRef; using llvm::object::ELFObjectFile; @@ -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/lib/TextAPI/ELF/ELFStub.cpp b/llvm/lib/InterfaceStub/ELFStub.cpp rename from llvm/lib/TextAPI/ELF/ELFStub.cpp rename to llvm/lib/InterfaceStub/ELFStub.cpp --- a/llvm/lib/TextAPI/ELF/ELFStub.cpp +++ b/llvm/lib/InterfaceStub/ELFStub.cpp @@ -6,7 +6,7 @@ // //===-----------------------------------------------------------------------===/ -#include "llvm/TextAPI/ELF/ELFStub.h" +#include "llvm/InterfaceStub/ELFStub.h" using namespace llvm; using namespace llvm::elfabi; diff --git a/llvm/tools/llvm-elfabi/LLVMBuild.txt b/llvm/lib/InterfaceStub/LLVMBuild.txt copy from llvm/tools/llvm-elfabi/LLVMBuild.txt copy to llvm/lib/InterfaceStub/LLVMBuild.txt --- a/llvm/tools/llvm-elfabi/LLVMBuild.txt +++ b/llvm/lib/InterfaceStub/LLVMBuild.txt @@ -1,4 +1,4 @@ -;===- ./tools/llvm-elfabi/LLVMBuild.txt ------------------------*- Conf -*--===; +;===- ./lib/InterfaceStub/LLVMBuild.txt ------------------------*- Conf -*--===; ; ; Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. ; See https://llvm.org/LICENSE.txt for license information. @@ -15,7 +15,7 @@ ;===------------------------------------------------------------------------===; [component_0] -type = Tool -name = llvm-elfabi -parent = Tools -required_libraries = Object Support TextAPI +type = Library +name = InterfaceStub +parent = Libraries +required_libraries = Object Support diff --git a/llvm/lib/TextAPI/ELF/TBEHandler.cpp b/llvm/lib/InterfaceStub/TBEHandler.cpp rename from llvm/lib/TextAPI/ELF/TBEHandler.cpp rename to llvm/lib/InterfaceStub/TBEHandler.cpp --- a/llvm/lib/TextAPI/ELF/TBEHandler.cpp +++ b/llvm/lib/InterfaceStub/TBEHandler.cpp @@ -6,12 +6,12 @@ // //===-----------------------------------------------------------------------===/ -#include "llvm/TextAPI/ELF/TBEHandler.h" -#include "llvm/ADT/StringSwitch.h" +#include "llvm/InterfaceStub/TBEHandler.h" #include "llvm/ADT/StringRef.h" +#include "llvm/ADT/StringSwitch.h" +#include "llvm/InterfaceStub/ELFStub.h" #include "llvm/Support/Error.h" #include "llvm/Support/YAMLTraits.h" -#include "llvm/TextAPI/ELF/ELFStub.h" using namespace llvm; using namespace llvm::elfabi; diff --git a/llvm/lib/LLVMBuild.txt b/llvm/lib/LLVMBuild.txt --- a/llvm/lib/LLVMBuild.txt +++ b/llvm/lib/LLVMBuild.txt @@ -30,6 +30,7 @@ FuzzMutate LineEditor Linker + InterfaceStub IR IRReader LTO 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,6 +1,4 @@ add_llvm_component_library(LLVMTextAPI - ELF/ELFStub.cpp - ELF/TBEHandler.cpp MachO/Architecture.cpp MachO/ArchitectureSet.cpp MachO/InterfaceFile.cpp 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 @@ -1,11 +1,11 @@ set(LLVM_LINK_COMPONENTS + InterfaceStub Object Support TextAPI ) add_llvm_tool(llvm-elfabi - ELFObjHandler.cpp ErrorCollector.cpp llvm-elfabi.cpp ) diff --git a/llvm/tools/llvm-elfabi/LLVMBuild.txt b/llvm/tools/llvm-elfabi/LLVMBuild.txt --- a/llvm/tools/llvm-elfabi/LLVMBuild.txt +++ b/llvm/tools/llvm-elfabi/LLVMBuild.txt @@ -18,4 +18,4 @@ type = Tool name = llvm-elfabi parent = Tools -required_libraries = Object Support TextAPI +required_libraries = InterfaceStub Object Support TextAPI 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,16 +6,16 @@ // //===-----------------------------------------------------------------------===/ -#include "ELFObjHandler.h" #include "ErrorCollector.h" +#include "llvm/InterfaceStub/ELFObjHandler.h" +#include "llvm/InterfaceStub/TBEHandler.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/TextAPI/ELF/TBEHandler.h" +#include "llvm/Support/raw_ostream.h" #include namespace llvm { diff --git a/llvm/unittests/CMakeLists.txt b/llvm/unittests/CMakeLists.txt --- a/llvm/unittests/CMakeLists.txt +++ b/llvm/unittests/CMakeLists.txt @@ -26,6 +26,7 @@ add_subdirectory(ExecutionEngine) add_subdirectory(Frontend) add_subdirectory(FuzzMutate) +add_subdirectory(InterfaceStub) add_subdirectory(IR) add_subdirectory(LineEditor) add_subdirectory(Linker) diff --git a/llvm/unittests/InterfaceStub/CMakeLists.txt b/llvm/unittests/InterfaceStub/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/llvm/unittests/InterfaceStub/CMakeLists.txt @@ -0,0 +1,9 @@ +set(LLVM_LINK_COMPONENTS + InterfaceStub +) + +add_llvm_unittest(InterfaceStubTests + ELFYAMLTest.cpp +) + +target_link_libraries(InterfaceStubTests PRIVATE LLVMTestingSupport) diff --git a/llvm/unittests/TextAPI/ELFYAMLTest.cpp b/llvm/unittests/InterfaceStub/ELFYAMLTest.cpp rename from llvm/unittests/TextAPI/ELFYAMLTest.cpp rename to llvm/unittests/InterfaceStub/ELFYAMLTest.cpp --- a/llvm/unittests/TextAPI/ELFYAMLTest.cpp +++ b/llvm/unittests/InterfaceStub/ELFYAMLTest.cpp @@ -7,8 +7,8 @@ //===-----------------------------------------------------------------------===/ #include "llvm/ADT/StringRef.h" -#include "llvm/TextAPI/ELF/ELFStub.h" -#include "llvm/TextAPI/ELF/TBEHandler.h" +#include "llvm/InterfaceStub/ELFStub.h" +#include "llvm/InterfaceStub/TBEHandler.h" #include "llvm/Support/Error.h" #include "llvm/Testing/Support/Error.h" #include "gtest/gtest.h" diff --git a/llvm/unittests/TextAPI/CMakeLists.txt b/llvm/unittests/TextAPI/CMakeLists.txt --- a/llvm/unittests/TextAPI/CMakeLists.txt +++ b/llvm/unittests/TextAPI/CMakeLists.txt @@ -3,7 +3,6 @@ ) add_llvm_unittest(TextAPITests - ELFYAMLTest.cpp TextStubV1Tests.cpp TextStubV2Tests.cpp TextStubV3Tests.cpp