[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / Driver / ps5-linker.c
blob62aa3a40e455af1004a84c18c819ab4472454088
1 // Test that a target emulation is supplied to the linker
3 // RUN: %clang --target=x86_64-sie-ps5 %s -### 2>&1 | FileCheck --check-prefixes=CHECK-EMU %s
5 // CHECK-EMU: {{ld(\.exe)?}}"
6 // CHECK-EMU-SAME: "-m" "elf_x86_64_fbsd"
8 // Test that PIE is the default for main components
10 // RUN: %clang --target=x86_64-sie-ps5 %s -### 2>&1 | FileCheck --check-prefixes=CHECK-PIE %s
12 // CHECK-PIE: {{ld(\.exe)?}}"
13 // CHECK-PIE-SAME: "-pie"
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
20 // CHECK-NO-PIE: {{ld(\.exe)?}}"
21 // CHECK-NO-PIE-NOT: "-pie"
22 // CHECK-SHARED: "--shared"
24 // Test the driver supplies an --image-base to the linker only for non-pie
25 // executables.
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
30 // CHECK-BASE: {{ld(\.exe)?}}"
31 // CHECK-BASE-SAME: "--image-base=0x400000"
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
37 // CHECK-NO-BASE: {{ld(\.exe)?}}"
38 // CHECK-NO-BASE-NOT: --image-base
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).
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
49 // CHECK-EXE: {{ld(\.exe)?}}"
50 // CHECK-EXE-SAME: "--eh-frame-hdr"
51 // CHECK-EXE-SAME: "--hash-style=sysv"
52 // CHECK-EXE-SAME: "--build-id=uuid"
53 // CHECK-EXE-SAME: "--unresolved-symbols=report-all"
54 // CHECK-EXE-SAME: "-z" "now"
55 // CHECK-EXE-SAME: "-z" "start-stop-visibility=hidden"
56 // CHECK-EXE-SAME: "-z" "rodynamic"
57 // CHECK-EXE-SAME: "-z" "common-page-size=0x4000"
58 // CHECK-EXE-SAME: "-z" "max-page-size=0x4000"
59 // CHECK-EXE-SAME: "-z" "dead-reloc-in-nonalloc=.debug_*=0xffffffffffffffff"
60 // CHECK-EXE-SAME: "-z" "dead-reloc-in-nonalloc=.debug_ranges=0xfffffffffffffffe"
61 // CHECK-EXE-SAME: "-z" "dead-reloc-in-nonalloc=.debug_loc=0xfffffffffffffffe"
63 // CHECK-NO-EXE: {{ld(\.exe)?}}"
64 // CHECK-NO-EXE-NOT: "--eh-frame-hdr"
65 // CHECK-NO-EXE-NOT: "--hash-style
66 // CHECK-NO-EXE-NOT: "--build-id
67 // CHECK-NO-EXE-NOT: "--unresolved-symbols
68 // CHECK-NO-EXE-NOT: "-z"
70 // Test that an appropriate linker script is supplied by the driver, but can
71 // be overridden with -T.
73 // RUN: %clang --target=x86_64-sie-ps5 %s -### 2>&1 | FileCheck --check-prefixes=CHECK-SCRIPT -DSCRIPT=main %s
74 // RUN: %clang --target=x86_64-sie-ps5 %s -shared -### 2>&1 | FileCheck --check-prefixes=CHECK-SCRIPT -DSCRIPT=prx %s
75 // RUN: %clang --target=x86_64-sie-ps5 %s -static -### 2>&1 | FileCheck --check-prefixes=CHECK-SCRIPT -DSCRIPT=static %s
76 // RUN: %clang --target=x86_64-sie-ps5 %s -r -### 2>&1 | FileCheck --check-prefixes=CHECK-NO-SCRIPT %s
77 // 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
79 // CHECK-SCRIPT: {{ld(\.exe)?}}"
80 // CHECK-SCRIPT-SAME: "--default-script" "[[SCRIPT]].script"
82 // CHECK-NO-SCRIPT: {{ld(\.exe)?}}"
83 // CHECK-NO-SCRIPT-NOT: "--default-script"
85 // CHECK-CUSTOM-SCRIPT: {{ld(\.exe)?}}"
86 // CHECK-CUSTOM-SCRIPT-SAME: "-T" "custom.script"
88 // Test that -static is forwarded to the linker
90 // RUN: %clang --target=x86_64-sie-ps5 -static %s -### 2>&1 | FileCheck --check-prefixes=CHECK-STATIC %s
92 // CHECK-STATIC: {{ld(\.exe)?}}"
93 // CHECK-STATIC-SAME: "-static"
95 // Test the driver's control over the JustMyCode behavior with linker flags.
97 // RUN: %clang --target=x86_64-sie-ps5 -fjmc %s -### 2>&1 | FileCheck --check-prefixes=CHECK,CHECK-JMC %s
98 // RUN: %clang --target=x86_64-sie-ps5 -flto -fjmc %s -### 2>&1 | FileCheck --check-prefixes=CHECK,CHECK-JMC %s
100 // CHECK: -plugin-opt=-enable-jmc-instrument
102 // Check the default library name.
103 // CHECK-JMC: "--push-state" "--whole-archive" "-lSceJmc_nosubmission" "--pop-state"
105 // Test that CRT objects and libraries are supplied to the linker and can be
106 // omitted with -noxxx options. These switches have some interaction with
107 // sanitizer RT libraries. That's checked in fsanitize.c
109 // 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
110 // 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
111 // 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
112 // RUN: %clang --target=x86_64-sie-ps5 %s -r -### 2>&1 | FileCheck --check-prefixes=CHECK-LD,CHECK-NO-CRT,CHECK-NO-LIBS %s
114 // RUN: %clang --target=x86_64-sie-ps5 %s -pthread -### 2>&1 | FileCheck --check-prefixes=CHECK-LD,CHECK-PTHREAD %s
116 // 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
117 // 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
118 // 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
120 // 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
121 // 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
122 // 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
124 // 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
125 // 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
126 // 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
128 // 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
129 // 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
130 // 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
132 // 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
133 // 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
134 // 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
136 // CHECK-LD: {{ld(\.exe)?}}"
137 // CHECK-MAIN-CRT-SAME: "crt1.o" "crti.o" "crtbegin.o"
138 // CHECK-SHARED-CRT-SAME: "crti.o" "crtbeginS.o"
139 // CHECK-STATIC-CRT-SAME: "crt1.o" "crti.o" "crtbeginT.o"
141 // CHECK-NO-LIBC-NOT: "-lc{{(_stub_weak)?}}"
142 // CHECK-NO-LIBCPP-NOT: "-l{{c_stub_weak|stdc\+\+}}"
144 // CHECK-DYNAMIC-LIBC-SAME: "-lc_stub_weak"
145 // CHECK-DYNAMIC-CORE-LIBS-SAME: "-lkernel_stub_weak"
146 // CHECK-STATIC-LIBCPP-SAME: "-lstdc++"
147 // CHECK-STATIC-LIBC-SAME: "-lm" "-lc"
148 // CHECK-STATIC-CORE-LIBS-SAME: "-lcompiler_rt" "-lkernel"
150 // CHECK-PTHREAD-SAME: "-lpthread"
152 // CHECK-MAIN-CRT-SAME: "crtend.o" "crtn.o"
153 // CHECK-SHARED-CRT-SAME: "crtendS.o" "crtn.o"
154 // CHECK-STATIC-CRT-SAME: "crtend.o" "crtn.o"
156 // CHECK-NO-CRT-NOT: "crt{{[^"]*}}.o"
157 // CHECK-NO-LIBS-NOT: "-l{{[^"]*}}"
159 // Test the driver's control over the -fcrash-diagnostics-dir behavior with linker flags.
161 // RUN: %clang --target=x86_64-sie-ps5 -fcrash-diagnostics-dir=mydumps %s -### 2>&1 | FileCheck --check-prefixes=CHECK-DIAG %s
162 // RUN: %clang --target=x86_64-sie-ps5 -flto -fcrash-diagnostics-dir=mydumps %s -### 2>&1 | FileCheck --check-prefixes=CHECK-DIAG %s
164 // CHECK-DIAG: -plugin-opt=-crash-diagnostics-dir=mydumps
166 // Test the driver passes a sysroot to the linker. Without --sysroot, its value
167 // is sourced from the SDK environment variable.
169 // RUN: env SCE_PROSPERO_SDK_DIR=mysdk %clang --target=x64_64-sie-ps5 %s -### 2>&1 | FileCheck --check-prefixes=CHECK-SYSROOT %s
170 // RUN: env SCE_PROSPERO_SDK_DIR=other %clang --target=x64_64-sie-ps5 %s -### --sysroot=mysdk 2>&1 | FileCheck --check-prefixes=CHECK-SYSROOT %s
172 // CHECK-SYSROOT: {{ld(\.exe)?}}"
173 // CHECK-SYSROOT-SAME: "--sysroot=mysdk"
175 // Test that "." is always added to library search paths. This is long-standing
176 // behavior, unique to PlayStation toolchains.
178 // RUN: %clang --target=x64_64-sie-ps5 %s -### 2>&1 | FileCheck --check-prefixes=CHECK-LDOT %s
180 // CHECK-LDOT: {{ld(\.exe)?}}"
181 // CHECK-LDOT-SAME: "-L."
183 // Test that <sdk-root>/target/lib is added to library search paths, if it
184 // exists and no --sysroot is specified. Also confirm that CRT objects are
185 // found there.
187 // RUN: rm -rf %t.dir && mkdir %t.dir
188 // RUN: env SCE_PROSPERO_SDK_DIR=%t.dir %clang --target=x64_64-sie-ps5 %s -### 2>&1 | FileCheck --check-prefixes=CHECK-NO-TARGETLIB %s
189 // RUN: env SCE_PROSPERO_SDK_DIR=%t.dir %clang --target=x64_64-sie-ps5 %s -### --sysroot=%t.dir 2>&1 | FileCheck --check-prefixes=CHECK-NO-TARGETLIB %s
191 // CHECK-NO-TARGETLIB: {{ld(\.exe)?}}"
192 // CHECK-NO-TARGETLIB-NOT: "-L{{.*[/\\]}}target/lib"
194 // RUN: mkdir -p %t.dir/target/lib
195 // RUN: touch %t.dir/target/lib/crti.o
196 // RUN: env SCE_PROSPERO_SDK_DIR=%t.dir %clang --target=x64_64-sie-ps5 %s -### 2>&1 | FileCheck --check-prefixes=CHECK-TARGETLIB %s
198 // CHECK-TARGETLIB: {{ld(\.exe)?}}"
199 // CHECK-TARGETLIB-SAME: "-L{{.*[/\\]}}target/lib"
200 // CHECK-TARGETLIB-SAME: "{{.*[/\\]}}target{{/|\\\\}}lib{{/|\\\\}}crti.o"