Skip to content

Commit 90bf3ec

Browse files
committed
[clang-offload-bundler] Add option -list
clang-offload-bundler is not only used by clang driver to bundle/unbundle files for offloading toolchains, but also used by out of tree tools to unbundle fat binaries generated by clang. It is important to be able to list the bundle IDs in a bundled file so that the bundles can be extracted. This patch adds an option -list to list bundle ID's in a bundled file. Each bundle ID is separated by new line. If the file is not a bundled file nothing is output and returns 0. Differential Revision: https://reviews.llvm.org/D92954
1 parent f6f6f63 commit 90bf3ec

File tree

2 files changed

+192
-41
lines changed

2 files changed

+192
-41
lines changed

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

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
// CK-HELP: {{.*}}USAGE: clang-offload-bundler [options]
3636
// CK-HELP: {{.*}}-allow-missing-bundles {{.*}}- Create empty files if bundles are missing when unbundling
3737
// CK-HELP: {{.*}}-inputs=<string> - [<input file>,...]
38+
// CK-HELP: {{.*}}-list {{.*}}- List bundle IDs in the bundled file.
3839
// CK-HELP: {{.*}}-outputs=<string> - [<output file>,...]
3940
// CK-HELP: {{.*}}-targets=<string> - [<offload kind>-<target triple>,...]
4041
// CK-HELP: {{.*}}-type=<string> - Type of the files to be bundled/unbundled.
@@ -54,15 +55,16 @@
5455
//
5556
// RUN: not clang-offload-bundler -type=i -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -inputs=%t.i,%t.tgt1,%t.tgt2 -outputs=%t.bundle.i -unbundle 2>&1 | FileCheck %s --check-prefix CK-ERR1
5657
// CK-ERR1: error: only one input file supported in unbundling mode
57-
// CK-ERR1: error: number of output files and targets should match in unbundling mode
58+
59+
// RUN: not clang-offload-bundler -type=i -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -inputs=%t.i -outputs=%t.bundle.i -unbundle 2>&1 | FileCheck %s --check-prefix CK-ERR1A
60+
// CK-ERR1A: error: number of output files and targets should match in unbundling mode
5861

5962
// RUN: not clang-offload-bundler -type=i -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu -inputs=%t.i,%t.tgt1,%t.tgt2 -outputs=%t.bundle.i 2>&1 | FileCheck %s --check-prefix CK-ERR2
6063
// RUN: not clang-offload-bundler -type=i -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -inputs=%t.i,%t.tgt1 -outputs=%t.bundle.i 2>&1 | FileCheck %s --check-prefix CK-ERR2
6164
// CK-ERR2: error: number of input files and targets should match in bundling mode
6265

6366
// RUN: not clang-offload-bundler -type=i -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -outputs=%t.i,%t.tgt1,%t.tgt2 -inputs=%t.bundle.i 2>&1 | FileCheck %s --check-prefix CK-ERR3
6467
// CK-ERR3: error: only one output file supported in bundling mode
65-
// CK-ERR3: error: number of input files and targets should match in bundling mode
6668

6769
// RUN: not clang-offload-bundler -type=i -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu -outputs=%t.i,%t.tgt1,%t.tgt2 -inputs=%t.bundle.i -unbundle 2>&1 | FileCheck %s --check-prefix CK-ERR4
6870
// RUN: not clang-offload-bundler -type=i -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -outputs=%t.i,%t.tgt1 -inputs=%t.bundle.i -unbundle 2>&1 | FileCheck %s --check-prefix CK-ERR4
@@ -76,19 +78,27 @@
7678
// CK-ERR6: error: '[[TYPE]]': invalid file type specified
7779

7880
// RUN: not clang-offload-bundler 2>&1 | FileCheck %s --check-prefix CK-ERR7
79-
// CK-ERR7-DAG: clang-offload-bundler: for the --type option: must be specified at least once!
80-
// CK-ERR7-DAG: clang-offload-bundler: for the --inputs option: must be specified at least once!
81-
// CK-ERR7-DAG: clang-offload-bundler: for the --outputs option: must be specified at least once!
82-
// CK-ERR7-DAG: clang-offload-bundler: for the --targets option: must be specified at least once!
81+
// CK-ERR7: clang-offload-bundler: for the --type option: must be specified at least once!
82+
83+
// RUN: not clang-offload-bundler -type=i -inputs=%t.i,%t.tgt1,%t.tgt2 2>&1 | FileCheck %s -check-prefix=CK-ERR7A
84+
// CK-ERR7A: error: for the --outputs option: must be specified at least once!
85+
86+
// RUN: not clang-offload-bundler -type=i -inputs=%t.i,%t.tgt1,%t.tgt2 -outputs=%t.bundle.i 2>&1 | FileCheck %s -check-prefix=CK-ERR7B
87+
// CK-ERR7B: error: for the --targets option: must be specified at least once!
8388

8489
// RUN: not clang-offload-bundler -type=i -targets=hxst-powerpcxxle-ibm-linux-gnu,openxp-pxxerpc64le-ibm-linux-gnu,xpenmp-x86_xx-pc-linux-gnu -inputs=%t.i,%t.tgt1,%t.tgt2 -outputs=%t.bundle.i 2>&1 | FileCheck %s --check-prefix CK-ERR8
8590
// CK-ERR8: error: invalid target 'hxst-powerpcxxle-ibm-linux-gnu', unknown offloading kind 'hxst', unknown target triple 'powerpcxxle-ibm-linux-gnu'
86-
// CK-ERR8: error: invalid target 'openxp-pxxerpc64le-ibm-linux-gnu', unknown offloading kind 'openxp', unknown target triple 'pxxerpc64le-ibm-linux-gnu'
87-
// CK-ERR8: error: invalid target 'xpenmp-x86_xx-pc-linux-gnu', unknown offloading kind 'xpenmp', unknown target triple 'x86_xx-pc-linux-gnu'
91+
92+
// RUN: not clang-offload-bundler -type=i -targets=host-powerpc64le-ibm-linux-gnu,openxp-pxxerpc64le-ibm-linux-gnu,xpenmp-x86_xx-pc-linux-gnu -inputs=%t.i,%t.tgt1,%t.tgt2 -outputs=%t.bundle.i 2>&1 | FileCheck %s --check-prefix CK-ERR8A
93+
// CK-ERR8A: error: invalid target 'openxp-pxxerpc64le-ibm-linux-gnu', unknown offloading kind 'openxp', unknown target triple 'pxxerpc64le-ibm-linux-gnu'
94+
95+
// RUN: not clang-offload-bundler -type=i -targets=host-powerpc64le-ibm-linux-gnu,openmp-powerpc64le-ibm-linux-gnu,xpenmp-x86_xx-pc-linux-gnu -inputs=%t.i,%t.tgt1,%t.tgt2 -outputs=%t.bundle.i 2>&1 | FileCheck %s --check-prefix CK-ERR8B
96+
// CK-ERR8B: error: invalid target 'xpenmp-x86_xx-pc-linux-gnu', unknown offloading kind 'xpenmp', unknown target triple 'x86_xx-pc-linux-gnu'
8897

8998
// RUN: not clang-offload-bundler -type=i -targets=openmp-powerpc64le-linux,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -inputs=%t.i,%t.tgt1,%t.tgt2 -outputs=%t.bundle.i 2>&1 | FileCheck %s --check-prefix CK-ERR9A
90-
// RUN: not clang-offload-bundler -type=i -targets=host-%itanium_abi_triple,host-%itanium_abi_triple,openmp-x86_64-pc-linux-gnu -inputs=%t.i,%t.tgt1,%t.tgt2 -outputs=%t.bundle.i 2>&1 | FileCheck %s --check-prefix CK-ERR9B
9199
// CK-ERR9A: error: expecting exactly one host target but got 0
100+
101+
// RUN: not clang-offload-bundler -type=i -targets=host-%itanium_abi_triple,host-%itanium_abi_triple,openmp-x86_64-pc-linux-gnu -inputs=%t.i,%t.tgt1,%t.tgt2 -outputs=%t.bundle.i 2>&1 | FileCheck %s --check-prefix CK-ERR9B
92102
// CK-ERR9B: error: Duplicate targets are not allowed
93103

94104
//
@@ -152,24 +162,28 @@
152162
//
153163
// Check text unbundle. Check if we get the exact same content that we bundled before for each file.
154164
//
165+
// RUN: clang-offload-bundler -type=i -inputs=%t.bundle3.i -list | FileCheck -check-prefix=CKLST %s
155166
// RUN: clang-offload-bundler -type=i -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -outputs=%t.res.i,%t.res.tgt1,%t.res.tgt2 -inputs=%t.bundle3.i -unbundle
156167
// RUN: diff %t.i %t.res.i
157168
// RUN: diff %t.tgt1 %t.res.tgt1
158169
// RUN: diff %t.tgt2 %t.res.tgt2
159170
// RUN: clang-offload-bundler -type=i -targets=openmp-powerpc64le-ibm-linux-gnu -outputs=%t.res.tgt1 -inputs=%t.bundle3.i -unbundle
160171
// RUN: diff %t.tgt1 %t.res.tgt1
172+
// RUN: clang-offload-bundler -type=ii -inputs=%t.bundle3.ii -list | FileCheck -check-prefix=CKLST %s
161173
// 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
162174
// RUN: diff %t.ii %t.res.ii
163175
// RUN: diff %t.tgt1 %t.res.tgt1
164176
// RUN: diff %t.tgt2 %t.res.tgt2
165177
// RUN: clang-offload-bundler -type=ii -targets=openmp-x86_64-pc-linux-gnu -outputs=%t.res.tgt2 -inputs=%t.bundle3.ii -unbundle
166178
// RUN: diff %t.tgt2 %t.res.tgt2
179+
// RUN: clang-offload-bundler -type=ll -inputs=%t.bundle3.ll -list | FileCheck -check-prefix=CKLST %s
167180
// 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
168181
// RUN: diff %t.ll %t.res.ll
169182
// RUN: diff %t.tgt1 %t.res.tgt1
170183
// RUN: diff %t.tgt2 %t.res.tgt2
171184
// RUN: clang-offload-bundler -type=ll -targets=openmp-powerpc64le-ibm-linux-gnu -outputs=%t.res.tgt1 -inputs=%t.bundle3.ll -unbundle
172185
// RUN: diff %t.tgt1 %t.res.tgt1
186+
// RUN: clang-offload-bundler -type=s -inputs=%t.bundle3.s -list | FileCheck -check-prefix=CKLST %s
173187
// 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
174188
// RUN: diff %t.s %t.res.s
175189
// RUN: diff %t.tgt1 %t.res.tgt1
@@ -182,6 +196,7 @@
182196
// RUN: diff %t.tgt2 %t.res.tgt2
183197

184198
// Check if we can unbundle a file with no magic strings.
199+
// RUN: clang-offload-bundler -type=s -inputs=%t.s -list | FileCheck -check-prefix=CKLST2 --allow-empty %s
185200
// 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 -allow-missing-bundles
186201
// RUN: diff %t.s %t.res.s
187202
// RUN: diff %t.empty %t.res.tgt1
@@ -202,18 +217,21 @@
202217
// RUN: clang-offload-bundler -type=gch -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -inputs=%t.ast,%t.tgt1,%t.tgt2 -outputs=%t.bundle3.gch
203218
// RUN: clang-offload-bundler -type=ast -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -inputs=%t.ast,%t.tgt1,%t.tgt2 -outputs=%t.bundle3.ast
204219
// RUN: clang-offload-bundler -type=ast -targets=openmp-powerpc64le-ibm-linux-gnu,host-%itanium_abi_triple,openmp-x86_64-pc-linux-gnu -inputs=%t.tgt1,%t.ast,%t.tgt2 -outputs=%t.bundle3.unordered.ast
220+
// RUN: clang-offload-bundler -type=bc -inputs=%t.bundle3.bc -list | FileCheck -check-prefix=CKLST %s
205221
// 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.bundle3.bc -unbundle
206222
// RUN: diff %t.bc %t.res.bc
207223
// RUN: diff %t.tgt1 %t.res.tgt1
208224
// RUN: diff %t.tgt2 %t.res.tgt2
209225
// RUN: clang-offload-bundler -type=bc -targets=openmp-powerpc64le-ibm-linux-gnu -outputs=%t.res.tgt1 -inputs=%t.bundle3.bc -unbundle
210226
// RUN: diff %t.tgt1 %t.res.tgt1
227+
// RUN: clang-offload-bundler -type=gch -inputs=%t.bundle3.gch -list | FileCheck -check-prefix=CKLST %s
211228
// 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
212229
// RUN: diff %t.ast %t.res.gch
213230
// RUN: diff %t.tgt1 %t.res.tgt1
214231
// RUN: diff %t.tgt2 %t.res.tgt2
215232
// RUN: clang-offload-bundler -type=gch -targets=openmp-x86_64-pc-linux-gnu -outputs=%t.res.tgt2 -inputs=%t.bundle3.gch -unbundle
216233
// RUN: diff %t.tgt2 %t.res.tgt2
234+
// RUN: clang-offload-bundler -type=ast -inputs=%t.bundle3.ast -list | FileCheck -check-prefix=CKLST %s
217235
// 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
218236
// RUN: diff %t.ast %t.res.ast
219237
// RUN: diff %t.tgt1 %t.res.tgt1
@@ -258,6 +276,7 @@
258276
// CK-OBJ-CMD: llvm-objcopy{{(.exe)?}}" "--set-section-flags=__CLANG_OFFLOAD_BUNDLE__host-[[HOST]]=readonly,exclude" "--set-section-flags=__CLANG_OFFLOAD_BUNDLE__openmp-powerpc64le-ibm-linux-gnu=readonly,exclude" "--set-section-flags=__CLANG_OFFLOAD_BUNDLE__openmp-x86_64-pc-linux-gnu=readonly,exclude" "[[TEMPOBJ]]" "[[OUTOBJ]]"
259277

260278
// RUN: clang-offload-bundler -type=o -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -inputs=%t.o,%t.tgt1,%t.tgt2 -outputs=%t.bundle3.o
279+
// RUN: clang-offload-bundler -type=o -inputs=%t.bundle3.o -list | FileCheck -check-prefix=CKLST %s
261280
// 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.bundle3.o -unbundle
262281
// RUN: diff %t.bundle3.o %t.res.o
263282
// RUN: diff %t.tgt1 %t.res.tgt1
@@ -270,6 +289,7 @@
270289
// RUN: diff %t.tgt1 %t.res.tgt1
271290

272291
// Check if we can unbundle a file with no magic strings.
292+
// RUN: clang-offload-bundler -type=o -inputs=%t.o -list | FileCheck -check-prefix=CKLST2 --allow-empty %s
273293
// 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 -allow-missing-bundles
274294
// RUN: diff %t.o %t.res.o
275295
// RUN: diff %t.empty %t.res.tgt1
@@ -318,6 +338,27 @@
318338
// RUN: -targets=hip-amdgcn-amd-amdhsa-gfx906,hip-amdgcn-amd-amdhsa-gfx906 \
319339
// RUN: 2>&1 | FileCheck -check-prefix=DUP %s
320340
// DUP: error: Duplicate targets are not allowed
341+
//
342+
// Check -list option
343+
//
344+
345+
// RUN: clang-offload-bundler -bundle-align=4096 -type=bc -targets=host-%itanium_abi_triple,openmp-powerpc64le-ibm-linux-gnu,openmp-x86_64-pc-linux-gnu -inputs=%t.bc,%t.tgt1,%t.tgt2 -outputs=%t.bundle3.bc
346+
// RUN: not clang-offload-bundler -type=bc -inputs=%t.bundle3.bc -unbundle -list 2>&1 | FileCheck -check-prefix=CKLST-ERR %s
347+
// CKLST-ERR: error: -unbundle and -list cannot be used together
348+
// RUN: not clang-offload-bundler -type=bc -inputs=%t.bundle3.bc -targets=host-%itanium_abi_triple -list 2>&1 | FileCheck -check-prefix=CKLST-ERR2 %s
349+
// CKLST-ERR2: error: -targets option is invalid for -list
350+
// RUN: not clang-offload-bundler -type=bc -inputs=%t.bundle3.bc -outputs=out.txt -list 2>&1 | FileCheck -check-prefix=CKLST-ERR3 %s
351+
// CKLST-ERR3: error: -outputs option is invalid for -list
352+
// RUN: not clang-offload-bundler -type=bc -inputs=%t.bundle3.bc,%t.bc -list 2>&1 | FileCheck -check-prefix=CKLST-ERR4 %s
353+
// CKLST-ERR4: error: only one input file supported for -list
354+
355+
// CKLST-DAG: host-
356+
// CKLST-DAG: openmp-powerpc64le-ibm-linux-gnu
357+
// CKLST-DAG: openmp-x86_64-pc-linux-gnu
358+
359+
// CKLST2-NOT: host-
360+
// CKLST2-NOT: openmp-powerpc64le-ibm-linux-gnu
361+
// CKLST2-NOT: openmp-x86_64-pc-linux-gnu
321362

322363
// Some code so that we can create a binary out of this file.
323364
int A = 0;

0 commit comments

Comments
 (0)