[PATCH] D49653: [LLD] [COFF] Handle comdat sections without leader symbols

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 22 14:48:55 PDT 2018


mstorsjo created this revision.
mstorsjo added reviewers: ruiu, rnk, pcc.

Discard them unless they have been associated by other means (yet unimplemented).

According to MS link.exe, such sections are illegal, but MinGW setups use them in their take on associative comdats.

This avoids leaving references to the bogus SectionChunk* PendingComdat, which cannot be dereferenced.

This fixes PR38183.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D49653

Files:
  COFF/InputFiles.cpp
  test/COFF/pending-comdat.s


Index: test/COFF/pending-comdat.s
===================================================================
--- /dev/null
+++ test/COFF/pending-comdat.s
@@ -0,0 +1,21 @@
+# REQUIRES: x86
+
+# RUN: llvm-mc -triple=x86_64-windows-gnu %s -filetype=obj -o %t.obj
+
+# RUN: not lld-link -lldmingw -out:%t.exe -entry:main -subsystem:console %t.obj 2>&1 | FileCheck %s
+
+# CHECK: error: undefined symbol: other
+
+# Check that the comdat section without a symbol isn't left pending once we iterate symbols
+# to print source of the undefined symbol.
+
+	.text
+	.globl main
+main:
+	call other
+	ret
+
+	.section	.data$pending,"w"
+	.linkonce	discard
+.Llocal:
+	.byte	0
Index: COFF/InputFiles.cpp
===================================================================
--- COFF/InputFiles.cpp
+++ COFF/InputFiles.cpp
@@ -233,6 +233,12 @@
       return Symtab->addRegular(this, Name, Sym.getGeneric(), SC);
     return Symtab->addUndefined(Name, this, false);
   }
+  if (SC == PendingComdat) {
+    StringRef Name;
+    COFFObj->getSymbolName(Sym, Name);
+    log("comdat section " + Name + " without leader and unassociated, discarding");
+    return nullptr;
+  }
   if (SC)
     return make<DefinedRegular>(this, /*Name*/ "", false,
                                 /*IsExternal*/ false, Sym.getGeneric(), SC);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49653.156715.patch
Type: text/x-patch
Size: 1299 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180722/d09a673a/attachment.bin>


More information about the llvm-commits mailing list