[ELF] Add a GRP_COMDAT test with a local signature symbol
authorFangrui Song <i@maskray.me>
Tue, 8 Jun 2021 16:22:30 +0000 (09:22 -0700)
committerFangrui Song <i@maskray.me>
Tue, 8 Jun 2021 16:22:30 +0000 (09:22 -0700)
See https://groups.google.com/g/generic-abi/c/2X6mR-s2zoc

Test that a local signature symbol does not suppress COMDAT deduplication.

lld/test/ELF/comdat-local-signature.s [new file with mode: 0644]

diff --git a/lld/test/ELF/comdat-local-signature.s b/lld/test/ELF/comdat-local-signature.s
new file mode 100644 (file)
index 0000000..eed92ca
--- /dev/null
@@ -0,0 +1,30 @@
+# REQUIRES: x86
+## COMDAT groups are deduplicated by the name of the signature symbol.
+## The local/global status is not part of the equation.
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o
+# RUN: ld.lld %t.o %t.o -o %t
+# RUN: llvm-readelf -s -x .zero -x .comdat %t | FileCheck %s
+
+# CHECK:      Type   Bind  Vis     Ndx     Name
+# CHECK-NEXT: NOTYPE LOCAL DEFAULT UND
+# CHECK-NEXT: NOTYPE LOCAL DEFAULT [[#A:]] zero
+# CHECK-NEXT: NOTYPE LOCAL DEFAULT [[#]]   comdat
+# CHECK-NEXT: NOTYPE LOCAL DEFAULT [[#A]]  zero
+# CHECK-NOT:  {{.}}
+
+## Non-GRP_COMDAT groups are never deduplicated.
+# CHECK:      Hex dump of section '.zero':
+# CHECK-NEXT: [[#%x,]] 0202
+
+## GRP_COMDAT groups are deduplicated.
+# CHECK:      Hex dump of section '.comdat':
+# CHECK-NEXT: [[#%x,]] 01 .{{$}}
+
+.section .zero,"aG",@progbits,zero
+zero:
+  .byte 2
+
+.section .comdat,"aG",@progbits,comdat,comdat
+comdat:
+  .byte 1