Skip to content

Commit e685621

Browse files
jdenny-ornlkrishna2803
authored andcommitted
[LinkerWrapper] Fix -fsave-optimization-record default file (llvm#149003)
As discussed in PR llvm#145603, the following command seems to fail to produce a YAML remarks file for offload LTO passes and thus for kernel-info: ``` clang -O2 -g -fopenmp --offload-arch=native test.c -foffload-lto \ -Rpass=kernel-info -fsave-optimization-record ``` The problem is that, in clang-linker-wrapper's clang call, clang names the file based on clang's main output file (from `-o`). That is a temporary file, so the YAML file becomes a temporary file, which the user never sees. This patch: - Makes clang honor `-dumpdir` for the default YAML remarks file in the case of LTO. - Extends clang-linker-wrapper to specify that option to clang. To demonstrate the appeal of the generality of `-dumpdir` (as opposed to a one-off `-fsave-optimization-record` solution in clang-linker-wrapper), this patch also fixes `-gsplit-dwarf`. Without this patch, when using `-gsplit-dwarf` and later debugging using rocgdb, the dwo directory for offload is a temporary file, so temporary file cleanup causes rocgdb to lose debug symbols for offload code. WARNING: The clang driver passes `-dumpdir` to various clang frontend calls. For LTO, that was previously being ignored, and now it's not. That changes some auxiliary file names, as revealed by changes in some existing tests' expected output: `clang/test/Driver/opt-record.c` and `clang/test/Driver/lto-dwo.c`. Hopefully this change does not introduce a backward compatibility issue for users.
1 parent dadad98 commit e685621

File tree

6 files changed

+97
-48
lines changed

6 files changed

+97
-48
lines changed

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -295,17 +295,22 @@ static void renderRemarksOptions(const ArgList &Args, ArgStringList &CmdArgs,
295295
Format = A->getValue();
296296

297297
SmallString<128> F;
298-
const Arg *A = Args.getLastArg(options::OPT_foptimization_record_file_EQ);
299-
if (A)
298+
if (const Arg *A =
299+
Args.getLastArg(options::OPT_foptimization_record_file_EQ)) {
300+
F = A->getValue();
301+
F += ".";
302+
} else if (const Arg *A = Args.getLastArg(options::OPT_dumpdir)) {
300303
F = A->getValue();
301-
else if (Output.isFilename())
304+
} else if (Output.isFilename()) {
302305
F = Output.getFilename();
306+
F += ".";
307+
}
303308

304309
assert(!F.empty() && "Cannot determine remarks output name.");
305310
// Append "opt.ld.<format>" to the end of the file name.
306311
CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) +
307-
"opt-remarks-filename=" + F +
308-
".opt.ld." + Format));
312+
"opt-remarks-filename=" + F + "opt.ld." +
313+
Format));
309314

310315
if (const Arg *A =
311316
Args.getLastArg(options::OPT_foptimization_record_passes_EQ))
@@ -1075,9 +1080,17 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args,
10751080
}
10761081
}
10771082

1078-
if (Args.hasArg(options::OPT_gsplit_dwarf))
1079-
CmdArgs.push_back(Args.MakeArgString(
1080-
Twine(PluginOptPrefix) + "dwo_dir=" + Output.getFilename() + "_dwo"));
1083+
if (Args.hasArg(options::OPT_gsplit_dwarf)) {
1084+
SmallString<128> F;
1085+
if (const Arg *A = Args.getLastArg(options::OPT_dumpdir)) {
1086+
F = A->getValue();
1087+
} else {
1088+
F = Output.getFilename();
1089+
F += "_";
1090+
}
1091+
CmdArgs.push_back(
1092+
Args.MakeArgString(Twine(PluginOptPrefix) + "dwo_dir=" + F + "dwo"));
1093+
}
10811094

10821095
if (IsThinLTO && !IsOSAIX)
10831096
CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) + "thinlto"));

clang/test/Driver/linker-wrapper-libs.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ int bar() { return weak; }
4848
// RUN: --linker-path=/usr/bin/ld %t.a %t.o -o a.out 2>&1 \
4949
// RUN: | FileCheck %s --check-prefix=LIBRARY-RESOLVES
5050

51-
// LIBRARY-RESOLVES: clang{{.*}} -o {{.*}}.img --target=nvptx64-nvidia-cuda -march=sm_70 {{.*}}.o {{.*}}.o
52-
// LIBRARY-RESOLVES: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx1030 {{.*}}.o {{.*}}.o
51+
// LIBRARY-RESOLVES: clang{{.*}} -o {{.*}}.img -dumpdir {{.*}}.img. --target=nvptx64-nvidia-cuda -march=sm_70 {{.*}}.o {{.*}}.o
52+
// LIBRARY-RESOLVES: clang{{.*}} -o {{.*}}.img -dumpdir {{.*}}.img. --target=amdgcn-amd-amdhsa -mcpu=gfx1030 {{.*}}.o {{.*}}.o
5353

5454
//
5555
// Check that we extract a static library that defines a global visibile to the
@@ -72,8 +72,8 @@ int bar() { return weak; }
7272
// RUN: --linker-path=/usr/bin/ld %t.a %t.o -o a.out 2>&1 \
7373
// RUN: | FileCheck %s --check-prefix=LIBRARY-GLOBAL
7474

75-
// LIBRARY-GLOBAL: clang{{.*}} -o {{.*}}.img --target=nvptx64-nvidia-cuda -march=sm_70 {{.*}}.o {{.*}}.o
76-
// LIBRARY-GLOBAL: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx1030 {{.*}}.o {{.*}}.o
75+
// LIBRARY-GLOBAL: clang{{.*}} -o {{.*}}.img -dumpdir {{.*}}.img. --target=nvptx64-nvidia-cuda -march=sm_70 {{.*}}.o {{.*}}.o
76+
// LIBRARY-GLOBAL: clang{{.*}} -o {{.*}}.img -dumpdir {{.*}}.img. --target=amdgcn-amd-amdhsa -mcpu=gfx1030 {{.*}}.o {{.*}}.o
7777

7878
//
7979
// Check that we do not extract a global symbol if the source file was not
@@ -95,8 +95,8 @@ int bar() { return weak; }
9595
// RUN: --linker-path=/usr/bin/ld %t.o %t.a -o a.out 2>&1 \
9696
// RUN: | FileCheck %s --check-prefix=LIBRARY-GLOBAL-NONE
9797

98-
// LIBRARY-GLOBAL-NONE-NOT: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx1030 {{.*}}.o {{.*}}.o
99-
// LIBRARY-GLOBAL-NONE-NOT: clang{{.*}} -o {{.*}}.img --target=nvptx64-nvidia-cuda -march=sm_70 {{.*}}.o {{.*}}.o
98+
// LIBRARY-GLOBAL-NONE-NOT: clang{{.*}} -o {{.*}}.img -dumpdir {{.*}}.img. --target=amdgcn-amd-amdhsa -mcpu=gfx1030 {{.*}}.o {{.*}}.o
99+
// LIBRARY-GLOBAL-NONE-NOT: clang{{.*}} -o {{.*}}.img -dumpdir {{.*}}.img. --target=nvptx64-nvidia-cuda -march=sm_70 {{.*}}.o {{.*}}.o
100100

101101
//
102102
// Check that we do not extract an external weak symbol.
@@ -116,9 +116,9 @@ int bar() { return weak; }
116116
// RUN: --linker-path=/usr/bin/ld %t.o %t.a -o a.out 2>&1 \
117117
// RUN: | FileCheck %s --check-prefix=LIBRARY-WEAK
118118

119-
// LIBRARY-WEAK: clang{{.*}} -o {{.*}}.img --target=nvptx64-nvidia-cuda -march=sm_70
119+
// LIBRARY-WEAK: clang{{.*}} -o {{.*}}.img -dumpdir {{.*}}.img. --target=nvptx64-nvidia-cuda -march=sm_70
120120
// LIBRARY-WEAK-NOT: {{.*}}.o {{.*}}.o
121-
// LIBRARY-WEAK: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx1030
121+
// LIBRARY-WEAK: clang{{.*}} -o {{.*}}.img -dumpdir {{.*}}.img. --target=amdgcn-amd-amdhsa -mcpu=gfx1030
122122

123123
//
124124
// Check that we do not extract an unneeded hidden symbol.
@@ -138,9 +138,9 @@ int bar() { return weak; }
138138
// RUN: --linker-path=/usr/bin/ld %t.o %t.a -o a.out 2>&1 \
139139
// RUN: | FileCheck %s --check-prefix=LIBRARY-HIDDEN
140140

141-
// LIBRARY-HIDDEN: clang{{.*}} -o {{.*}}.img --target=nvptx64-nvidia-cuda -march=sm_70
141+
// LIBRARY-HIDDEN: clang{{.*}} -o {{.*}}.img -dumpdir {{.*}}.img. --target=nvptx64-nvidia-cuda -march=sm_70
142142
// LIBRARY-HIDDEN-NOT: {{.*}}.o {{.*}}.o
143-
// LIBRARY-HIDDEN: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx1030
143+
// LIBRARY-HIDDEN: clang{{.*}} -o {{.*}}.img -dumpdir {{.*}}.img. --target=amdgcn-amd-amdhsa -mcpu=gfx1030
144144

145145
//
146146
// Check that we do not extract a static library that defines a global visibile
@@ -161,9 +161,9 @@ int bar() { return weak; }
161161
// RUN: --linker-path=/usr/bin/ld %t.o %t.a %t.a -o a.out 2>&1 \
162162
// RUN: | FileCheck %s --check-prefix=LIBRARY-GLOBAL-DEFINED
163163

164-
// LIBRARY-GLOBAL-DEFINED: clang{{.*}} -o {{.*}}.img --target=nvptx64-nvidia-cuda -march=sm_70 {{.*}}.o {{.*}}.o
164+
// LIBRARY-GLOBAL-DEFINED: clang{{.*}} -o {{.*}}.img -dumpdir {{.*}}.img. --target=nvptx64-nvidia-cuda -march=sm_70 {{.*}}.o {{.*}}.o
165165
// LIBRARY-GLOBAL-DEFINED-NOT: {{.*}}gfx1030{{.*}}.o
166-
// LIBRARY-GLOBAL-DEFINED: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx1030 {{.*}}.o {{.*}}.o
166+
// LIBRARY-GLOBAL-DEFINED: clang{{.*}} -o {{.*}}.img -dumpdir {{.*}}.img. --target=amdgcn-amd-amdhsa -mcpu=gfx1030 {{.*}}.o {{.*}}.o
167167

168168
//
169169
// Check that we can use --[no-]whole-archive to control extraction.
@@ -185,7 +185,7 @@ int bar() { return weak; }
185185
// RUN: --linker-path=/usr/bin/ld %t.o --whole-archive %t.a -o a.out 2>&1 \
186186
// RUN: | FileCheck %s --check-prefix=LIBRARY-WHOLE-ARCHIVE
187187

188-
// LIBRARY-WHOLE-ARCHIVE: clang{{.*}} -o {{.*}}.img --target=nvptx64-nvidia-cuda -march=sm_70 {{.*}}.o {{.*}}.o
189-
// LIBRARY-WHOLE-ARCHIVE: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx1030 {{.*}}.o {{.*}}.o
190-
// LIBRARY-WHOLE-ARCHIVE: clang{{.*}} -o {{.*}}.img --target=nvptx64-nvidia-cuda -march=sm_52 {{.*}}.o
191-
// LIBRARY-WHOLE-ARCHIVE: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx90a {{.*}}.o
188+
// LIBRARY-WHOLE-ARCHIVE: clang{{.*}} -o {{.*}}.img -dumpdir {{.*}}.img. --target=nvptx64-nvidia-cuda -march=sm_70 {{.*}}.o {{.*}}.o
189+
// LIBRARY-WHOLE-ARCHIVE: clang{{.*}} -o {{.*}}.img -dumpdir {{.*}}.img. --target=amdgcn-amd-amdhsa -mcpu=gfx1030 {{.*}}.o {{.*}}.o
190+
// LIBRARY-WHOLE-ARCHIVE: clang{{.*}} -o {{.*}}.img -dumpdir {{.*}}.img. --target=nvptx64-nvidia-cuda -march=sm_52 {{.*}}.o
191+
// LIBRARY-WHOLE-ARCHIVE: clang{{.*}} -o {{.*}}.img -dumpdir {{.*}}.img. --target=amdgcn-amd-amdhsa -mcpu=gfx90a {{.*}}.o

clang/test/Driver/linker-wrapper.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ __attribute__((visibility("protected"), used)) int x;
2222
// RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run \
2323
// RUN: --linker-path=/usr/bin/ld %t.o -o a.out 2>&1 | FileCheck %s --check-prefix=NVPTX-LINK
2424

25-
// NVPTX-LINK: clang{{.*}} -o {{.*}}.img --target=nvptx64-nvidia-cuda -march=sm_70 {{.*}}.o {{.*}}.o
25+
// NVPTX-LINK: clang{{.*}} -o {{.*}}.img -dumpdir a.out.nvptx64.sm_70.img. --target=nvptx64-nvidia-cuda -march=sm_70 {{.*}}.o {{.*}}.o
2626

2727
// RUN: clang-offload-packager -o %t.out \
2828
// RUN: --image=file=%t.elf.o,kind=openmp,triple=nvptx64-nvidia-cuda,arch=sm_70 \
@@ -40,7 +40,7 @@ __attribute__((visibility("protected"), used)) int x;
4040
// RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run \
4141
// RUN: --linker-path=/usr/bin/ld %t.o -o a.out 2>&1 | FileCheck %s --check-prefix=AMDGPU-LINK
4242

43-
// AMDGPU-LINK: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx908 -flto -Wl,--no-undefined {{.*}}.o {{.*}}.o
43+
// AMDGPU-LINK: clang{{.*}} -o {{.*}}.img -dumpdir a.out.amdgcn.gfx908.img. --target=amdgcn-amd-amdhsa -mcpu=gfx908 -flto -Wl,--no-undefined {{.*}}.o {{.*}}.o
4444

4545
// RUN: clang-offload-packager -o %t.out \
4646
// RUN: --image=file=%t.amdgpu.bc,kind=openmp,triple=amdgcn-amd-amdhsa,arch=gfx1030 \
@@ -57,7 +57,7 @@ __attribute__((visibility("protected"), used)) int x;
5757
// RUN: not clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run \
5858
// RUN: --linker-path=/usr/bin/ld %t.o -o a.out 2>&1 | FileCheck %s --check-prefix=SPIRV-LINK
5959

60-
// SPIRV-LINK: clang{{.*}} -o {{.*}}.img --target=spirv64-unknown-unknown {{.*}}.o --sycl-link -Xlinker -triple=spirv64-unknown-unknown -Xlinker -arch=
60+
// SPIRV-LINK: clang{{.*}} -o {{.*}}.img -dumpdir a.out.spirv64..img. --target=spirv64-unknown-unknown {{.*}}.o --sycl-link -Xlinker -triple=spirv64-unknown-unknown -Xlinker -arch=
6161

6262
// RUN: clang-offload-packager -o %t.out \
6363
// RUN: --image=file=%t.elf.o,kind=openmp,triple=x86_64-unknown-linux-gnu \
@@ -68,7 +68,7 @@ __attribute__((visibility("protected"), used)) int x;
6868
// RUN: --linker-path=/usr/bin/ld.lld --whole-archive %t.a --no-whole-archive \
6969
// RUN: %t.o -o a.out 2>&1 | FileCheck %s --check-prefix=CPU-LINK
7070

71-
// CPU-LINK: clang{{.*}} -o {{.*}}.img --target=x86_64-unknown-linux-gnu -Wl,--no-undefined {{.*}}.o {{.*}}.o -Wl,-Bsymbolic -shared -Wl,--whole-archive {{.*}}.a -Wl,--no-whole-archive
71+
// CPU-LINK: clang{{.*}} -o {{.*}}.img -dumpdir a.out.x86_64..img. --target=x86_64-unknown-linux-gnu -Wl,--no-undefined {{.*}}.o {{.*}}.o -Wl,-Bsymbolic -shared -Wl,--whole-archive {{.*}}.a -Wl,--no-whole-archive
7272

7373
// RUN: %clang -cc1 %s -triple x86_64-unknown-linux-gnu -emit-obj -o %t.o
7474
// RUN: clang-linker-wrapper --dry-run --host-triple=x86_64-unknown-linux-gnu -mllvm -openmp-opt-disable \
@@ -100,8 +100,8 @@ __attribute__((visibility("protected"), used)) int x;
100100
// RUN: clang-linker-wrapper --dry-run --host-triple=x86_64-unknown-linux-gnu \
101101
// RUN: --linker-path=/usr/bin/ld %t.o -o a.out 2>&1 | FileCheck %s --check-prefix=CUDA
102102

103-
// CUDA: clang{{.*}} -o [[IMG_SM70:.+]] --target=nvptx64-nvidia-cuda -march=sm_70
104-
// CUDA: clang{{.*}} -o [[IMG_SM52:.+]] --target=nvptx64-nvidia-cuda -march=sm_52
103+
// CUDA: clang{{.*}} -o [[IMG_SM70:.+]] -dumpdir a.out.nvptx64.sm_70.img. --target=nvptx64-nvidia-cuda -march=sm_70
104+
// CUDA: clang{{.*}} -o [[IMG_SM52:.+]] -dumpdir a.out.nvptx64.sm_52.img. --target=nvptx64-nvidia-cuda -march=sm_52
105105
// CUDA: fatbinary{{.*}}-64 --create {{.*}}.fatbin --image=profile=sm_70,file=[[IMG_SM70]] --image=profile=sm_52,file=[[IMG_SM52]]
106106
// CUDA: usr/bin/ld{{.*}} {{.*}}.openmp.image.{{.*}}.o {{.*}}.cuda.image.{{.*}}.o
107107

@@ -127,8 +127,8 @@ __attribute__((visibility("protected"), used)) int x;
127127
// RUN: --compress --compression-level=6 \
128128
// RUN: --linker-path=/usr/bin/ld %t.o -o a.out 2>&1 | FileCheck %s --check-prefix=HIP
129129

130-
// HIP: clang{{.*}} -o [[IMG_GFX90A:.+]] --target=amdgcn-amd-amdhsa -mcpu=gfx90a
131-
// HIP: clang{{.*}} -o [[IMG_GFX908:.+]] --target=amdgcn-amd-amdhsa -mcpu=gfx908
130+
// HIP: clang{{.*}} -o [[IMG_GFX90A:.+]] -dumpdir a.out.amdgcn.gfx90a.img. --target=amdgcn-amd-amdhsa -mcpu=gfx90a
131+
// HIP: clang{{.*}} -o [[IMG_GFX908:.+]] -dumpdir a.out.amdgcn.gfx908.img. --target=amdgcn-amd-amdhsa -mcpu=gfx908
132132
// HIP: clang-offload-bundler{{.*}}-type=o -bundle-align=4096 -compress -compression-level=6 -targets=host-x86_64-unknown-linux-gnu,hip-amdgcn-amd-amdhsa--gfx90a,hip-amdgcn-amd-amdhsa--gfx908 -input={{/dev/null|NUL}} -input=[[IMG_GFX90A]] -input=[[IMG_GFX908]] -output={{.*}}.hipfb
133133

134134
// RUN: clang-offload-packager -o %t.out \
@@ -157,7 +157,7 @@ __attribute__((visibility("protected"), used)) int x;
157157
// RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run --clang-backend \
158158
// RUN: --linker-path=/usr/bin/ld %t.o -o a.out 2>&1 | FileCheck %s --check-prefix=CLANG-BACKEND
159159

160-
// CLANG-BACKEND: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx908 -flto -Wl,--no-undefined {{.*}}.o
160+
// CLANG-BACKEND: clang{{.*}} -o {{.*}}.img -dumpdir a.out.amdgcn.gfx908.img. --target=amdgcn-amd-amdhsa -mcpu=gfx908 -flto -Wl,--no-undefined {{.*}}.o
161161

162162
// RUN: clang-offload-packager -o %t.out \
163163
// RUN: --image=file=%t.elf.o,kind=openmp,triple=nvptx64-nvidia-cuda,arch=sm_70
@@ -180,8 +180,8 @@ __attribute__((visibility("protected"), used)) int x;
180180
// RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run \
181181
// RUN: --linker-path=/usr/bin/ld %t-on.o %t-off.o %t.a -o a.out 2>&1 | FileCheck %s --check-prefix=AMD-TARGET-ID
182182

183-
// AMD-TARGET-ID: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx90a:xnack+ -flto -Wl,--no-undefined {{.*}}.o {{.*}}.o
184-
// AMD-TARGET-ID: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx90a:xnack- -flto -Wl,--no-undefined {{.*}}.o {{.*}}.o
183+
// AMD-TARGET-ID: clang{{.*}} -o {{.*}}.img -dumpdir a.out.amdgcn.gfx90a:xnack+.img. --target=amdgcn-amd-amdhsa -mcpu=gfx90a:xnack+ -flto -Wl,--no-undefined {{.*}}.o {{.*}}.o
184+
// AMD-TARGET-ID: clang{{.*}} -o {{.*}}.img -dumpdir a.out.amdgcn.gfx90a:xnack-.img. --target=amdgcn-amd-amdhsa -mcpu=gfx90a:xnack- -flto -Wl,--no-undefined {{.*}}.o {{.*}}.o
185185

186186
// RUN: clang-offload-packager -o %t-lib.out \
187187
// RUN: --image=file=%t.elf.o,kind=openmp,triple=amdgcn-amd-amdhsa,arch=generic
@@ -196,8 +196,8 @@ __attribute__((visibility("protected"), used)) int x;
196196
// RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run \
197197
// RUN: --linker-path=/usr/bin/ld %t1.o %t2.o %t.a -o a.out 2>&1 | FileCheck %s --check-prefix=ARCH-ALL
198198

199-
// ARCH-ALL: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx90a -flto -Wl,--no-undefined {{.*}}.o {{.*}}.o
200-
// ARCH-ALL: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa -mcpu=gfx908 -flto -Wl,--no-undefined {{.*}}.o {{.*}}.o
199+
// ARCH-ALL: clang{{.*}} -o {{.*}}.img -dumpdir a.out.amdgcn.gfx90a.img. --target=amdgcn-amd-amdhsa -mcpu=gfx90a -flto -Wl,--no-undefined {{.*}}.o {{.*}}.o
200+
// ARCH-ALL: clang{{.*}} -o {{.*}}.img -dumpdir a.out.amdgcn.gfx908.img. --target=amdgcn-amd-amdhsa -mcpu=gfx908 -flto -Wl,--no-undefined {{.*}}.o {{.*}}.o
201201

202202
// RUN: clang-offload-packager -o %t.out \
203203
// RUN: --image=file=%t.elf.o,kind=openmp,triple=x86_64-unknown-linux-gnu \
@@ -207,7 +207,7 @@ __attribute__((visibility("protected"), used)) int x;
207207
// RUN: --linker-path=/usr/bin/ld.lld -r %t.o \
208208
// RUN: %t.o -o a.out 2>&1 | FileCheck %s --check-prefix=RELOCATABLE-LINK
209209

210-
// RELOCATABLE-LINK: clang{{.*}} -o {{.*}}.img --target=x86_64-unknown-linux-gnu
210+
// RELOCATABLE-LINK: clang{{.*}} -o {{.*}}.img -dumpdir a.out.x86_64..img. --target=x86_64-unknown-linux-gnu
211211
// RELOCATABLE-LINK: /usr/bin/ld.lld{{.*}}-r
212212
// RELOCATABLE-LINK: llvm-objcopy{{.*}}a.out --remove-section .llvm.offloading
213213

@@ -219,7 +219,7 @@ __attribute__((visibility("protected"), used)) int x;
219219
// RUN: --linker-path=/usr/bin/ld.lld -r %t.o \
220220
// RUN: %t.o -o a.out 2>&1 | FileCheck %s --check-prefix=RELOCATABLE-LINK-HIP
221221

222-
// RELOCATABLE-LINK-HIP: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa
222+
// RELOCATABLE-LINK-HIP: clang{{.*}} -o {{.*}}.img -dumpdir a.out.amdgcn.gfx90a.img. --target=amdgcn-amd-amdhsa
223223
// RELOCATABLE-LINK-HIP: clang-offload-bundler{{.*}} -type=o -bundle-align=4096 -targets=host-x86_64-unknown-linux-gnu,hip-amdgcn-amd-amdhsa--gfx90a -input={{/dev/null|NUL}} -input={{.*}} -output={{.*}}
224224
// RELOCATABLE-LINK-HIP: /usr/bin/ld.lld{{.*}}-r
225225
// RELOCATABLE-LINK-HIP: llvm-objcopy{{.*}}a.out --remove-section .llvm.offloading
@@ -233,7 +233,7 @@ __attribute__((visibility("protected"), used)) int x;
233233
// RUN: --linker-path=/usr/bin/ld.lld -r %t.o \
234234
// RUN: %t.o -o a.out 2>&1 | FileCheck %s --check-prefix=RELOCATABLE-LINK-CUDA
235235

236-
// RELOCATABLE-LINK-CUDA: clang{{.*}} -o {{.*}}.img --target=nvptx64-nvidia-cuda
236+
// RELOCATABLE-LINK-CUDA: clang{{.*}} -o {{.*}}.img -dumpdir a.out.nvptx64.sm_89.img. --target=nvptx64-nvidia-cuda
237237
// RELOCATABLE-LINK-CUDA: fatbinary{{.*}} -64 --create {{.*}}.fatbin --image=profile=sm_89,file={{.*}}.img
238238
// RELOCATABLE-LINK-CUDA: /usr/bin/ld.lld{{.*}}-r
239239
// RELOCATABLE-LINK-CUDA: llvm-objcopy{{.*}}a.out --remove-section .llvm.offloading

clang/test/Driver/lto-dwo.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
11
// Confirm that -gsplit-dwarf=DIR is passed to linker
22

3-
// RUN: %clang --target=x86_64-unknown-linux -### %s -flto=thin -gsplit-dwarf -o a.out 2> %t
3+
// DEFINE: %{RUN-ELF} = %clang --target=x86_64-unknown-linux -### %s \
4+
// DEFINE: -flto=thin -gsplit-dwarf
5+
6+
// RUN: %{RUN-ELF} -o a.out 2> %t
47
// RUN: FileCheck -check-prefix=CHECK-LINK-ELF-DWO-DIR-DEFAULT < %t %s
58
// RUN: %clang_cl --target=x86_64-unknown-windows-msvc -### -fuse-ld=lld -flto -gsplit-dwarf -o a.out -- %s 2> %t
69
// RUN: FileCheck -check-prefix=CHECK-LINK-COFF-DWO-DIR-DEFAULT < %t %s
710
//
8-
// CHECK-LINK-ELF-DWO-DIR-DEFAULT: "-plugin-opt=dwo_dir=a.out_dwo"
11+
// CHECK-LINK-ELF-DWO-DIR-DEFAULT: "-plugin-opt=dwo_dir=a.out-dwo"
912
// CHECK-LINK-COFF-DWO-DIR-DEFAULT: "/dwodir:a.out_dwo"
13+
14+
// Check -dumpdir effect on -gsplit-dwarf.
15+
//
16+
// DEFINE: %{RUN-DUMPDIR} = %{RUN-ELF} -dumpdir /dir/file.ext
17+
//
18+
// RUN: %{RUN-ELF} 2>&1 | FileCheck %s -check-prefix=CHECK-NO-O
19+
// RUN: %{RUN-ELF} -o FOO 2>&1 | FileCheck %s -check-prefix=CHECK-O
20+
// RUN: %{RUN-DUMPDIR} 2>&1 | FileCheck %s -check-prefix=CHECK-DUMPDIR
21+
// RUN: %{RUN-DUMPDIR} -o FOO 2>&1 | FileCheck %s -check-prefix=CHECK-DUMPDIR
22+
//
23+
// CHECK-NO-O: "-plugin-opt=dwo_dir=a-dwo"
24+
// CHECK-O: "-plugin-opt=dwo_dir=FOO-dwo"
25+
// CHECK-DUMPDIR: "-plugin-opt=dwo_dir=/dir/file.extdwo"

clang/test/Driver/opt-record.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@
5858
// CHECK-NOPASS-NOT: "-plugin-opt=opt-remarks-format=yaml"
5959
// CHECK-NOPASS-NOT: "-plugin-opt=opt-remarks-hotness-threshold=100"
6060

61-
// CHECK-PASS-A: "-plugin-opt=opt-remarks-filename=a.out.opt.ld.yaml"
61+
// CHECK-PASS-A: "-plugin-opt=opt-remarks-filename=a-opt.ld.yaml"
6262
// CHECK-PASS-A-SAME: "-plugin-opt=opt-remarks-passes=inline"
6363
// CHECK-PASS-A-SAME: "-plugin-opt=opt-remarks-format=yaml"
6464
// CHECK-PASS-A-SAME: "-plugin-opt=opt-remarks-hotness-threshold=100"
6565

66-
// CHECK-PASS: "-plugin-opt=opt-remarks-filename=FOO.opt.ld.yaml"
66+
// CHECK-PASS: "-plugin-opt=opt-remarks-filename=FOO-opt.ld.yaml"
6767
// CHECK-PASS-SAME: "-plugin-opt=opt-remarks-passes=inline"
6868
// CHECK-PASS-SAME: "-plugin-opt=opt-remarks-format=yaml"
6969
// CHECK-PASS-SAME: "-plugin-opt=opt-remarks-hotness-threshold=100"
@@ -78,3 +78,17 @@
7878
// CHECK-PASS-RPASS-SAME: "-plugin-opt=opt-remarks-hotness-threshold=100"
7979

8080
// CHECK-PASS-AUTO: "-plugin-opt=opt-remarks-hotness-threshold=auto"
81+
82+
// Check -dumpdir effect on -foptimization-record-file.
83+
//
84+
// DEFINE: %{RUN-DUMPDIR} = \
85+
// DEFINE: %clang --target=x86_64-linux -### -fuse-ld=lld -B%S/Inputs/lld \
86+
// DEFINE: -flto -fsave-optimization-record -dumpdir /dir/file.ext %s
87+
//
88+
// RUN: %{RUN-DUMPDIR} 2>&1 | FileCheck %s -check-prefix=CHECK-DUMPDIR
89+
// RUN: %{RUN-DUMPDIR} -o FOO 2>&1 | FileCheck %s -check-prefix=CHECK-DUMPDIR
90+
// RUN: %{RUN-DUMPDIR} -foptimization-record-file=user-file.ext 2>&1 | \
91+
// RUN: FileCheck %s -check-prefix=CHECK-DUMPDIR-IGNORE
92+
//
93+
// CHECK-DUMPDIR: "-plugin-opt=opt-remarks-filename=/dir/file.extopt.ld.yaml"
94+
// CHECK-DUMPDIR-IGNORE: "-plugin-opt=opt-remarks-filename=user-file.ext.opt.ld.yaml"

0 commit comments

Comments
 (0)