Skip to content

Commit 4b55329

Browse files
committed
[clang-offload-bundler] Reuse original file extension for device archive member
This patch changes clang-offload-bundler to use the original file extension for the device archive member when unbundling archives instead of printing a warning and defaulting to ".o". Differential Revision: https://reviews.llvm.org/D114776
1 parent 15826eb commit 4b55329

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// REQUIRES: x86-registered-target
2+
// UNSUPPORTED: windows, darwin, aix
3+
4+
// Generate dummy fat object
5+
// RUN: %clang -O0 -target %itanium_abi_triple %s -c -o %t.host.o
6+
// RUN: echo 'Content of device file' > %t.tgt.o
7+
// RUN: clang-offload-bundler -type=o -targets=host-%itanium_abi_triple,openmp-%itanium_abi_triple -inputs=%t.host.o,%t.tgt.o -outputs=%t.fat.obj
8+
9+
// Then create a static archive with that object
10+
// RUN: rm -f %t.fat.a
11+
// RUN: llvm-ar cr %t.fat.a %t.fat.obj
12+
13+
// Unbundle device part from the archive. Check that bundler does not print warnings.
14+
// RUN: clang-offload-bundler -unbundle -type=a -targets=openmp-%itanium_abi_triple -inputs=%t.fat.a -outputs=%t.tgt.a 2>&1 | FileCheck --allow-empty --check-prefix=CHECK-WARNING %s
15+
// CHECK-WARNING-NOT: warning
16+
17+
// Check that device archive member inherited file extension from the original file.
18+
// RUN: llvm-ar t %t.tgt.a | FileCheck --check-prefix=CHECK-ARCHIVE %s
19+
// CHECK-ARCHIVE: {{\.obj$}}
20+
21+
void foo(void) {}

clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,21 +180,19 @@ struct OffloadTargetInfo {
180180
}
181181
};
182182

183-
static StringRef getDeviceFileExtension(StringRef Device) {
183+
static StringRef getDeviceFileExtension(StringRef Device,
184+
StringRef BundleFileName) {
184185
if (Device.contains("gfx"))
185186
return ".bc";
186187
if (Device.contains("sm_"))
187188
return ".cubin";
188-
189-
WithColor::warning() << "Could not determine extension for archive"
190-
"members, using \".o\"\n";
191-
return ".o";
189+
return sys::path::extension(BundleFileName);
192190
}
193191

194192
static std::string getDeviceLibraryFileName(StringRef BundleFileName,
195193
StringRef Device) {
196194
StringRef LibName = sys::path::stem(BundleFileName);
197-
StringRef Extension = getDeviceFileExtension(Device);
195+
StringRef Extension = getDeviceFileExtension(Device, BundleFileName);
198196

199197
std::string Result;
200198
Result += LibName;

0 commit comments

Comments
 (0)