[PATCH] D124792: [ifs] Add --strip-size flag
Alex Brachet via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon May 2 11:25:02 PDT 2022
abrachet created this revision.
abrachet added reviewers: haowei, mcgrathr.
Herald added subscribers: jhenderson, hiraditya.
Herald added a project: All.
abrachet requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
st_size may not be of importance to the abi if you are not using copy relocations. This is helpful when you want to check the abi of a shared object both when instrumented and not because asan will increase the size of objects to include the redzone.
https://reviews.llvm.org/D124792
Files:
llvm/lib/InterfaceStub/ELFObjHandler.cpp
llvm/lib/InterfaceStub/IFSHandler.cpp
llvm/test/tools/llvm-ifs/strip-size.test
llvm/tools/llvm-ifs/llvm-ifs.cpp
Index: llvm/tools/llvm-ifs/llvm-ifs.cpp
===================================================================
--- llvm/tools/llvm-ifs/llvm-ifs.cpp
+++ llvm/tools/llvm-ifs/llvm-ifs.cpp
@@ -107,6 +107,10 @@
cl::opt<bool> StripNeededLibs("strip-needed",
cl::desc("Strip needed libs from output"),
cl::cat(IfsCategory));
+cl::opt<bool> StripSize("strip-size",
+ cl::desc("Remove object size from the output"),
+ cl::cat(IfsCategory));
+
cl::list<std::string>
ExcludeSyms("exclude",
cl::desc("Remove symbols which match the pattern. Can be "
@@ -432,6 +436,10 @@
if (Error E = filterIFSSyms(Stub, StripUndefined, ExcludeSyms))
fatalError(std::move(E));
+ if (StripSize)
+ for (auto &Sym : Stub.Symbols)
+ Sym.Size = std::numeric_limits<uint64_t>::max();
+
if (OutputELFFilePath.getNumOccurrences() == 0 &&
OutputIFSFilePath.getNumOccurrences() == 0 &&
OutputTBDFilePath.getNumOccurrences() == 0) {
Index: llvm/test/tools/llvm-ifs/strip-size.test
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-ifs/strip-size.test
@@ -0,0 +1,20 @@
+# RUN: llvm-ifs %s --output-ifs - --strip-size | FileCheck %s
+
+# CHECK: Symbols:
+# CHECK-NEXT: - { Name: sym, Type: Object }
+# CHECK-NEXT: ...
+
+## Check that the size when emitting to elf defaults to 1
+# RUN: llvm-ifs %s --output-elf - --strip-size | llvm-ifs - --output-ifs - | \
+# RUN: FileCheck %s --check-prefix=ELF
+
+# ELF: Symbols:
+# ELF-NEXT: - { Name: sym, Type: Object, Size: 1 }
+# ELF-NEXT: ...
+
+--- !ifs-v1
+IfsVersion: 3.0
+Target: x86_64
+Symbols:
+ - { Name: sym, Type: Object, Size: 2 }
+...
Index: llvm/lib/InterfaceStub/IFSHandler.cpp
===================================================================
--- llvm/lib/InterfaceStub/IFSHandler.cpp
+++ llvm/lib/InterfaceStub/IFSHandler.cpp
@@ -119,9 +119,8 @@
// The need for symbol size depends on the symbol type.
if (Symbol.Type == IFSSymbolType::NoType) {
IO.mapOptional("Size", Symbol.Size, (uint64_t)0);
- } else if (Symbol.Type == IFSSymbolType::Func) {
- Symbol.Size = 0;
- } else {
+ } else if (Symbol.Type != IFSSymbolType::Func &&
+ Symbol.Size != std::numeric_limits<uint64_t>::max()) {
IO.mapRequired("Size", Symbol.Size);
}
IO.mapOptional("Undefined", Symbol.Undefined, false);
Index: llvm/lib/InterfaceStub/ELFObjHandler.cpp
===================================================================
--- llvm/lib/InterfaceStub/ELFObjHandler.cpp
+++ llvm/lib/InterfaceStub/ELFObjHandler.cpp
@@ -217,7 +217,10 @@
// time as long as it is not SHN_UNDEF. Set shndx to 1, which
// points to ".dynsym".
uint16_t Shndx = Sym.Undefined ? SHN_UNDEF : 1;
- DynSym.Content.add(DynStr.Content.getOffset(Sym.Name), Sym.Size, Bind,
+ uint64_t Size = Sym.Size;
+ if (Size == std::numeric_limits<uint64_t>::max())
+ Size = 1;
+ DynSym.Content.add(DynStr.Content.getOffset(Sym.Name), Size, Bind,
convertIFSSymbolTypeToELF(Sym.Type), 0, Shndx);
}
DynSym.Size = DynSym.Content.getSize();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124792.426466.patch
Type: text/x-patch
Size: 3269 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220502/b1cc4e75/attachment.bin>
More information about the llvm-commits
mailing list