[lld] r248132 - COFF: Fix ICF regression.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 20 13:19:12 PDT 2015


Author: ruiu
Date: Sun Sep 20 15:19:12 2015
New Revision: 248132

URL: http://llvm.org/viewvc/llvm-project?rev=248132&view=rev
Log:
COFF: Fix ICF regression.

This patch fixes a regression introduced by r247964. Relocations that
are referring the same symbol should be considered equal, but they
were not if they were pointing to non-section chunks.

Modified:
    lld/trunk/COFF/ICF.cpp
    lld/trunk/test/COFF/icf-circular.test

Modified: lld/trunk/COFF/ICF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/ICF.cpp?rev=248132&r1=248131&r2=248132&view=diff
==============================================================================
--- lld/trunk/COFF/ICF.cpp (original)
+++ lld/trunk/COFF/ICF.cpp Sun Sep 20 15:19:12 2015
@@ -137,11 +137,12 @@ bool ICF::equalsVariable(const SectionCh
   // Compare relocations.
   auto Eq = [&](const coff_relocation &R1, const coff_relocation &R2) {
     SymbolBody *B1 = A->File->getSymbolBody(R1.SymbolTableIndex)->repl();
-    if (auto *D1 = dyn_cast<DefinedRegular>(B1)) {
-      SymbolBody *B2 = B->File->getSymbolBody(R2.SymbolTableIndex)->repl();
+    SymbolBody *B2 = B->File->getSymbolBody(R2.SymbolTableIndex)->repl();
+    if (B1 == B2)
+      return true;
+    if (auto *D1 = dyn_cast<DefinedRegular>(B1))
       if (auto *D2 = dyn_cast<DefinedRegular>(B2))
         return D1->getChunk()->GroupID == D2->getChunk()->GroupID;
-    }
     return false;
   };
   return std::equal(A->Relocs.begin(), A->Relocs.end(), B->Relocs.begin(), Eq);

Modified: lld/trunk/test/COFF/icf-circular.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/icf-circular.test?rev=248132&r1=248131&r2=248132&view=diff
==============================================================================
--- lld/trunk/test/COFF/icf-circular.test (original)
+++ lld/trunk/test/COFF/icf-circular.test Sun Sep 20 15:19:12 2015
@@ -19,6 +19,9 @@ sections:
       - VirtualAddress:  5
         SymbolName:      foo
         Type:            IMAGE_REL_AMD64_REL32
+      - VirtualAddress:  10
+        SymbolName:      __ImageBase
+        Type:            IMAGE_REL_AMD64_REL32
   - Name:            '.text$mn'
     Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_LNK_COMDAT, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
     Alignment:       16
@@ -27,6 +30,9 @@ sections:
       - VirtualAddress:  5
         SymbolName:      bar
         Type:            IMAGE_REL_AMD64_REL32
+      - VirtualAddress:  10
+        SymbolName:      __ImageBase
+        Type:            IMAGE_REL_AMD64_REL32
 symbols:
   - Name:            '.text$mn'
     Value:           0
@@ -66,4 +72,10 @@ symbols:
     SimpleType:      IMAGE_SYM_TYPE_NULL
     ComplexType:     IMAGE_SYM_DTYPE_FUNCTION
     StorageClass:    IMAGE_SYM_CLASS_EXTERNAL
+  - Name:            __ImageBase
+    Value:           0
+    SectionNumber:   0
+    SimpleType:      IMAGE_SYM_TYPE_NULL
+    ComplexType:     IMAGE_SYM_DTYPE_NULL
+    StorageClass:    IMAGE_SYM_CLASS_EXTERNAL
 ...




More information about the llvm-commits mailing list