https://bugs.llvm.org/show_bug.cgi?id=48440

            Bug ID: 48440
           Summary: Linker error with static library containing offload
                    instructions
           Product: OpenMP
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Clang Compiler Support
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]

Created attachment 24248
  --> https://bugs.llvm.org/attachment.cgi?id=24248&action=edit
A reproducer with code and compile instructions

Hello,

I would like to report the following finding when working with
 clang from llvm11 using cuda10.1 on linux (x86 and ppc64le).

I compile objects using:
   clang++ -fopenmp -fopenmp-targets=nvptx64-nvidia-cuda -c saxpy.cxx

I create a static library as such:
   ar -crs libsaxpy.a saxpy.o

I want to compile an executable that links to the static library:
   clang++ -fopenmp -fopenmp-targets=nvptx64-nvidia-cuda  runsaxpy.cxx -L.
-lsaxpy -o runit

This results in a linker error:
   nvlink error   : Undefined reference to '_Z5saxpyidPdS_' in
'/tmp/runsaxpy-a03e51.cubin'

The curious thing is that the error vanishes if instead of linking to the
static library, I instruct the compiler to use the object file directly:
   clang++ -fopenmp -fopenmp-targets=nvptx64-nvidia-cuda  runsaxpy.cxx saxpy.o
-o runit

I can confirm that the code is offloaded to the gpu with nvprof:
   ==1356356== Profiling result:
            Type  Time(%)      Time     Calls       Avg       Min       Max 
Name
 GPU activities:   96.54%  99.970us         1  99.970us  99.970us  99.970us 
__omp_offloading_34_1f13a9_main_l5
                    1.98%  2.0490us         1  2.0490us  2.0490us  2.0490us 
[CUDA memcpy DtoH]
                    1.48%  1.5360us         1  1.5360us  1.5360us  1.5360us 
[CUDA memcpy HtoD]


I do not know if I am building the static library incorrectly of if I am
missing linker flags perhaps.

I attach a reproducer for what I observe.

Thanks a lot!

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to