This is an archive of the discontinued LLVM Phabricator instance.

[libc++] Set _LIBCPP_DLL_VIS on _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS in MinGW mode
ClosedPublic

Authored by mstorsjo on Apr 25 2019, 3:07 AM.

Details

Summary

Contrary to MSVC, MinGW compilers wants the dllexport attribute on the declaration of an explicit template instantiation, not on the definition.

GCC has always handled these attributes this way, and Clang is being made to match in D61118.

This is one of the parts necessary for building libc++ as a DLL on MinGW without forcibly exporting all symbols using --export-all-symbols. (In addition to this, another few tweaks to clang are needed.)

Diff Detail

Event Timeline

mstorsjo created this revision.Apr 25 2019, 3:07 AM

LGTM, though you'll wanna wait for a libc++ code owner too.

ldionne accepted this revision.Apr 25 2019, 10:43 AM

Contrary to MSVC, MinGW compilers wants the dllexport attribute on the declaration of an explicit template instantiation, not on the definition.

That sounds weird, I would expect an attribute on the explicit instantiation definition to work, since you don't technically need an explicit instantiation declaration to be visible in order to provide an explicit instantiation definition.

This revision is now accepted and ready to land.Apr 25 2019, 10:43 AM

Contrary to MSVC, MinGW compilers wants the dllexport attribute on the declaration of an explicit template instantiation, not on the definition.

That sounds weird, I would expect an attribute on the explicit instantiation definition to work, since you don't technically need an explicit instantiation declaration to be visible in order to provide an explicit instantiation definition.

You're right; if there's no instantiation declaration, then GCC doesn't warn and uses the attribute from the definition. I'ts only ignored (and warned about) by GCC if there's an earlier declaration.

I'll amend the corresponding clang patch to match this aspect, and land this one.

This revision was automatically updated to reflect the committed changes.