Skip to content

Commit 93d08ac

Browse files
author
Vyacheslav Zakharin
committed
[clang-offload-wrapper] Add standard notes for ELF offload images
The patch adds ELF notes into SHT_NOTE sections of ELF offload images passed to clang-offload-wrapper. The new notes use a null-terminated "LLVMOMPOFFLOAD" note name. There are currently three types of notes: VERSION: a string (not null-terminated) representing the ELF offload image structure. The current version '1.0' does not put any restrictions on the structure of the image. If we ever need to come up with a common structure for ELF offload images (e.g. to be able to analyze the images in libomptarget in some standard way), then we will introduce new versions. PRODUCER: a vendor specific name of the producing toolchain. Upstream LLVM uses "LLVM" (not null-terminated). PRODUCER_VERSION: a vendor specific version of the producing toolchain. Upstream LLVM uses LLVM_VERSION_STRING with optional <space> LLVM_REVISION. All three notes are not mandatory currently. Differential Revision: https://reviews.llvm.org/D99551
1 parent 877572c commit 93d08ac

File tree

4 files changed

+318
-7
lines changed

4 files changed

+318
-7
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
--- !ELF
2+
FileHeader:
3+
Class: ELFCLASS[[BITS]]
4+
Data: ELFDATA2[[ENCODING]]
5+
Type: ET_REL

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919
//
2020
// Check bitcode produced by the wrapper tool.
2121
//
22-
// RUN: clang-offload-wrapper -target=x86_64-pc-linux-gnu -o %t.wrapper.bc %t.tgt
22+
// RUN: clang-offload-wrapper -target=x86_64-pc-linux-gnu -o %t.wrapper.bc %t.tgt 2>&1 | FileCheck %s --check-prefix ELF-WARNING
2323
// RUN: llvm-dis %t.wrapper.bc -o - | FileCheck %s --check-prefix CHECK-IR
2424

25+
// ELF-WARNING: is not an ELF image, so notes cannot be added to it.
2526
// CHECK-IR: target triple = "x86_64-pc-linux-gnu"
2627

2728
// CHECK-IR-DAG: [[ENTTY:%.+]] = type { i8*, i8*, i{{32|64}}, i32, i32 }
@@ -53,3 +54,24 @@
5354
// CHECK-IR: ret void
5455

5556
// CHECK-IR: declare void @__tgt_unregister_lib([[DESCTY]]*)
57+
58+
// Check that clang-offload-wrapper adds LLVMOMPOFFLOAD notes
59+
// into the ELF offload images:
60+
// RUN: yaml2obj %S/Inputs/empty-elf-template.yaml -o %t.64le -DBITS=64 -DENCODING=LSB
61+
// RUN: clang-offload-wrapper -target=x86_64-pc-linux-gnu -o %t.wrapper.elf64le.bc %t.64le
62+
// RUN: llvm-dis %t.wrapper.elf64le.bc -o - | FileCheck %s --check-prefix OMPNOTES
63+
// RUN: yaml2obj %S/Inputs/empty-elf-template.yaml -o %t.64be -DBITS=64 -DENCODING=MSB
64+
// RUN: clang-offload-wrapper -target=x86_64-pc-linux-gnu -o %t.wrapper.elf64be.bc %t.64be
65+
// RUN: llvm-dis %t.wrapper.elf64be.bc -o - | FileCheck %s --check-prefix OMPNOTES
66+
// RUN: yaml2obj %S/Inputs/empty-elf-template.yaml -o %t.32le -DBITS=32 -DENCODING=LSB
67+
// RUN: clang-offload-wrapper -target=x86_64-pc-linux-gnu -o %t.wrapper.elf32le.bc %t.32le
68+
// RUN: llvm-dis %t.wrapper.elf32le.bc -o - | FileCheck %s --check-prefix OMPNOTES
69+
// RUN: yaml2obj %S/Inputs/empty-elf-template.yaml -o %t.32be -DBITS=32 -DENCODING=MSB
70+
// RUN: clang-offload-wrapper -target=x86_64-pc-linux-gnu -o %t.wrapper.elf32be.bc %t.32be
71+
// RUN: llvm-dis %t.wrapper.elf32be.bc -o - | FileCheck %s --check-prefix OMPNOTES
72+
73+
// There is no clean way for extracting the offload image
74+
// from the object file currently, so try to find
75+
// the inserted ELF notes in the device image variable's
76+
// initializer:
77+
// OMPNOTES: @{{.+}} = internal unnamed_addr constant [{{[0-9]+}} x i8] c"{{.*}}LLVMOMPOFFLOAD{{.*}}LLVMOMPOFFLOAD{{.*}}LLVMOMPOFFLOAD{{.*}}"

clang/tools/clang-offload-wrapper/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
set(LLVM_LINK_COMPONENTS BitWriter Core Support TransformUtils)
1+
set(LLVM_LINK_COMPONENTS BitWriter Core Object Support TransformUtils)
22

33
add_clang_tool(clang-offload-wrapper
44
ClangOffloadWrapper.cpp

0 commit comments

Comments
 (0)