Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lld / test / ELF / debug-dead-reloc.s
blobfcf53205079ed6a58635f60d9f00057b80e61b2c
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).
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 --emit-relocs --gc-sections %t.o %t1.o %t1.o -o %t
9 # RUN: llvm-objdump -s %t | FileCheck %s
10 # RUN: llvm-readobj -r %t | FileCheck %s --check-prefix=REL
12 # CHECK: Contents of section .debug_loc:
13 # CHECK-NEXT: 0000 01000000 00000000 01000000 00000000
14 # CHECK: Contents of section .debug_ranges:
15 # CHECK-NEXT: 0000 01000000 00000000 01000000 00000000
16 # CHECK: Contents of section .debug_addr:
17 # CHECK-NEXT: 0000 {{.*}}000 00000000 {{.*}}000 00000000
18 # CHECK-NEXT: 0010 00000000 00000000 {{.*}}000 00000000
19 # CHECK: Contents of section .debug_foo:
20 # CHECK-NEXT: 0000 00000000 00000000 08000000 00000000
21 # CHECK-NEXT: 0010 00000000 00000000 08000000 00000000
23 # REL: Relocations [
24 # REL-NEXT: .rela.text {
25 # REL-NEXT: 0x201121 R_X86_64_PLT32 group 0xFFFFFFFFFFFFFFFC
26 # REL-NEXT: }
27 # REL-NEXT: .rela.debug_loc {
28 # REL-NEXT: 0x0 R_X86_64_NONE - 0x8
29 # REL-NEXT: 0x8 R_X86_64_NONE - 0x8
30 # REL-NEXT: }
31 # REL-NEXT: .rela.debug_ranges {
32 # REL-NEXT: 0x0 R_X86_64_NONE - 0x10
33 # REL-NEXT: 0x8 R_X86_64_NONE - 0x10
34 # REL-NEXT: }
35 # REL-NEXT: .rela.debug_addr {
36 # REL-NEXT: 0x0 R_X86_64_64 .text 0x1D
37 # REL-NEXT: 0x8 R_X86_64_64 group 0x20
38 # REL-NEXT: 0x10 R_X86_64_NONE - 0x18
39 # REL-NEXT: 0x18 R_X86_64_64 group 0x20
40 # REL-NEXT: }
41 # REL-NEXT: .rela.debug_foo {
42 # REL-NEXT: 0x0 R_X86_64_NONE - 0x8
43 # REL-NEXT: 0x8 R_X86_64_NONE - 0x8
44 # REL-NEXT: 0x10 R_X86_64_NONE - 0x8
45 # REL-NEXT: 0x18 R_X86_64_NONE - 0x8
46 # REL-NEXT: }
47 # REL-NEXT: ]
49 ## -z dead-reloc-in-nonalloc= can override the tombstone value.
50 # RUN: ld.lld --gc-sections -z dead-reloc-in-nonalloc=.debug_loc=42 %t.o %t1.o %t1.o -o %t42
51 # RUN: llvm-objdump -s %t42 | FileCheck %s --check-prefix=OVERRIDE
53 # OVERRIDE: Contents of section .debug_loc:
54 # OVERRIDE-NEXT: 0000 2a000000 00000000 2a000000 00000000
56 .section .text.1,"ax"
57 .byte 0
58 .section .text.2,"axe"
59 .byte 0
60 .section .text.3,"axG",@progbits,group,comdat
61 .globl group
62 group:
63 .byte 0
65 ## Resolved to UINT64_C(1), with the addend ignored.
66 ## UINT64_C(-1) is a reserved value (base address selection entry) which can't be used.
67 .section .debug_loc
68 .quad .text.1+8
69 .section .debug_ranges
70 .quad .text.2+16
72 .section .debug_addr
73 ## .text.3 is a local symbol. The symbol defined in a non-prevailing group is
74 ## discarded. Resolved to UINT64_C(0).
75 .quad .text.3+24
76 ## group is a non-local symbol. The relocation from the second %t1.o gets
77 ## resolved to the prevailing copy.
78 .quad group+32
80 .section .debug_foo
81 .quad .text.1+8
83 ## We only deal with DW_FORM_addr. Don't special case short-range absolute
84 ## relocations. Treat them like regular absolute relocations referencing
85 ## discarded symbols, which are resolved to the addend.
86 .long .text.1+8
87 .long 0