1# REQUIRES: x86 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=. 4 5# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o 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 9# RUN: llvm-objdump -s %t | FileCheck %s --check-prefixes=COMMON,AA 10## 0xaaaaaaaa == 2863311530 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 - 13 14# COMMON: Contents of section .debug_addr: 15# COMMON-NEXT: 0000 [[ADDR:[0-9a-f]+]] 00000000 00000000 00000000 16 17# AA: Contents of section .debug_info: 18# AA-NEXT: 0000 [[ADDR]] 00000000 aaaaaaaa 00000000 19# AA: Contents of section .not_debug: 20# AA-NEXT: 0000 bbbbbbbb 2a000000 00000000 . 21 22## Specifying zero can get a behavior similar to GNU ld. 23# RUN: ld.lld --icf=all -z dead-reloc-in-nonalloc=.debug_info=0 %t.o %tabs.o -o %tzero 24# RUN: llvm-objdump -s %tzero | FileCheck %s --check-prefixes=COMMON,ZERO 25 26# ZERO: Contents of section .debug_info: 27# ZERO-NEXT: 0000 {{[0-9a-f]+}}000 00000000 00000000 00000000 28 29## Glob works. 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 - 32 33## If a section matches multiple option. The last option wins. 34# RUN: ld.lld --icf=all -z dead-reloc-in-nonalloc='.debug_info=1' \ 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 . 44 45## Test all possible invalid cases. 46# RUN: not ld.lld -z dead-reloc-in-nonalloc= 2>&1 | FileCheck %s --check-prefix=USAGE 47# RUN: not ld.lld -z dead-reloc-in-nonalloc=a= 2>&1 | FileCheck %s --check-prefix=USAGE 48# RUN: not ld.lld -z dead-reloc-in-nonalloc==0 2>&1 | FileCheck %s --check-prefix=USAGE 49 50# USAGE: error: -z dead-reloc-in-nonalloc=: expected <section_glob>=<value> 51 52# RUN: not ld.lld -z dead-reloc-in-nonalloc=a=-1 2>&1 | FileCheck %s --check-prefix=NON-INTEGER 53 54# NON-INTEGER: error: -z dead-reloc-in-nonalloc=: expected a non-negative integer, but got '-1' 55 56# RUN: not ld.lld -z dead-reloc-in-nonalloc='['=0 2>&1 | FileCheck %s --check-prefix=INVALID 57 58# INVALID: error: -z dead-reloc-in-nonalloc=: invalid glob pattern, unmatched '[': [ 59 60.globl _start 61_start: 62 ret 63 64## .text.1 will be folded by ICF or discarded by --gc-sections. 65.section .text.1,"ax" 66 ret 67 68.section .debug_addr 69 .quad .text+8 70 .quad .text.1+8 71 72.section .debug_info 73 .quad .text+8 74 .quad .text.1+8 75 76## Test a non-.debug_ section. 77.section .not_debug 78 .long .text.1+8 79 80 .quad bar 81