JonChesterfield added a comment.

Debugged this because I need save-temps (or hack up a binary by hand) to debug 
something else. The problem is addClangTargetOptions gets called to add target 
options to clang. With save temps, an early clang invocation runs the 
preprocessor alone. That gets passed the target specific flags, something like:

  "clang-13" "-cc1" "-mllvm" "--amdhsa-code-object-version=3" "-triple" 
"amdgcn-amd-amdhsa" "-aux-triple" "x86_64-pc-linux-gnu" "-E" "-save-temps=cwd" 
"-disable-free" "-main-file-name" "firstprivate.c" "-target-cpu" "gfx906" 
"-fcuda-is-device" "-emit-llvm-bc" "-mlink-builtin-bitcode" 
"/home/amd/llvm-install/lib/libomptarget-amdgcn-gfx906.bc" 
"-fno-split-dwarf-inlining" "-debugger-tuning=gdb" "-O2" 
"-fdebug-compilation-dir" "/home/amd/aomp/aomp/test/smoke/firstprivate" 
"-ferror-limit" "19" "-fmessage-length=102" "-fopenmp" 
"-fopenmp-cuda-parallel-target-regions" "-fgnuc-version=4.2.1" 
"-fopenmp-is-device" "-munsafe-fp-atomics" "-faddrsig" "-o" 
"firstprivate-openmp-amdgcn-amd-amdhsa.i" "-x" "c" "firstprivate.c"

Deleted some parts of that. The "-E" gives preprocessor behaviour. Things like 
-O2 or munsafe-fp-atomics don't matter to the preprocessor but are passed 
anyway, so there's prior art for it ignoring arguments when called as save 
temps. Whichever of emit-llvm-bc and E comes last wins, and the target options 
come after the E, so currently clang emits (binary) bytecode which is later 
interpreted as cpp-output, which can't handle bytecode.

With this patch applied, the problem of overriding the E flag is sidestepped. 
There are alternatives, but this approach looks cleaner than the others I can 
think of.

Note that it isn't a complete fix for save-temps, but it gets me as far as 
`multiple definition of `__dummy.omp_offloading.entry'`, which I vaguely 
remember marking as a weak symbol for the aomp toolchain. It lets clang get as 
far as emitting the device binary I wanted access to, so I'm now very sure this 
patch works.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96769/new/

https://reviews.llvm.org/D96769

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to