Debian Codegraph @

clang/test/Driver/ps5-linker.c

raw
1 // Test that a target emulation is supplied to the linker
2
3 // RUN: %clang --target=x86_64-sie-ps5 %s -### 2>&1 | FileCheck --check-prefixes=CHECK-EMU %s
4
5 // CHECK-EMU: {{ld(\.exe)?}}"
6 // CHECK-EMU-SAME: "-m" "elf_x86_64_fbsd"
7
8 // Test that PIE is the default for main components
9
10 // RUN: %clang --target=x86_64-sie-ps5 %s -### 2>&1 | FileCheck --check-prefixes=CHECK-PIE %s
11
12 // CHECK-PIE: {{ld(\.exe)?}}"
13 // CHECK-PIE-SAME: "-pie"
14
15 // RUN: %clang --target=x86_64-sie-ps5 -no-pie %s -### 2>&1 | FileCheck --check-prefixes=CHECK-NO-PIE %s
16 // RUN: %clang --target=x86_64-sie-ps5 -r %s -### 2>&1 | FileCheck --check-prefixes=CHECK-NO-PIE %s
17 // RUN: %clang --target=x86_64-sie-ps5 -shared %s -### 2>&1 | FileCheck --check-prefixes=CHECK-NO-PIE,CHECK-SHARED %s
18 // RUN: %clang --target=x86_64-sie-ps5 -static %s -### 2>&1 | FileCheck --check-prefixes=CHECK-NO-PIE %s
19
20 // CHECK-NO-PIE: {{ld(\.exe)?}}"
21 // CHECK-NO-PIE-NOT: "-pie"
22 // CHECK-SHARED: "--shared"
23
24 // Test the driver supplies an --image-base to the linker only for non-pie
25 // executables.
26
27 // RUN: %clang --target=x86_64-sie-ps5 -static %s -### 2>&1 | FileCheck --check-prefixes=CHECK-BASE %s
28 // RUN: %clang --target=x86_64-sie-ps5 -no-pie %s -### 2>&1 | FileCheck --check-prefixes=CHECK-BASE %s
29
30 // CHECK-BASE: {{ld(\.exe)?}}"
31 // CHECK-BASE-SAME: "--image-base=0x400000"
32
33 // RUN: %clang --target=x86_64-sie-ps5 %s -### 2>&1 | FileCheck --check-prefixes=CHECK-NO-BASE %s
34 // RUN: %clang --target=x86_64-sie-ps5 -r %s -### 2>&1 | FileCheck --check-prefixes=CHECK-NO-BASE %s
35 // RUN: %clang --target=x86_64-sie-ps5 -shared %s -### 2>&1 | FileCheck --check-prefixes=CHECK-NO-BASE %s
36
37 // CHECK-NO-BASE: {{ld(\.exe)?}}"
38 // CHECK-NO-BASE-NOT: --image-base
39
40 // Test the driver passes PlayStation-specific options to the linker that are
41 // appropriate for the type of output. Many options don't apply for relocatable
42 // output (-r).
43
44 // RUN: %clang --target=x86_64-sie-ps5 %s -### 2>&1 | FileCheck --check-prefixes=CHECK-EXE %s
45 // RUN: %clang --target=x86_64-sie-ps5 %s -shared -### 2>&1 | FileCheck --check-prefixes=CHECK-EXE %s
46 // RUN: %clang --target=x86_64-sie-ps5 %s -static -### 2>&1 | FileCheck --check-prefixes=CHECK-EXE %s
47 // RUN: %clang --target=x86_64-sie-ps5 %s -r -### 2>&1 | FileCheck --check-prefixes=CHECK-NO-EXE %s
48
49 // CHECK-EXE: {{ld(\.exe)?}}"
50 // CHECK-EXE-SAME: "--eh-frame-hdr"
51 // CHECK-EXE-SAME: "--hash-style=sysv"
52 // CHECK-EXE-SAME: "--unresolved-symbols=report-all"
53 // CHECK-EXE-SAME: "-z" "now"
54 // CHECK-EXE-SAME: "-z" "start-stop-visibility=hidden"
55 // CHECK-EXE-SAME: "-z" "rodynamic"
56 // CHECK-EXE-SAME: "-z" "common-page-size=0x4000"
57 // CHECK-EXE-SAME: "-z" "max-page-size=0x4000"
58 // CHECK-EXE-SAME: "-z" "dead-reloc-in-nonalloc=.debug_*=0xffffffffffffffff"
59 // CHECK-EXE-SAME: "-z" "dead-reloc-in-nonalloc=.debug_ranges=0xfffffffffffffffe"
60 // CHECK-EXE-SAME: "-z" "dead-reloc-in-nonalloc=.debug_loc=0xfffffffffffffffe"
61
62 // CHECK-NO-EXE: {{ld(\.exe)?}}"
63 // CHECK-NO-EXE-NOT: "--eh-frame-hdr"
64 // CHECK-NO-EXE-NOT: "--hash-style
65 // CHECK-NO-EXE-NOT: "--unresolved-symbols
66 // CHECK-NO-EXE-NOT: "-z"
67
68 // Test that --build-id is supplied to the linker for non-static executables
69 // and -shared.
70
71 // RUN: %clang --target=x86_64-sie-ps5 %s -### 2>&1 | FileCheck --check-prefixes=CHECK-BUILD-ID %s
72 // RUN: %clang --target=x86_64-sie-ps5 %s -shared -### 2>&1 | FileCheck --check-prefixes=CHECK-BUILD-ID %s
73 // RUN: %clang --target=x86_64-sie-ps5 %s -static -### 2>&1 | FileCheck --check-prefixes=CHECK-NO-BUILD-ID %s
74 // RUN: %clang --target=x86_64-sie-ps5 %s -r -### 2>&1 | FileCheck --check-prefixes=CHECK-NO-BUILD-ID %s
75
76 // CHECK-BUILD-ID: {{ld(\.exe)?}}"
77 // CHECK-BUILD-ID-SAME: "--build-id=uuid"
78
79 // CHECK-NO-BUILD-ID: {{ld(\.exe)?}}"
80 // CHECK-NO-BUILD-ID-NOT: "--build-id
81
82 // Test that an appropriate linker script is supplied by the driver, but can
83 // be overridden with -T.
84
85 // RUN: %clang --target=x86_64-sie-ps5 %s -### 2>&1 | FileCheck --check-prefixes=CHECK-SCRIPT -DSCRIPT=main %s
86 // RUN: %clang --target=x86_64-sie-ps5 %s -shared -### 2>&1 | FileCheck --check-prefixes=CHECK-SCRIPT -DSCRIPT=prx %s
87 // RUN: %clang --target=x86_64-sie-ps5 %s -static -### 2>&1 | FileCheck --check-prefixes=CHECK-SCRIPT -DSCRIPT=static %s
88 // RUN: %clang --target=x86_64-sie-ps5 %s -r -### 2>&1 | FileCheck --check-prefixes=CHECK-NO-SCRIPT %s
89 // RUN: %clang --target=x86_64-sie-ps5 %s -T custom.script -### 2>&1 | FileCheck --check-prefixes=CHECK-CUSTOM-SCRIPT --implicit-check-not "\"{{-T|--script|--default-script}}\"" %s
90
91 // CHECK-SCRIPT: {{ld(\.exe)?}}"
92 // CHECK-SCRIPT-SAME: "--default-script" "[[SCRIPT]].script"
93
94 // CHECK-NO-SCRIPT: {{ld(\.exe)?}}"
95 // CHECK-NO-SCRIPT-NOT: "--default-script"
96
97 // CHECK-CUSTOM-SCRIPT: {{ld(\.exe)?}}"
98 // CHECK-CUSTOM-SCRIPT-SAME: "-T" "custom.script"
99
100 // Test that -static is forwarded to the linker
101
102 // RUN: %clang --target=x86_64-sie-ps5 -static %s -### 2>&1 | FileCheck --check-prefixes=CHECK-STATIC %s
103
104 // CHECK-STATIC: {{ld(\.exe)?}}"
105 // CHECK-STATIC-SAME: "-static"
106
107 // Test the driver's control over the JustMyCode behavior with linker flags.
108
109 // RUN: %clang --target=x86_64-sie-ps5 -fjmc %s -### 2>&1 | FileCheck --check-prefixes=CHECK,CHECK-JMC %s
110 // RUN: %clang --target=x86_64-sie-ps5 -flto -fjmc %s -### 2>&1 | FileCheck --check-prefixes=CHECK,CHECK-JMC %s
111
112 // CHECK: -plugin-opt=-enable-jmc-instrument
113
114 // Check the default library name.
115 // CHECK-JMC: "--push-state" "--whole-archive" "-lSceJmc_nosubmission" "--pop-state"
116
117 // Test that CRT objects and libraries are supplied to the linker and can be
118 // omitted with -noxxx options. These switches have some interaction with
119 // sanitizer RT libraries. That's checked in fsanitize.c
120
121 // RUN: %clang --target=x86_64-sie-ps5 %s -### 2>&1 | FileCheck --check-prefixes=CHECK-LD,CHECK-MAIN-CRT,CHECK-DYNAMIC-LIBC,CHECK-DYNAMIC-CORE-LIBS %s
122 // RUN: %clang --target=x86_64-sie-ps5 %s -shared -### 2>&1 | FileCheck --check-prefixes=CHECK-LD,CHECK-SHARED-CRT,CHECK-DYNAMIC-LIBC,CHECK-DYNAMIC-CORE-LIBS %s
123 // RUN: %clang --target=x86_64-sie-ps5 %s -static -### 2>&1 | FileCheck --check-prefixes=CHECK-LD,CHECK-STATIC-CRT,CHECK-STATIC-LIBCPP,CHECK-STATIC-LIBC,CHECK-STATIC-CORE-LIBS %s
124 // RUN: %clang --target=x86_64-sie-ps5 %s -r -### 2>&1 | FileCheck --check-prefixes=CHECK-LD,CHECK-NO-CRT,CHECK-NO-LIBS %s
125
126 // RUN: %clang --target=x86_64-sie-ps5 %s -pthread -### 2>&1 | FileCheck --check-prefixes=CHECK-LD,CHECK-PTHREAD %s
127
128 // RUN: %clang --target=x86_64-sie-ps5 %s -nostartfiles -### 2>&1 | FileCheck --check-prefixes=CHECK-LD,CHECK-NO-CRT,CHECK-DYNAMIC-LIBC,CHECK-DYNAMIC-CORE-LIBS %s
129 // RUN: %clang --target=x86_64-sie-ps5 %s -nostartfiles -shared -### 2>&1 | FileCheck --check-prefixes=CHECK-LD,CHECK-NO-CRT,CHECK-DYNAMIC-LIBC,CHECK-DYNAMIC-CORE-LIBS %s
130 // RUN: %clang --target=x86_64-sie-ps5 %s -nostartfiles -static -### 2>&1 | FileCheck --check-prefixes=CHECK-LD,CHECK-NO-CRT,CHECK-STATIC-LIBCPP,CHECK-STATIC-LIBC,CHECK-STATIC-CORE-LIBS %s
131
132 // RUN: %clang --target=x86_64-sie-ps5 %s -nodefaultlibs -pthread -fjmc -### 2>&1 | FileCheck --check-prefixes=CHECK-LD,CHECK-MAIN-CRT,CHECK-NO-LIBS %s
133 // RUN: %clang --target=x86_64-sie-ps5 %s -nodefaultlibs -pthread -fjmc -shared -### 2>&1 | FileCheck --check-prefixes=CHECK-LD,CHECK-SHARED-CRT,CHECK-NO-LIBS %s
134 // RUN: %clang --target=x86_64-sie-ps5 %s -nodefaultlibs -pthread -fjmc -static -### 2>&1 | FileCheck --check-prefixes=CHECK-LD,CHECK-STATIC-CRT,CHECK-NO-LIBS %s
135
136 // RUN: %clang --target=x86_64-sie-ps5 %s -nostdlib -pthread -fjmc -### 2>&1 | FileCheck --check-prefixes=CHECK-LD,CHECK-NO-CRT,CHECK-NO-LIBS %s
137 // RUN: %clang --target=x86_64-sie-ps5 %s -nostdlib -pthread -fjmc -shared -### 2>&1 | FileCheck --check-prefixes=CHECK-LD,CHECK-NO-CRT,CHECK-NO-LIBS %s
138 // RUN: %clang --target=x86_64-sie-ps5 %s -nostdlib -pthread -fjmc -static -### 2>&1 | FileCheck --check-prefixes=CHECK-LD,CHECK-NO-CRT,CHECK-NO-LIBS %s
139
140 // RUN: %clang --target=x86_64-sie-ps5 %s -nolibc -### 2>&1 | FileCheck --check-prefixes=CHECK-LD,CHECK-MAIN-CRT,CHECK-NO-LIBC,CHECK-DYNAMIC-CORE-LIBS %s
141 // RUN: %clang --target=x86_64-sie-ps5 %s -nolibc -shared -### 2>&1 | FileCheck --check-prefixes=CHECK-LD,CHECK-SHARED-CRT,CHECK-NO-LIBC,CHECK-DYNAMIC-CORE-LIBS %s
142 // RUN: %clang --target=x86_64-sie-ps5 %s -nolibc -static -### 2>&1 | FileCheck --check-prefixes=CHECK-LD,CHECK-STATIC-CRT,CHECK-STATIC-LIBCPP,CHECK-NO-LIBC,CHECK-STATIC-CORE-LIBS %s
143
144 // RUN: %clang --target=x86_64-sie-ps5 %s -nostdlib++ -### 2>&1 | FileCheck --check-prefixes=CHECK-LD,CHECK-MAIN-CRT,CHECK-NO-LIBCPP,CHECK-DYNAMIC-CORE-LIBS %s
145 // RUN: %clang --target=x86_64-sie-ps5 %s -nostdlib++ -shared -### 2>&1 | FileCheck --check-prefixes=CHECK-LD,CHECK-SHARED-CRT,CHECK-NO-LIBCPP,CHECK-DYNAMIC-CORE-LIBS %s
146 // RUN: %clang --target=x86_64-sie-ps5 %s -nostdlib++ -static -### 2>&1 | FileCheck --check-prefixes=CHECK-LD,CHECK-STATIC-CRT,CHECK-NO-LIBCPP,CHECK-STATIC-LIBC,CHECK-STATIC-CORE-LIBS %s
147
148 // CHECK-LD: {{ld(\.exe)?}}"
149 // CHECK-MAIN-CRT-SAME: "-l:crt1.o" "-l:crti.o" "-l:crtbegin.o"
150 // CHECK-SHARED-CRT-SAME: "-l:crti.o" "-l:crtbeginS.o"
151 // CHECK-STATIC-CRT-SAME: "-l:crt1.o" "-l:crti.o" "-l:crtbeginT.o"
152
153 // CHECK-NO-LIBC-NOT: "-lc{{(_stub_weak)?}}"
154 // CHECK-NO-LIBCPP-NOT: "-l{{c_stub_weak|stdc\+\+}}"
155
156 // CHECK-DYNAMIC-LIBC-SAME: "-lc_stub_weak"
157 // CHECK-DYNAMIC-CORE-LIBS-SAME: "-lkernel_stub_weak"
158 // CHECK-STATIC-LIBCPP-SAME: "-lstdc++"
159 // CHECK-STATIC-LIBC-SAME: "-lm" "-lc"
160 // CHECK-STATIC-CORE-LIBS-SAME: "-lcompiler_rt" "-lkernel"
161
162 // CHECK-PTHREAD-SAME: "-lpthread"
163
164 // CHECK-MAIN-CRT-SAME: "-l:crtend.o" "-l:crtn.o"
165 // CHECK-SHARED-CRT-SAME: "-l:crtendS.o" "-l:crtn.o"
166 // CHECK-STATIC-CRT-SAME: "-l:crtend.o" "-l:crtn.o"
167
168 // CHECK-NO-CRT-NOT: "-l:crt
169 // CHECK-NO-LIBS-NOT: "-l{{[^"]*}}"
170
171 // Test the driver's control over the -fcrash-diagnostics-dir behavior with linker flags.
172
173 // RUN: %clang --target=x86_64-sie-ps5 -fcrash-diagnostics-dir=mydumps %s -### 2>&1 | FileCheck --check-prefixes=CHECK-DIAG %s
174 // RUN: %clang --target=x86_64-sie-ps5 -flto -fcrash-diagnostics-dir=mydumps %s -### 2>&1 | FileCheck --check-prefixes=CHECK-DIAG %s
175
176 // CHECK-DIAG: -plugin-opt=-crash-diagnostics-dir=mydumps
177
178 // Test the driver passes a sysroot to the linker. Without --sysroot, its value
179 // is sourced from the SDK environment variable.
180
181 // RUN: env SCE_PROSPERO_SDK_DIR=mysdk %clang --target=x64_64-sie-ps5 %s -### 2>&1 | FileCheck --check-prefixes=CHECK-SYSROOT %s
182 // RUN: env SCE_PROSPERO_SDK_DIR=other %clang --target=x64_64-sie-ps5 %s -### --sysroot=mysdk 2>&1 | FileCheck --check-prefixes=CHECK-SYSROOT %s
183
184 // CHECK-SYSROOT: {{ld(\.exe)?}}"
185 // CHECK-SYSROOT-SAME: "--sysroot=mysdk"
186
187 // Test implicit library search paths are supplied to the linker, after any
188 // search paths specified by the user. <sdk-root>/target/lib is implicitly
189 // added if it exists. CRT objects are found there if not on user search paths.
190 // "." is always implicitly added to library search paths. These are
191 // long-standing and entrenched behaviors, unique to PlayStation toolchains.
192
193 // RUN: rm -rf %t.dir && mkdir %t.dir
194 // RUN: env SCE_PROSPERO_SDK_DIR=%t.dir %clang --target=x64_64-sie-ps5 %s -### -Luser 2>&1 | FileCheck --check-prefixes=CHECK-NO-TARGETLIB %s
195 // RUN: %clang --target=x64_64-sie-ps5 %s -### -Luser --sysroot=%t.dir 2>&1 | FileCheck --check-prefixes=CHECK-NO-TARGETLIB %s
196
197 // CHECK-NO-TARGETLIB: {{ld(\.exe)?}}"
198 // CHECK-NO-TARGETLIB-SAME: "-Luser"
199 // CHECK-NO-TARGETLIB-NOT: "-L{{.*[/\\]}}target/lib"
200 // CHECK-NO-TARGETLIB-SAME: "-L."
201
202 // RUN: mkdir -p %t.dir/myroot/target/lib
203 // RUN: env SCE_PROSPERO_SDK_DIR=%t.dir/myroot %clang --target=x64_64-sie-ps5 %s -### -Luser 2>&1 | FileCheck --check-prefixes=CHECK-TARGETLIB %s
204 // RUN: %clang --target=x64_64-sie-ps5 %s -### -Luser --sysroot=%t.dir/myroot 2>&1 | FileCheck --check-prefixes=CHECK-TARGETLIB %s
205
206 // CHECK-TARGETLIB: {{ld(\.exe)?}}"
207 // CHECK-TARGETLIB-SAME: "-Luser"
208 // CHECK-TARGETLIB-SAME: "-L{{.*}}myroot{{/|\\\\}}target{{/|\\\\}}lib"
209 // CHECK-TARGETLIB-SAME: "-L."
210
211 // Test that -ffat-lto-objects is forwarded to the linker.
212
213 // RUN: %clang --target=x86_64-sie-ps5 -flto=full -ffat-lto-objects %s -### 2>&1 | FileCheck --check-prefixes=CHECK-FAT-LTO %s
214 // RUN: %clang --target=x86_64-sie-ps5 -flto=full -funified-lto -ffat-lto-objects %s -### 2>&1 | FileCheck --check-prefixes=CHECK-FAT-LTO %s
215 // RUN: %clang --target=x86_64-sie-ps5 -flto=full %s -### 2>&1 | FileCheck --check-prefixes=CHECK-NO-FAT-LTO %s
216 // RUN: %clang --target=x86_64-sie-ps5 -flto=full -funified-lto %s -### 2>&1 | FileCheck --check-prefixes=CHECK-NO-FAT-LTO %s
217
218 // CHECK-FAT-LTO: {{ld(\.exe)?}}"
219 // CHECK-FAT-LTO-SAME: "--fat-lto-objects"
220 // CHECK-NO-FAT-LTO: {{ld(\.exe)?}}"
221 // CHECK-NO-FAT-LTO-NOT: "--fat-lto-objects"
222 // CHECK-NO-FAT-LTO-SAME: {{$}}