Skip to content

Commit 60a99f4

Browse files
committed
[Clang][Bundler] Do not require host triple for extracting device bundles
Bundler currently requires host triple to be provided no matter if you are performing bundling or unbundling, but for unbundling operation such requirement is too restrictive. You may for example want to examine device part of the object for a particular offload target, but you have to extract host part as well even though you do not need it. Host triple isn't really needed for unbundling, so this patch removes that requirement. Differential Revision: https://reviews.llvm.org/D66601 llvm-svn: 370143
1 parent 57076d3 commit 60a99f4

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

clang/test/Driver/clang-offload-bundler.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,20 @@
156156
// RUN: diff %t.i %t.res.i
157157
// RUN: diff %t.tgt1 %t.res.tgt1
158158
// RUN: diff %t.tgt2 %t.res.tgt2
159+
// RUN: clang-offload-bundler -type=i -targets=openmp-powerpc64le-ibm-linux-gnu -outputs=%t.res.tgt1 -inputs=%t.bundle3.i -unbundle
160+
// RUN: diff %t.tgt1 %t.res.tgt1
159161
// RUN: clang-offload-bundler -type=ii -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -outputs=%t.res.ii,%t.res.tgt1,%t.res.tgt2 -inputs=%t.bundle3.ii -unbundle
160162
// RUN: diff %t.ii %t.res.ii
161163
// RUN: diff %t.tgt1 %t.res.tgt1
162164
// RUN: diff %t.tgt2 %t.res.tgt2
165+
// RUN: clang-offload-bundler -type=ii -targets=openmp-x86_64-pc-linux-gnu -outputs=%t.res.tgt2 -inputs=%t.bundle3.ii -unbundle
166+
// RUN: diff %t.tgt2 %t.res.tgt2
163167
// RUN: clang-offload-bundler -type=ll -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -outputs=%t.res.ll,%t.res.tgt1,%t.res.tgt2 -inputs=%t.bundle3.ll -unbundle
164168
// RUN: diff %t.ll %t.res.ll
165169
// RUN: diff %t.tgt1 %t.res.tgt1
166170
// RUN: diff %t.tgt2 %t.res.tgt2
171+
// RUN: clang-offload-bundler -type=ll -targets=openmp-powerpc64le-ibm-linux-gnu -outputs=%t.res.tgt1 -inputs=%t.bundle3.ll -unbundle
172+
// RUN: diff %t.tgt1 %t.res.tgt1
167173
// RUN: clang-offload-bundler -type=s -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -outputs=%t.res.s,%t.res.tgt1,%t.res.tgt2 -inputs=%t.bundle3.s -unbundle
168174
// RUN: diff %t.s %t.res.s
169175
// RUN: diff %t.tgt1 %t.res.tgt1
@@ -172,6 +178,8 @@
172178
// RUN: diff %t.s %t.res.s
173179
// RUN: diff %t.tgt1 %t.res.tgt1
174180
// RUN: diff %t.tgt2 %t.res.tgt2
181+
// RUN: clang-offload-bundler -type=s -targets=openmp-x86_64-pc-linux-gnu -outputs=%t.res.tgt2 -inputs=%t.bundle3.s -unbundle
182+
// RUN: diff %t.tgt2 %t.res.tgt2
175183

176184
// Check if we can unbundle a file with no magic strings.
177185
// RUN: clang-offload-bundler -type=s -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -outputs=%t.res.s,%t.res.tgt1,%t.res.tgt2 -inputs=%t.s -unbundle
@@ -183,6 +191,10 @@
183191
// RUN: diff %t.empty %t.res.tgt1
184192
// RUN: diff %t.empty %t.res.tgt2
185193

194+
// Check that bindler prints an error if given host bundle does not exist in the fat binary.
195+
// RUN: not clang-offload-bundler -type=s -targets=host-x86_64-xxx-linux-gnu,openmp-powerpc64le-ibm-linux-gnu -outputs=%t.res.s,%t.res.tgt1 -inputs=%t.bundle3.s -unbundle 2>&1 | FileCheck %s --check-prefix CK-NO-HOST-BUNDLE
196+
// CK-NO-HOST-BUNDLE: error: Can't find bundle for the host target
197+
186198
//
187199
// Check binary bundle/unbundle. The content that we have before bundling must be the same we have after unbundling.
188200
//
@@ -194,10 +206,14 @@
194206
// RUN: diff %t.bc %t.res.bc
195207
// RUN: diff %t.tgt1 %t.res.tgt1
196208
// RUN: diff %t.tgt2 %t.res.tgt2
209+
// RUN: clang-offload-bundler -type=bc -targets=openmp-powerpc64le-ibm-linux-gnu -outputs=%t.res.tgt1 -inputs=%t.bundle3.bc -unbundle
210+
// RUN: diff %t.tgt1 %t.res.tgt1
197211
// RUN: clang-offload-bundler -type=gch -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -outputs=%t.res.gch,%t.res.tgt1,%t.res.tgt2 -inputs=%t.bundle3.gch -unbundle
198212
// RUN: diff %t.ast %t.res.gch
199213
// RUN: diff %t.tgt1 %t.res.tgt1
200214
// RUN: diff %t.tgt2 %t.res.tgt2
215+
// RUN: clang-offload-bundler -type=gch -targets=openmp-x86_64-pc-linux-gnu -outputs=%t.res.tgt2 -inputs=%t.bundle3.gch -unbundle
216+
// RUN: diff %t.tgt2 %t.res.tgt2
201217
// RUN: clang-offload-bundler -type=ast -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -outputs=%t.res.ast,%t.res.tgt1,%t.res.tgt2 -inputs=%t.bundle3.ast -unbundle
202218
// RUN: diff %t.ast %t.res.ast
203219
// RUN: diff %t.tgt1 %t.res.tgt1
@@ -210,6 +226,8 @@
210226
// RUN: diff %t.ast %t.res.ast
211227
// RUN: diff %t.tgt1 %t.res.tgt1
212228
// RUN: diff %t.tgt2 %t.res.tgt2
229+
// RUN: clang-offload-bundler -type=ast -targets=openmp-powerpc64le-ibm-linux-gnu -outputs=%t.res.tgt1 -inputs=%t.bundle3.ast -unbundle
230+
// RUN: diff %t.tgt1 %t.res.tgt1
213231

214232
// Check if we can unbundle a file with no magic strings.
215233
// RUN: clang-offload-bundler -type=bc -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -outputs=%t.res.bc,%t.res.tgt1,%t.res.tgt2 -inputs=%t.bc -unbundle
@@ -247,6 +265,8 @@
247265
// RUN: diff %t.o %t.res.o
248266
// RUN: diff %t.tgt1 %t.res.tgt1
249267
// RUN: diff %t.tgt2 %t.res.tgt2
268+
// RUN: clang-offload-bundler -type=o -targets=openmp-powerpc64le-ibm-linux-gnu -outputs=%t.res.tgt1 -inputs=%t.bundle3.o -unbundle
269+
// RUN: diff %t.tgt1 %t.res.tgt1
250270

251271
// Check if we can unbundle a file with no magic strings.
252272
// RUN: clang-offload-bundler -type=o -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -outputs=%t.res.o,%t.res.tgt1,%t.res.tgt2 -inputs=%t.o -unbundle

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -791,8 +791,9 @@ static bool UnbundleFiles() {
791791
return false;
792792
}
793793

794-
// If we found elements, we emit an error if none of those were for the host.
795-
if (!FoundHostBundle) {
794+
// If we found elements, we emit an error if none of those were for the host
795+
// in case host bundle name was provided in command line.
796+
if (!FoundHostBundle && HostInputIndex != ~0u) {
796797
errs() << "error: Can't find bundle for the host target\n";
797798
return true;
798799
}
@@ -895,7 +896,9 @@ int main(int argc, const char **argv) {
895896
++Index;
896897
}
897898

898-
if (HostTargetNum != 1) {
899+
// Host triple is not really needed for unbundling operation, so do not
900+
// treat missing host triple as error if we do unbundling.
901+
if ((Unbundle && HostTargetNum > 1) || (!Unbundle && HostTargetNum != 1)) {
899902
Error = true;
900903
errs() << "error: expecting exactly one host target but got "
901904
<< HostTargetNum << ".\n";

0 commit comments

Comments
 (0)