Problems compiling an offloading program

Dear all, using Clang 17 (commit 44bb442fd5be) I can compile

#include <iostream>

int main(void)
    int my_value = 1;

    #pragma omp target map(tofrom: my_value)
        my_value = 2;

    std::cout << my_value << std::endl;
    return 0;

using clang++ -save-temps -v -fuse-ld=lld -fopenmp -fopenmp-targets=x86_64-unknown-unknown-elf -o test test.cpp but when I add -Wl,-v after -v, the clang-linker-wrapper does not do our output anything, so no executable is created. Is this intentional?

Took me some time to find out that the -Wl,-v was causing this since I started with it.

Am I doing something wrong in passing flags to the linker using -Wl,?

The clang-linker-wrapper forwards most of its arguments to the host linker. If you do this you will find that -v is probably not what you expect for ld.lld

$> ld.lld -v
LLD 17.0.0 (compatible with GNU linkers) 

For this reason there’s a special flag in the linker wrapper called --wrapper-verbose which is what we map to when the user uses clang -v. Here’s a summary of what we do

  • ld.lld -v prints the version
  • ld.lld --verbose prints verbose linker information
  • clang-linker-wrapper -v prints the version
  • clang-linker-wrapper --wrapper-verbose prints verbose output for sub-jobs created as part of the offload linking
  • clang -v passes --wrapper-verbose to the linker wrapper.

Thanks a lot for your explanations!

I think in the end I was confused by the different behavior of GCC vs. Clang w.r.t. -v and -Wl,-v. I tried it out, and when compiling a normal program using GCC, with -v I do not get verbose linker output (from ld) and have to activate it via -Wl,-v. With Clang, -v already outputs the precise linker command.

I was not aware of this and used the -Wl,-v for Clang even though it was not necessary. This also worked previously even when compiling for OpenMP offloading, but now with the linker wrapper, the problem was that no output (executable) is generated anymore, which confused me.