Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CUDA: Host-side virtual destructor of template class leaks into PTX as weak function #108548

Open
mkuron opened this issue Sep 13, 2024 · 0 comments
Assignees
Labels

Comments

@mkuron
Copy link
Contributor

mkuron commented Sep 13, 2024

Consider the following bit of code:

void _Adjust_manually_vector_aligned()
{}

template <size_t>
constexpr void _Deallocate() {
    _Adjust_manually_vector_aligned();
}

struct basic_string {
    constexpr ~basic_string() {
        _Deallocate<8>();
    }
};

template <class Var_t>
class E {
  virtual ~E() = default;
  basic_string _name;
};

template class E<float>;

Including this into a CUDA file (you don't even have to use the class in a device-side function or variable) leads to errors like ptxas fatal : Unresolved extern function '_Z31_Adjust_manually_vector_alignedv' or, when compiling with -fgpu-rdc, corresponding errors from nvlink. The resulting PTX contains unreferenced .weak .funcs of the defaulted virtual destructor. This bears some similarity to #98151, but the circumstances under which the extraneous symbol is emitted differ.

The code for basic_string and the functions it calls was reduced from https://github.com/microsoft/STL/blob/vs-2022-17.0/stl/inc/xstring and https://github.com/microsoft/STL/blob/vs-2022-17.0/stl/inc/xmemory. The current issue makes it impossible to use std::string in template classes with defaulted virtual destructors when using CUDA on Windows in C++20 mode.

Godbolt: https://godbolt.org/z/7MTda4Kq4

NVCC does not show this issue, it never generates .weak .func symbols for host-side destructors. Clang appears to only be generating these extraneous .weak .func symbols for code that exactly follows the above pattern; eliminating the templates, the virtual, the default, or the constexprs makes the problem go away.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants