diff --git a/lld/COFF/ICF.cpp b/lld/COFF/ICF.cpp index 7a0ff4056495..f0b024a2b7a7 100644 --- a/lld/COFF/ICF.cpp +++ b/lld/COFF/ICF.cpp @@ -137,11 +137,12 @@ bool ICF::equalsVariable(const SectionChunk *A, const SectionChunk *B) { // 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(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(B1)) if (auto *D2 = dyn_cast(B2)) return D1->getChunk()->GroupID == D2->getChunk()->GroupID; - } return false; }; return std::equal(A->Relocs.begin(), A->Relocs.end(), B->Relocs.begin(), Eq); diff --git a/lld/test/COFF/icf-circular.test b/lld/test/COFF/icf-circular.test index 7348cd9d22ff..7319e135e2e6 100644 --- a/lld/test/COFF/icf-circular.test +++ b/lld/test/COFF/icf-circular.test @@ -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 ...