git: 4558fc4f91dc - stable/14 - Merge commit 7a66a26658f4 from llvm git (by Fangrui Song):
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 01 Sep 2025 20:15:48 UTC
The branch stable/14 has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=4558fc4f91dc1d3909083ea664b384595f66c3ae commit 4558fc4f91dc1d3909083ea664b384595f66c3ae Author: Ed Maste <emaste@FreeBSD.org> AuthorDate: 2025-08-28 12:48:17 +0000 Commit: Ed Maste <emaste@FreeBSD.org> CommitDate: 2025-09-01 20:15:35 +0000 Merge commit 7a66a26658f4 from llvm git (by Fangrui Song): --discard-locals/--discard-all: allow and keep symbols referenced by relocations In GNU objcopy, symbols referenced by relocations are retained. Our COFF (https://reviews.llvm.org/D56480) and Mach-O (https://reviews.llvm.org/D75104) ports port the behavior, but the ELF port doesn't. This PR implements the behavior for ELF. Close #47468 (tcl has a use case that requires `strip -x tclStubLib.o` to strip local symbols not referenced by relocations.) Pull Request: https://github.com/llvm/llvm-project/pull/130704 PR: 258820 Approved by: dim Differential Revision: https://reviews.freebsd.org/D52198 (cherry picked from commit 959806e0a8448ef5df372468b8deddc20d976702) --- .../llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp | 25 +++++++++++----------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/contrib/llvm-project/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp b/contrib/llvm-project/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp index 075455c03415..7de9b4dd2ea1 100644 --- a/contrib/llvm-project/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp +++ b/contrib/llvm-project/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp @@ -368,7 +368,7 @@ static Error updateAndRemoveSymbols(const CommonConfig &Config, // (like GroupSection or RelocationSection). This way, we know which // symbols are still 'needed' and which are not. if (Config.StripUnneeded || !Config.UnneededSymbolsToRemove.empty() || - !Config.OnlySection.empty()) { + !Config.OnlySection.empty() || Config.DiscardMode != DiscardType::None) { for (SectionBase &Sec : Obj.sections()) Sec.markSymbols(); } @@ -390,22 +390,23 @@ static Error updateAndRemoveSymbols(const CommonConfig &Config, if (Config.StripDebug && Sym.Type == STT_FILE) return true; - if ((Config.DiscardMode == DiscardType::All || - (Config.DiscardMode == DiscardType::Locals && - StringRef(Sym.Name).starts_with(".L"))) && - Sym.Binding == STB_LOCAL && Sym.getShndx() != SHN_UNDEF && - Sym.Type != STT_FILE && Sym.Type != STT_SECTION) - return true; - if ((Config.StripUnneeded || Config.UnneededSymbolsToRemove.matches(Sym.Name)) && (!Obj.isRelocatable() || 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; + if (!Sym.Referenced) { + if ((Config.DiscardMode == DiscardType::All || + (Config.DiscardMode == DiscardType::Locals && + StringRef(Sym.Name).starts_with(".L"))) && + Sym.Binding == STB_LOCAL && Sym.getShndx() != SHN_UNDEF && + Sym.Type != STT_FILE && Sym.Type != STT_SECTION) + return true; + // We want to remove undefined symbols if all references have been + // stripped. + if (!Config.OnlySection.empty() && Sym.getShndx() == SHN_UNDEF) + return true; + } return false; };