Index: lld/trunk/ELF/ICF.cpp =================================================================== --- lld/trunk/ELF/ICF.cpp +++ lld/trunk/ELF/ICF.cpp @@ -80,9 +80,10 @@ #include "SyntheticSections.h" #include "Writer.h" #include "lld/Common/Threads.h" -#include "llvm/ADT/Hashing.h" +#include "llvm/ADT/StringExtras.h" #include "llvm/BinaryFormat/ELF.h" #include "llvm/Object/ELF.h" +#include "llvm/Support/xxhash.h" #include #include @@ -155,12 +156,6 @@ }; } -// Returns a hash value for S. Note that the information about -// relocation targets is not included in the hash value. -template static uint32_t getHash(InputSection *S) { - return hash_combine(S->Flags, S->getSize(), S->NumRelocations, S->Data); -} - // Returns true if section S is subject of ICF. static bool isEligible(InputSection *S) { if (!S->Live || S->KeepUnique || !(S->Flags & SHF_ALLOC)) @@ -441,7 +436,7 @@ // Initially, we use hash values to partition sections. parallelForEach(Sections, [&](InputSection *S) { // Set MSB to 1 to avoid collisions with non-hash IDs. - S->Class[0] = getHash(S) | (1U << 31); + S->Class[0] = xxHash64(toStringRef(S->Data)) | (1U << 31); }); // From now on, sections in Sections vector are ordered so that sections Index: lld/trunk/test/ELF/icf-safe.s =================================================================== --- lld/trunk/test/ELF/icf-safe.s +++ lld/trunk/test/ELF/icf-safe.s @@ -10,10 +10,6 @@ # RUN: ld.lld %t1.o %t2.o -o %t2 --icf=all --print-icf-sections --export-dynamic | FileCheck --check-prefix=ALL-EXPORT %s # RUN: ld.lld %t1copy.o -o %t4 --icf=safe 2>&1 | FileCheck --check-prefix=OBJCOPY %s -# CHECK-NOT: selected section {{.*}}:(.rodata.l1) -# CHECK: selected section {{.*}}:(.rodata.l3) -# CHECK: removing identical section {{.*}}:(.rodata.l4) - # CHECK-NOT: selected section {{.*}}:(.text.f1) # CHECK: selected section {{.*}}:(.text.f3) # CHECK: removing identical section {{.*}}:(.text.f4) @@ -22,6 +18,10 @@ # CHECK: selected section {{.*}}:(.rodata.h3) # CHECK: removing identical section {{.*}}:(.rodata.h4) +# CHECK-NOT: selected section {{.*}}:(.rodata.l1) +# CHECK: selected section {{.*}}:(.rodata.l3) +# CHECK: removing identical section {{.*}}:(.rodata.l4) + # CHECK-NOT: selected section {{.*}}:(.rodata.g1) # CHECK: selected section {{.*}}:(.rodata.g3) # CHECK: removing identical section {{.*}}:(.rodata.g4) @@ -30,21 +30,21 @@ # With --icf=all address-significance implies keep-unique only for rodata, not # text. -# ALL-NOT: selected section {{.*}}:(.rodata.l1) -# ALL: selected section {{.*}}:(.rodata.l3) -# ALL: removing identical section {{.*}}:(.rodata.l4) - # ALL: selected section {{.*}}:(.text.f3) # ALL: removing identical section {{.*}}:(.text.f4) +# ALL-NOT: selected section {{.*}}:(.rodata.h1) +# ALL: selected section {{.*}}:(.rodata.h3) +# ALL: removing identical section {{.*}}:(.rodata.h4) + # ALL: selected section {{.*}}:(.text.f1) # ALL: removing identical section {{.*}}:(.text.f2) # ALL: removing identical section {{.*}}:(.text.non_addrsig1) # ALL: removing identical section {{.*}}:(.text.non_addrsig2) -# ALL-NOT: selected section {{.*}}:(.rodata.h1) -# ALL: selected section {{.*}}:(.rodata.h3) -# ALL: removing identical section {{.*}}:(.rodata.h4) +# ALL-NOT: selected section {{.*}}:(.rodata.l1) +# ALL: selected section {{.*}}:(.rodata.l3) +# ALL: removing identical section {{.*}}:(.rodata.l4) # ALL-NOT: selected section {{.*}}:(.rodata.g1) # ALL: selected section {{.*}}:(.rodata.g3) @@ -58,36 +58,36 @@ # STB_LOCAL or STV_HIDDEN symbols. The dynsym entries should have prevented # anything else from being merged. # EXPORT-NOT: selected section -# EXPORT: selected section {{.*}}:(.rodata.l3) -# EXPORT: removing identical section {{.*}}:(.rodata.l4) -# EXPORT-NOT: selected section # EXPORT: selected section {{.*}}:(.rodata.h3) # EXPORT: removing identical section {{.*}}:(.rodata.h4) # EXPORT-NOT: selected section # EXPORT: selected section {{.*}}:(.text) # EXPORT: removing identical section {{.*}}:(.text) # EXPORT-NOT: selected section +# EXPORT: selected section {{.*}}:(.rodata.l3) +# EXPORT: removing identical section {{.*}}:(.rodata.l4) +# EXPORT-NOT: selected section # If --icf=all is specified when exporting we can also merge the exported text # sections, but not the exported rodata. # ALL-EXPORT-NOT: selected section -# ALL-EXPORT: selected section {{.*}}:(.rodata.l3) -# ALL-EXPORT: removing identical section {{.*}}:(.rodata.l4) -# ALL-EXPORT-NOT: selected section # ALL-EXPORT: selected section {{.*}}:(.text.f3) # ALL-EXPORT: removing identical section {{.*}}:(.text.f4) # ALL-EXPORT-NOT: selected section +# ALL-EXPORT: selected section {{.*}}:(.rodata.h3) +# ALL-EXPORT: removing identical section {{.*}}:(.rodata.h4) +# ALL-EXPORT-NOT: selected section # ALL-EXPORT: selected section {{.*}}:(.text.f1) # ALL-EXPORT: removing identical section {{.*}}:(.text.f2) # ALL-EXPORT: removing identical section {{.*}}:(.text.non_addrsig1) # ALL-EXPORT: removing identical section {{.*}}:(.text.non_addrsig2) # ALL-EXPORT-NOT: selected section -# ALL-EXPORT: selected section {{.*}}:(.rodata.h3) -# ALL-EXPORT: removing identical section {{.*}}:(.rodata.h4) -# ALL-EXPORT-NOT: selected section # ALL-EXPORT: selected section {{.*}}:(.text) # ALL-EXPORT: removing identical section {{.*}}:(.text) # ALL-EXPORT-NOT: selected section +# ALL-EXPORT: selected section {{.*}}:(.rodata.l3) +# ALL-EXPORT: removing identical section {{.*}}:(.rodata.l4) +# ALL-EXPORT-NOT: selected section # OBJCOPY: --icf=safe is incompatible with object files created using objcopy or ld -r