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=.
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 -
14 # COMMON: Contents of section .debug_addr:
15 # COMMON-NEXT: 0000 [[ADDR:[0-9a-f]+]] 00000000 00000000 00000000
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 .
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
26 # ZERO: Contents of section .debug_info:
27 # ZERO-NEXT: 0000 {{[0-9a-f]+}}000 00000000 00000000 00000000
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 -
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 -
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
42 # SHARED: Contents of section .not_debug:
43 # SHARED-NEXT: 0000 08000000 00000000 00000000 .
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
50 # USAGE: error: -z dead-reloc-in-nonalloc=: expected <section_glob>=<value>
52 # RUN: not ld.lld -z dead-reloc-in-nonalloc=a=-1 2>&1 | FileCheck %s --check-prefix=NON-INTEGER
54 # NON-INTEGER: error: -z dead-reloc-in-nonalloc=: expected a non-negative integer, but got '-1'
56 # RUN: not ld.lld -z dead-reloc-in-nonalloc='['=0 2>&1 | FileCheck %s --check-prefix=INVALID
58 # INVALID: error: -z dead-reloc-in-nonalloc=: invalid glob pattern, unmatched '[': [
64 ## .text.1 will be folded by ICF or discarded by --gc-sections.
76 ## Test a non-.debug_ section.