[libcxx-commits] [PATCH] D100539: [libcxx] Base MSVC autolinking on _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS

Martin Storsjö via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu Apr 15 03:00:30 PDT 2021


mstorsjo created this revision.
mstorsjo added reviewers: smeenai, rnk, compnerd.
mstorsjo requested review of this revision.
Herald added a project: libc++.
Herald added a reviewer: libc++.

Previously the decision of which library to try to autolink was
based on _DLL, however the _DLL define (which is set by the compiler)
is tied to whether using a dynamically linked CRT or not, and the choice
of dynamic or static CRT is entirely orthogonal to whether libc++ is
linked dynamically or statically.

If _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS isn't defined, then all
declarations are decorated with dllimport, and there's no doubt that
the DLL version of the library is what must be linked.

_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS is defined if building with
LIBCXX_ENABLE_SHARED disabled, and thus the static library is what
should be linked.

If defining _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS manually but wanting
to link against the DLL version of the library, that's not a canonical
configuration, and then it's probably reasonable to manually define
_LIBCPP_NO_AUTO_LINK too, and manually link against the desired
library.

This fixes, among other issues, running tests for the library if
built with LIBCXX_ENABLE_STATIC disabled.

This issue was brought up when autolinking was introduced in
https://reviews.llvm.org/D40660, but was shrugged off back then,
but it is causing real issues, and instead of avoiding the issue
by disabling the autolinking feature, we should fix it to actually
match how the library was built.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D100539

Files:
  libcxx/include/__config


Index: libcxx/include/__config
===================================================================
--- libcxx/include/__config
+++ libcxx/include/__config
@@ -1413,7 +1413,7 @@
 
 #ifndef _LIBCPP_NO_AUTO_LINK
 #  if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY)
-#    if defined(_DLL)
+#    if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
 #      pragma comment(lib, "c++.lib")
 #    else
 #      pragma comment(lib, "libc++.lib")


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100539.337681.patch
Type: text/x-patch
Size: 458 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210415/a9b5738c/attachment.bin>


More information about the libcxx-commits mailing list