[PATCH] D24877: [libc++] Default to DLL semantics on Windows

Shoaib Meenai via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 23 12:37:02 PDT 2016

smeenai created this revision.
smeenai added reviewers: compnerd, EricWF, mclow.lists.
smeenai added a subscriber: cfe-commits.

On Windows builds, we currently require `_LIBCPP_DLL` to be specified in
order for dllexport/dllimport annotations to be generated. I believe
it's better to do the opposite, i.e. require a macro to be present in
order to *not* include the annotations, since building libc++ shared is
more common.

The problem with having the DLL annotations be opt-in is that any
project using the libc++ headers and linking against a libc++ DLL must
specify `_LIBCPP_DLL` in its build system, otherwise the libc++ headers
will not be annotated with dllimport. This lack of annotation will then
cause inefficient code generation, since the linker will generate import
thunks. No compile-time errors will be reported (except in the case of
data symbols, for which import thunks are not possible) about this
inefficient code generation.

In contrast, having the DLL annotations be opt-out means that any
project using the libc++ headers and linking against a static libc++
will fail to link with missing import table entries if the project
forgets to specify the macro to suppress DLL annotations. Link errors
seem far preferable to silent inefficient code generation.



Index: include/__config
--- include/__config
+++ include/__config
@@ -548,15 +548,16 @@
 #ifdef _WIN32
-// only really useful for a DLL. _LIBCPP_DLL should be a compiler builtin define ideally...
-#if defined(_LIBCPP_DLL) && defined(cxx_EXPORTS)
+#if !defined(_LIBCPP_STATIC_BUILD)
+#if defined(cxx_EXPORTS)
 # define _LIBCPP_DLL_VIS __declspec(dllexport)
-#elif defined(_LIBCPP_DLL)
 # define _LIBCPP_DLL_VIS __declspec(dllimport)
 # define _LIBCPP_DLL_VIS

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24877.72326.patch
Type: text/x-patch
Size: 815 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160923/499dfa76/attachment.bin>

More information about the cfe-commits mailing list