[llvm] 31e61c5 - [ifs] Add option to hide undefined symbols
Haowei Wu via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 27 11:16:09 PDT 2021
Author: Haowei Wu
Date: 2021-08-27T11:15:56-07:00
New Revision: 31e61c58b0663d2706a1166dd354ba8e282565ec
URL: https://github.com/llvm/llvm-project/commit/31e61c58b0663d2706a1166dd354ba8e282565ec
DIFF: https://github.com/llvm/llvm-project/commit/31e61c58b0663d2706a1166dd354ba8e282565ec.diff
LOG: [ifs] Add option to hide undefined symbols
This change add an option to llvm-ifs to hide undefined symbols from
its output.
Differential Revision: https://reviews.llvm.org/D108428
Added:
llvm/test/tools/llvm-ifs/strip-undefined-symbols.test
Modified:
llvm/include/llvm/InterfaceStub/IFSHandler.h
llvm/lib/InterfaceStub/IFSHandler.cpp
llvm/tools/llvm-ifs/llvm-ifs.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/InterfaceStub/IFSHandler.h b/llvm/include/llvm/InterfaceStub/IFSHandler.h
index de627492366fe..6ae6a421318eb 100644
--- a/llvm/include/llvm/InterfaceStub/IFSHandler.h
+++ b/llvm/include/llvm/InterfaceStub/IFSHandler.h
@@ -51,6 +51,9 @@ Error validateIFSTarget(IFSStub &Stub, bool ParseTriple);
void stripIFSTarget(IFSStub &Stub, bool StripTriple, bool StripArch,
bool StripEndianness, bool StripBitWidth);
+/// Strips symbols from IFS symbol table that are undefined.
+void stripIFSUndefinedSymbols(IFSStub &Stub);
+
/// Parse llvm triple string into a IFSTarget struct.
IFSTarget parseTriple(StringRef TripleStr);
diff --git a/llvm/lib/InterfaceStub/IFSHandler.cpp b/llvm/lib/InterfaceStub/IFSHandler.cpp
index d3d351fa2ed45..bfee204e4642a 100644
--- a/llvm/lib/InterfaceStub/IFSHandler.cpp
+++ b/llvm/lib/InterfaceStub/IFSHandler.cpp
@@ -327,3 +327,13 @@ void ifs::stripIFSTarget(IFSStub &Stub, bool StripTriple, bool StripArch,
Stub.Target.ObjectFormat.reset();
}
}
+
+void ifs::stripIFSUndefinedSymbols(IFSStub &Stub) {
+ for (auto Iter = Stub.Symbols.begin(); Iter != Stub.Symbols.end();) {
+ if (Iter->Undefined) {
+ Iter = Stub.Symbols.erase(Iter);
+ } else {
+ Iter++;
+ }
+ }
+}
diff --git a/llvm/test/tools/llvm-ifs/strip-undefined-symbols.test b/llvm/test/tools/llvm-ifs/strip-undefined-symbols.test
new file mode 100644
index 0000000000000..380e275f490c4
--- /dev/null
+++ b/llvm/test/tools/llvm-ifs/strip-undefined-symbols.test
@@ -0,0 +1,17 @@
+# RUN: llvm-ifs --input-format=ELF --strip-undefined --output-format=IFS --output=- %p/Inputs/gnu_hash.so | FileCheck %s
+
+# CHECK: --- !ifs-v1
+# CHECK-NEXT: IfsVersion: 3.0
+# CHECK-NEXT: SoName: libsomething.so
+# CHECK-NEXT: Target: { ObjectFormat: ELF, Arch: x86_64, Endianness: little, BitWidth: 64 }
+# CHECK-NEXT: NeededLibs:
+# CHECK-NEXT: - libm.so.6
+# CHECK-NEXT: - libc.so.6
+# CHECK-NEXT: - ld-linux-x86-64.so.2
+# CHECK-NEXT: Symbols:
+# CHECK-NEXT: - { Name: AGlobalInteger, Type: Object, Size: 4 }
+# CHECK-NEXT: - { Name: AThreadLocalLongInteger, Type: TLS, Size: 8 }
+# CHECK-NEXT: - { Name: _Z11rotateArrayPii, Type: Func }
+# CHECK-NEXT: - { Name: _fini, Type: Func }
+# CHECK-NEXT: - { Name: _init, Type: Func }
+# CHECK-NEXT: ...
diff --git a/llvm/tools/llvm-ifs/llvm-ifs.cpp b/llvm/tools/llvm-ifs/llvm-ifs.cpp
index 77269967a2988..d034793f019f6 100644
--- a/llvm/tools/llvm-ifs/llvm-ifs.cpp
+++ b/llvm/tools/llvm-ifs/llvm-ifs.cpp
@@ -99,6 +99,11 @@ cl::opt<bool> StripIFSTarget(
"strip-ifs-target",
cl::desc("Strip all target information away from IFS output"),
cl::cat(IfsCategory));
+cl::opt<bool>
+ StripUndefined("strip-undefined",
+ cl::desc("Strip undefined symbols from IFS output"),
+ cl::cat(IfsCategory));
+
cl::opt<std::string>
SoName("soname",
cl::desc("Manually set the DT_SONAME entry of any emitted files"),
@@ -443,6 +448,8 @@ int main(int argc, char *argv[]) {
stripIFSTarget(Stub, StripIFSTarget, StripIFSArch,
StripIFSEndiannessWidth, StripIFSBitWidth);
}
+ if (StripUndefined)
+ stripIFSUndefinedSymbols(Stub);
Error IFSWriteError = writeIFS(OutputFilePath.getValue(), Stub);
if (IFSWriteError)
fatalError(std::move(IFSWriteError));
More information about the llvm-commits
mailing list