From c1cc8d0eca459a5f49e8e6b99a93b0e1d05a13ba Mon Sep 17 00:00:00 2001 From: George Rimar Date: Fri, 24 May 2019 15:04:50 +0000 Subject: [llvm-objcopy] - Strip undefined symbols if they are no longer referenced following --only-section This is https://bugs.llvm.org/show_bug.cgi?id=40004. In this patch I teach llvm-objcopy to remove undefined symbols if them are not used anymore after applying -j/--only-section option. Differential revision: https://reviews.llvm.org/D62317 llvm-svn: 361642 --- llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'llvm/tools') diff --git a/llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp b/llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp index b2e750d15f0..be25bd5ee43 100644 --- a/llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp +++ b/llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp @@ -387,7 +387,8 @@ static Error updateAndRemoveSymbols(const CopyConfig &Config, Object &Obj) { // The purpose of this loop is to mark symbols referenced by sections // (like GroupSection or RelocationSection). This way, we know which // symbols are still 'needed' and which are not. - if (Config.StripUnneeded || !Config.UnneededSymbolsToRemove.empty()) { + if (Config.StripUnneeded || !Config.UnneededSymbolsToRemove.empty() || + !Config.OnlySection.empty()) { for (auto &Section : Obj.sections()) Section.markSymbols(); } @@ -415,6 +416,11 @@ static Error updateAndRemoveSymbols(const CopyConfig &Config, Object &Obj) { isUnneededSymbol(Sym)) return true; + // We want to remove undefined symbols if all references have been stripped. + if (!Config.OnlySection.empty() && !Sym.Referenced && + Sym.getShndx() == SHN_UNDEF) + return true; + return false; }; -- cgit v1.2.3