Skip to content

Commit 5b8f3b0

Browse files
authored
[clang-offload-extract] Ignore zero padding in .tgting section (#4622)
This patch changes clang-offload-extract to ignore zero padding when reading .tgtimg section contents. Such padding can be added to the section by (msvc) linker. Signed-off-by: Sergey Dmitriev <serguei.n.dmitriev@intel.com>
1 parent 2404d02 commit 5b8f3b0

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
// RUN: echo 'Target image 1' > %t.bin0
2424
// RUN: echo 'Target image 2' > %t.bin1
2525
// RUN: clang-offload-wrapper -kind=openmp -target=tg0 %t.bin0 -kind=sycl -target=tg1 %t.bin1 -o %t.wrapped.bc
26-
// RUN: %clang %s %t.wrapped.bc -o %t.fat.bin
26+
// RUN: %clang -fdeclspec %s %t.wrapped.bc -o %t.fat.bin
2727

2828
//
2929
// Extract target images.
@@ -41,6 +41,11 @@
4141
//
4242
// Some code so that we can build an offload executable from this file.
4343
//
44+
#pragma section(".tgtimg", read)
45+
__declspec(allocate(".tgtimg"))
46+
__declspec(align(sizeof(void*) * 2))
47+
const void* padding[2] = {0, 0};
48+
4449
#ifdef _WIN32
4550
char __start_omp_offloading_entries = 1;
4651
char __stop_omp_offloading_entries = 1;

clang/tools/clang-offload-extract/ClangOffloadExtract.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ int main(int argc, const char **argv) {
124124
DataOrErr->size() / sizeof(ImgInfoTy));
125125

126126
for (auto &Img : ImgInfo) {
127+
// Ignore zero padding that can be inserted by the linker.
128+
if (!Img.Addr)
129+
continue;
130+
127131
// Find section which contains this image.
128132
// TODO: can use more efficient algorithm than linear search. For example
129133
// sections and images could be sorted by address then one pass performed

0 commit comments

Comments
 (0)