[lld] r352508 - lld-link: Allow backward references between associated comdats

Nico Weber via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 29 07:50:31 PST 2019


Author: nico
Date: Tue Jan 29 07:50:31 2019
New Revision: 352508

URL: http://llvm.org/viewvc/llvm-project?rev=352508&view=rev
Log:
lld-link: Allow backward references between associated comdats

References between associated comdats are invalid per COFF spec, but the newest
Windows SDK contains obj files that have these references
(https://bugs.chromium.org/p/chromium/issues/detail?id=925943#c13). So add back
support for them and add tests for them. The old code handled them fine.

This makes lld-link match the behavior of newer link.exe versions as far as I
can tell. (The behavior before this change matched the behavior of older
link.exe versions.)

This mostly reverts r352254.

Differential Revision: https://reviews.llvm.org/D57387

Modified:
    lld/trunk/COFF/InputFiles.cpp
    lld/trunk/test/COFF/associative-comdat-order.test

Modified: lld/trunk/COFF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/InputFiles.cpp?rev=352508&r1=352507&r2=352508&view=diff
==============================================================================
--- lld/trunk/COFF/InputFiles.cpp (original)
+++ lld/trunk/COFF/InputFiles.cpp Tue Jan 29 07:50:31 2019
@@ -250,16 +250,12 @@ void ObjFile::readAssociativeDefinition(
   // Check whether the parent is prevailing. If it is, so are we, and we read
   // the section; otherwise mark it as discarded.
   if (Parent) {
-    if (Parent->Selection == IMAGE_COMDAT_SELECT_ASSOCIATIVE) {
-      Diag();
-      return;
-    }
-
     SectionChunk *C = readSection(SectionNumber, Def, "");
-    C->Selection = IMAGE_COMDAT_SELECT_ASSOCIATIVE;
     SparseChunks[SectionNumber] = C;
-    if (SparseChunks[SectionNumber])
-      Parent->addAssociative(SparseChunks[SectionNumber]);
+    if (C) {
+      C->Selection = IMAGE_COMDAT_SELECT_ASSOCIATIVE;
+      Parent->addAssociative(C);
+    }
   } else {
     SparseChunks[SectionNumber] = nullptr;
   }

Modified: lld/trunk/test/COFF/associative-comdat-order.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/associative-comdat-order.test?rev=352508&r1=352507&r2=352508&view=diff
==============================================================================
--- lld/trunk/test/COFF/associative-comdat-order.test (original)
+++ lld/trunk/test/COFF/associative-comdat-order.test Tue Jan 29 07:50:31 2019
@@ -6,11 +6,17 @@
 # FORWARD-NOT: lld-link: error:
 
 # Tests that an associative comdat being associated with another
-# associated comdat earlier in the file produces an error.
+# associated comdat earlier in the file works.
 # RUN: sed -e s/ASSOC1/3/ -e s/ASSOC2/1/ %s | yaml2obj > %t.obj
-# RUN: not lld-link /include:symbol /dll /noentry /nodefaultlib %t.obj /out:%t.exe 2>&1 | FileCheck --check-prefix=BACKWARD %s
-# BACKWARD: lld-link: error: {{.*}}: associative comdat .text$ac2 (sec 2) has invalid reference to section .text$ac1 (sec 1)
-# BACKWARD-NOT: lld-link: error:
+
+# RUN: lld-link /include:symbol /dll /noentry /nodefaultlib %t.obj /out:%t.exe
+# RUN: llvm-objdump -s %t.exe | FileCheck --check-prefix=BACKWARD %s
+# BACKWARD: Contents of section .text:
+# BACKWARD:   180001000 01000000 02000000 03000000 ............
+
+# RUN: lld-link /dll /noentry /nodefaultlib %t.obj /out:%t.exe
+# RUN: llvm-objdump -s %t.exe | FileCheck --check-prefix=BACKWARDDROP %s
+# BACKWARDDROP-NOT: Contents of section .text:
 
 --- !COFF
 header:          
@@ -24,11 +30,11 @@ sections:
   - Name:            '.text$ac2'
     Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_LNK_COMDAT, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
     Alignment:       1
-    SectionData:     '01000000'
+    SectionData:     '02000000'
   - Name:            '.text$nm'
     Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_LNK_COMDAT, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
     Alignment:       1
-    SectionData:     '01000000'
+    SectionData:     '03000000'
 symbols:         
   - Name:            '.text$ac1'
     Value:           0




More information about the llvm-commits mailing list