[libcxx-commits] [libcxx] [libc++] Introduce a new attribute keyword for Clang improves compatibility with Mingw-GCC (PR #141040)
Martin Storsjö via libcxx-commits
libcxx-commits at lists.llvm.org
Thu May 22 06:18:16 PDT 2025
mstorsjo wrote:
> In MinGW environment, Clang handles dllexport attribute of internal class that defined in class template in different way from GCC. This incompatibility should be fixed but breaks ABI of libc++
I didn't quite see this bit answered here; in which way would that break the ABI, if we'd fix this incompatibility? If we'd make libc++.dll export more symbols than we did before, that wouldn't break anything for preexisting callers of the DLL. New binaries built would obviously require the new libc++.dll though, but that's generally the rule anyway.
> But MinGW-GCC handles template instantiation differently:
>
> * When exporting: `extern template __declspec(dllexport) class TheTemplateClass<T>;`
> allows exporting the outer template instantiation, but not its nested types (e.g., InnerClass).
> * When importing: `extern template __declspec(dllimport) class TheTemplateClass<T>;`
> causes MinGW-GCC to also try importing nested types such as TheTemplateClass::InnerClass,
> even if they were never exported. This leads to linker errors like: `undefined reference to TheTemplateClass<T>::InnerClass::...`
This is indeed self-inconsistent, and is the issue that I reported at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89087. Now as libstdc++ doesn't use explicit dllexports, but just uses the default fallback behaviour of exporting all symbols, they're not really hit by this issue, so there's not much pressure to fix it on their side. (We could also do the same in libc++, by explicitly passing `-Wl,--export-all-symbols` when building libc++.dll.)
Can you elaborate on what would break if we'd try to fix this on the Clang side (making Clang do similarly to what GCC does, but self-consistently by making it export the nested class, like the dllimport behaviour seems to expect)?
https://github.com/llvm/llvm-project/pull/141040
More information about the libcxx-commits
mailing list