diff options
| author | George Rimar <grimar@accesssoftek.com> | 2019-05-24 15:04:50 +0000 |
|---|---|---|
| committer | George Rimar <grimar@accesssoftek.com> | 2019-05-24 15:04:50 +0000 |
| commit | c1cc8d0eca459a5f49e8e6b99a93b0e1d05a13ba (patch) | |
| tree | 77fdf4b64d5f502ac0620103d84ee18a0ca3bf70 /llvm/tools | |
| parent | aa7754cc9038b2c8a2bf1fb0e3a148f94cf4e8c5 (diff) | |
| download | bcm5719-llvm-c1cc8d0eca459a5f49e8e6b99a93b0e1d05a13ba.tar.gz bcm5719-llvm-c1cc8d0eca459a5f49e8e6b99a93b0e1d05a13ba.zip | |
[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
Diffstat (limited to 'llvm/tools')
| -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; }; |

