Issue |
153517
|
Summary |
clang-offload-wrapper creating broken .o file
|
Labels |
new issue
|
Assignees |
|
Reporter |
ZuseZ4
|
Currently on llvm 21.1.0 rc3: https://github.com/rust-lang/rust/commit/3fb4be20c1f41b32697224abd10be814102466ed
I am working on reproducing the behavior of clang's offloading pipeline in rustc. As part of that, I run clang on a minimal openmp (kernel mode) example, and look at the output from `-save-temps`, `--dry-run` and `-###`. I figured the first steps out, so I am now especially looking at the clang-linker-wrapper which seems to be doing plenty of things.
I started compiling the c++ example file via `myclang++ -fuse-ld=lld -fopenmp -fopenmp-offload-mandatory --offload-arch=gfx90a omp_bare.cpp -o bare -save-temps`. myclang is based on the same llvm commit as rustc.
So far I generated a `lib.ll` (host, x86-64) and a `device.ll` (target amdgcn-amd-amdhsa) file from the same rust source file "lib.rs", using rustc.
I then run the following 3 commands, which I got from the clang invocation above (slightly cleaned up)
```
clang-offload-packager -o host.out --image=file=device.ll,triple=amdgcn-amd-amdhsa,arch=gfx90a,kind=openmp
clang-21 -cc1 -triple x86_64-unknown-linux-gnu -S -dumpdir asdf -save-temps=cwd -disable-free -clear-ast-before-backend -main-file-name lib.rs -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -ferror-limit 19 -fopenmp -fopenmp-offload-mandatory -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fembed-offload-object=host.out -fopenmp-targets=amdgcn-amd-amdhsa -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o host.s -x ir lib.ll
clang-21 -cc1as -triple x86_64-unknown-linux-gnu -filetype obj -main-file-name lib.rs -target-cpu x86-64 -dwarf-version=5 -mrelocation-model pic -o host.o host.s
```
So far, so good. I now have `device.ll host.o host.out host.s lib.ll`. The last step of the clang offload invocation is (again slightly simplified)
```
clang-linker-wrapper --should-extract=gfx90a --device-linker=amdgcn-amd-amdhsa=-lompdevice --host-triple=x86_64-unknown-linux-gnu --linker-path=/path/rust/build/x86_64-unknown-linux-gnu/lld/bin/ld.lld --hash-style=gnu --eh-frame-hdr -m elf_x86_64 -pie -dynamic-linker -o bare /lib/../lib64/Scrt1.o /lib/../lib64/crti.o /path/gcc/x86_64/12/crtbeginS.o -L/path/gcc/x86_64/12 -L/path/gcc/x86_64/12/../../../../lib64 -L/lib/../lib64 -L/usr/lib64 -L/lib -L/usr/lib host.o -lstdc++ -lm -lomp -lomptarget -lgcc_s -lgcc -lpthread -lc -lgcc_s -lgcc /path/gcc/x86_64/12/crtendS.o /lib/../lib64/crtn.o
```
It gives
```
ld.lld: error: host-amdgcn-amd-amdhsa-gfx90a.o:1: malformed number: '
>>> ; ModuleID = 'lib-openmp-amdgcn-amd-amdhsa-gfx90a.bc'
>>> ^
clang: error: ld.lld command failed with exit code 1 (use -v to see invocation)
```
Inspecting the `host-amdgcn-amd-amdhsa-gfx90a.o` file (where does it even get generated?) shows that it's just our `device.ll` file, which we started with. The clang-linker-wrapper somehow creates a copy and incorrectly names it a .o file.
If I append `--save-temps` and `--dry-run` to the clang-linker-wrapper invocation above, I get the following output:
```
"/path/prog/llvm/bin/clang" --no-default-config -o bare.amdgcn.gfx90a.img --target=amdgcn-amd-amdhsa -mcpu=gfx90a -flto -Wl,--no-undefined host-amdgcn-amd-amdhsa-gfx90a.o -Wl,--save-temps -Xlinker -lompdevice
"/path/rust/build/x86_64-unknown-linux-gnu/lld/bin/ld.lld" {some-args}
```
It already fails at the clang invocation, since `host-amdgcn-amd-amdhsa-gfx90a.o` is an incorrectly named device.ll file. `clang-linker-wrapper` also must create that file in some way before calling clang, but does so in a way that's not printed by `--dry-run`.
I'll add more details later.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs