113 lines · plain
1# REQUIRES: aarch64, x862## Test we resolve symbolic relocations in .debug_* sections to a tombstone3## value if the referenced symbol is discarded (--gc-sections, non-prevailing4## section group, SHF_EXCLUDE, /DISCARD/, etc).5 6# RUN: echo '.globl _start; _start: call group' | llvm-mc -filetype=obj -triple=x86_64 - -o %t.o7# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t1.o8# RUN: ld.lld --emit-relocs --gc-sections %t.o %t1.o %t1.o -o %t9# RUN: llvm-objdump -s %t | FileCheck %s10# RUN: llvm-readobj -r %t | FileCheck %s --check-prefix=REL11 12# RUN: echo '.globl _start; _start: bl group' | llvm-mc -filetype=obj -triple=aarch64 - -o %t.a64.o13# RUN: llvm-mc -filetype=obj -triple=aarch64 %s -o %t1.a64.o14# RUN: ld.lld --emit-relocs --gc-sections %t.a64.o %t1.a64.o %t1.a64.o -o %t.a6415# RUN: llvm-objdump -s %t.a64 | FileCheck %s16 17# CHECK: Contents of section .debug_loc:18# CHECK-NEXT: 0000 01000000 00000000 01000000 0000000019# CHECK: Contents of section .debug_ranges:20# CHECK-NEXT: 0000 01000000 00000000 01000000 0000000021# CHECK: Contents of section .debug_addr:22# CHECK-NEXT: 0000 {{.*}}00 00000000 {{.*}}00 0000000023# CHECK-NEXT: 0010 00000000 00000000 {{.*}}00 0000000024# CHECK: Contents of section .debug_names:25# CHECK-NEXT: 0000 00000000 00000000 00000000 ffffffff .26# CHECK-NEXT: 0010 ffffffff ffffffff .27# CHECK: Contents of section .debug_foo:28# CHECK-NEXT: 0000 00000000 00000000 00000000 0000000029# CHECK-NEXT: 0010 00000000 00000000 00000000 0000000030 31# REL: Relocations [32# REL-NEXT: .rela.text {33# REL-NEXT: 0x201121 R_X86_64_PLT32 group 0xFFFFFFFFFFFFFFFC34# REL-NEXT: }35# REL-NEXT: .rela.debug_loc {36# REL-NEXT: 0x0 R_X86_64_NONE - 0x837# REL-NEXT: 0x8 R_X86_64_NONE - 0x838# REL-NEXT: }39# REL-NEXT: .rela.debug_ranges {40# REL-NEXT: 0x0 R_X86_64_NONE - 0x1041# REL-NEXT: 0x8 R_X86_64_NONE - 0x1042# REL-NEXT: }43# REL-NEXT: .rela.debug_addr {44# REL-NEXT: 0x0 R_X86_64_64 .text 0x1D45# REL-NEXT: 0x8 R_X86_64_64 group 0x2046# REL-NEXT: 0x10 R_X86_64_NONE - 0x1847# REL-NEXT: 0x18 R_X86_64_64 group 0x2048# REL-NEXT: }49# REL-NEXT: .rela.debug_names {50# REL-NEXT: 0x0 R_X86_64_32 .debug_info 0x051# REL-NEXT: 0x4 R_X86_64_64 .debug_info 0x052# REL-NEXT: 0xC R_X86_64_NONE - 0x053# REL-NEXT: 0x10 R_X86_64_NONE - 0x054# REL-NEXT: }55# REL-NEXT: .rela.debug_foo {56# REL-NEXT: 0x0 R_X86_64_NONE - 0x857# REL-NEXT: 0x8 R_X86_64_NONE - 0x858# REL-NEXT: 0x10 R_X86_64_NONE - 0x859# REL-NEXT: 0x18 R_X86_64_NONE - 0x860# REL-NEXT: }61# REL-NEXT: ]62 63## -z dead-reloc-in-nonalloc= can override the tombstone value.64# RUN: ld.lld --gc-sections -z dead-reloc-in-nonalloc=.debug_loc=42 %t.o %t1.o %t1.o -o %t4265# RUN: llvm-objdump -s %t42 | FileCheck %s --check-prefix=OVERRIDE66 67# OVERRIDE: Contents of section .debug_loc:68# OVERRIDE-NEXT: 0000 2a000000 00000000 2a000000 0000000069 70.section .text.1,"ax"71 .byte 072.section .text.2,"axe"73 .byte 074.section .text.3,"axG",@progbits,group,comdat75.globl group76group:77 .byte 078 79## Resolved to UINT64_C(1), with the addend ignored.80## UINT64_C(-1) is a reserved value (base address selection entry) which can't be used.81.section .debug_loc82 .quad .text.1+883.section .debug_ranges84 .quad .text.2+1685 86.section .debug_addr87## .text.3 is a local symbol. The symbol defined in a non-prevailing group is88## discarded. Resolved to UINT64_C(0).89 .quad .text.3+2490## group is a non-local symbol. The relocation from the second %t1.o gets91## resolved to the prevailing copy.92 .quad group+3293 94.section .debug_info,"G",@progbits,5657452045627120676,comdat95.Ltu_begin0:96 97.section .debug_names98## .debug_names may reference a local type unit defined in a COMDAT .debug_info99## section (-g -gpubnames -fdebug-types-section). If the referenced section is100## non-prevailing, resolve to UINT32_MAX.101.long .Ltu_begin0102## ... or UINT64_MAX for DWARF64.103.quad .Ltu_begin0104 105.section .debug_foo106 .quad .text.1+8107 108## We only deal with DW_FORM_addr. Don't special case short-range absolute109## relocations. Treat them like regular absolute relocations referencing110## discarded symbols, which are resolved to the addend.111 .long .text.1+8112 .long 0113