diff options
Diffstat (limited to 'llvm/tools/llvm-objcopy')
-rw-r--r-- | llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
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; }; |