[lld] [lld][ELF] Demote symbols in discarded sections to Undefined. (PR #68777)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 17 01:11:33 PDT 2023
================
@@ -3061,6 +3061,37 @@ void LinkerDriver::link(opt::InputArgList &args) {
script->addOrphanSections();
}
+ // Demote symbols defined relative to input sections that are discarded by
+ // /DISCARD/ so that relocations referencing them will get reported.
+ if (script->seenDiscard) {
+ llvm::TimeTraceScope timeScope("Demote symbols in discarded sections");
+ parallelForEach(symtab.getSymbols(), [](Symbol *sym) {
+ Defined *d = dyn_cast<Defined>(sym);
+ if (!d)
+ return;
+ if (d->section && !d->section->isLive()) {
+ uint32_t secIdx = 0;
+ if (d->file) {
+ uint32_t idx = 0;
+ for (SectionBase *s : d->file->getSections()) {
+ if (s == d->section) {
+ secIdx = idx;
+ break;
+ }
+ idx++;
----------------
MaskRay wrote:
There is a performance issue. If an object file has many discarded symbols, the quadratic time complexity will not be acceptable. I have fixed this in https://github.com/maskray/llvm-project/tree/lld-symbols-in-discard
https://github.com/llvm/llvm-project/pull/68777
More information about the llvm-commits
mailing list