[lld] [ELF] --retain-symbols-file: keep listed symbols in .symtab, not .dynsym (PR #209063)
Igor Kudrin via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 13 22:38:07 PDT 2026
================
@@ -339,10 +339,15 @@ void MarkLive<ELFT, TrackWhyLive>::markSymbol(Symbol *sym, StringRef reason) {
enqueue(isec, d->value, sym, {std::nullopt, reason});
}
-template <class ELFT> static void markUsedLocalSymbols(InputSectionBase &sec) {
+// If -r or --emit-relocs, ensure referenced symbols are preserved in .symtab.
+// --discard-* drops only locals; --retain-symbols-file also drops globals, so
+// mark those too.
+template <class ELFT>
+static void markUsedSymbols(Ctx &ctx, InputSectionBase &sec) {
+ bool retain = ctx.arg.retainSymbols.has_value();
auto mark = [&](const auto &rel) {
Symbol &sym = sec.file->getRelocTargetSym(rel);
- if (sym.isLocal())
+ if (sym.isLocal() || retain)
----------------
igorkudrin wrote:
If only `|| retain` is removed, the test fails. But when the whole `if (...)` is deleted, all tests pass:
```
auto mark = [&](const auto &rel) {
sec.file->getRelocTargetSym(rel).setFlags(USED);
};
```
https://github.com/llvm/llvm-project/pull/209063
More information about the llvm-commits
mailing list