This is an archive of the discontinued LLVM Phabricator instance.

[OpenMP] Use new offloading binary when embedding offloading images
ClosedPublic

Authored by jhuber6 on Mar 29 2022, 1:46 PM.

Details

Summary

The previous patch introduced the offloading binary format so we can
store some metada along with the binary image. This patch introduces
using this inside the linker wrapper and Clang instead of the previous
method that embedded the metadata in the section name.

Diff Detail

Event Timeline

jhuber6 created this revision.Mar 29 2022, 1:46 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 29 2022, 1:46 PM
jhuber6 requested review of this revision.Mar 29 2022, 1:46 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptMar 29 2022, 1:46 PM
jhuber6 updated this revision to Diff 419490.Mar 31 2022, 8:59 AM

Fixing unrelated formatting changes.

jhuber6 updated this revision to Diff 422580.Apr 13 2022, 11:36 AM

Fix test after move to opaque pointers.

jdoerfert added inline comments.Apr 15 2022, 2:53 PM
clang/test/Frontend/embed-object.ll
6

Can we salvage the test intention and embed two objects?

clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
314

This should be a proper conditional and error check.

319

Why is the cast at the call site not in the callee? Are these casts even necessary at all?

455

Isn't this 99% the same as above, from offset = 0 to the end?

jhuber6 updated this revision to Diff 423176.Apr 15 2022, 3:20 PM

Addressing comments.

jhuber6 marked 4 inline comments as done.Apr 15 2022, 3:21 PM
This revision is now accepted and ready to land.Apr 15 2022, 4:04 PM
This revision was landed with ongoing or failed builds.Apr 15 2022, 5:35 PM
This revision was automatically updated to reflect the committed changes.
mgorny added a subscriber: mgorny.Jul 21 2022, 5:52 AM

I'm sorry for noticing it this late but this change seems to have broken the test on 32-bit x86:

FAIL: Clang :: Frontend/embed-object.ll (8280 of 15613)
******************** TEST 'Clang :: Frontend/embed-object.ll' FAILED ********************
Script:
--
: 'RUN: at line 1';   /var/tmp/portage/sys-devel/clang-15.0.0.9999/work/x/y/clang-abi_x86_32.x86/bin/clang -cc1 -internal-isystem /var/tmp/portage/sys-devel/clang-15.0.0.9999/work/x/y/clang-abi_x86_32.x86/bin/../../../../lib/clang/15.0.0/include -nostdsysteminc -triple x86_64-unknown-linux-gnu -emit-llvm     -fembed-offload-object=/var/tmp/portage/sys-devel/clang-15.0.0.9999/work/clang/test/Frontend/Inputs/empty.h     -fembed-offload-object=/var/tmp/portage/sys-devel/clang-15.0.0.9999/work/clang/test/Frontend/Inputs/empty.h -x ir /var/tmp/portage/sys-devel/clang-15.0.0.9999/work/clang/test/Frontend/embed-object.ll -o -     | /usr/lib/llvm/15/bin/FileCheck /var/tmp/portage/sys-devel/clang-15.0.0.9999/work/clang/test/Frontend/embed-object.ll -check-prefix=CHECK
--
Exit Code: 1

Command Output (stderr):
--
+ : 'RUN: at line 1'
+ /var/tmp/portage/sys-devel/clang-15.0.0.9999/work/x/y/clang-abi_x86_32.x86/bin/clang -cc1 -internal-isystem /var/tmp/portage/sys-devel/clang-15.0.0.9999/work/x/y/clang-abi_x86_32.x86/bin/../../../../lib/clang/15.0.0/include -nostdsysteminc -triple x86_64-unknown-linux-gnu -emit-llvm -fembed-offload-object=/var/tmp/portage/sys-devel/clang-15.0.0.9999/work/clang/test/Frontend/Inputs/empty.h -fembed-offload-object=/var/tmp/portage/sys-devel/clang-15.0.0.9999/work/clang/test/Frontend/Inputs/empty.h -x ir /var/tmp/portage/sys-devel/clang-15.0.0.9999/work/clang/test/Frontend/embed-object.ll -o -
+ /usr/lib/llvm/15/bin/FileCheck /var/tmp/portage/sys-devel/clang-15.0.0.9999/work/clang/test/Frontend/embed-object.ll -check-prefix=CHECK
warning: overriding the module target triple with x86_64-unknown-linux-gnu [-Woverride-module]
1 warning generated.
/var/tmp/portage/sys-devel/clang-15.0.0.9999/work/clang/test/Frontend/embed-object.ll:6:10: error: CHECK: expected string not found in input
; CHECK: @[[OBJECT_1:.+]] = private constant [0 x i8] zeroinitializer, section ".llvm.offloading", align 8, !exclude
         ^
<stdin>:1:1: note: scanning from here
; ModuleID = '/var/tmp/portage/sys-devel/clang-15.0.0.9999/work/clang/test/Frontend/embed-object.ll'
^
<stdin>:8:20: note: possible intended match here
@llvm.embedded.object.1 = private constant [0 x i8] zeroinitializer, section ".llvm.offloading", align 4, !exclude !0
                   ^

Input file: <stdin>
Check file: /var/tmp/portage/sys-devel/clang-15.0.0.9999/work/clang/test/Frontend/embed-object.ll

-dump-input=help explains the following input dump.

Input was:
<<<<<<
           1: ; ModuleID = '/var/tmp/portage/sys-devel/clang-15.0.0.9999/work/clang/test/Frontend/embed-object.ll' 
check:6'0     X~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: no match found
           2: source_filename = "/var/tmp/portage/sys-devel/clang-15.0.0.9999/work/clang/test/Frontend/embed-object.ll" 
check:6'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           3: target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 
check:6'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           4: target triple = "x86_64-unknown-linux-gnu" 
check:6'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           5:  
check:6'0     ~
           6: @x = private constant i8 1 
check:6'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~
           7: @llvm.embedded.object = private constant [0 x i8] zeroinitializer, section ".llvm.offloading", align 4, !exclude !0 
check:6'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           8: @llvm.embedded.object.1 = private constant [0 x i8] zeroinitializer, section ".llvm.offloading", align 4, !exclude !0 
check:6'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
check:6'1                        ?                                                                                                   possible intended match
           9: @llvm.compiler.used = appending global [3 x ptr] [ptr @x, ptr @llvm.embedded.object, ptr @llvm.embedded.object.1], section "llvm.metadata" 
check:6'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          10:  
check:6'0     ~
          11: define i32 @foo() { 
check:6'0     ~~~~~~~~~~~~~~~~~~~~
          12:  ret i32 0 
check:6'0     ~~~~~~~~~~~
          13: } 
check:6'0     ~~
           .
           .
           .
>>>>>>

--

********************
FAIL: Clang :: Frontend/embed-object.c (8281 of 15613)
******************** TEST 'Clang :: Frontend/embed-object.c' FAILED ********************
Script:
--
: 'RUN: at line 1';   /var/tmp/portage/sys-devel/clang-15.0.0.9999/work/x/y/clang-abi_x86_32.x86/bin/clang -cc1 -internal-isystem /var/tmp/portage/sys-devel/clang-15.0.0.9999/work/x/y/clang-abi_x86_32.x86/bin/../../../../lib/clang/15.0.0/include -nostdsysteminc -x c -triple x86_64-unknown-linux-gnu -emit-llvm -fembed-offload-object=/var/tmp/portage/sys-devel/clang-15.0.0.9999/work/clang/test/Frontend/Inputs/empty.h -o - /var/tmp/portage/sys-devel/clang-15.0.0.9999/work/clang/test/Frontend/embed-object.c | /usr/lib/llvm/15/bin/FileCheck /var/tmp/portage/sys-devel/clang-15.0.0.9999/work/clang/test/Frontend/embed-object.c
--
Exit Code: 1

Command Output (stderr):
--
+ : 'RUN: at line 1'
+ /usr/lib/llvm/15/bin/FileCheck /var/tmp/portage/sys-devel/clang-15.0.0.9999/work/clang/test/Frontend/embed-object.c
+ /var/tmp/portage/sys-devel/clang-15.0.0.9999/work/x/y/clang-abi_x86_32.x86/bin/clang -cc1 -internal-isystem /var/tmp/portage/sys-devel/clang-15.0.0.9999/work/x/y/clang-abi_x86_32.x86/bin/../../../../lib/clang/15.0.0/include -nostdsysteminc -x c -triple x86_64-unknown-linux-gnu -emit-llvm -fembed-offload-object=/var/tmp/portage/sys-devel/clang-15.0.0.9999/work/clang/test/Frontend/Inputs/empty.h -o - /var/tmp/portage/sys-devel/clang-15.0.0.9999/work/clang/test/Frontend/embed-object.c
/var/tmp/portage/sys-devel/clang-15.0.0.9999/work/clang/test/Frontend/embed-object.c:3:11: error: CHECK: expected string not found in input
// CHECK: @[[OBJECT:.+]] = private constant [0 x i8] zeroinitializer, section ".llvm.offloading", align 8, !exclude
          ^
<stdin>:1:1: note: scanning from here
; ModuleID = '/var/tmp/portage/sys-devel/clang-15.0.0.9999/work/clang/test/Frontend/embed-object.c'
^
<stdin>:6:13: note: possible intended match here
@llvm.embedded.object = private constant [0 x i8] zeroinitializer, section ".llvm.offloading", align 4, !exclude !0
            ^

Input file: <stdin>
Check file: /var/tmp/portage/sys-devel/clang-15.0.0.9999/work/clang/test/Frontend/embed-object.c

-dump-input=help explains the following input dump.

Input was:
<<<<<<
           1: ; ModuleID = '/var/tmp/portage/sys-devel/clang-15.0.0.9999/work/clang/test/Frontend/embed-object.c' 
check:3'0     X~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: no match found
           2: source_filename = "/var/tmp/portage/sys-devel/clang-15.0.0.9999/work/clang/test/Frontend/embed-object.c" 
check:3'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           3: target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 
check:3'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           4: target triple = "x86_64-unknown-linux-gnu" 
check:3'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           5:  
check:3'0     ~
           6: @llvm.embedded.object = private constant [0 x i8] zeroinitializer, section ".llvm.offloading", align 4, !exclude !0 
check:3'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
check:3'1                 ?                                                                                                        possible intended match
           7: @llvm.compiler.used = appending global [1 x ptr] [ptr @llvm.embedded.object], section "llvm.metadata" 
check:3'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           8:  
check:3'0     ~
           9: ; Function Attrs: noinline nounwind optnone 
check:3'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          10: define dso_local void @foo() #0 { 
check:3'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          11: entry: 
check:3'0     ~~~~~~~
           .
           .
           .
>>>>>>

--

********************

I'm sorry for noticing it this late but this change seems to have broken the test on 32-bit x86:

Seems to be a difference in the alignment, I'm not sure why this changes though because the test should specify x86_64.

I'm sorry for noticing it this late but this change seems to have broken the test on 32-bit x86:

Seems to be a difference in the alignment, I'm not sure why this changes though because the test should specify x86_64.

Actually I think the alignment comes from alignof on a struct which doesn't care about the target, just the machine compiling it. Even still that struct has int64_t members so I figured it would be 8-byte aligned. I should probably just hard-code it to 8.