[CUDA][HIP] Fix linkage for -fgpu-rdc
authorYaxun (Sam) Liu <yaxun.liu@amd.com>
Wed, 28 Oct 2020 14:44:21 +0000 (10:44 -0400)
committerYaxun (Sam) Liu <yaxun.liu@amd.com>
Tue, 3 Nov 2020 13:07:19 +0000 (08:07 -0500)
commitabd8cd9199d1e14cae961e1067b78df7044179a3
tree9ebeb3833d3a57f2075f0019781fbedaf789938e
parentc009d11bdac4a7f4a3a8ae85e42da053828a6f24
[CUDA][HIP] Fix linkage for -fgpu-rdc

Currently for explicit template function instantiation in CUDA/HIP device
compilation clang emits instantiated kernel with external linkage
and instantiated device function with internal linkage.

This is fine for -fno-gpu-rdc since there is only one TU.

However this causes duplicate symbols for kernels for -fgpu-rdc if
the same instantiation happen in multiple TU. Or missing symbols
if a device function calls an explicitly instantiated template function
in a different TU.

To make explicit template function instantiation work for
-fgpu-rdc we need to follow the C++ linkage paradigm, i.e.
use weak_odr linkage.

Differential Revision: https://reviews.llvm.org/D90311
clang/lib/CodeGen/CodeGenModule.cpp
clang/test/CodeGenCUDA/device-fun-linkage.cu [new file with mode: 0644]