How to pass linker flags to device linking step in OpenMP offloading compilation

Dear all,

I am trying to pass certain flags to the linker step during OpenMP offloading compilation. I tried e.g. clang++ ... -Xopenmp-target=<target-triple> -Wl,<flag> but I get a warning unused argument during compilation. If I pass, as a test, -Xopenmp-target=<target-triple> -O3, this works. So it seems the optimization flag is forwarded to the target toolchain, but the linker flag is not.

I was not yet able to figure out what exactly is the intended way of passing linker flags to the device linking step.

I am currently using the old driver. As target triple I used x86_64-unknown-unknown-elf for testing. I would appreciate any hints a lot on how to correctly pass those flags.

Best regards,

Kai Plociennik

Are you sure that this is not the general issue that any linker flags genuinely are not used during compilation, but only during the linkage step?
So any commands that look like
% clang++ ... -c ... -Wl,<flag>
will cause such a warning, independently of any OpenMP or offload issues.

I think we misunderstood. To clarify: I use e.g.

clang++ -save-temps -fopenmp -fopenmp-targets=x86_64-unknown-unknown-elf test.cpp -o test

to compile my source file to an executable. To this end, the driver creates several compile, offload and link steps, one of which is

g++ -shared ... -o a.out-openmp-x86_64-unknown-unknown-elf test-openmp-x86_64-unknown-unknown-elf.o

to create the device image that is linked into the host executable. It is this linking step in which I want to include further command line arguments, so that I can link test-openmp-x86_64-unknown-unknown-elf.o against dedicated libraries.

To this end, I tried to modify the clang++ invocation above e.g. to

clang++ -save-temps -fopenmp -fopenmp-targets=x86_64-unknown-unknown-elf -Xopenmp-target=x86_64-unknown-unknown-elf -Wl,-L/home/my_folder test.cpp -o test

and was expecting to see -L/home/my_folder in the linking step for the device image, but this does not seem to happen.

I hope this helps to clarify what I want to achieve.

Noticed you were talking about the old driver, I don’t know of a way to do that specifically using the old-driver but we’re planning on removing that eventually anyway. If there is a reason you cannot use the new driver please let me know so I can fix it.

Sorry for the late response, device linking is done through the so-called “linker-wrapper” which derives those flags internally. Recently I added the -Xoffload-linker flag which will probably do what you wish. This command simply forwards an argument to the device linking phase. So you should be able to do something like this to forward it specifically.

-Xoffload-linker <arg>
-Xoffload-linker-<triple> <arg>

That being said, the device linking phase should inherit the -L library paths when we perform that section, so I’m not sure what’s going wrong there. If you want to view the internal device linking command line arguments use -v to see them.

Thanks a lot for your answer, I will try to use the new driver when I have time, indeed this would be better for several reasons, and maybe also your above suggestions help.

In the meantime I got things working so everything is OK here for now.