1# There is some bad quoting interaction between lit's internal shell, which is
2# implemented in Python, and the Cygwin implementations of the Unix utilities.
3# Avoid running these tests on Windows for now by requiring a real shell.
4
5# REQUIRES: shell
6
7# REQUIRES: x86
8# RUN: mkdir -p %t.dir
9# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
10# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux \
11# RUN:   %p/Inputs/libsearch-st.s -o %t2.o
12# RUN: rm -f %t.dir/libxyz.a
13# RUN: llvm-ar rcs %t.dir/libxyz.a %t2.o
14
15# RUN: echo "EXTERN( undef undef2 )" > %t.script
16# RUN: ld.lld %t -o %t2 %t.script
17# RUN: llvm-readobj %t2 > /dev/null
18
19# RUN: echo "GROUP(\"%t\")" > %t.script
20# RUN: ld.lld -o %t2 %t.script
21# RUN: llvm-readobj %t2 > /dev/null
22
23# RUN: echo "INPUT(\"%t\")" > %t.script
24# RUN: ld.lld -o %t2 %t.script
25# RUN: llvm-readobj %t2 > /dev/null
26
27# RUN: echo "GROUP(\"%t\" libxyz.a )" > %t.script
28# RUN: not ld.lld -o %t2 %t.script 2>/dev/null
29# RUN: ld.lld -o %t2 %t.script -L%t.dir
30# RUN: llvm-readobj %t2 > /dev/null
31
32# RUN: echo "GROUP(\"%t\" =libxyz.a )" > %t.script
33# RUN: not ld.lld -o %t2 %t.script  2>/dev/null
34# RUN: ld.lld -o %t2 %t.script --sysroot=%t.dir
35# RUN: llvm-readobj %t2 > /dev/null
36
37# RUN: echo "GROUP(\"%t\" -lxyz )" > %t.script
38# RUN: not ld.lld -o %t2 %t.script  2>/dev/null
39# RUN: ld.lld -o %t2 %t.script -L%t.dir
40# RUN: llvm-readobj %t2 > /dev/null
41
42# RUN: echo "GROUP(\"%t\" libxyz.a )" > %t.script
43# RUN: not ld.lld -o %t2 %t.script  2>/dev/null
44# RUN: ld.lld -o %t2 %t.script -L%t.dir
45# RUN: llvm-readobj %t2 > /dev/null
46
47# RUN: echo "GROUP(\"%t\" /libxyz.a )" > %t.script
48# RUN: echo "GROUP(\"%t\" /libxyz.a )" > %t.dir/xyz.script
49# RUN: not ld.lld -o %t2 %t.script 2>/dev/null
50# RUN: not ld.lld -o %t2 %t.script --sysroot=%t.dir  2>/dev/null
51# RUN: ld.lld -o %t2 %t.dir/xyz.script --sysroot=%t.dir
52# RUN: llvm-readobj %t2 > /dev/null
53
54# RUN: echo "GROUP(\"%t.script2\")" > %t.script1
55# RUN: echo "GROUP(\"%t\")" > %t.script2
56# RUN: ld.lld -o %t2 %t.script1
57# RUN: llvm-readobj %t2 > /dev/null
58
59# RUN: echo "ENTRY(_label)" > %t.script
60# RUN: ld.lld -o %t2 %t.script %t
61# RUN: llvm-readobj %t2 > /dev/null
62
63# The entry symbol should not cause an undefined error.
64# RUN: echo "ENTRY(_wrong_label)" > %t.script
65# RUN: ld.lld -o %t2 %t.script %t
66# RUN: ld.lld --entry=abc -o %t2 %t
67
68# -e has precedence over linker script's ENTRY.
69# RUN: echo "ENTRY(_label)" > %t.script
70# RUN: ld.lld -e _start -o %t2 %t.script %t
71# RUN: llvm-readobj -file-headers -symbols %t2 | \
72# RUN:   FileCheck -check-prefix=ENTRY-OVERLOAD %s
73
74# ENTRY-OVERLOAD: Entry: [[ENTRY:0x[0-9A-F]+]]
75# ENTRY-OVERLOAD: Name: _start
76# ENTRY-OVERLOAD-NEXT: Value: [[ENTRY]]
77
78# The entry symbol can be a linker-script-defined symbol.
79# RUN: echo "ENTRY(foo); foo = 1;" > %t.script
80# RUN: ld.lld -o %t2 %t.script %t
81# RUN: llvm-readobj -file-headers -symbols %t2 | \
82# RUN:   FileCheck -check-prefix=ENTRY-SCRIPT %s
83
84# ENTRY-SCRIPT: Entry: 0x1
85
86# RUN: echo "OUTPUT_FORMAT(elf64-x86-64) /*/*/ GROUP(\"%t\" )" > %t.script
87# RUN: ld.lld -o %t2 %t.script
88# RUN: llvm-readobj %t2 > /dev/null
89
90# RUN: echo "GROUP(AS_NEEDED(\"%t\"))" > %t.script
91# RUN: ld.lld -o %t2 %t.script
92# RUN: llvm-readobj %t2 > /dev/null
93
94# RUN: rm -f %t.out
95# RUN: echo "OUTPUT(\"%t.out\")" > %t.script
96# RUN: ld.lld %t.script %t
97# RUN: llvm-readobj %t.out > /dev/null
98
99# RUN: echo "SEARCH_DIR(/lib/foo/blah)" > %t.script
100# RUN: ld.lld %t.script %t
101# RUN: llvm-readobj %t.out > /dev/null
102
103# RUN: echo ";SEARCH_DIR(x);SEARCH_DIR(y);" > %t.script
104# RUN: ld.lld %t.script %t
105# RUN: llvm-readobj %t.out > /dev/null
106
107# RUN: echo ";" > %t.script
108# RUN: ld.lld %t.script %t
109# RUN: llvm-readobj %t.out > /dev/null
110
111# RUN: echo "INCLUDE \"%t.script2\" OUTPUT(\"%t.out\")" > %t.script1
112# RUN: echo "GROUP(\"%t\")" > %t.script2
113# RUN: ld.lld %t.script1
114# RUN: llvm-readobj %t2 > /dev/null
115
116# RUN: echo "FOO(BAR)" > %t.script
117# RUN: not ld.lld -o foo %t.script > %t.log 2>&1
118# RUN: FileCheck -check-prefix=ERR1 %s < %t.log
119
120# ERR1: unknown directive: FOO
121
122.globl _start, _label
123_start:
124  mov $60, %rax
125  mov $42, %rdi
126_label:
127  syscall
128