[libcxx-commits] [libcxx] dfa8892 - [libcxx] Omit dllimport in public headers in MinGW mode

Martin Storsjö via libcxx-commits libcxx-commits at lists.llvm.org
Mon Jun 6 13:19:33 PDT 2022


Author: Martin Storsjö
Date: 2022-06-06T23:19:22+03:00
New Revision: dfa88927ae1411ccc3b248b7e624f2acf623d947

URL: https://github.com/llvm/llvm-project/commit/dfa88927ae1411ccc3b248b7e624f2acf623d947
DIFF: https://github.com/llvm/llvm-project/commit/dfa88927ae1411ccc3b248b7e624f2acf623d947.diff

LOG: [libcxx] Omit dllimport in public headers in MinGW mode

In MinGW environments, thanks to slightly different code generation
and linker tricks, it's possible to link against a DLL C++ standard
library without dllimport attributes.

This allows using one single set of headers for linking against
either the DLL or a static library, leaving the decision entirely
up to the linking stage (where it can be switched with options like
-static-libstdc++).

This matches how libstdc++ headers work; there's no dllimport attributes
by default (unless the user has defined _GLIBCXX_DLL when including
headers).

This allows using one single set of headers while linking against
either a DLL or a static library, just like on Unix platforms.

This matches how libc++ has been used in MinGW configurations for
years (by first building the DLL, then configuring a static-only
build and installing on top, overwriting the libc++ config file
with one for static linking) by multiple MinGW toolchains, making
the dllimport-less use the de-facto tested configuration in the wild.

This also allows building all of libc++ in one single CMake
configuration, instead of having to do two separate builds on top of
each other.

(Linking against a DLL without dllimport can break if e.g. templates
use inconsistent visibility attributes - in cases where it still
works when using explicit dllimport; such a case was fixed in
948dd664c3ed30dd853df03cb931436f280bad4a / D99932. With this as the
default configuration, we can catch such issues in CI.)

Differential Revision: https://reviews.llvm.org/D125924

Added: 
    

Modified: 
    libcxx/include/__config

Removed: 
    


################################################################################
diff  --git a/libcxx/include/__config b/libcxx/include/__config
index 583039a0018ad..31a31b1b09f80 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -537,7 +537,7 @@ typedef __char32_t char32_t;
 #  define _LIBCPP_CRT_FUNC
 #endif
 
-#if defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
+#if defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) || (defined(__MINGW32__) && !defined(_LIBCPP_BUILDING_LIBRARY))
 #  define _LIBCPP_DLL_VIS
 #  define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
 #  define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS


        


More information about the libcxx-commits mailing list