Skip to content

Commit c663c8b

Browse files
committed
[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.
1 parent f709fbb commit c663c8b

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

lld/test/ELF/dead-reloc-in-nonalloc.s

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,46 @@
11
# REQUIRES: x86
2-
## Test that -z dead-reloc-in-nonalloc= can customize the tombstone value we
3-
## use for an absolute relocation referencing a discarded symbol.
2+
## Test an absolute relocation referencing an undefined or DSO symbol, relocating
3+
## a non-SHF_ALLOC section. Also test -z dead-reloc-in-nonalloc=.
44

55
# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o
6-
# RUN: ld.lld --icf=all -z dead-reloc-in-nonalloc=.debug_info=0xaaaaaaaa \
7-
# RUN: -z dead-reloc-in-nonalloc=.not_debug=0xbbbbbbbb %t.o -o %t
6+
# RUN: echo '.globl bar; bar = 42' | llvm-mc -filetype=obj -triple=x86_64 - -o %tabs.o
7+
# RUN: ld.lld --gc-sections -z dead-reloc-in-nonalloc=.debug_info=0xaaaaaaaa \
8+
# RUN: -z dead-reloc-in-nonalloc=.not_debug=0xbbbbbbbb %t.o %tabs.o -o %t
89
# RUN: llvm-objdump -s %t | FileCheck %s --check-prefixes=COMMON,AA
910
## 0xaaaaaaaa == 2863311530
10-
# RUN: ld.lld --icf=all -z dead-reloc-in-nonalloc=.debug_info=2863311530 \
11-
# RUN: -z dead-reloc-in-nonalloc=.not_debug=0xbbbbbbbb %t.o -o - | cmp %t -
11+
# RUN: ld.lld --gc-sections -z dead-reloc-in-nonalloc=.debug_info=2863311530 \
12+
# RUN: -z dead-reloc-in-nonalloc=.not_debug=0xbbbbbbbb %t.o %tabs.o -o - | cmp %t -
1213

1314
# COMMON: Contents of section .debug_addr:
1415
# COMMON-NEXT: 0000 [[ADDR:[0-9a-f]+]] 00000000 00000000 00000000
1516

1617
# AA: Contents of section .debug_info:
1718
# AA-NEXT: 0000 [[ADDR]] 00000000 aaaaaaaa 00000000
1819
# AA: Contents of section .not_debug:
19-
# AA-NEXT: 0000 bbbbbbbb
20+
# AA-NEXT: 0000 bbbbbbbb bbbbbbbb 00000000 .
2021

2122
## Specifying zero can get a behavior similar to GNU ld.
22-
# RUN: ld.lld --icf=all -z dead-reloc-in-nonalloc=.debug_info=0 %t.o -o %tzero
23+
# RUN: ld.lld --icf=all -z dead-reloc-in-nonalloc=.debug_info=0 %t.o %tabs.o -o %tzero
2324
# RUN: llvm-objdump -s %tzero | FileCheck %s --check-prefixes=COMMON,ZERO
2425

2526
# ZERO: Contents of section .debug_info:
2627
# ZERO-NEXT: 0000 {{[0-9a-f]+}}000 00000000 00000000 00000000
2728

2829
## Glob works.
29-
# RUN: ld.lld --icf=all -z dead-reloc-in-nonalloc='.debug_i*=0xaaaaaaaa' \
30-
# RUN: -z dead-reloc-in-nonalloc='[.]not_debug=0xbbbbbbbb' %t.o -o - | cmp %t -
30+
# RUN: ld.lld --gc-sections -z dead-reloc-in-nonalloc='.debug_i*=0xaaaaaaaa' \
31+
# RUN: -z dead-reloc-in-nonalloc='[.]not_debug=0xbbbbbbbb' %t.o %tabs.o -o - | cmp %t -
3132

3233
## If a section matches multiple option. The last option wins.
3334
# RUN: ld.lld --icf=all -z dead-reloc-in-nonalloc='.debug_info=1' \
34-
# RUN: -z dead-reloc-in-nonalloc='.debug_i*=0' %t.o -o - | cmp %tzero -
35+
# RUN: -z dead-reloc-in-nonalloc='.debug_i*=0' %t.o %tabs.o -o - | cmp %tzero -
36+
37+
# RUN: llvm-mc -filetype=obj -triple=x86_64 %S/Inputs/shared.s -o %t1.o
38+
# RUN: ld.lld -shared -soname=t1.so %t1.o -o %t1.so
39+
# RUN: ld.lld --gc-sections %t.o %t1.so -o %tso
40+
# RUN: llvm-objdump -s %tso | FileCheck %s --check-prefix=SHARED
41+
42+
# SHARED: Contents of section .not_debug:
43+
# SHARED-NEXT: 0000 08000000 00000000 00000000 .
3544

3645
## Test all possible invalid cases.
3746
# RUN: not ld.lld -z dead-reloc-in-nonalloc= 2>&1 | FileCheck %s --check-prefix=USAGE
@@ -52,7 +61,7 @@
5261
_start:
5362
ret
5463

55-
## .text.1 will be folded by ICF.
64+
## .text.1 will be folded by ICF or discarded by --gc-sections.
5665
.section .text.1,"ax"
5766
ret
5867

@@ -67,3 +76,5 @@ _start:
6776
## Test a non-.debug_ section.
6877
.section .not_debug
6978
.long .text.1+8
79+
80+
.quad bar

0 commit comments

Comments
 (0)