Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lld / test / ELF / linkerscript / discard-section.s
blob24f3b2b73e991f7dc6ef1d054a7efcd0e438a099
1 # REQUIRES: x86
2 ## Test relocations referencing symbols defined relative to sections discarded by /DISCARD/.
4 # RUN: rm -rf %t && split-file %s %t && cd %t
5 # RUN: llvm-mc -filetype=obj -triple=x86_64 a.s -o a.o
6 # RUN: llvm-mc -filetype=obj -triple=x86_64 b.s -o b.o
7 # RUN: not ld.lld --threads=1 -T a.lds a.o b.o -z undefs -o /dev/null 2>&1 | FileCheck %s --check-prefix=LOCAL --implicit-check-not=error:
8 # RUN: not ld.lld --threads=1 -T a.lds a.o b.o -o /dev/null 2>&1 | FileCheck %s --check-prefixes=LOCAL,NONLOCAL --implicit-check-not=error:
9 # RUN: ld.lld -r -T a.lds a.o b.o -o a.ro 2>&1 | FileCheck %s --check-prefix=WARNING --implicit-check-not=warning:
10 # RUN: llvm-readelf -r -s a.ro | FileCheck %s --check-prefix=RELOC
12 # LOCAL: error: relocation refers to a discarded section: .aaa
13 # LOCAL-NEXT: >>> defined in a.o
14 # LOCAL-NEXT: >>> referenced by a.o:(.bbb+0x0)
16 # NONLOCAL: error: relocation refers to a symbol in a discarded section: global
17 # NONLOCAL-NEXT: >>> defined in a.o
18 # NONLOCAL-NEXT: >>> referenced by b.o:(.data+0x0)
20 # NONLOCAL: error: relocation refers to a symbol in a discarded section: weak
21 # NONLOCAL-NEXT: >>> defined in a.o
22 # NONLOCAL-NEXT: >>> referenced by b.o:(.data+0x8)
24 # NONLOCAL: error: relocation refers to a symbol in a discarded section: weakref1
25 # NONLOCAL-NEXT: >>> defined in a.o
26 # NONLOCAL-NEXT: >>> referenced by b.o:(.data+0x10)
28 # NONLOCAL: error: relocation refers to a symbol in a discarded section: weakref2
29 # NONLOCAL-NEXT: >>> defined in a.o
30 # NONLOCAL-NEXT: >>> referenced by b.o:(.data+0x18)
32 # WARNING: warning: relocation refers to a discarded section: .aaa
33 # WARNING-NEXT: >>> referenced by a.o:(.rela.bbb+0x0)
35 # RELOC: Relocation section '.rela.bbb' at offset {{.*}} contains 1 entries:
36 # RELOC-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend
37 # RELOC-NEXT: 0000000000000000 0000000000000000 R_X86_64_NONE 0
38 # RELOC-EMPTY:
39 # RELOC-NEXT: Relocation section '.rela.data' at offset {{.*}} contains 4 entries:
40 # RELOC-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend
41 # RELOC-NEXT: 0000000000000000 0000000500000001 R_X86_64_64 0000000000000000 global + 0
42 # RELOC-NEXT: 0000000000000008 0000000700000001 R_X86_64_64 0000000000000000 weak + 0
43 # RELOC-NEXT: 0000000000000010 0000000600000001 R_X86_64_64 0000000000000000 weakref1 + 0
44 # RELOC-NEXT: 0000000000000018 0000000800000001 R_X86_64_64 0000000000000000 weakref2 + 0
46 # RELOC: Num: Value Size Type Bind Vis Ndx Name
47 # RELOC-NEXT: 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
48 # RELOC-NEXT: 1: 0000000000000000 0 SECTION LOCAL DEFAULT 1 .text
49 # RELOC-NEXT: 2: 0000000000000000 0 SECTION LOCAL DEFAULT 2 .bbb
50 # RELOC-NEXT: 3: 0000000000000000 0 SECTION LOCAL DEFAULT 4 .data
51 # RELOC-NEXT: 4: 0000000000000000 0 NOTYPE GLOBAL DEFAULT 1 _start
52 # RELOC-NEXT: 5: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND global
53 # RELOC-NEXT: 6: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND weakref1
54 # RELOC-NEXT: 7: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND weak
55 # RELOC-NEXT: 8: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND weakref2
56 # RELOC-EMPTY:
58 #--- a.s
59 .globl _start
60 _start:
62 .section .aaa,"a"
63 .globl global, weakref1
64 .weak weak, weakref2
65 global:
66 weak:
67 weakref1:
68 weakref2:
69 .quad 0
71 .section .bbb,"aw"
72 .quad .aaa
74 #--- b.s
75 .weak weakref1, weakref2
76 .section .data,"aw"
77 .quad global
78 .quad weak
79 .quad weakref1
80 .quad weakref2
82 #--- a.lds
83 SECTIONS { /DISCARD/ : { *(.aaa) } }