Index: llvm/include/llvm/InterfaceStub/IFSHandler.h =================================================================== --- llvm/include/llvm/InterfaceStub/IFSHandler.h +++ llvm/include/llvm/InterfaceStub/IFSHandler.h @@ -54,6 +54,9 @@ /// Strips symbols from IFS symbol table that are undefined. void stripIFSUndefinedSymbols(IFSStub &Stub); +/// Strips all NeededLibs. +void stripIFSNeededLibs(IFSStub &Stub); + /// Parse llvm triple string into a IFSTarget struct. IFSTarget parseTriple(StringRef TripleStr); Index: llvm/lib/InterfaceStub/IFSHandler.cpp =================================================================== --- llvm/lib/InterfaceStub/IFSHandler.cpp +++ llvm/lib/InterfaceStub/IFSHandler.cpp @@ -337,3 +337,7 @@ } } } + +void ifs::stripIFSNeededLibs(IFSStub &Stub) { + Stub.NeededLibs.clear(); +} Index: llvm/test/tools/llvm-ifs/strip-needed.test =================================================================== --- /dev/null +++ llvm/test/tools/llvm-ifs/strip-needed.test @@ -0,0 +1,26 @@ +## Test --strip-needed flag + +# RUN: llvm-ifs --input-format=IFS --strip-needed --output-ifs=- %s | FileCheck %s + +# RUN: llvm-ifs --input-format=IFS --output-elf=- %s | \ +# RUN: obj2yaml | FileCheck %s --check-prefix=FROM-ELF + +# RUN: llvm-ifs --input-format=IFS --strip-needed --output-elf=- %s | \ +# RUN: obj2yaml | FileCheck %s --check-prefix=FROM-ELF-STRIP-NEEDED + +--- !ifs-v1 +IfsVersion: 3.0 +Target: { ObjectFormat: ELF, Arch: AArch64, Endianness: little, BitWidth: 64 } +NeededLibs: + - '' +Symbols: [] +... + +# CHECK: --- !ifs-v1 +# CHECK-NEXT: IfsVersion: {{[1-9]\d*\.(0|([1-9]\d*))}} +# CHECK-NEXT: Target: { ObjectFormat: ELF, Arch: AArch64, Endianness: little, BitWidth: 64 } +# CHECK-NEXT: Symbols: [] +# CHECK-NEXT: ... + +# FROM-ELF: DT_NEEDED +# FROM-ELF-STRIP-NEEDED-NOT: DT_NEEDED Index: llvm/tools/llvm-ifs/llvm-ifs.cpp =================================================================== --- llvm/tools/llvm-ifs/llvm-ifs.cpp +++ llvm/tools/llvm-ifs/llvm-ifs.cpp @@ -103,6 +103,9 @@ StripUndefined("strip-undefined", cl::desc("Strip undefined symbols from IFS output"), cl::cat(IfsCategory)); +cl::opt StripIFSNeededLibs("strip-needed", + cl::desc("Strip needed libs from IFS output"), + cl::cat(IfsCategory)); cl::opt SoName("soname", @@ -417,6 +420,9 @@ if (OverrideError) fatalError(std::move(OverrideError)); + if (StripIFSNeededLibs) + stripIFSNeededLibs(Stub); + if (OutputELFFilePath.getNumOccurrences() == 0 && OutputIFSFilePath.getNumOccurrences() == 0 && OutputTBDFilePath.getNumOccurrences() == 0) {