summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFangrui Song <i@maskray.me>2024-01-23 17:23:52 -0800
committerFangrui Song <i@maskray.me>2024-01-23 17:23:52 -0800
commitc663c8b8839e8a3e780426c1ab4d0005df90a116 (patch)
tree2641a8cab7c0020992369f1f1d54f8092fd6121d
parentf709fbb1bb5e6240aad4edeb2f0e417df74cfa27 (diff)
[ELF,test] Improve dead-reloc-in-nonalloc.s
Test an absolute relocation referencing a DSO symbol, relocating a non-SHF_ALLOC section. Also test --gc-sections.
-rw-r--r--lld/test/ELF/dead-reloc-in-nonalloc.s35
1 files changed, 23 insertions, 12 deletions
diff --git a/lld/test/ELF/dead-reloc-in-nonalloc.s b/lld/test/ELF/dead-reloc-in-nonalloc.s
index 3857ead6e55d..145604eb883a 100644
--- a/lld/test/ELF/dead-reloc-in-nonalloc.s
+++ b/lld/test/ELF/dead-reloc-in-nonalloc.s
@@ -1,14 +1,15 @@
# REQUIRES: x86
-## Test that -z dead-reloc-in-nonalloc= can customize the tombstone value we
-## use for an absolute relocation referencing a discarded symbol.
+## Test an absolute relocation referencing an undefined or DSO symbol, relocating
+## a non-SHF_ALLOC section. Also test -z dead-reloc-in-nonalloc=.
# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o
-# RUN: ld.lld --icf=all -z dead-reloc-in-nonalloc=.debug_info=0xaaaaaaaa \
-# RUN: -z dead-reloc-in-nonalloc=.not_debug=0xbbbbbbbb %t.o -o %t
+# RUN: echo '.globl bar; bar = 42' | llvm-mc -filetype=obj -triple=x86_64 - -o %tabs.o
+# RUN: ld.lld --gc-sections -z dead-reloc-in-nonalloc=.debug_info=0xaaaaaaaa \
+# RUN: -z dead-reloc-in-nonalloc=.not_debug=0xbbbbbbbb %t.o %tabs.o -o %t
# RUN: llvm-objdump -s %t | FileCheck %s --check-prefixes=COMMON,AA
## 0xaaaaaaaa == 2863311530
-# RUN: ld.lld --icf=all -z dead-reloc-in-nonalloc=.debug_info=2863311530 \
-# RUN: -z dead-reloc-in-nonalloc=.not_debug=0xbbbbbbbb %t.o -o - | cmp %t -
+# RUN: ld.lld --gc-sections -z dead-reloc-in-nonalloc=.debug_info=2863311530 \
+# RUN: -z dead-reloc-in-nonalloc=.not_debug=0xbbbbbbbb %t.o %tabs.o -o - | cmp %t -
# COMMON: Contents of section .debug_addr:
# COMMON-NEXT: 0000 [[ADDR:[0-9a-f]+]] 00000000 00000000 00000000
@@ -16,22 +17,30 @@
# AA: Contents of section .debug_info:
# AA-NEXT: 0000 [[ADDR]] 00000000 aaaaaaaa 00000000
# AA: Contents of section .not_debug:
-# AA-NEXT: 0000 bbbbbbbb
+# AA-NEXT: 0000 bbbbbbbb bbbbbbbb 00000000 .
## Specifying zero can get a behavior similar to GNU ld.
-# RUN: ld.lld --icf=all -z dead-reloc-in-nonalloc=.debug_info=0 %t.o -o %tzero
+# RUN: ld.lld --icf=all -z dead-reloc-in-nonalloc=.debug_info=0 %t.o %tabs.o -o %tzero
# RUN: llvm-objdump -s %tzero | FileCheck %s --check-prefixes=COMMON,ZERO
# ZERO: Contents of section .debug_info:
# ZERO-NEXT: 0000 {{[0-9a-f]+}}000 00000000 00000000 00000000
## Glob works.
-# RUN: ld.lld --icf=all -z dead-reloc-in-nonalloc='.debug_i*=0xaaaaaaaa' \
-# RUN: -z dead-reloc-in-nonalloc='[.]not_debug=0xbbbbbbbb' %t.o -o - | cmp %t -
+# RUN: ld.lld --gc-sections -z dead-reloc-in-nonalloc='.debug_i*=0xaaaaaaaa' \
+# RUN: -z dead-reloc-in-nonalloc='[.]not_debug=0xbbbbbbbb' %t.o %tabs.o -o - | cmp %t -
## If a section matches multiple option. The last option wins.
# RUN: ld.lld --icf=all -z dead-reloc-in-nonalloc='.debug_info=1' \
-# RUN: -z dead-reloc-in-nonalloc='.debug_i*=0' %t.o -o - | cmp %tzero -
+# RUN: -z dead-reloc-in-nonalloc='.debug_i*=0' %t.o %tabs.o -o - | cmp %tzero -
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64 %S/Inputs/shared.s -o %t1.o
+# RUN: ld.lld -shared -soname=t1.so %t1.o -o %t1.so
+# RUN: ld.lld --gc-sections %t.o %t1.so -o %tso
+# RUN: llvm-objdump -s %tso | FileCheck %s --check-prefix=SHARED
+
+# SHARED: Contents of section .not_debug:
+# SHARED-NEXT: 0000 08000000 00000000 00000000 .
## Test all possible invalid cases.
# RUN: not ld.lld -z dead-reloc-in-nonalloc= 2>&1 | FileCheck %s --check-prefix=USAGE
@@ -52,7 +61,7 @@
_start:
ret
-## .text.1 will be folded by ICF.
+## .text.1 will be folded by ICF or discarded by --gc-sections.
.section .text.1,"ax"
ret
@@ -67,3 +76,5 @@ _start:
## Test a non-.debug_ section.
.section .not_debug
.long .text.1+8
+
+ .quad bar