[lld] f4b4bc2 - [ELF] --icf: switch to xxh3_64bits

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 18 17:57:36 PDT 2023


Author: Fangrui Song
Date: 2023-07-18T17:57:31-07:00
New Revision: f4b4bc2f18dc0e44afde05735fb673d3de4d5c39

URL: https://github.com/llvm/llvm-project/commit/f4b4bc2f18dc0e44afde05735fb673d3de4d5c39
DIFF: https://github.com/llvm/llvm-project/commit/f4b4bc2f18dc0e44afde05735fb673d3de4d5c39.diff

LOG: [ELF] --icf: switch to xxh3_64bits

for more efficient section content hashing. Also clean up the tests a
bit and properly test the formatting of --print-icf-sections.

Added: 
    

Modified: 
    lld/ELF/ICF.cpp
    lld/test/ELF/icf-preemptible.s
    lld/test/ELF/icf-safe.s
    lld/test/ELF/print-icf.s

Removed: 
    


################################################################################
diff  --git a/lld/ELF/ICF.cpp b/lld/ELF/ICF.cpp
index 841011c97a6cfa..9d7251037fb6d6 100644
--- a/lld/ELF/ICF.cpp
+++ b/lld/ELF/ICF.cpp
@@ -494,7 +494,7 @@ template <class ELFT> void ICF<ELFT>::run() {
   // Initially, we use hash values to partition sections.
   parallelForEach(sections, [&](InputSection *s) {
     // Set MSB to 1 to avoid collisions with unique IDs.
-    s->eqClass[0] = xxHash64(s->content()) | (1U << 31);
+    s->eqClass[0] = xxh3_64bits(s->content()) | (1U << 31);
   });
 
   // Perform 2 rounds of relocation hash propagation. 2 is an empirical value to

diff  --git a/lld/test/ELF/icf-preemptible.s b/lld/test/ELF/icf-preemptible.s
index 7630d7e0358b30..4bd1eca438b19f 100644
--- a/lld/test/ELF/icf-preemptible.s
+++ b/lld/test/ELF/icf-preemptible.s
@@ -5,25 +5,30 @@
 # RUN:   FileCheck --check-prefixes=EXE %s
 
 # RUN: ld.lld -shared %t.o --icf=all --print-icf-sections -o /dev/null | \
-# RUN:   FileCheck --check-prefix=DSO %s --implicit-check-not=removing
+# RUN:   FileCheck --check-prefix=DSO %s
 
 ## Definitions are non-preemptible in an executable.
-# EXE:      selected section {{.*}}:(.text.h1)
+# EXE-NOT:  {{.}}
+# EXE:      selected section {{.*}}:(.text.g1)
+# EXE-NEXT:   removing identical section {{.*}}:(.text.g2)
+# EXE-NEXT:   removing identical section {{.*}}:(.text.g3)
+# EXE-NEXT: selected section {{.*}}:(.text.f1)
+# EXE-NEXT:   removing identical section {{.*}}:(.text.f2)
+# EXE-NEXT: selected section {{.*}}:(.text.h1)
 # EXE-NEXT:   removing identical section {{.*}}:(.text.h2)
 # EXE-NEXT:   removing identical section {{.*}}:(.text.h3)
-# EXE:      selected section {{.*}}:(.text.f1)
-# EXE-NEXT:   removing identical section {{.*}}:(.text.f2)
-# EXE-NEXT: selected section {{.*}}:(.text.g1)
-# EXE:        removing identical section {{.*}}:(.text.g2)
-# EXE-NEXT:   removing identical section {{.*}}:(.text.g3)
+# EXE-NOT:  {{.}}
 
 ## Definitions are preemptible in a DSO. Only leaf functions can be folded.
-# DSO:      selected section {{.*}}:(.text.f1)
-# DSO-NEXT:   removing identical section {{.*}}:(.text.f2)
-# DSO-NEXT: selected section {{.*}}:(.text.g1)
+# DSO-NOT:  {{.}}
+# DSO:      selected section {{.*}}:(.text.g1)
 # DSO-NEXT:   removing identical section {{.*}}:(.text.g3)
+# DSO-NEXT: selected section {{.*}}:(.text.f1)
+# DSO-NEXT:   removing identical section {{.*}}:(.text.f2)
+# DSO-NOT:  {{.}}
 
-.globl f1, f2, g1, g2, g3
+.globl _start, f1, f2, g1, g2, g3
+_start:
 
 .section .text.f1
 f1: ret

diff  --git a/lld/test/ELF/icf-safe.s b/lld/test/ELF/icf-safe.s
index 919a1d13d47cbf..96776feccbc677 100644
--- a/lld/test/ELF/icf-safe.s
+++ b/lld/test/ELF/icf-safe.s
@@ -14,45 +14,37 @@
 # RUN: ld.lld %t1changed.o -o %t4 --icf=safe 2>&1 | FileCheck --check-prefix=SH_LINK_0 %s
 # RUN: ld.lld %t1reloc.o -o %t4 --icf=safe 2>&1 | FileCheck --check-prefix=SH_LINK_0 %s
 
-# CHECK-NOT: selected section {{.*}}:(.text.f1)
-# CHECK: selected section {{.*}}:(.text.f3)
-# CHECK:   removing identical section {{.*}}:(.text.f4)
-
-# CHECK-NOT: selected section {{.*}}:(.rodata.h1)
-# 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)
-
-# CHECK-NOT: selected section {{.*}}:(.text.non_addrsig{{.}})
+# CHECK-NOT:  {{.}}
+# CHECK:      selected section {{.*}}:(.rodata.h3)
+# CHECK-NEXT:   removing identical section {{.*}}:(.rodata.h4)
+# CHECK-NEXT: selected section {{.*}}:(.text.f3)
+# CHECK-NEXT:   removing identical section {{.*}}:(.text.f4)
+# CHECK-NEXT: selected section {{.*}}:(.rodata.g3)
+# CHECK-NEXT:   removing identical section {{.*}}:(.rodata.g4)
+# CHECK-NEXT: selected section {{.*}}:(.rodata.l3)
+# CHECK-NEXT:   removing identical section {{.*}}:(.rodata.l4)
+# CHECK-NEXT: selected section {{.*}}:(.text)
+# CHECK-NEXT:   removing identical section {{.*}}:(.text)
+# CHECK-NOT:  {{.}}
 
 # With --icf=all address-significance implies keep-unique only for rodata, not
 # text.
-# 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-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)
-# ALL:   removing identical section {{.*}}:(.rodata.g4)
-
-# 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:  {{.}}
+# ALL:      selected section {{.*}}:(.rodata.h3)
+# ALL-NEXT:   removing identical section {{.*}}:(.rodata.h4)
+# ALL-NEXT: selected section {{.*}}:(.text.f3)
+# ALL-NEXT:   removing identical section {{.*}}:(.text.f4)
+# ALL-NEXT: selected section {{.*}}:(.text.f1)
+# ALL-NEXT:   removing identical section {{.*}}:(.text.f2)
+# ALL-NEXT:   removing identical section {{.*}}:(.text.non_addrsig1)
+# ALL-NEXT:   removing identical section {{.*}}:(.text.non_addrsig2)
+# ALL-NEXT: selected section {{.*}}:(.rodata.g3)
+# ALL-NEXT:   removing identical section {{.*}}:(.rodata.g4)
+# ALL-NEXT: selected section {{.*}}:(.rodata.l3)
+# ALL-NEXT:   removing identical section {{.*}}:(.rodata.l4)
+# ALL-NEXT: selected section {{.*}}:(.text)
+# ALL-NEXT:   removing identical section {{.*}}:(.text)
+# ALL-NOT:  {{.}}
 
 # llvm-mc normally emits an empty .text section into every object file. Since
 # nothing actually refers to it via a relocation, it doesn't have any associated
@@ -61,40 +53,35 @@
 # only two sections merged are the two empty sections and the sections with only
 # 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.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
+# EXPORT-NOT:  {{.}}
+# EXPORT:      selected section {{.*}}:(.rodata.h3)
+# EXPORT-NEXT:   removing identical section {{.*}}:(.rodata.h4)
+# EXPORT-NEXT: selected section {{.*}}:(.rodata.l3)
+# EXPORT-NEXT:   removing identical section {{.*}}:(.rodata.l4)
+# EXPORT-NOT:  {{.}}
 
 # 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 {{.*}}:(.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)
-# 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
-# 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-NOT:  {{.}}
+# ALL-EXPORT:      selected section {{.*}}:(.rodata.h3)
+# ALL-EXPORT-NEXT:   removing identical section {{.*}}:(.rodata.h4)
+# ALL-EXPORT-NEXT: selected section {{.*}}:(.text.f3)
+# ALL-EXPORT-NEXT:   removing identical section {{.*}}:(.text.f4)
+# ALL-EXPORT-NEXT: selected section {{.*}}:(.text.f1)
+# ALL-EXPORT-NEXT:   removing identical section {{.*}}:(.text.f2)
+# ALL-EXPORT-NEXT:   removing identical section {{.*}}:(.text.non_addrsig1)
+# ALL-EXPORT-NEXT:   removing identical section {{.*}}:(.text.non_addrsig2)
+# ALL-EXPORT-NEXT: selected section {{.*}}:(.rodata.l3)
+# ALL-EXPORT-NEXT:   removing identical section {{.*}}:(.rodata.l4)
+# ALL-EXPORT-NEXT: selected section {{.*}}:(.text)
+# ALL-EXPORT-NEXT:   removing identical section {{.*}}:(.text)
+# ALL-EXPORT-NOT:  {{.}}
 
 # SH_LINK_0: --icf=safe conservatively ignores SHT_LLVM_ADDRSIG [index [[#]]] with sh_link=0 (likely created using objcopy or ld -r)
 
+.globl _start
+_start:
+
 .section .text.f1,"ax", at progbits
 .globl f1
 f1:

diff  --git a/lld/test/ELF/print-icf.s b/lld/test/ELF/print-icf.s
index cb6116d51cdc9b..f74e689f87e61d 100644
--- a/lld/test/ELF/print-icf.s
+++ b/lld/test/ELF/print-icf.s
@@ -2,20 +2,19 @@
 
 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/print-icf.s -o %t1
-# RUN: ld.lld %t %t1 -o %t2 --icf=all --print-icf-sections | FileCheck %s
+# RUN: ld.lld %t %t1 -o %t2 --icf=all --print-icf-sections | FileCheck %s --match-full-lines --strict-whitespace
 # RUN: ld.lld %t %t1 -o %t2 --icf=all --no-print-icf-sections --print-icf-sections | FileCheck %s
-# RUN: ld.lld %t %t1 -o %t2 --icf=all --print-icf-sections --no-print-icf-sections | FileCheck -allow-empty -check-prefix=PRINT %s
-
-# CHECK: selected section {{.*}}:(.text.f2)
-# CHECK:   removing identical section {{.*}}:(.text.f4)
-# CHECK:   removing identical section {{.*}}:(.text.f7)
-# CHECK: selected section {{.*}}:(.text.f1)
-# CHECK:   removing identical section {{.*}}:(.text.f3)
-# CHECK:   removing identical section {{.*}}:(.text.f5)
-# CHECK:   removing identical section {{.*}}:(.text.f6)
-
-# PRINT-NOT: selected
-# PRINT-NOT: removing
+# RUN: ld.lld %t %t1 -o %t2 --icf=all --print-icf-sections --no-print-icf-sections | count 0
+
+#  CHECK-NOT:{{.}}
+#      CHECK:selected section {{.*}}:(.text.f1)
+# CHECK-NEXT:  removing identical section {{.*}}:(.text.f3)
+# CHECK-NEXT:  removing identical section {{.*}}:(.text.f5)
+# CHECK-NEXT:  removing identical section {{.*}}:(.text.f6)
+#      CHECK:selected section {{.*}}:(.text.f2)
+# CHECK-NEXT:  removing identical section {{.*}}:(.text.f4)
+# CHECK-NEXT:  removing identical section {{.*}}:(.text.f7)
+#  CHECK-NOT:{{.}}
 
 .globl _start, f1, f2
 _start:


        


More information about the llvm-commits mailing list