1# REQUIRES: x86
2## Test we resolve symbolic relocations in .debug_* sections to a tombstone
3## value if the referenced symbol is discarded (--gc-sections, non-prevailing
4## section group, SHF_EXCLUDE, /DISCARD/, etc).
5
6# RUN: echo '.globl _start; _start: call group' | llvm-mc -filetype=obj -triple=x86_64 - -o %t.o
7# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t1.o
8# RUN: ld.lld --gc-sections %t.o %t1.o %t1.o -o %t
9# RUN: llvm-objdump -s %t | FileCheck %s
10
11# CHECK:      Contents of section .debug_loc:
12# CHECK-NEXT:  0000 01000000 00000000 01000000 00000000
13# CHECK-NEXT: Contents of section .debug_ranges:
14# CHECK-NEXT:  0000 01000000 00000000 01000000 00000000
15# CHECK-NEXT: Contents of section .debug_addr:
16# CHECK-NEXT:  0000 {{.*}}000 00000000 {{.*}}000 00000000
17# CHECK-NEXT:  0010 00000000  00000000 {{.*}}000 00000000
18# CHECK-NEXT: Contents of section .debug_foo:
19# CHECK-NEXT:  0000 00000000 00000000 08000000 00000000
20# CHECK-NEXT:  0010 00000000 00000000 08000000 00000000
21
22## -z dead-reloc-in-nonalloc= can override the tombstone value.
23# RUN: ld.lld --gc-sections -z dead-reloc-in-nonalloc=.debug_loc=42 %t.o %t1.o %t1.o -o %t42
24# RUN: llvm-objdump -s %t42 | FileCheck %s --check-prefix=OVERRIDE
25
26# OVERRIDE:      Contents of section .debug_loc:
27# OVERRIDE-NEXT:  0000 2a000000 00000000 2a000000 00000000
28
29.section .text.1,"ax"
30  .byte 0
31.section .text.2,"axe"
32  .byte 0
33.section .text.3,"axG",@progbits,group,comdat
34.globl group
35group:
36  .byte 0
37
38## Resolved to UINT64_C(1), with the addend ignored.
39## UINT64_C(-1) is a reserved value (base address selection entry) which can't be used.
40.section .debug_loc
41  .quad .text.1+8
42.section .debug_ranges
43  .quad .text.2+16
44
45.section .debug_addr
46## .text.3 is a local symbol. The symbol defined in a non-prevailing group is
47## discarded. Resolved to UINT64_C(0).
48  .quad .text.3+24
49## group is a non-local symbol. The relocation from the second %t1.o gets
50## resolved to the prevailing copy.
51  .quad group+32
52
53.section .debug_foo
54  .quad .text.1+8
55
56## We only deal with DW_FORM_addr. Don't special case short-range absolute
57## relocations. Treat them like regular absolute relocations referencing
58## discarded symbols, which are resolved to the addend.
59  .long .text.1+8
60  .long 0
61