[llvm] d650cbc - [elfabi] Move llvm-elfabi related code to InterfaceStub library
Haowei Wu via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 13 11:51:56 PDT 2020
Author: Haowei Wu
Date: 2020-08-13T11:51:44-07:00
New Revision: d650cbc349ccc4f477568c2827f1bce650020058
URL: https://github.com/llvm/llvm-project/commit/d650cbc349ccc4f477568c2827f1bce650020058
DIFF: https://github.com/llvm/llvm-project/commit/d650cbc349ccc4f477568c2827f1bce650020058.diff
LOG: [elfabi] Move llvm-elfabi related code to InterfaceStub library
This change moves elfabi related code to llvm/InterfaceStub library
so it can be shared by multiple llvm tools without causing cyclic
dependencies.
Differential Revision: https://reviews.llvm.org/D85678
Added:
llvm/include/llvm/InterfaceStub/ELFObjHandler.h
llvm/include/llvm/InterfaceStub/ELFStub.h
llvm/include/llvm/InterfaceStub/TBEHandler.h
llvm/lib/InterfaceStub/CMakeLists.txt
llvm/lib/InterfaceStub/ELFObjHandler.cpp
llvm/lib/InterfaceStub/ELFStub.cpp
llvm/lib/InterfaceStub/LLVMBuild.txt
llvm/lib/InterfaceStub/TBEHandler.cpp
llvm/unittests/InterfaceStub/CMakeLists.txt
llvm/unittests/InterfaceStub/ELFYAMLTest.cpp
Modified:
llvm/lib/CMakeLists.txt
llvm/lib/LLVMBuild.txt
llvm/lib/TextAPI/CMakeLists.txt
llvm/tools/llvm-elfabi/CMakeLists.txt
llvm/tools/llvm-elfabi/LLVMBuild.txt
llvm/tools/llvm-elfabi/llvm-elfabi.cpp
llvm/unittests/CMakeLists.txt
llvm/unittests/TextAPI/CMakeLists.txt
Removed:
llvm/include/llvm/TextAPI/ELF/ELFStub.h
llvm/include/llvm/TextAPI/ELF/TBEHandler.h
llvm/lib/TextAPI/ELF/ELFStub.cpp
llvm/lib/TextAPI/ELF/TBEHandler.cpp
llvm/tools/llvm-elfabi/ELFObjHandler.cpp
llvm/tools/llvm-elfabi/ELFObjHandler.h
llvm/unittests/TextAPI/ELFYAMLTest.cpp
################################################################################
diff --git a/llvm/tools/llvm-elfabi/ELFObjHandler.h b/llvm/include/llvm/InterfaceStub/ELFObjHandler.h
similarity index 96%
rename from llvm/tools/llvm-elfabi/ELFObjHandler.h
rename to llvm/include/llvm/InterfaceStub/ELFObjHandler.h
index 97f0d68f4d4f..1ffd9a614eec 100644
--- 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
similarity index 93%
rename from llvm/include/llvm/TextAPI/ELF/ELFStub.h
rename to llvm/include/llvm/InterfaceStub/ELFStub.h
index 76b2af121662..7832c1c7413b 100644
--- 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 <vector>
#include <set>
+#include <vector>
namespace llvm {
namespace elfabi {
@@ -42,15 +42,13 @@ struct ELFSymbol {
bool Undefined;
bool Weak;
Optional<std::string> 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<std::string> SoName;
diff --git a/llvm/include/llvm/TextAPI/ELF/TBEHandler.h b/llvm/include/llvm/InterfaceStub/TBEHandler.h
similarity index 100%
rename from llvm/include/llvm/TextAPI/ELF/TBEHandler.h
rename to llvm/include/llvm/InterfaceStub/TBEHandler.h
index 76484410987f..5c523eba037e 100644
--- 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 <memory>
namespace llvm {
diff --git a/llvm/lib/CMakeLists.txt b/llvm/lib/CMakeLists.txt
index abe3ec59aec1..35d204d7d63e 100644
--- 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
index 000000000000..be2529f6d605
--- /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
similarity index 91%
rename from llvm/tools/llvm-elfabi/ELFObjHandler.cpp
rename to llvm/lib/InterfaceStub/ELFObjHandler.cpp
index 124fffbb9cf6..82e7a3c8b1ba 100644
--- 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 @@ 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);
}
}
@@ -212,16 +210,16 @@ static Expected<uint64_t> 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;
}
}
@@ -259,8 +257,8 @@ static ELFSymbol createELFSym(StringRef SymName,
/// @param DynStr StringRef to the dynamic string table.
template <class ELFT>
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 @@ buildStub(const ELFObjectFile<ELFT> &ElfObj) {
if (Error Err = populateDynamic<ELFT>(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<const uint8_t *> DynStrPtr =
ElfFile->toMappedAddr(DynEnt.StrTabAddr);
if (!DynStrPtr)
@@ -355,9 +353,8 @@ buildStub(const ELFObjectFile<ELFT> &ElfObj) {
if (!DynSymPtr)
return appendToError(DynSymPtr.takeError(),
"when locating .dynsym section contents");
- Elf_Sym_Range DynSyms =
- ArrayRef<Elf_Sym>(reinterpret_cast<const Elf_Sym *>(*DynSymPtr),
- *SymCount);
+ Elf_Sym_Range DynSyms = ArrayRef<Elf_Sym>(
+ reinterpret_cast<const Elf_Sym *>(*DynSymPtr), *SymCount);
Error SymReadError = populateSymbols<ELFT>(*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
similarity index 95%
rename from llvm/lib/TextAPI/ELF/ELFStub.cpp
rename to llvm/lib/InterfaceStub/ELFStub.cpp
index f8463497093b..3c637695d8e7 100644
--- 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/lib/InterfaceStub/LLVMBuild.txt b/llvm/lib/InterfaceStub/LLVMBuild.txt
new file mode 100644
index 000000000000..e69544d4f5f6
--- /dev/null
+++ b/llvm/lib/InterfaceStub/LLVMBuild.txt
@@ -0,0 +1,21 @@
+;===- ./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.
+; SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+;
+;===------------------------------------------------------------------------===;
+;
+; This is an LLVMBuild description file for the components in this subdirectory.
+;
+; For more information on the LLVMBuild system, please see:
+;
+; http://llvm.org/docs/LLVMBuild.html
+;
+;===------------------------------------------------------------------------===;
+
+[component_0]
+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
similarity index 98%
rename from llvm/lib/TextAPI/ELF/TBEHandler.cpp
rename to llvm/lib/InterfaceStub/TBEHandler.cpp
index cb597d8896e8..06a2f9bf2451 100644
--- 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
index 824abd36fc99..a81c6a1fe3fa 100644
--- a/llvm/lib/LLVMBuild.txt
+++ b/llvm/lib/LLVMBuild.txt
@@ -30,6 +30,7 @@ subdirectories =
FuzzMutate
LineEditor
Linker
+ InterfaceStub
IR
IRReader
LTO
diff --git a/llvm/lib/TextAPI/CMakeLists.txt b/llvm/lib/TextAPI/CMakeLists.txt
index 36528f0995d8..b63bc64b31f1 100644
--- 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
index bd3ec851887a..43b4b5b5faa9 100644
--- 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
index b1a80e9e4a15..4e8021442fb6 100644
--- 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
index 044b5f77c6d7..8bf2ad4ed537 100644
--- 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 <string>
namespace llvm {
diff --git a/llvm/unittests/CMakeLists.txt b/llvm/unittests/CMakeLists.txt
index d7dbaeaa32fe..850bc14b207f 100644
--- a/llvm/unittests/CMakeLists.txt
+++ b/llvm/unittests/CMakeLists.txt
@@ -26,6 +26,7 @@ add_subdirectory(Demangle)
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
index 000000000000..22ff0af67a3d
--- /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
similarity index 98%
rename from llvm/unittests/TextAPI/ELFYAMLTest.cpp
rename to llvm/unittests/InterfaceStub/ELFYAMLTest.cpp
index 8217507b5a5d..2b86b89fbbb6 100644
--- 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
index 775ec2f1d1e8..d575d57610b9 100644
--- a/llvm/unittests/TextAPI/CMakeLists.txt
+++ b/llvm/unittests/TextAPI/CMakeLists.txt
@@ -3,7 +3,6 @@ set(LLVM_LINK_COMPONENTS
)
add_llvm_unittest(TextAPITests
- ELFYAMLTest.cpp
TextStubV1Tests.cpp
TextStubV2Tests.cpp
TextStubV3Tests.cpp
More information about the llvm-commits
mailing list