Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lld / test / ELF / basic.s
blob587fd1641500a02fd14a110458decb1540e7f1f2
1 # REQUIRES: x86
3 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
4 # RUN: ld.lld %t -o %t2
5 # RUN: llvm-readobj --file-headers --sections -l --symbols %t2 \
6 # RUN: | FileCheck %s
7 # RUN: ld.lld %t -o /dev/null
9 ## exits with return code 42 on linux
10 .globl _start
11 _start:
12 mov $60, %rax
13 mov $42, %rdi
14 syscall
16 # CHECK: ElfHeader {
17 # CHECK-NEXT: Ident {
18 # CHECK-NEXT: Magic: (7F 45 4C 46)
19 # CHECK-NEXT: Class: 64-bit (0x2)
20 # CHECK-NEXT: DataEncoding: LittleEndian (0x1)
21 # CHECK-NEXT: FileVersion: 1
22 # CHECK-NEXT: OS/ABI: SystemV (0x0)
23 # CHECK-NEXT: ABIVersion: 0
24 # CHECK-NEXT: Unused: (00 00 00 00 00 00 00)
25 # CHECK-NEXT: }
26 # CHECK-NEXT: Type: Executable (0x2)
27 # CHECK-NEXT: Machine: EM_X86_64 (0x3E)
28 # CHECK-NEXT: Version: 1
29 # CHECK-NEXT: Entry: [[ENTRY:0x[0-9A-F]+]]
30 # CHECK-NEXT: ProgramHeaderOffset: 0x40
31 # CHECK-NEXT: SectionHeaderOffset: 0x1A0
32 # CHECK-NEXT: Flags [ (0x0)
33 # CHECK-NEXT: ]
34 # CHECK-NEXT: HeaderSize: 64
35 # CHECK-NEXT: ProgramHeaderEntrySize: 56
36 # CHECK-NEXT: ProgramHeaderCount: 4
37 # CHECK-NEXT: SectionHeaderEntrySize: 64
38 # CHECK-NEXT: SectionHeaderCount: 6
39 # CHECK-NEXT: StringTableSectionIndex: 4
40 # CHECK-NEXT: }
41 # CHECK-NEXT: Sections [
42 # CHECK-NEXT: Section {
43 # CHECK-NEXT: Index: 0
44 # CHECK-NEXT: Name: (0)
45 # CHECK-NEXT: Type: SHT_NULL (0x0)
46 # CHECK-NEXT: Flags [ (0x0)
47 # CHECK-NEXT: ]
48 # CHECK-NEXT: Address: 0x0
49 # CHECK-NEXT: Offset: 0x0
50 # CHECK-NEXT: Size: 0
51 # CHECK-NEXT: Link: 0
52 # CHECK-NEXT: Info: 0
53 # CHECK-NEXT: AddressAlignment: 0
54 # CHECK-NEXT: EntrySize: 0
55 # CHECK-NEXT: }
56 # CHECK-NEXT: Section {
57 # CHECK-NEXT: Index: 1
58 # CHECK-NEXT: Name: .text
59 # CHECK-NEXT: Type: SHT_PROGBITS (0x1)
60 # CHECK-NEXT: Flags [ (0x6)
61 # CHECK-NEXT: SHF_ALLOC (0x2)
62 # CHECK-NEXT: SHF_EXECINSTR (0x4)
63 # CHECK-NEXT: ]
64 # CHECK-NEXT: Address: 0x201120
65 # CHECK-NEXT: Offset: 0x120
66 # CHECK-NEXT: Size: 16
67 # CHECK-NEXT: Link: 0
68 # CHECK-NEXT: Info: 0
69 # CHECK-NEXT: AddressAlignment: 4
70 # CHECK-NEXT: EntrySize: 0
71 # CHECK-NEXT: }
72 # CHECK-NEXT: Section {
73 # CHECK-NEXT: Index: 2
74 # CHECK-NEXT: Name: .comment
75 # CHECK-NEXT: Type: SHT_PROGBITS (0x1)
76 # CHECK-NEXT: Flags [ (0x30)
77 # CHECK-NEXT: SHF_MERGE (0x10)
78 # CHECK-NEXT: SHF_STRINGS (0x20)
79 # CHECK-NEXT: ]
80 # CHECK-NEXT: Address: 0x0
81 # CHECK-NEXT: Offset: 0x130
82 # CHECK-NEXT: Size: 8
83 # CHECK-NEXT: Link: 0
84 # CHECK-NEXT: Info: 0
85 # CHECK-NEXT: AddressAlignment: 1
86 # CHECK-NEXT: EntrySize: 1
87 # CHECK-NEXT: }
88 # CHECK-NEXT: Section {
89 # CHECK-NEXT: Index: 3
90 # CHECK-NEXT: Name: .symtab
91 # CHECK-NEXT: Type: SHT_SYMTAB (0x2)
92 # CHECK-NEXT: Flags [ (0x0)
93 # CHECK-NEXT: ]
94 # CHECK-NEXT: Address: 0x0
95 # CHECK-NEXT: Offset: 0x138
96 # CHECK-NEXT: Size: 48
97 # CHECK-NEXT: Link: 5
98 # CHECK-NEXT: Info: 1
99 # CHECK-NEXT: AddressAlignment: 8
100 # CHECK-NEXT: EntrySize: 24
101 # CHECK-NEXT: }
102 # CHECK-NEXT: Section {
103 # CHECK-NEXT: Index: 4
104 # CHECK-NEXT: Name: .shstrtab
105 # CHECK-NEXT: Type: SHT_STRTAB (0x3)
106 # CHECK-NEXT: Flags [ (0x0)
107 # CHECK-NEXT: ]
108 # CHECK-NEXT: Address: 0x0
109 # CHECK-NEXT: Offset: 0x168
110 # CHECK-NEXT: Size: 42
111 # CHECK-NEXT: Link: 0
112 # CHECK-NEXT: Info: 0
113 # CHECK-NEXT: AddressAlignment: 1
114 # CHECK-NEXT: EntrySize: 0
115 # CHECK-NEXT: }
116 # CHECK-NEXT: Section {
117 # CHECK-NEXT: Index: 5
118 # CHECK-NEXT: Name: .strtab
119 # CHECK-NEXT: Type: SHT_STRTAB (0x3)
120 # CHECK-NEXT: Flags [ (0x0)
121 # CHECK-NEXT: ]
122 # CHECK-NEXT: Address: 0x0
123 # CHECK-NEXT: Offset: 0x192
124 # CHECK-NEXT: Size: 8
125 # CHECK-NEXT: Link: 0
126 # CHECK-NEXT: Info: 0
127 # CHECK-NEXT: AddressAlignment: 1
128 # CHECK-NEXT: EntrySize: 0
129 # CHECK-NEXT: }
130 # CHECK-NEXT: ]
131 # CHECK-NEXT: ProgramHeaders [
132 # CHECK-NEXT: ProgramHeader {
133 # CHECK-NEXT: Type: PT_PHDR (0x6)
134 # CHECK-NEXT: Offset: 0x40
135 # CHECK-NEXT: VirtualAddress: 0x200040
136 # CHECK-NEXT: PhysicalAddress: 0x200040
137 # CHECK-NEXT: FileSize: 224
138 # CHECK-NEXT: MemSize: 224
139 # CHECK-NEXT: Flags [ (0x4)
140 # CHECK-NEXT: PF_R (0x4)
141 # CHECK-NEXT: ]
142 # CHECK-NEXT: Alignment: 8
143 # CHECK-NEXT: }
144 # CHECK-NEXT: ProgramHeader {
145 # CHECK-NEXT: Type: PT_LOAD (0x1)
146 # CHECK-NEXT: Offset: 0x0
147 # CHECK-NEXT: VirtualAddress: 0x200000
148 # CHECK-NEXT: PhysicalAddress: 0x200000
149 # CHECK-NEXT: FileSize: 288
150 # CHECK-NEXT: MemSize: 288
151 # CHECK-NEXT: Flags [
152 # CHECK-NEXT: PF_R
153 # CHECK-NEXT: ]
154 # CHECK-NEXT: Alignment: 4096
155 # CHECK-NEXT: }
156 # CHECK-NEXT: ProgramHeader {
157 # CHECK-NEXT: Type: PT_LOAD (0x1)
158 # CHECK-NEXT: Offset: 0x120
159 # CHECK-NEXT: VirtualAddress: 0x201120
160 # CHECK-NEXT: PhysicalAddress: 0x201120
161 # CHECK-NEXT: FileSize: 16
162 # CHECK-NEXT: MemSize: 16
163 # CHECK-NEXT: Flags [ (0x5)
164 # CHECK-NEXT: PF_R (0x4)
165 # CHECK-NEXT: PF_X (0x1)
166 # CHECK-NEXT: ]
167 # CHECK-NEXT: Alignment: 4096
168 # CHECK-NEXT: }
169 # CHECK-NEXT: ProgramHeader {
170 # CHECK-NEXT: Type: PT_GNU_STACK
171 # CHECK-NEXT: Offset: 0x0
172 # CHECK-NEXT: VirtualAddress: 0x0
173 # CHECK-NEXT: PhysicalAddress: 0x0
174 # CHECK-NEXT: FileSize: 0
175 # CHECK-NEXT: MemSize: 0
176 # CHECK-NEXT: Flags [
177 # CHECK-NEXT: PF_R
178 # CHECK-NEXT: PF_W
179 # CHECK-NEXT: ]
180 # CHECK-NEXT: Alignment: 0
181 # CHECK-NEXT: }
182 # CHECK-NEXT: ]
183 # CHECK-NEXT: Symbols [
184 # CHECK-NEXT: Symbol {
185 # CHECK-NEXT: Name: (0)
186 # CHECK-NEXT: Value: 0x0
187 # CHECK-NEXT: Size: 0
188 # CHECK-NEXT: Binding: Local (0x0)
189 # CHECK-NEXT: Type: None (0x0)
190 # CHECK-NEXT: Other: 0
191 # CHECK-NEXT: Section: Undefined (0x0)
192 # CHECK-NEXT: }
193 # CHECK-NEXT: Symbol {
194 # CHECK-NEXT: Name: _start
195 # CHECK-NEXT: Value: [[ENTRY]]
196 # CHECK-NEXT: Size: 0
197 # CHECK-NEXT: Binding: Global (0x1)
198 # CHECK-NEXT: Type: None (0x0)
199 # CHECK-NEXT: Other: 0
200 # CHECK-NEXT: Section: .text
201 # CHECK-NEXT: }
202 # CHECK-NEXT: ]
204 ## Test for the response file (POSIX quoting style)
205 # RUN: echo " -o %t2" > %t.responsefile
206 # RUN: ld.lld %t --rsp-quoting=posix @%t.responsefile
207 # RUN: llvm-readobj --file-headers --sections -l --symbols %t2 \
208 # RUN: | FileCheck %s
210 ## Test for the response file (Windows quoting style)
211 # RUN: echo " c:\blah\foo" > %t.responsefile
212 # RUN: not ld.lld --rsp-quoting=windows %t @%t.responsefile 2>&1 | FileCheck \
213 # RUN: %s --check-prefix=WINRSP
214 # WINRSP: cannot open c:\blah\foo
216 ## Test for the response file (invalid quoting style)
217 # RUN: not ld.lld --rsp-quoting=patatino %t 2>&1 | FileCheck %s \
218 # RUN: --check-prefix=INVRSP
219 # INVRSP: invalid response file quoting: patatino
221 ## Test erroring on a recursive response file, but only once.
222 # RUN: echo @%t.responsefile > %t.responsefile
223 # RUN: not ld.lld %t @%t.responsefile 2>&1 | FileCheck %s --check-prefix=RECRSP
224 # RECRSP: recursive expansion of: '{{.*}}.responsefile'
225 # RECRSP-NOT: recursive expansion of
227 # RUN: not ld.lld %t.foo -o /dev/null 2>&1 | \
228 # RUN: FileCheck -DMSG=%errc_ENOENT --check-prefix=MISSING %s
229 # MISSING: cannot open {{.*}}.foo: [[MSG]]
231 # RUN: not ld.lld -o /dev/null 2>&1 | \
232 # RUN: FileCheck --check-prefix=NO_INPUT %s
233 # NO_INPUT: ld.lld{{.*}}: no input files
235 # RUN: not ld.lld %t.no.such.file -o /dev/null 2>&1 | \
236 # RUN: FileCheck -DMSG=%errc_ENOENT --check-prefix=CANNOT_OPEN %s
237 # CANNOT_OPEN: cannot open {{.*}}.no.such.file: [[MSG]]
239 # RUN: not ld.lld --foo 2>&1 | FileCheck --check-prefix=UNKNOWN %s
240 # UNKNOWN: unknown argument '--foo'
242 # RUN: not ld.lld %t -o /dev/null -m wrong_emul_fbsd 2>&1 | FileCheck --check-prefix=UNKNOWN_EMUL %s
243 # UNKNOWN_EMUL: unknown emulation: wrong_emul_fbsd