Index: lld/trunk/ELF/ICF.cpp =================================================================== --- lld/trunk/ELF/ICF.cpp +++ lld/trunk/ELF/ICF.cpp @@ -245,7 +245,6 @@ if (&SA == &SB) return true; - // Or, the two sections must be in the same equivalence class. auto *DA = dyn_cast>(&SA); auto *DB = dyn_cast>(&SB); if (!DA || !DB) @@ -253,6 +252,11 @@ if (DA->Value != DB->Value) return false; + // Either both symbols must be absolute... + if (!DA->Section || !DB->Section) + return !DA->Section && !DB->Section; + + // Or the two sections must be in the same equivalence class. auto *X = dyn_cast>(DA->Section); auto *Y = dyn_cast>(DB->Section); if (!X || !Y) Index: lld/trunk/test/ELF/Inputs/icf-absolute.s =================================================================== --- lld/trunk/test/ELF/Inputs/icf-absolute.s +++ lld/trunk/test/ELF/Inputs/icf-absolute.s @@ -0,0 +1,3 @@ +.globl a1, a2 +a1 = 1 +a2 = 1 Index: lld/trunk/test/ELF/icf-absolute.s =================================================================== --- lld/trunk/test/ELF/icf-absolute.s +++ lld/trunk/test/ELF/icf-absolute.s @@ -0,0 +1,20 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %S/Inputs/icf-absolute.s -o %t2 +# RUN: ld.lld %t %t2 -o %t3 --icf=all --verbose | FileCheck %s + +# CHECK: selected .text.f1 +# CHECK: removed .text.f2 + +.globl _start, f1, f2 +_start: + ret + +.section .text.f1, "ax" +f1: + .byte a1 + +.section .text.f2, "ax" +f2: + .byte a2