<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - Linker error with static library containing offload instructions"
href="https://bugs.llvm.org/show_bug.cgi?id=48440">48440</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Linker error with static library containing offload instructions
</td>
</tr>
<tr>
<th>Product</th>
<td>OpenMP
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Clang Compiler Support
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>gcgt96@durham.ac.uk
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=24248" name="attach_24248" title="A reproducer with code and compile instructions">attachment 24248</a> <a href="attachment.cgi?id=24248&action=edit" title="A reproducer with code and compile instructions">[details]</a></span>
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!</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>