[lld] [lld][ELF] Demote symbols in discarded sections to Undefined. (PR #68777)

Bevin Hansson via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 16 02:19:59 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++;
----------------
bevin-hansson wrote:

I changed the section index code in both places. It was not giving the right index. I'm not sure why I didn't notice it earlier. I'm pretty sure it worked before.

https://github.com/llvm/llvm-project/pull/68777


More information about the llvm-commits mailing list