Commit Graph

152 Commits

Author SHA1 Message Date
Eric Fiselier
801e00b0cd Correctly default to using the system libc++abi on Apple.
This patch fixes a regression where libc++ didn't correctly
select the system libc++abi when no in-tree version was found.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@294712 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-10 05:07:03 +00:00
Eric Fiselier
d60b66ad4f Split exception.cpp and new.cpp implementation into different files for different runtimes.
exception.cpp is a bloody mess. It's full of confusing #ifdef branches for
each different ABI library we support, and it's getting unmaintainable.

This patch breaks down exception.cpp into multiple different header files,
roughly one per implementation. Additionally it moves the definitions of
exceptions in new.cpp into the correct implementation header.

This patch also removes an unmaintained libc++abi configuration.
This configuration may still be used by Apple internally but there
are no other possible users. If it turns out that Apple still uses
this configuration internally I will re-add it in a later commit.
See http://llvm.org/PR31904.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@294707 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-10 04:25:33 +00:00
Petr Hosek
f4699a5b99 [libcxx][CMake] Support in-tree libunwind when building as part of runtimes
When building as part of runtimes, there is no predefined order in
which the runtimes are loaded, so the targets from other projects
might not be available. We need to rely on HAVE_<name> variables
instead in that case.

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

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@294553 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-09 02:19:43 +00:00
Eric Fiselier
1138f041fc Remove CMake hack
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@294116 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-05 01:19:02 +00:00
Eric Fiselier
b89eba01e8 Recommit [libcxx] Never use <cassert> within libc++
It is my opinion that libc++ should never use `<cassert>`, including in the `dylib`.
This patch remove all uses of `assert` from within libc++ and replaces most of them with `_LIBCPP_ASSERT` instead.

Additionally this patch turn `LIBCXX_ENABLE_ASSERTIONS`  off by default,
because the standard library should not be aborting user programs unless explicitly asked to.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@294107 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-04 23:22:28 +00:00
Eric Fiselier
a49c64f182 Revert "[libcxx] Never use <cassert> within libc++"
This reverts commit r292883. Unfortunately <string_view> uses
_LIBCPP_ASSERT in a way which is not compatible with the C++11 dylib
build. I'll investigate more tomorrow.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@292923 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-24 12:26:01 +00:00
Eric Fiselier
2c90d1f776 [libcxx] Never use <cassert> within libc++
Summary:
It is my opinion that libc++ should never use `<cassert>`, including in the `dylib`. This patch remove all uses of `assert` from within libc++ and replaces most of them with `_LIBCPP_ASSERT` instead.

Additionally this patch turn `LIBCXX_ENABLE_ASSERTIONS`  off by default, because the standard library should not be aborting user programs unless explicitly asked to.

Reviewers: mclow.lists, compnerd, smeenai

Reviewed By: mclow.lists

Subscribers: mgorny, cfe-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@292883 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-24 04:57:33 +00:00
Eric Fiselier
8e39559043 Don't strip -m32 from the user provide command line flags. This fixes the compiler-rt 32 bit sanitizer build
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@292291 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-17 23:27:56 +00:00
Eric Fiselier
bde2871b62 Improve CMake and LIT support for Windows
This patch contains multiple cleanups and fixes to better support building on
Windows.

* [Test] Fix handling of library runtime search paths by correctly adding them
  to the PATH variable when running the tests.

* [Test] Don't explicitly force "--target=i686-pc-windows" when running the
  test suite. Clang++ seems to deduce the correct target.

* [Test] Fix `.sh.cpp` tests on Windows by properly escaping flags used in
  shell commands. Specifically windows style paths which included spaces
  were causing these tests to fail.

* [CMake] Add "vcruntime" to the list of supported C++ ABI libraries in CMake, and
  teach the test suite how to handle it. For now libc++ defaults to using
  "vcruntime" on Windows except when libc++abi is in tree; That is probably
  a bug and should be changed to always use vcruntime, at least for now.

* [Misc] Move the "c++-build" include directory to the libc++ binary dir
  instead of the top level project dir and rename it "c++build". This is just
  misc cleanup. Libc++ shouldn't be creating internal build files and directories
  at the top-level projects root.

* [Misc] Build type_info's destructor when building for MSVC. This is a temporary
  work around to prevent link errors until we have a proper type_info
  implementation.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@292157 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-16 20:47:35 +00:00
Petr Hosek
6948dbedca Reland "[CMake][libcxx] Check that we have libcxxabi before using it"
This relands commit r291726.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@292086 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-16 00:33:11 +00:00
Petr Hosek
c59c3172dc Reland "[CMake][libcxx] Do not rely on the existence of c++abi or unwind targets"
This relands commit r291727.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@292085 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-16 00:33:09 +00:00
Petr Hosek
3508e7a877 Reland "[CMake][libcxx] Move Python check to main CMake file"
This relands commit r291728.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@292084 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-16 00:33:07 +00:00
Eric Fiselier
157fd34124 [libc++][CMake] Use debug MSVC runtimes when libc++ is built in debug mode
Summary: This patch allows libc++ to be built against the debug MSVC runtimes instead of just the release ones.

Reviewers: rnk, majnemer, compnerd, smeenai

Subscribers: mgorny, cfe-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@292006 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-14 07:54:39 +00:00
Eric Fiselier
fdd3c91b5f [libc++] [CMake] Link with /nodefaultlibs on Windows
Summary:
This patch attempts to fix the libc++ build/link so that it doesn't use an default C++ libraries on Windows.  This is needed to prevent linking to MSVC's STL library.

Additionally this patch changes libc++ so that it is always linked with the non-debug DLL's (e.g. `/MD`). This is needed so that the test suite can correctly link the same libraries without needing to know which configuration `c++.dll` was linked with.


Reviewers: compnerd, rnk, majnemer, kimgr, awson, halyavin, smeenai

Subscribers: cfe-commits, mgorny

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

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@292001 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-14 06:06:47 +00:00
Petr Hosek
0758410191 Revert "[CMake][libcxx] Move Python check to main CMake file"
This reverts commit 39441fe9f0.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@291728 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-11 23:56:33 +00:00
Petr Hosek
b81ce92008 Revert "[CMake][libcxx] Do not rely on the existence of c++abi or unwind targets"
This reverts commit 94fc5a96f5.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@291727 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-11 23:56:31 +00:00
Petr Hosek
010074a596 Revert "[CMake][libcxx] Check that we have libcxxabi before using it"
This reverts commit 8c91834411.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@291726 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-11 23:56:29 +00:00
Petr Hosek
8c91834411 [CMake][libcxx] Check that we have libcxxabi before using it
When doing standalone build, check that we actually have libcxxabi
before attempting to use it.

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

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@291723 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-11 23:11:40 +00:00
Petr Hosek
94fc5a96f5 [CMake][libcxx] Do not rely on the existence of c++abi or unwind targets
There is no guaranteed order in which CMake files for individual
runtimes are invoked and therefore we cannot rely on existence of
targets defined in other runtimes. Use the new HAVE_<name> options
instead in those cases.

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

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@291632 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-11 00:56:10 +00:00
Petr Hosek
39441fe9f0 [CMake][libcxx] Move Python check to main CMake file
This is to make sure this check is called even when building as
part of LLVM runtimes when we are doing standalone but not out of
tree build.

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

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@291592 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-10 19:51:17 +00:00
Asiri Rathnayake
da39f1bc79 [libcxx] Fix externally-threaded shared library builds after r291275.
Need to allow unresolved symbols in the dylib. This was previously done for
LIBCXX_HAS_EXTERNAL_THREAD_API, but we have since split that into two with
LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY being the externally-threaded variant.

Also a minor CMakeLists.txt cleanup.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@291433 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-09 10:38:56 +00:00
Eric Fiselier
bab7b41d2e Configure default ABI library as NONE on Windows
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@291306 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-06 23:59:52 +00:00
Eric Fiselier
66134e8a5f [libc++] Cleanup and document <__threading_support>
Summary:
This patch attempts to clean up the macro configuration mess in `<__threading_support>`, specifically the mess involving external threading variants. Additionally this patch adds design documentation for `<__threading_support>` and the configuration macros it uses.

The primary change in this patch is separating the idea of an "external API" provided by `<__external_threading>` and the idea of having an external threading library. Now `_LIBCPP_HAS_THREAD_API_EXTERNAL` means that libc++ should use `<__external_threading>` and that the header is expected to exist.  Additionally the new macro `_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL` is now used to configure for using an "external library"  with the default threading API.

Reviewers: compnerd, rmaprath

Subscribers: smeenai, cfe-commits, mgorny

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

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@291275 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-06 20:05:40 +00:00
Asiri Rathnayake
e262e7b914 [libcxx] Add build/test support for the externally threaded libc++abi variant
Differential revision: https://reviews.llvm.org/D27576

Reviewers: EricWF

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@290889 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-03 12:59:50 +00:00
Eric Fiselier
cfc5515b9d Recommit r290839 - Fix configuring and building libc++ w/o an ABI library.
This patch re-commits a previous attempt to support building libc++ w/o
an ABI library. That patch was originally reverted because:

1) It forgot to teach the test suite about "default" ABI libraries.

2) Some LLVM builders don't clear the CMake cache between builds. The previous
   patch caused those builders to fail since their old cache entry for
   LIBCXX_CXX_ABI="" is no longer valid.

The updated patch addresses both issues. It works around (2) by adding
a hack to force the builders to update their cache entries. The hack will
be removed shortly once all LLVM builders have run.

Original commit message
-----------------------

Typically libc++ uses libc++abi or libcxxrt to provide the ABI and runtime bits
of the C++ STL. However we also support building w/o an ABI library entirely.
This patch fixes building libc++ w/o an ABI library (and incorporates the
`~type_info()` fix in D28211).

The main changes in this patch are:

1) Add `-DLIBCXX_CXX_ABI=default` instead of using the empty string to mean "default".
2) Fix CMake bits which treated "none" as "default" on OS X.
3) Teach the source files to respect `-D_LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY`.
4) Define ~type_info() when _LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY is defined.

Unfortunately this patch doesn't help clean up the macro mess that we use to
configure for different ABI libraries.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@290849 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-03 01:18:48 +00:00
Eric Fiselier
983f38443b Revert r290839 - Fix configuring and building libc++ w/o an ABI library
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@290841 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-02 22:27:45 +00:00
Eric Fiselier
ea38cde827 Fix configuring and building libc++ w/o an ABI library.
Typically libc++ uses libc++abi or libcxxrt to provide the ABI and runtime bits
of the C++ STL. However we also support building w/o an ABI library entirely.
This patch fixes building libc++ w/o an ABI library (and incorporates the
`~type_info()` fix in D28211).

The main changes in this patch are:

1) Add `-DLIBCXX_CXX_ABI=default` instead of using the empty string to mean "default".
2) Fix CMake bits which treated "none" as "default" on OS X.
3) Teach the source files to respect `-D_LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY`.
4) Define ~type_info() when _LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY is defined.

Unfortunately this patch doesn't help clean up the macro mess that we use to
configure for different ABI libraries.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@290839 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-02 21:58:06 +00:00
Saleem Abdulrasool
766e557e5a build: tweak macros for Windows build
Move the windows specific macro definitions for compiling c++ into the
target.  Add a number of newer options that are necessary to properly
build libc++ for windows.  This ensures that we do not accidentally
autolink msvcprt (Microsoft's C++ runtime library), do not define linker
pragmas which are msvcprt specific, and do not accidentally encode the
incorrect version of the msvc compatibility version.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@290837 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-02 21:40:17 +00:00
Saleem Abdulrasool
1ca3c45316 build: further improve flags handling for cl
This allows us to build with cl (or rather clang-cl) by using the
correct spelling for `-include` (`/FI` for cl).  clang-cl and cl default
to C++11/C++14 as they support it rather than permitting an explicit
language standard.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@290802 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-01 20:20:40 +00:00
Petr Hosek
513447dbb9 [libcxx][CMake] Move the warning to HandleOutOfTreeLLVM
This currently gives a warning when building libcxx under runtimes.

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

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@289418 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-12 05:05:46 +00:00
Shoaib Meenai
c6d8e8a9cc [libc++] Add _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS
It's useful to be able to disable visibility annotations entirely; for
example, if we're building libc++ static to include in another library,
and we don't want any libc++ functions getting exported out of that
library. This is a generalization of _LIBCPP_DISABLE_DLL_IMPORT_EXPORT.

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

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@288690 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-05 19:40:12 +00:00
Eric Fiselier
60479ea31b Make LIBCXX_ENABLE_STATIC_ABI_LIBRARY merge libc++.a and libc++abi.a
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@287373 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-18 19:53:45 +00:00
Eric Fiselier
5e000c6a82 Add check-cxx-abilist target when supported.
This patch adds a `check-cxx-abilist` target which verifies the libc++.so ABI
when the current build configuration matches the configuration used to generate
the ABI lists.

In order to make this change `HandleOutOfTreeLLVM.cmake` needed to be modified
to include `LLVMConfig.cmake` so that `TARGET_TRIPLE` is defined. Hopefully
the changes needed to accommodate this won't break existing build
configurations.


git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@286789 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-14 02:43:12 +00:00
Eric Fiselier
6e467a8987 Fix GCC libc++abi build
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@286783 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-13 22:27:00 +00:00
Petr Hosek
d842fed6f8 [CMake] Check runtimes subdir when looking for libcxxabi
The runtimes subdir is the new location for runtimes, we should
include it when looking for libcxxabi headers.

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

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@286333 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-09 03:22:28 +00:00
Eric Fiselier
2d2f0c0af3 Add start of filesystem benchmarks
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@285524 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-30 22:53:00 +00:00
Eric Fiselier
8330b1ec02 [libcxx] Build with -fvisibility-inlines-hidden -- Remove 20 inline definitions from the dylib
Summary:
This patch turns on `-fvisibility-inlines-hidden` when building  the dylib. This is important so that libc++.dylib doesn't accidentally export inline-functions which are ODR used somewhere in the dylib.

On OS X this change has no effect on the current ABI of the dylib. Unfortunately on Linux there are already ~20 inline functions which are unintentionally exported by the dylib. Almost all of these are implicitly generated destructors. I believe removing these function definitions is safe because every "linkage unit" which uses these functions has its own definition, and therefore shouldn't be dependent on libc++.dylib to provide them.

Also could a FreeBSD maintainer comment on the ABI compatibility of this patch?



Reviewers: mclow.lists, emaste, dexonsmith, joker-eph-DISABLED, jroelofs, danalbert, mehdi_amini, compnerd, dim

Subscribers: beanz, mgorny, cfe-commits, modocache

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

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@285101 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-25 19:43:44 +00:00
Petr Hosek
44197a11b1 [libcxx] Use C++14 when building libc++ with musl
musl's pthread implementations use volatile types in their structs
which is not being constexpr in C++11 but is in C++14.

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

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@284950 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-23 21:48:27 +00:00
Eric Fiselier
29026ad78a Disable Modules when building the libc++ sources.
Libc++ will not build with modules enabled. In order to support an in-tree
libc++ when LLVM_ENABLE_MODULES is ON we need to explicitly disable the feature.

Unfortunately the libc++ sources are fundamentally non-modular. For example
iostream.cpp defines cout, cerr, wout, ... as char buffers instead of streams
in order to better control initialization/destruction. Not shockingly Clang
diagnoses this. Many other sources files define _LIBCPP_BUILDING_FOO macros to
provide definitions for normally inline symbols (See bind.cpp). Finally The
current module.map prohibits using <strstream> in C++11 so we can't build
strstream.cpp.

I think I can fix most of these issues but until then just disable modules.


git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@284230 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-14 12:56:52 +00:00
Eric Fiselier
742d878b02 Fix documentation mis-spelling.
I promise to stop misspelling things when the English language gains a program
that does strict semantic checking.


git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@283759 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-10 14:45:06 +00:00
Eric Fiselier
3bf8a9cb67 Fix linker script generation for in-tree builds
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@283700 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-09 21:34:03 +00:00
Michal Gorny
ffac2247af [cmake] Split linked libraries into private & public, for linker script
Introduce LIBCXX_LIBRARIES_PUBLIC in addition to LIBCXX_LIBRARIES that
holds 'public' interface libraries -- that is, libraries that both
libc++ links to and programs linked against it need to link to.

Currently this includes the ABI library and optionally -lunwind (when
LIBCXXABI_USE_LLVM_UNWINDER is on). The libraries are included in the
linker script, in order to make it possible to link C++ programs using
clang with compiler-rt runtime out-of-the-box.

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

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@283659 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-08 10:27:45 +00:00
Michal Gorny
c3e00f6d37 Revert r282483 - [cmake] Add linker option "-Wl,-z,defs" in standalone build
Revert r282483 as it causes build failures due to missing symbols when
not linking to -lgcc_s (i.e. doing pure LLVM stack build). The patch can
be reintroduced when the build system is fixed to add all needed
libraries (libunwind, compiler-rt).

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@282524 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-27 18:54:02 +00:00
Michal Gorny
0e5fbd4d40 [cmake] Add linker option "-Wl,-z,defs" in standalone build
Add the "-Wl,-z,defs" linker option that is used to prevent
underlinking. It is already used by LLVM itself but does not get
propagated into stand-alone build of libc++. This patch ensures
that the option is passed in independently of whether libc++ is built
in-tree or out-of-tree.

Patch by Lei Zhang.

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

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@282483 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-27 12:15:35 +00:00
Michal Gorny
b79ca0a818 [cmake] Strip possibly-inherited compiler flags in in-tree build only
Strip the set of flags (including debug defs, -m32) that could
be inherited from top-level LLVM build only when in-tree build is
performed. This prevents libcxx from confusingly and undesiredly
stripping user-supplied flags e.g. when performing packaging system
controlled multi-ABI build.

Otherwise, in order to perform 32-bit builds the build scripts would
have to use LIBCXX_BUILD_32_BITS. However, -m32 is only one of the many
different ABI flags for different targets, and it really makes no sense
to add separate CMake options for each possible -m* flag and then keep
a mapping from well-known flags to the custom CMake options.

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

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@282475 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-27 07:55:26 +00:00
Eric Fiselier
74c9857af9 Expect DLL builds on Windows by default and require a custom __config for static
builds.

On Windows the __declspec(dllimport) and __declspec(dllexport) attributes
require linking to a DLL, not a static library. Previously these annotations
were disabled by default unless _LIBCPP_DLL was defined. However the DLL
configuration is probably the more common one, so it should be supported by
default.

This patch enables import/export attributes by default and adds a
_LIBCPP_DISABLE_DLL_IMPORT_EXPORT macro which can be used to disable this
behavior. If libc++ is built as a static library on Windows then a custom __config
header will be generated that predefines this macro.

This patch is based off work by Shoaib Meenai.


git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@282449 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-26 22:19:41 +00:00
Eric Fiselier
6dbed46df6 [libc++] Add _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY to support GCC ABI compatibility
Summary:
GCC and Clang handle visibility attributes on the out-of-line definition of externally instantiated templates differently. For example in the reproducer below Clang will emit both 'foo' and 'bar' with default visibility while GCC only emits a non-hidden 'foo'.  

```
// RUN: g++ -std=c++11 -shared -O3 test.cpp && sym_extract.py a.out
// RUN: clang++ -std=c++11 -shared -O3 test.cpp && sym_extract.py a.out
#define INLINE_VISIBILITY __attribute__((visibility("hidden"), always_inline))

template <class T>
struct Foo {
  void foo();
  void bar();
};

template <class T>
void Foo<T>::foo() {}

template <class T>
inline INLINE_VISIBILITY
void Foo<T>::bar() {}

template struct Foo<int>;
```

This difference creates ABI incompatibilities between Clang and GCC built dylibs. Specifically GCC built dylibs lack definitions for various member functions of `basic_string`, `basic_istream`, `basic_ostream`, `basic_iostream`, and `basic_streambuf` (All of these types are externally instantiated). 

Surprisingly these missing symbols don't cause many problems because the functions are marked `always_inline`  therefore the dylib definition is rarely needed. However when an out-of-line definition is required then GCC built dylibs will fail to link. For example [GCC built dylibs cannot build Clang](http://stackoverflow.com/questions/39454262/clang-build-errors).

This patch works around this issue by adding `_LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY` which is used to mark externally instantiated member functions as always inline. When building the library `_LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY` sets the symbol's visibility to "default" instead of "hidden", otherwise it acts exactly the same as `_LIBCPP_INLINE_VISIBILITY`.

After applying this patch GCC dylibs now contain:
  * `_ZNSt3__115basic_streambufIcNS_11char_traitsIcEEE7sungetcEv`
  * `_ZNSt3__115basic_streambufIwNS_11char_traitsIwEEE5gbumpEi`
  * `_ZNSt3__115basic_streambufIwNS_11char_traitsIwEEE7sungetcEv`
  * `_ZNSt3__115basic_streambufIcNS_11char_traitsIcEEE9sputbackcEc`
  * `_ZNSt3__113basic_istreamIwNS_11char_traitsIwEEE3getERNS_15basic_streambufIwS2_EE`
  * `_ZNSt3__113basic_ostreamIwNS_11char_traitsIwEEElsEPFRNS_9basic_iosIwS2_EES6_E`
  * `_ZNSt3__115basic_streambufIcNS_11char_traitsIcEEE4setpEPcS4_`
  * `_ZNSt3__113basic_ostreamIwNS_11char_traitsIwEEEC1EPNS_15basic_streambufIwS2_EE`
  * `_ZNSt3__115basic_streambufIcNS_11char_traitsIcEEE6snextcEv`
  * `_ZNSt3__113basic_istreamIcNS_11char_traitsIcEEE4swapERS3_`
  * `_ZNSt3__113basic_istreamIwNS_11char_traitsIwEEE4swapERS3_`
  * `_ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6__initEPKcm`
  * `_ZNSt3__113basic_istreamIcNS_11char_traitsIcEEErsEPFRNS_8ios_baseES5_E`
  * `_ZNSt3__115basic_streambufIcNS_11char_traitsIcEEE9pubsetbufEPcl`
  * `_ZNSt3__115basic_streambufIcNS_11char_traitsIcEEE10pubseekoffExNS_8ios_base7seekdirEj`
  * `_ZNSt3__113basic_istreamIwNS_11char_traitsIwEEErsEPFRNS_9basic_iosIwS2_EES6_E`
  * `_ZNSt3__115basic_streambufIwNS_11char_traitsIwEEE5pbumpEi`
  * `_ZNSt3__113basic_ostreamIcNS_11char_traitsIcEEE5seekpENS_4fposI11__mbstate_tEE`
  * `_ZNSt3__113basic_istreamIcNS_11char_traitsIcEEE7getlineEPcl`
  * `_ZNSt3__115basic_streambufIcNS_11char_traitsIcEEE5sgetcEv`
  * `_ZNSt3__113basic_istreamIcNS_11char_traitsIcEEE3getERNS_15basic_streambufIcS2_EE`
  * `_ZNSt3__113basic_ostreamIcNS_11char_traitsIcEEElsEPFRNS_8ios_baseES5_E`
  * `_ZNSt3__115basic_streambufIcNS_11char_traitsIcEEE8in_availEv`
  * `_ZNSt3__113basic_istreamIwNS_11char_traitsIwEEErsEPFRNS_8ios_baseES5_E`
  * `_ZNSt3__115basic_streambufIcNS_11char_traitsIcEEE6sbumpcEv`
  * `_ZNSt3__113basic_ostreamIcNS_11char_traitsIcEEElsEPFRNS_9basic_iosIcS2_EES6_E`
  * `_ZNSt3__113basic_istreamIcNS_11char_traitsIcEEE3getERc`
  * `_ZNSt3__115basic_streambufIwNS_11char_traitsIwEEE6snextcEv`
  * `_ZNSt3__112basic_stringIwNS_11char_traitsIwEENS_9allocatorIwEEE6__initEmw`
  * `_ZNSt3__113basic_istreamIwNS_11char_traitsIwEEE7getlineEPwl`
  * `_ZNSt3__113basic_ostreamIcNS_11char_traitsIcEEE5tellpEv`
  * `_ZNSt3__113basic_istreamIwNS_11char_traitsIwEEE3getERw`
  * `_ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6__initEmc`
  * `_ZNSt3__115basic_streambufIcNS_11char_traitsIcEEE7pubsyncEv`
  * `_ZNSt3__113basic_istreamIcNS_11char_traitsIcEEE3getEPcl`
  * `_ZNSt3__113basic_istreamIcNS_11char_traitsIcEEEC2EPNS_15basic_streambufIcS2_EE`
  * `_ZNSt3__113basic_istreamIcNS_11char_traitsIcEEErsEPFRNS_9basic_iosIcS2_EES6_E`
  * `_ZNSt3__115basic_streambufIwNS_11char_traitsIwEEE7pubsyncEv`
  * `_ZNSt3__115basic_streambufIcNS_11char_traitsIcEEE5sputcEc`
  * `_ZNSt3__113basic_ostreamIwNS_11char_traitsIwEEE5seekpExNS_8ios_base7seekdirE`
  * `_ZNKSt3__115basic_streambufIcNS_11char_traitsIcEEE6getlocEv`
  * `_ZNSt3__115basic_streambufIcNS_11char_traitsIcEEE5gbumpEi`
  * `_ZNSt3__114basic_iostreamIcNS_11char_traitsIcEEE4swapERS3_`
  * `_ZNSt3__113basic_ostreamIwNS_11char_traitsIwEEE5seekpENS_4fposI11__mbstate_tEE`
  * `_ZNSt3__113basic_ostreamIwNS_11char_traitsIwEEE5tellpEv`
  * `_ZNSt3__113basic_ostreamIwNS_11char_traitsIwEEElsEPFRS3_S4_E`
  * `_ZNSt3__113basic_istreamIwNS_11char_traitsIwEEE3getEPwl`
  * `_ZNSt3__113basic_istreamIwNS_11char_traitsIwEEEC2EPNS_15basic_streambufIwS2_EE`
  * `_ZNSt3__113basic_ostreamIcNS_11char_traitsIcEEElsEPFRS3_S4_E`
  * `_ZNSt3__115basic_streambufIcNS_11char_traitsIcEEE4setgEPcS4_S4_`
  * `_ZNSt3__112basic_stringIwNS_11char_traitsIwEENS_9allocatorIwEEE6__initEPKwmm`
  * `_ZNSt3__115basic_streambufIwNS_11char_traitsIwEEE4setgEPwS4_S4_`
  * `_ZNSt3__113basic_istreamIwNS_11char_traitsIwEEEC1EPNS_15basic_streambufIwS2_EE`
  * `_ZNSt3__115basic_streambufIcNS_11char_traitsIcEEE8pubimbueERKNS_6localeE`
  * `_ZNSt3__113basic_ostreamIcNS_11char_traitsIcEEE4swapERS3_`
  * `_ZNSt3__113basic_ostreamIwNS_11char_traitsIwEEEC2EPNS_15basic_streambufIwS2_EE`
  * `_ZNSt3__115basic_streambufIwNS_11char_traitsIwEEE10pubseekposENS_4fposI11__mbstate_tEEj`
  * `_ZNSt3__115basic_streambufIcNS_11char_traitsIcEEE5pbumpEi`
  * `_ZNSt3__115basic_streambufIwNS_11char_traitsIwEEE5sgetcEv`
  * `_ZNSt3__113basic_ostreamIwNS_11char_traitsIwEEE4swapERS3_`
  * `_ZNSt3__115basic_streambufIcNS_11char_traitsIcEEE10pubseekposENS_4fposI11__mbstate_tEEj`
  * `_ZNSt3__115basic_streambufIcNS_11char_traitsIcEEE5sputnEPKcl`
  * `_ZNSt3__113basic_ostreamIcNS_11char_traitsIcEEE5seekpExNS_8ios_base7seekdirE`
  * `_ZNSt3__115basic_streambufIwNS_11char_traitsIwEEE5sgetnEPwl`
  * `_ZNSt3__113basic_ostreamIwNS_11char_traitsIwEEElsEPFRNS_8ios_baseES5_E`
  * `_ZNSt3__115basic_streambufIwNS_11char_traitsIwEEE4setpEPwS4_`
  * `_ZNSt3__115basic_streambufIcNS_11char_traitsIcEEE5sgetnEPcl`
  * `_ZNKSt3__115basic_streambufIwNS_11char_traitsIwEEE6getlocEv`
  * `_ZNSt3__114basic_iostreamIcNS_11char_traitsIcEEEC2EPNS_15basic_streambufIcS2_EE`
  * `_ZNSt3__115basic_streambufIwNS_11char_traitsIwEEE8pubimbueERKNS_6localeE`
  * `_ZNSt3__114basic_iostreamIcNS_11char_traitsIcEEEC1EPNS_15basic_streambufIcS2_EE`
  * `_ZNSt3__115basic_streambufIwNS_11char_traitsIwEEE8in_availEv`
  * `_ZNSt3__113basic_istreamIcNS_11char_traitsIcEEEC1EPNS_15basic_streambufIcS2_EE`
  * `_ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6__initEPKcmm`
  * `_ZNSt3__115basic_streambufIwNS_11char_traitsIwEEE6sbumpcEv`
  * `_ZNSt3__115basic_streambufIwNS_11char_traitsIwEEE10pubseekoffExNS_8ios_base7seekdirEj`
  * `_ZNSt3__113basic_ostreamIcNS_11char_traitsIcEEEC2EPNS_15basic_streambufIcS2_EE`
  * `_ZNSt3__113basic_istreamIwNS_11char_traitsIwEEErsEPFRS3_S4_E`
  * `_ZNSt3__115basic_streambufIwNS_11char_traitsIwEEE9sputbackcEw`
  * `_ZNSt3__112basic_stringIwNS_11char_traitsIwEENS_9allocatorIwEEE6__initEPKwm`
  * `_ZNSt3__115basic_streambufIwNS_11char_traitsIwEEE5sputnEPKwl`
  * `_ZNSt3__113basic_istreamIcNS_11char_traitsIcEEErsEPFRS3_S4_E`
  * `_ZNSt3__113basic_ostreamIcNS_11char_traitsIcEEEC1EPNS_15basic_streambufIcS2_EE`
  * `_ZNSt3__115basic_streambufIwNS_11char_traitsIwEEE9pubsetbufEPwl`
  * `_ZNSt3__115basic_streambufIwNS_11char_traitsIwEEE5sputcEw`


This patch has no effect on Clang based builds.



Reviewers: mclow.lists, eugenis, danalbert, jroelofs, EricWF

Subscribers: beanz, cfe-commits, mgorny

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

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@281681 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-16 00:00:48 +00:00
Eric Fiselier
833d644ed1 [libc++] Fix and document visibility attributes for Clang, GCC and Windows.
Summary:
This patch fixes a number of problems with the visibility macros across GCC (on Unix) and Windows (DLL import/export semantics). All of the visibility macros are now documented under `DesignDocs/VisibilityMacros.rst`. Now I'll no longer forget the subtleties of each!

This patch adds two new visibility macros:

* `_LIBCPP_ENUM_VIS` for controlling the typeinfo of enum types. Only Clang supports this.
* `_LIBCPP_EXTERN_TEMPLATE_TYPE_VIS` for redefining visibility on explicit instantiation declarations. Clang and Windows require this.

After applying this patch GCC only emits one -Wattribute warning opposed to 30+.


Reviewers: mclow.lists, EricWF

Subscribers: beanz, mgorny, cfe-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@281673 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-15 22:27:07 +00:00
Asiri Rathnayake
040945b81f [libcxx] Introduce an externally-threaded libc++ variant.
This patch further decouples libc++ from pthread, allowing libc++ to be built
against other threading systems. There are two main use cases:

- Building libc++ against a thread library other than pthreads.

- Building libc++ with an "external" thread API, allowing a separate library to
  provide the implementation of that API.

The two use cases are quite similar, the second one being sligtly more
de-coupled than the first. The cmake option LIBCXX_HAS_EXTERNAL_THREAD_API
enables both kinds of builds. One needs to place an <__external_threading>
header file containing an implementation of the "libc++ thread API" declared
in the <__threading_support> header.

For the second use case, the implementation of the libc++ thread API can
delegate to a custom "external" thread API where the implementation of this
external API is provided in a seperate library. This mechanism allows toolchain
vendors to distribute a build of libc++ with a custom thread-porting-layer API
(which is the "external" API above), platform vendors (recipients of the
toolchain/libc++) are then required to provide their implementation of this API
to be linked with (end-user) C++ programs.

Note that the second use case still requires establishing the basic types that
get passed between the external thread library and the libc++ library
(e.g. __libcpp_mutex_t). These cannot be opaque pointer types (libc++ sources
won't compile otherwise). It should also be noted that the second use case can
have a slight performance penalty; as all the thread constructs need to cross a
library boundary through an additional function call.

When the header <__external_threading> is omitted, libc++ is built with the
"libc++ thread API" (declared in <__threading_support>) as the "external" thread
API (basic types are pthread based). An implementation (pthread based) of this
API is provided in test/support/external_threads.cpp, which is built into a
separate DSO and linked in when running the libc++ test suite. A test run
therefore demonstrates the second use case (less the intermediate custom API).

Differential revision: https://reviews.llvm.org/D21968

Reviewers: bcraig, compnerd, EricWF, mclow.lists

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@281179 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-11 21:46:40 +00:00
Eric Fiselier
01609afe24 Enable installation of libc++experimental by default.
When libc++experimental was originally created it was empty and therefore there
was no reason to install it. Now that the library contains
<experimental/memory_resource> and <experimental/filesystem> there is a good
reason to install it.

Specifically this patch enables the installation whenever LIBCXX_INSTALL_LIBRARY
is true and LIBCPP_ENABLE_EXPERIMENTAL_LIBRARY is true.


git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@280773 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-07 01:15:10 +00:00