2016-06-02 02:16:28 +00:00
|
|
|
.. _BuildingLibcxx:
|
2015-08-22 19:40:49 +00:00
|
|
|
|
|
|
|
===============
|
|
|
|
Building libc++
|
|
|
|
===============
|
|
|
|
|
|
|
|
.. contents::
|
|
|
|
:local:
|
|
|
|
|
2016-05-03 22:32:08 +00:00
|
|
|
.. _build instructions:
|
|
|
|
|
2021-07-06 10:39:01 -04:00
|
|
|
The instructions on this page are aimed at vendors who ship libc++ as part of an
|
2023-05-22 23:25:16 -07:00
|
|
|
operating system distribution, a toolchain or similar shipping vehicles. If you
|
2021-07-06 10:39:01 -04:00
|
|
|
are a user merely trying to use libc++ in your program, you most likely want to
|
|
|
|
refer to your vendor's documentation, or to the general documentation for using
|
|
|
|
libc++ :ref:`here <using-libcxx>`.
|
2015-08-22 19:40:49 +00:00
|
|
|
|
2021-07-06 10:39:01 -04:00
|
|
|
.. warning::
|
|
|
|
If your operating system already provides libc++, it is important to be careful
|
|
|
|
not to replace it. Replacing your system's libc++ installation could render it
|
|
|
|
non-functional. Use the CMake option ``CMAKE_INSTALL_PREFIX`` to select a safe
|
|
|
|
place to install libc++.
|
2015-08-22 19:40:49 +00:00
|
|
|
|
|
|
|
|
2021-07-06 10:39:01 -04:00
|
|
|
The default build
|
|
|
|
=================
|
2015-08-22 19:40:49 +00:00
|
|
|
|
2021-10-07 16:19:11 -04:00
|
|
|
The default way of building libc++, libc++abi and libunwind is to root the CMake
|
|
|
|
invocation at ``<monorepo>/runtimes``. While those projects are under the LLVM
|
|
|
|
umbrella, they are different in nature from other build tools, so it makes sense
|
|
|
|
to treat them as a separate set of entities. The default build can be achieved
|
|
|
|
with the following CMake invocation:
|
2015-08-22 19:40:49 +00:00
|
|
|
|
2019-11-07 12:40:05 -08:00
|
|
|
.. code-block:: bash
|
2015-08-22 19:40:49 +00:00
|
|
|
|
2019-11-07 12:40:05 -08:00
|
|
|
$ git clone https://github.com/llvm/llvm-project.git
|
|
|
|
$ cd llvm-project
|
2021-07-06 10:39:01 -04:00
|
|
|
$ mkdir build
|
2021-10-07 16:19:11 -04:00
|
|
|
$ cmake -G Ninja -S runtimes -B build -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" # Configure
|
|
|
|
$ ninja -C build cxx cxxabi unwind # Build
|
|
|
|
$ ninja -C build check-cxx check-cxxabi check-unwind # Test
|
|
|
|
$ ninja -C build install-cxx install-cxxabi install-unwind # Install
|
2021-07-06 10:39:01 -04:00
|
|
|
|
|
|
|
.. note::
|
|
|
|
See :ref:`CMake Options` below for more configuration options.
|
|
|
|
|
2021-10-07 16:19:11 -04:00
|
|
|
After building the various ``install-XXX`` targets, shared libraries for libc++, libc++abi and
|
|
|
|
libunwind should now be present in ``<CMAKE_INSTALL_PREFIX>/lib``, and headers in
|
|
|
|
``<CMAKE_INSTALL_PREFIX>/include/c++/v1``. See :ref:`using an alternate libc++ installation
|
|
|
|
<alternate libcxx>` for information on how to use this libc++ over the default one.
|
2021-07-06 10:39:01 -04:00
|
|
|
|
2021-10-07 16:19:11 -04:00
|
|
|
In the default configuration, the runtimes will be built using the compiler available by default
|
|
|
|
on your system. Of course, you can change what compiler is being used with the usual CMake
|
|
|
|
variables. If you wish to build the runtimes from a just-built Clang, the bootstrapping build
|
|
|
|
explained below makes this task easy.
|
2021-07-06 10:39:01 -04:00
|
|
|
|
|
|
|
|
|
|
|
Bootstrapping build
|
|
|
|
===================
|
|
|
|
|
2021-10-07 16:19:11 -04:00
|
|
|
It is possible to build Clang and then build the runtimes using that just-built compiler in a
|
|
|
|
single CMake invocation. This is usually the correct way to build the runtimes when putting together
|
|
|
|
a toolchain, or when the system compiler is not adequate to build them (too old, unsupported, etc.).
|
|
|
|
To do this, use the following CMake invocation, and in particular notice how we're now rooting the
|
|
|
|
CMake invocation at ``<monorepo>/llvm``:
|
2015-08-22 19:40:49 +00:00
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
2021-07-06 10:39:01 -04:00
|
|
|
$ mkdir build
|
2021-10-07 16:19:11 -04:00
|
|
|
$ cmake -G Ninja -S llvm -B build -DLLVM_ENABLE_PROJECTS="clang" \ # Configure
|
|
|
|
-DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" \
|
2021-07-06 10:39:01 -04:00
|
|
|
-DLLVM_RUNTIME_TARGETS="<target-triple>"
|
2021-10-07 16:19:11 -04:00
|
|
|
$ ninja -C build runtimes # Build
|
|
|
|
$ ninja -C build check-runtimes # Test
|
|
|
|
$ ninja -C build install-runtimes # Install
|
2015-08-22 19:40:49 +00:00
|
|
|
|
2021-10-07 16:19:11 -04:00
|
|
|
.. note::
|
|
|
|
This type of build is also commonly called a "Runtimes build", but we would like to move
|
|
|
|
away from that terminology, which is too confusing.
|
2015-08-22 19:40:49 +00:00
|
|
|
|
2023-09-07 13:22:07 -04:00
|
|
|
.. warning::
|
|
|
|
Adding the `--fresh` flag to the top-level cmake invocation in a bootstrapping build *will not*
|
|
|
|
freshen the cmake cache of any of the enabled runtimes.
|
|
|
|
|
2021-02-22 01:20:28 +02:00
|
|
|
Support for Windows
|
2021-07-06 10:39:01 -04:00
|
|
|
===================
|
2017-02-10 03:58:20 +00:00
|
|
|
|
2021-02-22 01:20:28 +02:00
|
|
|
libcxx supports being built with clang-cl, but not with MSVC's cl.exe, as
|
2021-03-17 11:40:17 +02:00
|
|
|
cl doesn't support the ``#include_next`` extension. Furthermore, VS 2017 or
|
2021-02-22 01:20:28 +02:00
|
|
|
newer (19.14) is required.
|
|
|
|
|
|
|
|
libcxx also supports being built with clang targeting MinGW environments.
|
2017-02-10 03:58:20 +00:00
|
|
|
|
|
|
|
CMake + Visual Studio
|
2021-07-06 10:39:01 -04:00
|
|
|
---------------------
|
2017-02-10 03:58:20 +00:00
|
|
|
|
|
|
|
Building with Visual Studio currently does not permit running tests. However,
|
|
|
|
it is the simplest way to build.
|
|
|
|
|
|
|
|
.. code-block:: batch
|
|
|
|
|
2022-03-30 13:13:45 +03:00
|
|
|
> cmake -G "Visual Studio 16 2019" -S runtimes -B build ^
|
|
|
|
-T "ClangCL" ^
|
|
|
|
-DLLVM_ENABLE_RUNTIMES=libcxx ^
|
|
|
|
-DLIBCXX_ENABLE_SHARED=YES ^
|
2022-07-19 10:44:06 -04:00
|
|
|
-DLIBCXX_ENABLE_STATIC=NO
|
2021-07-06 10:39:01 -04:00
|
|
|
> cmake --build build
|
2017-02-10 03:58:20 +00:00
|
|
|
|
2021-02-22 01:20:28 +02:00
|
|
|
CMake + ninja (MSVC)
|
2021-07-06 10:39:01 -04:00
|
|
|
--------------------
|
2017-02-10 03:58:20 +00:00
|
|
|
|
|
|
|
Building with ninja is required for development to enable tests.
|
2021-05-03 22:14:00 +03:00
|
|
|
A couple of tests require Bash to be available, and a couple dozens
|
|
|
|
of tests require other posix tools (cp, grep and similar - LLVM's tests
|
|
|
|
require the same). Without those tools the vast majority of tests
|
|
|
|
can still be ran successfully.
|
2021-02-22 01:20:28 +02:00
|
|
|
|
|
|
|
If Git for Windows is available, that can be used to provide the bash
|
|
|
|
shell by adding the right bin directory to the path, e.g.
|
2021-03-17 11:40:17 +02:00
|
|
|
``set PATH=%PATH%;C:\Program Files\Git\usr\bin``.
|
2021-02-22 01:20:28 +02:00
|
|
|
|
|
|
|
Alternatively, one can also choose to run the whole build in a MSYS2
|
|
|
|
shell. That can be set up e.g. by starting a Visual Studio Tools Command
|
|
|
|
Prompt (for getting the environment variables pointing to the headers and
|
|
|
|
import libraries), and making sure that clang-cl is available in the
|
|
|
|
path. From there, launch an MSYS2 shell via e.g.
|
2021-03-17 11:40:17 +02:00
|
|
|
``C:\msys64\msys2_shell.cmd -full-path -mingw64`` (preserving the earlier
|
2021-02-22 01:20:28 +02:00
|
|
|
environment, allowing the MSVC headers/libraries and clang-cl to be found).
|
|
|
|
|
|
|
|
In either case, then run:
|
2017-02-10 03:58:20 +00:00
|
|
|
|
|
|
|
.. code-block:: batch
|
|
|
|
|
2022-03-30 13:13:45 +03:00
|
|
|
> cmake -G Ninja -S runtimes -B build ^
|
2017-02-10 03:58:20 +00:00
|
|
|
-DCMAKE_C_COMPILER=clang-cl ^
|
2021-02-22 01:20:28 +02:00
|
|
|
-DCMAKE_CXX_COMPILER=clang-cl ^
|
2022-07-19 10:44:06 -04:00
|
|
|
-DLLVM_ENABLE_RUNTIMES=libcxx
|
2021-07-06 10:39:01 -04:00
|
|
|
> ninja -C build cxx
|
|
|
|
> ninja -C build check-cxx
|
2021-02-22 01:20:28 +02:00
|
|
|
|
|
|
|
If you are running in an MSYS2 shell and you have installed the
|
|
|
|
MSYS2-provided clang package (which defaults to a non-MSVC target), you
|
2021-10-12 15:59:08 -04:00
|
|
|
should add e.g. ``-DCMAKE_CXX_COMPILER_TARGET=x86_64-windows-msvc`` (replacing
|
2021-03-17 11:40:17 +02:00
|
|
|
``x86_64`` with the architecture you're targeting) to the ``cmake`` command
|
|
|
|
line above. This will instruct ``check-cxx`` to use the right target triple
|
|
|
|
when invoking ``clang++``.
|
2021-02-22 01:20:28 +02:00
|
|
|
|
|
|
|
CMake + ninja (MinGW)
|
2021-07-06 10:39:01 -04:00
|
|
|
---------------------
|
2021-02-22 01:20:28 +02:00
|
|
|
|
|
|
|
libcxx can also be built in MinGW environments, e.g. with the MinGW
|
|
|
|
compilers in MSYS2. This requires clang to be available (installed with
|
2021-03-17 11:40:17 +02:00
|
|
|
e.g. the ``mingw-w64-x86_64-clang`` package), together with CMake and ninja.
|
2021-02-22 01:20:28 +02:00
|
|
|
|
|
|
|
.. code-block:: bash
|
2017-02-10 03:58:20 +00:00
|
|
|
|
2022-03-30 13:13:45 +03:00
|
|
|
> cmake -G Ninja -S runtimes -B build \
|
2021-02-22 01:20:28 +02:00
|
|
|
-DCMAKE_C_COMPILER=clang \
|
|
|
|
-DCMAKE_CXX_COMPILER=clang++ \
|
2023-10-11 16:35:08 +03:00
|
|
|
-DLLVM_ENABLE_LLD=ON \
|
|
|
|
-DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi" \
|
|
|
|
-DLIBCXXABI_ENABLE_SHARED=OFF \
|
|
|
|
-DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=ON
|
2021-07-06 10:39:01 -04:00
|
|
|
> ninja -C build cxx
|
|
|
|
> ninja -C build check-cxx
|
2021-02-22 01:20:28 +02:00
|
|
|
|
2015-08-22 19:40:49 +00:00
|
|
|
.. _`libc++abi`: http://libcxxabi.llvm.org/
|
|
|
|
|
|
|
|
|
|
|
|
.. _CMake Options:
|
|
|
|
|
|
|
|
CMake Options
|
|
|
|
=============
|
|
|
|
|
|
|
|
Here are some of the CMake variables that are used often, along with a
|
|
|
|
brief explanation and LLVM-specific notes. For full documentation, check the
|
|
|
|
CMake docs or execute ``cmake --help-variable VARIABLE_NAME``.
|
|
|
|
|
|
|
|
**CMAKE_BUILD_TYPE**:STRING
|
|
|
|
Sets the build type for ``make`` based generators. Possible values are
|
|
|
|
Release, Debug, RelWithDebInfo and MinSizeRel. On systems like Visual Studio
|
|
|
|
the user sets the build type with the IDE settings.
|
|
|
|
|
|
|
|
**CMAKE_INSTALL_PREFIX**:PATH
|
|
|
|
Path where LLVM will be installed if "make install" is invoked or the
|
|
|
|
"INSTALL" target is built.
|
|
|
|
|
|
|
|
**CMAKE_CXX_COMPILER**:STRING
|
|
|
|
The C++ compiler to use when building and testing libc++.
|
|
|
|
|
|
|
|
|
|
|
|
.. _libcxx-specific options:
|
|
|
|
|
|
|
|
libc++ specific options
|
|
|
|
-----------------------
|
|
|
|
|
2016-05-03 22:32:08 +00:00
|
|
|
.. option:: LIBCXX_INSTALL_LIBRARY:BOOL
|
|
|
|
|
|
|
|
**Default**: ``ON``
|
|
|
|
|
|
|
|
Toggle the installation of the library portion of libc++.
|
|
|
|
|
|
|
|
.. option:: LIBCXX_INSTALL_HEADERS:BOOL
|
|
|
|
|
|
|
|
**Default**: ``ON``
|
|
|
|
|
|
|
|
Toggle the installation of the libc++ headers.
|
|
|
|
|
2015-08-22 19:40:49 +00:00
|
|
|
.. option:: LIBCXX_ENABLE_SHARED:BOOL
|
|
|
|
|
|
|
|
**Default**: ``ON``
|
|
|
|
|
2016-09-16 03:47:53 +00:00
|
|
|
Build libc++ as a shared library. Either `LIBCXX_ENABLE_SHARED` or
|
|
|
|
`LIBCXX_ENABLE_STATIC` has to be enabled.
|
2016-08-08 22:57:25 +00:00
|
|
|
|
|
|
|
.. option:: LIBCXX_ENABLE_STATIC:BOOL
|
|
|
|
|
|
|
|
**Default**: ``ON``
|
|
|
|
|
2016-09-16 03:47:53 +00:00
|
|
|
Build libc++ as a static library. Either `LIBCXX_ENABLE_SHARED` or
|
|
|
|
`LIBCXX_ENABLE_STATIC` has to be enabled.
|
2015-08-22 19:40:49 +00:00
|
|
|
|
2022-08-18 22:44:46 -04:00
|
|
|
.. option:: LIBCXX_LIBDIR_SUFFIX:STRING
|
|
|
|
|
|
|
|
Extra suffix to append to the directory where libraries are to be installed.
|
|
|
|
This option overrides `LLVM_LIBDIR_SUFFIX`.
|
|
|
|
|
2019-01-06 06:14:31 +00:00
|
|
|
.. option:: LIBCXX_HERMETIC_STATIC_LIBRARY:BOOL
|
|
|
|
|
|
|
|
**Default**: ``OFF``
|
|
|
|
|
2019-04-10 23:44:27 +00:00
|
|
|
Do not export any symbols from the static libc++ library.
|
2019-01-06 06:14:31 +00:00
|
|
|
This is useful when the static libc++ library is being linked into shared
|
|
|
|
libraries that may be used in with other shared libraries that use different
|
2019-08-23 19:42:09 +00:00
|
|
|
C++ library. We want to avoid exporting any libc++ symbols in that case.
|
2019-01-06 06:14:31 +00:00
|
|
|
|
2019-03-21 00:04:31 +00:00
|
|
|
.. option:: LIBCXX_ENABLE_FILESYSTEM:BOOL
|
|
|
|
|
2021-07-29 07:54:48 +02:00
|
|
|
**Default**: ``ON`` except on Windows when using MSVC.
|
2019-03-21 00:04:31 +00:00
|
|
|
|
|
|
|
This option can be used to enable or disable the filesystem components on
|
2021-07-29 07:54:48 +02:00
|
|
|
platforms that may not support them. For example on Windows when using MSVC.
|
2019-03-21 00:04:31 +00:00
|
|
|
|
2021-08-23 15:32:36 -04:00
|
|
|
.. option:: LIBCXX_ENABLE_WIDE_CHARACTERS:BOOL
|
|
|
|
|
|
|
|
**Default**: ``ON``
|
|
|
|
|
|
|
|
This option can be used to disable support for ``wchar_t`` in the library. It also
|
|
|
|
allows the library to work on top of a C Standard Library that does not provide
|
|
|
|
support for ``wchar_t``. This is especially useful in embedded settings where
|
|
|
|
C Standard Libraries don't always provide all the usual bells and whistles.
|
|
|
|
|
2022-09-23 18:33:20 +02:00
|
|
|
.. option:: LIBCXX_ENABLE_TIME_ZONE_DATABASE:BOOL
|
|
|
|
|
|
|
|
**Default**: ``ON``
|
|
|
|
|
|
|
|
Whether to include support for time zones in the library. Disabling
|
|
|
|
time zone support can be useful when porting to platforms that don't
|
|
|
|
ship the IANA time zone database. When time zones are not supported,
|
|
|
|
time zone support in <chrono> will be disabled.
|
|
|
|
|
Prepare Compiler-RT for GnuInstallDirs, matching libcxx, document all
This is a second attempt at D101497, which landed as
9a9bc76c0eb72f0f2732c729a460abbd5239c2e3 but had to be reverted in
8cf7ddbdd4e5af966a369e170c73250f2e3920e7.
This issue was that in the case that `COMPILER_RT_INSTALL_PATH` is
empty, expressions like "${COMPILER_RT_INSTALL_PATH}/bin" evaluated to
"/bin" not "bin" as intended and as was originally.
One solution is to make `COMPILER_RT_INSTALL_PATH` always non-empty,
defaulting it to `CMAKE_INSTALL_PREFIX`. D99636 adopted that approach.
But, I think it is more ergonomic to allow those project-specific paths
to be relative the global ones. Also, making install paths absolute by
default inhibits the proper behavior of functions like
`GNUInstallDirs_get_absolute_install_dir` which make relative install
paths absolute in a more complicated way.
Given all this, I will define a function like the one asked for in
https://gitlab.kitware.com/cmake/cmake/-/issues/19568 (and needed for a
similar use-case).
---
Original message:
Instead of using `COMPILER_RT_INSTALL_PATH` through the CMake for
complier-rt, just use it to define variables for the subdirs which
themselves are used.
This preserves compatibility, but later on we might consider getting rid
of `COMPILER_RT_INSTALL_PATH` and just changing the defaults for the
subdir variables directly.
---
There was a seaming bug where the (non-Apple) per-target libdir was
`${target}` not `lib/${target}`. I suspect that has to do with the docs
on `COMPILER_RT_INSTALL_PATH` saying was the library dir when that's no
longer true, so I just went ahead and fixed it, allowing me to define
fewer and more sensible variables.
That last part should be the only behavior changes; everything else
should be a pure refactoring.
---
I added some documentation of these variables too. In particular, I
wanted to highlight the gotcha where `-DSomeCachePath=...` without the
`:PATH` will lead CMake to make the path absolute. See [1] for
discussion of the problem, and [2] for the brief official documentation
they added as a result.
[1]: https://cmake.org/pipermail/cmake/2015-March/060204.html
[2]: https://cmake.org/cmake/help/latest/manual/cmake.1.html#options
In 38b2dec37ee735d5409148e71ecba278caf0f969 the problem was somewhat
misidentified and so `:STRING` was used, but `:PATH` is better as it
sets the correct type from the get-go.
---
D99484 is the main thrust of the `GnuInstallDirs` work. Once this lands,
it should be feasible to follow both of these up with a simple patch for
compiler-rt analogous to the one for libcxx.
Reviewed By: phosek, #libc_abi, #libunwind
Differential Revision: https://reviews.llvm.org/D105765
2021-04-28 22:36:47 +00:00
|
|
|
.. option:: LIBCXX_INSTALL_LIBRARY_DIR:PATH
|
|
|
|
|
2022-08-18 22:44:46 -04:00
|
|
|
**Default**: ``lib${LIBCXX_LIBDIR_SUFFIX}``
|
Prepare Compiler-RT for GnuInstallDirs, matching libcxx, document all
This is a second attempt at D101497, which landed as
9a9bc76c0eb72f0f2732c729a460abbd5239c2e3 but had to be reverted in
8cf7ddbdd4e5af966a369e170c73250f2e3920e7.
This issue was that in the case that `COMPILER_RT_INSTALL_PATH` is
empty, expressions like "${COMPILER_RT_INSTALL_PATH}/bin" evaluated to
"/bin" not "bin" as intended and as was originally.
One solution is to make `COMPILER_RT_INSTALL_PATH` always non-empty,
defaulting it to `CMAKE_INSTALL_PREFIX`. D99636 adopted that approach.
But, I think it is more ergonomic to allow those project-specific paths
to be relative the global ones. Also, making install paths absolute by
default inhibits the proper behavior of functions like
`GNUInstallDirs_get_absolute_install_dir` which make relative install
paths absolute in a more complicated way.
Given all this, I will define a function like the one asked for in
https://gitlab.kitware.com/cmake/cmake/-/issues/19568 (and needed for a
similar use-case).
---
Original message:
Instead of using `COMPILER_RT_INSTALL_PATH` through the CMake for
complier-rt, just use it to define variables for the subdirs which
themselves are used.
This preserves compatibility, but later on we might consider getting rid
of `COMPILER_RT_INSTALL_PATH` and just changing the defaults for the
subdir variables directly.
---
There was a seaming bug where the (non-Apple) per-target libdir was
`${target}` not `lib/${target}`. I suspect that has to do with the docs
on `COMPILER_RT_INSTALL_PATH` saying was the library dir when that's no
longer true, so I just went ahead and fixed it, allowing me to define
fewer and more sensible variables.
That last part should be the only behavior changes; everything else
should be a pure refactoring.
---
I added some documentation of these variables too. In particular, I
wanted to highlight the gotcha where `-DSomeCachePath=...` without the
`:PATH` will lead CMake to make the path absolute. See [1] for
discussion of the problem, and [2] for the brief official documentation
they added as a result.
[1]: https://cmake.org/pipermail/cmake/2015-March/060204.html
[2]: https://cmake.org/cmake/help/latest/manual/cmake.1.html#options
In 38b2dec37ee735d5409148e71ecba278caf0f969 the problem was somewhat
misidentified and so `:STRING` was used, but `:PATH` is better as it
sets the correct type from the get-go.
---
D99484 is the main thrust of the `GnuInstallDirs` work. Once this lands,
it should be feasible to follow both of these up with a simple patch for
compiler-rt analogous to the one for libcxx.
Reviewed By: phosek, #libc_abi, #libunwind
Differential Revision: https://reviews.llvm.org/D105765
2021-04-28 22:36:47 +00:00
|
|
|
|
|
|
|
Path where built libc++ libraries should be installed. If a relative path,
|
|
|
|
relative to ``CMAKE_INSTALL_PREFIX``.
|
|
|
|
|
|
|
|
.. option:: LIBCXX_INSTALL_INCLUDE_DIR:PATH
|
|
|
|
|
|
|
|
**Default**: ``include/c++/v1``
|
|
|
|
|
|
|
|
Path where target-agnostic libc++ headers should be installed. If a relative
|
|
|
|
path, relative to ``CMAKE_INSTALL_PREFIX``.
|
|
|
|
|
|
|
|
.. option:: LIBCXX_INSTALL_INCLUDE_TARGET_DIR:PATH
|
|
|
|
|
|
|
|
**Default**: ``include/c++/v1`` or
|
2022-12-05 22:20:51 +00:00
|
|
|
``include/${LLVM_DEFAULT_TARGET_TRIPLE}/c++/v1``
|
Prepare Compiler-RT for GnuInstallDirs, matching libcxx, document all
This is a second attempt at D101497, which landed as
9a9bc76c0eb72f0f2732c729a460abbd5239c2e3 but had to be reverted in
8cf7ddbdd4e5af966a369e170c73250f2e3920e7.
This issue was that in the case that `COMPILER_RT_INSTALL_PATH` is
empty, expressions like "${COMPILER_RT_INSTALL_PATH}/bin" evaluated to
"/bin" not "bin" as intended and as was originally.
One solution is to make `COMPILER_RT_INSTALL_PATH` always non-empty,
defaulting it to `CMAKE_INSTALL_PREFIX`. D99636 adopted that approach.
But, I think it is more ergonomic to allow those project-specific paths
to be relative the global ones. Also, making install paths absolute by
default inhibits the proper behavior of functions like
`GNUInstallDirs_get_absolute_install_dir` which make relative install
paths absolute in a more complicated way.
Given all this, I will define a function like the one asked for in
https://gitlab.kitware.com/cmake/cmake/-/issues/19568 (and needed for a
similar use-case).
---
Original message:
Instead of using `COMPILER_RT_INSTALL_PATH` through the CMake for
complier-rt, just use it to define variables for the subdirs which
themselves are used.
This preserves compatibility, but later on we might consider getting rid
of `COMPILER_RT_INSTALL_PATH` and just changing the defaults for the
subdir variables directly.
---
There was a seaming bug where the (non-Apple) per-target libdir was
`${target}` not `lib/${target}`. I suspect that has to do with the docs
on `COMPILER_RT_INSTALL_PATH` saying was the library dir when that's no
longer true, so I just went ahead and fixed it, allowing me to define
fewer and more sensible variables.
That last part should be the only behavior changes; everything else
should be a pure refactoring.
---
I added some documentation of these variables too. In particular, I
wanted to highlight the gotcha where `-DSomeCachePath=...` without the
`:PATH` will lead CMake to make the path absolute. See [1] for
discussion of the problem, and [2] for the brief official documentation
they added as a result.
[1]: https://cmake.org/pipermail/cmake/2015-March/060204.html
[2]: https://cmake.org/cmake/help/latest/manual/cmake.1.html#options
In 38b2dec37ee735d5409148e71ecba278caf0f969 the problem was somewhat
misidentified and so `:STRING` was used, but `:PATH` is better as it
sets the correct type from the get-go.
---
D99484 is the main thrust of the `GnuInstallDirs` work. Once this lands,
it should be feasible to follow both of these up with a simple patch for
compiler-rt analogous to the one for libcxx.
Reviewed By: phosek, #libc_abi, #libunwind
Differential Revision: https://reviews.llvm.org/D105765
2021-04-28 22:36:47 +00:00
|
|
|
|
|
|
|
Path where target-specific libc++ headers should be installed. If a relative
|
|
|
|
path, relative to ``CMAKE_INSTALL_PREFIX``.
|
|
|
|
|
2022-10-03 16:41:58 -05:00
|
|
|
.. option:: LIBCXX_SHARED_OUTPUT_NAME:STRING
|
|
|
|
|
|
|
|
**Default**: ``c++``
|
|
|
|
|
|
|
|
Output name for the shared libc++ runtime library.
|
|
|
|
|
|
|
|
.. option:: LIBCXX_ADDITIONAL_COMPILE_FLAGS:STRING
|
|
|
|
|
|
|
|
**Default**: ``""``
|
|
|
|
|
|
|
|
Additional Compile only flags which can be provided in cache.
|
|
|
|
|
|
|
|
.. option:: LIBCXX_ADDITIONAL_LIBRARIES:STRING
|
|
|
|
|
|
|
|
**Default**: ``""``
|
|
|
|
|
|
|
|
Additional libraries libc++ is linked to which can be provided in cache.
|
|
|
|
|
2016-05-03 22:32:08 +00:00
|
|
|
|
2015-08-22 19:40:49 +00:00
|
|
|
.. _ABI Library Specific Options:
|
|
|
|
|
|
|
|
ABI Library Specific Options
|
|
|
|
----------------------------
|
|
|
|
|
|
|
|
.. option:: LIBCXX_CXX_ABI:STRING
|
|
|
|
|
2022-03-01 08:42:13 -05:00
|
|
|
**Values**: ``none``, ``libcxxabi``, ``system-libcxxabi``, ``libcxxrt``, ``libstdc++``, ``libsupc++``, ``vcruntime``.
|
2015-08-22 19:40:49 +00:00
|
|
|
|
|
|
|
Select the ABI library to build libc++ against.
|
|
|
|
|
|
|
|
.. option:: LIBCXX_CXX_ABI_INCLUDE_PATHS:PATHS
|
|
|
|
|
|
|
|
Provide additional search paths for the ABI library headers.
|
|
|
|
|
|
|
|
.. option:: LIBCXX_CXX_ABI_LIBRARY_PATH:PATH
|
|
|
|
|
2022-03-01 08:42:13 -05:00
|
|
|
Provide the path to the ABI library that libc++ should link against. This is only
|
|
|
|
useful when linking against an out-of-tree ABI library.
|
2015-08-22 19:40:49 +00:00
|
|
|
|
|
|
|
.. option:: LIBCXX_ENABLE_STATIC_ABI_LIBRARY:BOOL
|
|
|
|
|
|
|
|
**Default**: ``OFF``
|
|
|
|
|
|
|
|
If this option is enabled, libc++ will try and link the selected ABI library
|
|
|
|
statically.
|
|
|
|
|
2015-10-15 22:41:51 +00:00
|
|
|
.. option:: LIBCXX_ENABLE_ABI_LINKER_SCRIPT:BOOL
|
|
|
|
|
|
|
|
**Default**: ``ON`` by default on UNIX platforms other than Apple unless
|
|
|
|
'LIBCXX_ENABLE_STATIC_ABI_LIBRARY' is ON. Otherwise the default value is ``OFF``.
|
|
|
|
|
|
|
|
This option generate and installs a linker script as ``libc++.so`` which
|
|
|
|
links the correct ABI library.
|
|
|
|
|
2015-08-22 19:40:49 +00:00
|
|
|
.. option:: LIBCXXABI_USE_LLVM_UNWINDER:BOOL
|
|
|
|
|
2024-01-11 10:13:21 -05:00
|
|
|
**Default**: ``ON``
|
2015-08-22 19:40:49 +00:00
|
|
|
|
|
|
|
Build and use the LLVM unwinder. Note: This option can only be used when
|
|
|
|
libc++abi is the C++ ABI library used.
|
|
|
|
|
2022-10-03 16:41:58 -05:00
|
|
|
.. option:: LIBCXXABI_ADDITIONAL_COMPILE_FLAGS:STRING
|
|
|
|
|
|
|
|
**Default**: ``""``
|
|
|
|
|
|
|
|
Additional Compile only flags which can be provided in cache.
|
|
|
|
|
|
|
|
.. option:: LIBCXXABI_ADDITIONAL_LIBRARIES:STRING
|
|
|
|
|
|
|
|
**Default**: ``""``
|
|
|
|
|
|
|
|
Additional libraries libc++abi is linked to which can be provided in cache.
|
|
|
|
|
2015-08-22 19:40:49 +00:00
|
|
|
|
[libcxx] Add support for benchmark tests using Google Benchmark.
Summary:
This patch does the following:
1. Checks in a copy of the Google Benchmark library into the libc++ repo under `utils/google-benchmark`.
2. Teaches libc++ how to build Google Benchmark against both (A) in-tree libc++ and (B) the platforms native STL.
3. Allows performance benchmarks to be built as part of the libc++ build.
Building the benchmarks (and Google Benchmark) is off by default. It must be enabled using the CMake option `-DLIBCXX_INCLUDE_BENCHMARKS=ON`. When this option is enabled the tests under `libcxx/benchmarks` can be built using the `libcxx-benchmarks` target.
On Linux platforms where libstdc++ is the default STL the CMake option `-DLIBCXX_BUILD_BENCHMARKS_NATIVE_STDLIB=ON` can be used to build each benchmark test against libstdc++ as well. This is useful for comparing performance between standard libraries.
Support for benchmarks is currently very minimal. They must be manually run by the user and there is no mechanism for detecting performance regressions.
Known Issues:
* `-DLIBCXX_INCLUDE_BENCHMARKS=ON` is only supported for Clang, and not GCC, since the `-stdlib=libc++` option is needed to build Google Benchmark.
Reviewers: danalbert, dberlin, chandlerc, mclow.lists, jroelofs
Subscribers: chandlerc, dberlin, tberghammer, danalbert, srhines, hfinkel
Differential Revision: https://reviews.llvm.org/D22240
llvm-svn: 276049
2016-07-19 23:07:03 +00:00
|
|
|
libc++ Feature Options
|
2015-08-22 19:40:49 +00:00
|
|
|
----------------------
|
|
|
|
|
|
|
|
.. option:: LIBCXX_ENABLE_EXCEPTIONS:BOOL
|
|
|
|
|
|
|
|
**Default**: ``ON``
|
|
|
|
|
|
|
|
Build libc++ with exception support.
|
|
|
|
|
|
|
|
.. option:: LIBCXX_ENABLE_RTTI:BOOL
|
|
|
|
|
|
|
|
**Default**: ``ON``
|
|
|
|
|
|
|
|
Build libc++ with run time type information.
|
2023-12-12 17:11:53 +01:00
|
|
|
This option may only be set to OFF when LIBCXX_ENABLE_EXCEPTIONS=OFF.
|
2015-08-22 19:40:49 +00:00
|
|
|
|
2019-07-04 19:08:16 +00:00
|
|
|
.. option:: LIBCXX_INCLUDE_TESTS:BOOL
|
|
|
|
|
2021-02-18 11:58:48 -05:00
|
|
|
**Default**: ``ON`` (or value of ``LLVM_INCLUDE_TESTS``)
|
2019-07-04 19:08:16 +00:00
|
|
|
|
|
|
|
Build the libc++ tests.
|
|
|
|
|
[libcxx] Add support for benchmark tests using Google Benchmark.
Summary:
This patch does the following:
1. Checks in a copy of the Google Benchmark library into the libc++ repo under `utils/google-benchmark`.
2. Teaches libc++ how to build Google Benchmark against both (A) in-tree libc++ and (B) the platforms native STL.
3. Allows performance benchmarks to be built as part of the libc++ build.
Building the benchmarks (and Google Benchmark) is off by default. It must be enabled using the CMake option `-DLIBCXX_INCLUDE_BENCHMARKS=ON`. When this option is enabled the tests under `libcxx/benchmarks` can be built using the `libcxx-benchmarks` target.
On Linux platforms where libstdc++ is the default STL the CMake option `-DLIBCXX_BUILD_BENCHMARKS_NATIVE_STDLIB=ON` can be used to build each benchmark test against libstdc++ as well. This is useful for comparing performance between standard libraries.
Support for benchmarks is currently very minimal. They must be manually run by the user and there is no mechanism for detecting performance regressions.
Known Issues:
* `-DLIBCXX_INCLUDE_BENCHMARKS=ON` is only supported for Clang, and not GCC, since the `-stdlib=libc++` option is needed to build Google Benchmark.
Reviewers: danalbert, dberlin, chandlerc, mclow.lists, jroelofs
Subscribers: chandlerc, dberlin, tberghammer, danalbert, srhines, hfinkel
Differential Revision: https://reviews.llvm.org/D22240
llvm-svn: 276049
2016-07-19 23:07:03 +00:00
|
|
|
.. option:: LIBCXX_INCLUDE_BENCHMARKS:BOOL
|
2015-10-13 23:48:28 +00:00
|
|
|
|
2016-08-29 19:50:49 +00:00
|
|
|
**Default**: ``ON``
|
[libcxx] Add support for benchmark tests using Google Benchmark.
Summary:
This patch does the following:
1. Checks in a copy of the Google Benchmark library into the libc++ repo under `utils/google-benchmark`.
2. Teaches libc++ how to build Google Benchmark against both (A) in-tree libc++ and (B) the platforms native STL.
3. Allows performance benchmarks to be built as part of the libc++ build.
Building the benchmarks (and Google Benchmark) is off by default. It must be enabled using the CMake option `-DLIBCXX_INCLUDE_BENCHMARKS=ON`. When this option is enabled the tests under `libcxx/benchmarks` can be built using the `libcxx-benchmarks` target.
On Linux platforms where libstdc++ is the default STL the CMake option `-DLIBCXX_BUILD_BENCHMARKS_NATIVE_STDLIB=ON` can be used to build each benchmark test against libstdc++ as well. This is useful for comparing performance between standard libraries.
Support for benchmarks is currently very minimal. They must be manually run by the user and there is no mechanism for detecting performance regressions.
Known Issues:
* `-DLIBCXX_INCLUDE_BENCHMARKS=ON` is only supported for Clang, and not GCC, since the `-stdlib=libc++` option is needed to build Google Benchmark.
Reviewers: danalbert, dberlin, chandlerc, mclow.lists, jroelofs
Subscribers: chandlerc, dberlin, tberghammer, danalbert, srhines, hfinkel
Differential Revision: https://reviews.llvm.org/D22240
llvm-svn: 276049
2016-07-19 23:07:03 +00:00
|
|
|
|
|
|
|
Build the libc++ benchmark tests and the Google Benchmark library needed
|
|
|
|
to support them.
|
|
|
|
|
2018-11-14 20:38:46 +00:00
|
|
|
.. option:: LIBCXX_BENCHMARK_TEST_ARGS:STRING
|
|
|
|
|
|
|
|
**Default**: ``--benchmark_min_time=0.01``
|
|
|
|
|
|
|
|
A semicolon list of arguments to pass when running the libc++ benchmarks using the
|
|
|
|
``check-cxx-benchmarks`` rule. By default we run the benchmarks for a very short amount of time,
|
|
|
|
since the primary use of ``check-cxx-benchmarks`` is to get test and sanitizer coverage, not to
|
|
|
|
get accurate measurements.
|
|
|
|
|
2016-10-30 22:53:00 +00:00
|
|
|
.. option:: LIBCXX_BENCHMARK_NATIVE_STDLIB:STRING
|
[libcxx] Add support for benchmark tests using Google Benchmark.
Summary:
This patch does the following:
1. Checks in a copy of the Google Benchmark library into the libc++ repo under `utils/google-benchmark`.
2. Teaches libc++ how to build Google Benchmark against both (A) in-tree libc++ and (B) the platforms native STL.
3. Allows performance benchmarks to be built as part of the libc++ build.
Building the benchmarks (and Google Benchmark) is off by default. It must be enabled using the CMake option `-DLIBCXX_INCLUDE_BENCHMARKS=ON`. When this option is enabled the tests under `libcxx/benchmarks` can be built using the `libcxx-benchmarks` target.
On Linux platforms where libstdc++ is the default STL the CMake option `-DLIBCXX_BUILD_BENCHMARKS_NATIVE_STDLIB=ON` can be used to build each benchmark test against libstdc++ as well. This is useful for comparing performance between standard libraries.
Support for benchmarks is currently very minimal. They must be manually run by the user and there is no mechanism for detecting performance regressions.
Known Issues:
* `-DLIBCXX_INCLUDE_BENCHMARKS=ON` is only supported for Clang, and not GCC, since the `-stdlib=libc++` option is needed to build Google Benchmark.
Reviewers: danalbert, dberlin, chandlerc, mclow.lists, jroelofs
Subscribers: chandlerc, dberlin, tberghammer, danalbert, srhines, hfinkel
Differential Revision: https://reviews.llvm.org/D22240
llvm-svn: 276049
2016-07-19 23:07:03 +00:00
|
|
|
|
2016-10-30 22:53:00 +00:00
|
|
|
**Default**:: ``""``
|
|
|
|
|
|
|
|
**Values**:: ``libc++``, ``libstdc++``
|
[libcxx] Add support for benchmark tests using Google Benchmark.
Summary:
This patch does the following:
1. Checks in a copy of the Google Benchmark library into the libc++ repo under `utils/google-benchmark`.
2. Teaches libc++ how to build Google Benchmark against both (A) in-tree libc++ and (B) the platforms native STL.
3. Allows performance benchmarks to be built as part of the libc++ build.
Building the benchmarks (and Google Benchmark) is off by default. It must be enabled using the CMake option `-DLIBCXX_INCLUDE_BENCHMARKS=ON`. When this option is enabled the tests under `libcxx/benchmarks` can be built using the `libcxx-benchmarks` target.
On Linux platforms where libstdc++ is the default STL the CMake option `-DLIBCXX_BUILD_BENCHMARKS_NATIVE_STDLIB=ON` can be used to build each benchmark test against libstdc++ as well. This is useful for comparing performance between standard libraries.
Support for benchmarks is currently very minimal. They must be manually run by the user and there is no mechanism for detecting performance regressions.
Known Issues:
* `-DLIBCXX_INCLUDE_BENCHMARKS=ON` is only supported for Clang, and not GCC, since the `-stdlib=libc++` option is needed to build Google Benchmark.
Reviewers: danalbert, dberlin, chandlerc, mclow.lists, jroelofs
Subscribers: chandlerc, dberlin, tberghammer, danalbert, srhines, hfinkel
Differential Revision: https://reviews.llvm.org/D22240
llvm-svn: 276049
2016-07-19 23:07:03 +00:00
|
|
|
|
|
|
|
Build the libc++ benchmark tests and Google Benchmark library against the
|
2019-10-01 20:34:50 +00:00
|
|
|
specified standard library on the platform. On Linux this can be used to
|
2016-10-30 22:53:00 +00:00
|
|
|
compare libc++ to libstdc++ by building the benchmark tests against both
|
|
|
|
standard libraries.
|
|
|
|
|
|
|
|
.. option:: LIBCXX_BENCHMARK_NATIVE_GCC_TOOLCHAIN:STRING
|
|
|
|
|
|
|
|
Use the specified GCC toolchain and standard library when building the native
|
|
|
|
stdlib benchmark tests.
|
[libcxx] Add support for benchmark tests using Google Benchmark.
Summary:
This patch does the following:
1. Checks in a copy of the Google Benchmark library into the libc++ repo under `utils/google-benchmark`.
2. Teaches libc++ how to build Google Benchmark against both (A) in-tree libc++ and (B) the platforms native STL.
3. Allows performance benchmarks to be built as part of the libc++ build.
Building the benchmarks (and Google Benchmark) is off by default. It must be enabled using the CMake option `-DLIBCXX_INCLUDE_BENCHMARKS=ON`. When this option is enabled the tests under `libcxx/benchmarks` can be built using the `libcxx-benchmarks` target.
On Linux platforms where libstdc++ is the default STL the CMake option `-DLIBCXX_BUILD_BENCHMARKS_NATIVE_STDLIB=ON` can be used to build each benchmark test against libstdc++ as well. This is useful for comparing performance between standard libraries.
Support for benchmarks is currently very minimal. They must be manually run by the user and there is no mechanism for detecting performance regressions.
Known Issues:
* `-DLIBCXX_INCLUDE_BENCHMARKS=ON` is only supported for Clang, and not GCC, since the `-stdlib=libc++` option is needed to build Google Benchmark.
Reviewers: danalbert, dberlin, chandlerc, mclow.lists, jroelofs
Subscribers: chandlerc, dberlin, tberghammer, danalbert, srhines, hfinkel
Differential Revision: https://reviews.llvm.org/D22240
llvm-svn: 276049
2016-07-19 23:07:03 +00:00
|
|
|
|
2024-01-17 18:56:07 -08:00
|
|
|
.. option:: LIBCXX_ASSERTION_HANDLER_FILE:PATH
|
|
|
|
|
|
|
|
**Default**:: ``"${CMAKE_CURRENT_SOURCE_DIR}/vendor/llvm/default_assertion_handler.in"``
|
|
|
|
|
|
|
|
Specify the path to a header that contains a custom implementation of the
|
|
|
|
assertion handler that gets invoked when a hardening assertion fails. If
|
|
|
|
provided, this header will be included by the library, replacing the
|
|
|
|
default assertion handler.
|
|
|
|
|
[libcxx] Add support for benchmark tests using Google Benchmark.
Summary:
This patch does the following:
1. Checks in a copy of the Google Benchmark library into the libc++ repo under `utils/google-benchmark`.
2. Teaches libc++ how to build Google Benchmark against both (A) in-tree libc++ and (B) the platforms native STL.
3. Allows performance benchmarks to be built as part of the libc++ build.
Building the benchmarks (and Google Benchmark) is off by default. It must be enabled using the CMake option `-DLIBCXX_INCLUDE_BENCHMARKS=ON`. When this option is enabled the tests under `libcxx/benchmarks` can be built using the `libcxx-benchmarks` target.
On Linux platforms where libstdc++ is the default STL the CMake option `-DLIBCXX_BUILD_BENCHMARKS_NATIVE_STDLIB=ON` can be used to build each benchmark test against libstdc++ as well. This is useful for comparing performance between standard libraries.
Support for benchmarks is currently very minimal. They must be manually run by the user and there is no mechanism for detecting performance regressions.
Known Issues:
* `-DLIBCXX_INCLUDE_BENCHMARKS=ON` is only supported for Clang, and not GCC, since the `-stdlib=libc++` option is needed to build Google Benchmark.
Reviewers: danalbert, dberlin, chandlerc, mclow.lists, jroelofs
Subscribers: chandlerc, dberlin, tberghammer, danalbert, srhines, hfinkel
Differential Revision: https://reviews.llvm.org/D22240
llvm-svn: 276049
2016-07-19 23:07:03 +00:00
|
|
|
|
|
|
|
libc++ ABI Feature Options
|
|
|
|
--------------------------
|
2015-10-13 23:48:28 +00:00
|
|
|
|
|
|
|
The following options allow building libc++ for a different ABI version.
|
|
|
|
|
|
|
|
.. option:: LIBCXX_ABI_VERSION:STRING
|
|
|
|
|
|
|
|
**Default**: ``1``
|
|
|
|
|
|
|
|
Defines the target ABI version of libc++.
|
|
|
|
|
|
|
|
.. option:: LIBCXX_ABI_UNSTABLE:BOOL
|
|
|
|
|
|
|
|
**Default**: ``OFF``
|
|
|
|
|
|
|
|
Build the "unstable" ABI version of libc++. Includes all ABI changing features
|
|
|
|
on top of the current stable version.
|
|
|
|
|
2018-10-30 21:44:53 +00:00
|
|
|
.. option:: LIBCXX_ABI_NAMESPACE:STRING
|
|
|
|
|
|
|
|
**Default**: ``__n`` where ``n`` is the current ABI version.
|
|
|
|
|
|
|
|
This option defines the name of the inline ABI versioning namespace. It can be used for building
|
|
|
|
custom versions of libc++ with unique symbol names in order to prevent conflicts or ODR issues
|
|
|
|
with other libc++ versions.
|
|
|
|
|
|
|
|
.. warning::
|
2022-02-07 14:52:17 -05:00
|
|
|
When providing a custom namespace, it's the user's responsibility to ensure the name won't cause
|
2018-11-16 14:57:47 +00:00
|
|
|
conflicts with other names defined by libc++, both now and in the future. In particular, inline
|
2022-02-07 14:52:17 -05:00
|
|
|
namespaces of the form ``__[0-9]+`` could cause conflicts with future versions of the library,
|
|
|
|
and so should be avoided.
|
2018-10-30 21:44:53 +00:00
|
|
|
|
2017-10-04 23:17:12 +00:00
|
|
|
.. option:: LIBCXX_ABI_DEFINES:STRING
|
|
|
|
|
|
|
|
**Default**: ``""``
|
|
|
|
|
|
|
|
A semicolon-separated list of ABI macros to persist in the site config header.
|
|
|
|
See ``include/__config`` for the list of ABI macros.
|
|
|
|
|
2019-05-29 02:21:37 +00:00
|
|
|
|
2015-08-22 19:40:49 +00:00
|
|
|
.. _LLVM-specific variables:
|
|
|
|
|
|
|
|
LLVM-specific options
|
|
|
|
---------------------
|
|
|
|
|
2022-08-18 22:44:46 -04:00
|
|
|
.. option:: LLVM_LIBDIR_SUFFIX:STRING
|
|
|
|
|
|
|
|
Extra suffix to append to the directory where libraries are to be
|
|
|
|
installed. On a 64-bit architecture, one could use ``-DLLVM_LIBDIR_SUFFIX=64``
|
|
|
|
to install libraries to ``/usr/lib64``.
|
|
|
|
|
2015-08-22 19:40:49 +00:00
|
|
|
.. option:: LLVM_BUILD_32_BITS:BOOL
|
|
|
|
|
|
|
|
Build 32-bits executables and libraries on 64-bits systems. This option is
|
2019-10-01 20:34:50 +00:00
|
|
|
available only on some 64-bits Unix systems. Defaults to OFF.
|
2015-08-22 19:40:49 +00:00
|
|
|
|
|
|
|
.. option:: LLVM_LIT_ARGS:STRING
|
|
|
|
|
|
|
|
Arguments given to lit. ``make check`` and ``make clang-test`` are affected.
|
|
|
|
By default, ``'-sv --no-progress-bar'`` on Visual C++ and Xcode, ``'-sv'`` on
|
|
|
|
others.
|
|
|
|
|
|
|
|
|
2024-01-17 18:56:07 -08:00
|
|
|
.. _assertion-handler:
|
|
|
|
|
|
|
|
Overriding the default assertion handler
|
[libc++][hardening] In production hardening modes, trap rather than abort (#78561)
In the hardening modes that can be used in production (`fast` and
`extensive`), make a failed assertion invoke a trap instruction rather
than calling verbose abort. In the debug mode, still keep calling
verbose abort to provide a better user experience and to allow us to
keep our existing testing infrastructure for verifying assertion
messages. Since the debug mode by definition enables all assertions, we
can be sure that we still check all the assertion messages in the
library when running the test suite in the debug mode.
The main motivation to use trapping in production is to achieve better
code generation and reduce the binary size penalty. This way, the
assertion handler can compile to a single instruction, whereas the
existing mechanism with verbose abort results in generating a function
call that in general cannot be optimized away (made worse by the fact
that it's a variadic function, imposing an additional penalty). See the
[RFC](https://discourse.llvm.org/t/rfc-hardening-in-libc/73925) for more
details. Note that this mechanism can now be completely [overridden at
CMake configuration
time](https://github.com/llvm/llvm-project/pull/77883).
This patch also significantly refactors `check_assertion.h` and expands
its test coverage. The main changes:
- when overriding `verbose_abort`, don't do matching inside the function
-- just print the error message to `stderr`. This removes the need to
set a global matcher and allows to do matching in the parent process
after the child finishes;
- remove unused logic for matching source locations and for using
wildcards;
- make matchers simple functors;
- introduce `DeathTestResult` that keeps data about the test run,
primarily to make it easier to test.
In addition to the refactoring, `check_assertion.h` can now recognize
when a process exits due to a trap.
2024-01-19 13:48:13 -08:00
|
|
|
========================================
|
|
|
|
|
|
|
|
When the library wants to terminate due to a hardening assertion failure, the
|
|
|
|
program is aborted by invoking a trap instruction (or in debug mode, by
|
|
|
|
a special verbose termination function that prints an error message and calls
|
|
|
|
``std::abort()``). This is done to minimize the code size impact of enabling
|
|
|
|
hardening in the library. However, vendors can also override that mechanism at
|
|
|
|
CMake configuration time.
|
|
|
|
|
|
|
|
Under the hood, a hardening assertion will invoke the
|
|
|
|
``_LIBCPP_ASSERTION_HANDLER`` macro upon failure. A vendor may provide a header
|
|
|
|
that contains a custom definition of this macro and specify the path to the
|
|
|
|
header via the ``LIBCXX_ASSERTION_HANDLER_FILE`` CMake variable. If provided,
|
|
|
|
this header will be included by the library and replace the default
|
|
|
|
implementation. The header must not include any standard library headers
|
|
|
|
(directly or transitively) because doing so will almost always create a circular
|
|
|
|
dependency. The ``_LIBCPP_ASSERTION_HANDLER(message)`` macro takes a single
|
|
|
|
parameter that contains an error message explaining the hardening failure and
|
|
|
|
some details about the source location that triggered it.
|
2024-01-17 18:56:07 -08:00
|
|
|
|
|
|
|
When a hardening assertion fails, it means that the program is about to invoke
|
|
|
|
library undefined behavior. For this reason, the custom assertion handler is
|
|
|
|
generally expected to terminate the program. If a custom assertion handler
|
|
|
|
decides to avoid doing so (e.g. it chooses to log and continue instead), it does
|
|
|
|
so at its own risk -- this approach should only be used in non-production builds
|
|
|
|
and with an understanding of potential consequences. Furthermore, the custom
|
|
|
|
assertion handler should not throw any exceptions as it may be invoked from
|
|
|
|
standard library functions that are marked ``noexcept`` (so throwing will result
|
|
|
|
in ``std::terminate`` being called).
|
|
|
|
|
|
|
|
|
2015-08-22 19:40:49 +00:00
|
|
|
Using Alternate ABI libraries
|
|
|
|
=============================
|
|
|
|
|
2021-07-06 10:39:01 -04:00
|
|
|
In order to implement various features like exceptions, RTTI, ``dynamic_cast`` and
|
|
|
|
more, libc++ requires what we refer to as an ABI library. Typically, that library
|
|
|
|
implements the `Itanium C++ ABI <https://itanium-cxx-abi.github.io/cxx-abi/abi.html>`_.
|
2015-08-22 19:40:49 +00:00
|
|
|
|
2021-07-06 10:39:01 -04:00
|
|
|
By default, libc++ uses libc++abi as an ABI library. However, it is possible to use
|
|
|
|
other ABI libraries too.
|
2015-08-22 19:40:49 +00:00
|
|
|
|
|
|
|
Using libsupc++ on Linux
|
|
|
|
------------------------
|
|
|
|
|
|
|
|
You will need libstdc++ in order to provide libsupc++.
|
|
|
|
|
|
|
|
Figure out where the libsupc++ headers are on your system. On Ubuntu this
|
|
|
|
is ``/usr/include/c++/<version>`` and ``/usr/include/c++/<version>/<target-triple>``
|
|
|
|
|
|
|
|
You can also figure this out by running
|
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
|
|
|
$ echo | g++ -Wp,-v -x c++ - -fsyntax-only
|
|
|
|
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
|
|
|
|
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../x86_64-linux-gnu/include"
|
|
|
|
#include "..." search starts here:
|
|
|
|
#include <...> search starts here:
|
|
|
|
/usr/include/c++/4.7
|
|
|
|
/usr/include/c++/4.7/x86_64-linux-gnu
|
|
|
|
/usr/include/c++/4.7/backward
|
|
|
|
/usr/lib/gcc/x86_64-linux-gnu/4.7/include
|
|
|
|
/usr/local/include
|
|
|
|
/usr/lib/gcc/x86_64-linux-gnu/4.7/include-fixed
|
|
|
|
/usr/include/x86_64-linux-gnu
|
|
|
|
/usr/include
|
|
|
|
End of search list.
|
|
|
|
|
|
|
|
Note that the first two entries happen to be what we are looking for. This
|
2021-07-06 10:39:01 -04:00
|
|
|
may not be correct on all platforms.
|
2015-08-22 19:40:49 +00:00
|
|
|
|
|
|
|
We can now run CMake:
|
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
2022-02-09 12:08:44 -05:00
|
|
|
$ cmake -G Ninja -S runtimes -B build \
|
|
|
|
-DLLVM_ENABLE_RUNTIMES="libcxx" \
|
2021-07-06 10:39:01 -04:00
|
|
|
-DLIBCXX_CXX_ABI=libstdc++ \
|
|
|
|
-DLIBCXX_CXX_ABI_INCLUDE_PATHS="/usr/include/c++/4.7/;/usr/include/c++/4.7/x86_64-linux-gnu/"
|
|
|
|
$ ninja -C build install-cxx
|
2015-08-22 19:40:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
You can also substitute ``-DLIBCXX_CXX_ABI=libsupc++``
|
|
|
|
above, which will cause the library to be linked to libsupc++ instead
|
|
|
|
of libstdc++, but this is only recommended if you know that you will
|
|
|
|
never need to link against libstdc++ in the same executable as libc++.
|
|
|
|
GCC ships libsupc++ separately but only as a static library. If a
|
|
|
|
program also needs to link against libstdc++, it will provide its
|
|
|
|
own copy of libsupc++ and this can lead to subtle problems.
|
|
|
|
|
2016-06-02 02:16:28 +00:00
|
|
|
Using libcxxrt on Linux
|
|
|
|
------------------------
|
|
|
|
|
|
|
|
You will need to keep the source tree of `libcxxrt`_ available
|
|
|
|
on your build machine and your copy of the libcxxrt shared library must
|
|
|
|
be placed where your linker will find it.
|
|
|
|
|
|
|
|
We can now run CMake like:
|
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
2022-02-09 12:08:44 -05:00
|
|
|
$ cmake -G Ninja -S runtimes -B build \
|
|
|
|
-DLLVM_ENABLE_RUNTIMES="libcxx" \
|
2021-07-06 10:39:01 -04:00
|
|
|
-DLIBCXX_CXX_ABI=libcxxrt \
|
|
|
|
-DLIBCXX_CXX_ABI_INCLUDE_PATHS=path/to/libcxxrt-sources/src
|
|
|
|
$ ninja -C build install-cxx
|
2016-06-02 02:16:28 +00:00
|
|
|
|
|
|
|
Unfortunately you can't simply run clang with "-stdlib=libc++" at this point, as
|
|
|
|
clang is set up to link for libc++ linked to libsupc++. To get around this
|
|
|
|
you'll have to set up your linker yourself (or patch clang). For example,
|
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
|
|
|
$ clang++ -stdlib=libc++ helloworld.cpp \
|
|
|
|
-nodefaultlibs -lc++ -lcxxrt -lm -lc -lgcc_s -lgcc
|
|
|
|
|
|
|
|
Alternately, you could just add libcxxrt to your libraries list, which in most
|
|
|
|
situations will give the same result:
|
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
|
|
|
$ clang++ -stdlib=libc++ helloworld.cpp -lcxxrt
|
|
|
|
|
2021-07-06 10:39:01 -04:00
|
|
|
.. _`libcxxrt`: https://github.com/libcxxrt/libcxxrt
|