2010-12-10 19:47:54 +00:00
#===============================================================================
# Setup Project
#===============================================================================
Reland "[CMake] Bumps minimum version to 3.20.0.
This reverts commit d763c6e5e2d0a6b34097aa7dabca31e9aff9b0b6.
Adds the patch by @hans from
https://github.com/llvm/llvm-project/issues/62719
This patch fixes the Windows build.
d763c6e5e2d0a6b34097aa7dabca31e9aff9b0b6 reverted the reviews
D144509 [CMake] Bumps minimum version to 3.20.0.
This partly undoes D137724.
This change has been discussed on discourse
https://discourse.llvm.org/t/rfc-upgrading-llvms-minimum-required-cmake-version/66193
Note this does not remove work-arounds for older CMake versions, that
will be done in followup patches.
D150532 [OpenMP] Compile assembly files as ASM, not C
Since CMake 3.20, CMake explicitly passes "-x c" (or equivalent)
when compiling a file which has been set as having the language
C. This behaviour change only takes place if "cmake_minimum_required"
is set to 3.20 or newer, or if the policy CMP0119 is set to new.
Attempting to compile assembly files with "-x c" fails, however
this is workarounded in many cases, as OpenMP overrides this with
"-x assembler-with-cpp", however this is only added for non-Windows
targets.
Thus, after increasing cmake_minimum_required to 3.20, this breaks
compiling the GNU assembly for Windows targets; the GNU assembly is
used for ARM and AArch64 Windows targets when building with Clang.
This patch unbreaks that.
D150688 [cmake] Set CMP0091 to fix Windows builds after the cmake_minimum_required bump
The build uses other mechanism to select the runtime.
Fixes #62719
Reviewed By: #libc, Mordante
Differential Revision: https://reviews.llvm.org/D151344
2023-05-24 18:12:32 +02:00
cmake_minimum_required ( VERSION 3.20.0 )
2024-05-25 17:41:21 +02:00
set ( LLVM_SUBPROJECT_TITLE "libc++" )
2010-12-10 19:47:54 +00:00
2022-01-01 07:03:31 +00:00
set ( LLVM_COMMON_CMAKE_UTILS "${CMAKE_CURRENT_SOURCE_DIR}/../cmake" )
2010-12-10 19:47:54 +00:00
# Add path for custom modules
2022-01-01 07:03:31 +00:00
list ( INSERT CMAKE_MODULE_PATH 0
2010-12-10 19:47:54 +00:00
" $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / c m a k e "
" $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / c m a k e / M o d u l e s "
2023-02-20 16:26:19 +01:00
" $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / . . / r u n t i m e s / c m a k e / M o d u l e s "
2022-01-01 07:03:31 +00:00
" $ { L L V M _ C O M M O N _ C M A K E _ U T I L S } "
" $ { L L V M _ C O M M O N _ C M A K E _ U T I L S } / M o d u l e s "
2010-12-10 19:47:54 +00:00
)
2021-01-25 09:50:03 +01:00
set ( CMAKE_FOLDER "libc++" )
2020-08-24 11:01:05 +02:00
set ( LIBCXX_SOURCE_DIR ${ CMAKE_CURRENT_SOURCE_DIR } )
set ( LIBCXX_BINARY_DIR ${ CMAKE_CURRENT_BINARY_DIR } )
2022-01-19 06:45:07 +00:00
include ( GNUInstallDirs )
2023-02-17 11:31:41 +01:00
include ( WarningFlags )
2020-08-24 11:01:05 +02:00
2016-02-08 03:50:18 +00:00
# Require out of source build.
include ( MacroEnsureOutOfSourceBuild )
MACRO_ENSURE_OUT_OF_SOURCE_BUILD (
" $ { P R O J E C T _ N A M E } r e q u i r e s a n o u t o f s o u r c e b u i l d . P l e a s e c r e a t e a s e p a r a t e
b u i l d d i r e c t o r y a n d r u n ' c m a k e / p a t h / t o / $ { P R O J E C T _ N A M E } [ o p t i o n s ] ' t h e r e . "
)
2018-10-01 01:31:23 +00:00
if ( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC" )
message ( STATUS "Configuring for clang-cl" )
set ( LIBCXX_TARGETING_CLANG_CL ON )
endif ( )
2016-02-08 03:50:18 +00:00
2017-01-14 06:06:47 +00:00
if ( MSVC )
2018-10-01 01:00:11 +00:00
message ( STATUS "Configuring for MSVC" )
2017-01-14 06:06:47 +00:00
endif ( )
2010-12-10 19:47:54 +00:00
#===============================================================================
# Setup CMake Options
#===============================================================================
2016-09-07 01:15:10 +00:00
include ( CMakeDependentOption )
2017-03-11 03:24:18 +00:00
include ( HandleCompilerRT )
2010-12-10 19:47:54 +00:00
2015-07-30 22:30:34 +00:00
# Basic options ---------------------------------------------------------------
2015-07-29 23:46:55 +00:00
option ( LIBCXX_ENABLE_SHARED "Build libc++ as a shared library." ON )
2016-08-08 22:57:25 +00:00
option ( LIBCXX_ENABLE_STATIC "Build libc++ as a static library." ON )
2024-11-14 13:06:43 +01:00
option ( LIBCXX_ENABLE_EXCEPTIONS "Enable exceptions in the built library." ON )
option ( LIBCXX_ENABLE_RTTI
" U s e r u n t i m e t y p e i n f o r m a t i o n .
T h i s o p t i o n m a y o n l y b e s e t t o O F F w h e n L I B C X X _ E N A B L E _ E X C E P T I O N S = O F F . " O N )
2023-05-31 11:20:24 -07:00
option ( LIBCXX_ENABLE_FILESYSTEM
" W h e t h e r t o i n c l u d e s u p p o r t f o r p a r t s o f t h e l i b r a r y t h a t r e l y o n a f i l e s y s t e m b e i n g
a v a i l a b l e o n t h e p l a t f o r m . T h i s i n c l u d e s t h i n g s l i k e m o s t p a r t s o f < f i l e s y s t e m > a n d
o t h e r s l i k e < f s t r e a m > " O N )
2015-07-30 22:30:34 +00:00
option ( LIBCXX_INCLUDE_TESTS "Build the libc++ tests." ${ LLVM_INCLUDE_TESTS } )
2023-11-08 09:10:00 -10:00
set ( LIBCXX_SUPPORTED_HARDENING_MODES none fast extensive debug )
set ( LIBCXX_HARDENING_MODE "none" CACHE STRING
2023-07-12 10:12:51 -07:00
" S p e c i f y t h e d e f a u l t h a r d e n i n g m o d e t o u s e . T h i s m o d e w i l l b e u s e d i n s i d e t h e
c o m p i l e d l i b r a r y a n d w i l l b e t h e d e f a u l t w h e n c o m p i l i n g u s e r c o d e . N o t e t h a t
u s e r s c a n o v e r r i d e t h i s s e t t i n g i n t h e i r o w n c o d e . T h i s d o e s n o t a f f e c t t h e
A B I . S u p p o r t e d v a l u e s a r e $ { L I B C X X _ S U P P O R T E D _ H A R D E N I N G _ M O D E S } . " )
if ( NOT "${LIBCXX_HARDENING_MODE}" IN_LIST LIBCXX_SUPPORTED_HARDENING_MODES )
message ( FATAL_ERROR
" U n s u p p o r t e d h a r d e n i n g m o d e : ' $ { L I B C X X _ H A R D E N I N G _ M O D E } ' . S u p p o r t e d v a l u e s a r e $ { L I B C X X _ S U P P O R T E D _ H A R D E N I N G _ M O D E S } . " )
endif ( )
2024-01-17 18:56:07 -08:00
set ( LIBCXX_ASSERTION_HANDLER_FILE
2024-07-24 11:03:52 -05:00
" v e n d o r / l l v m / d e f a u l t _ a s s e r t i o n _ h a n d l e r . i n "
2024-01-17 18:56:07 -08:00
C A C H E S T R I N G
" S p e c i f y t h e p a t h t o a h e a d e r t h a t c o n t a i n s a c u s t o m i m p l e m e n t a t i o n o f t h e
a s s e r t i o n h a n d l e r t h a t g e t s i n v o k e d w h e n a h a r d e n i n g a s s e r t i o n f a i l s . I f
p r o v i d e d , t h i s h e a d e r w i l l b e i n c l u d e d b y t h e l i b r a r y , r e p l a c i n g t h e
2024-07-24 11:03:52 -05:00
d e f a u l t a s s e r t i o n h a n d l e r . I f t h i s i s s p e c i f i e d a s a r e l a t i v e p a t h , i t
i s a s s u m e d t o b e r e l a t i v e t o ' < m o n o r e p o > / l i b c x x ' . " )
if ( NOT IS_ABSOLUTE "${LIBCXX_ASSERTION_HANDLER_FILE}" )
set ( LIBCXX_ASSERTION_HANDLER_FILE "${CMAKE_CURRENT_SOURCE_DIR}/${LIBCXX_ASSERTION_HANDLER_FILE}" )
endif ( )
2020-10-15 10:32:09 -04:00
option ( LIBCXX_ENABLE_RANDOM_DEVICE
" W h e t h e r t o i n c l u d e s u p p o r t f o r s t d : : r a n d o m _ d e v i c e i n t h e l i b r a r y . D i s a b l i n g
t h i s c a n b e u s e f u l w h e n b u i l d i n g t h e l i b r a r y f o r p l a t f o r m s t h a t d o n ' t h a v e
a s o u r c e o f r a n d o m n e s s , s u c h a s s o m e e m b e d d e d p l a t f o r m s . W h e n t h i s i s n o t
s u p p o r t e d , m o s t o f < r a n d o m > w i l l s t i l l b e a v a i l a b l e , b u t s t d : : r a n d o m _ d e v i c e
w i l l n o t . " O N )
2020-10-09 15:31:05 -04:00
option ( LIBCXX_ENABLE_LOCALIZATION
" W h e t h e r t o i n c l u d e s u p p o r t f o r l o c a l i z a t i o n i n t h e l i b r a r y . D i s a b l i n g
l o c a l i z a t i o n c a n b e u s e f u l w h e n p o r t i n g t o p l a t f o r m s t h a t d o n ' t s u p p o r t
t h e C l o c a l e API ( e.g. embedded ) . W h e n l o c a l i z a t i o n i s n o t s u p p o r t e d ,
s e v e r a l p a r t s o f t h e l i b r a r y w i l l b e d i s a b l e d : < i o s t r e a m > , < r e g e x > , < l o c a l e >
w i l l b e c o m p l e t e l y u n u s a b l e , a n d o t h e r p a r t s m a y b e o n l y p a r t l y a v a i l a b l e . " O N )
2021-05-25 20:11:08 +02:00
option ( LIBCXX_ENABLE_UNICODE
" W h e t h e r t o i n c l u d e s u p p o r t f o r U n i c o d e i n t h e l i b r a r y . D i s a b l i n g U n i c o d e c a n
2021-09-09 11:14:33 -04:00
b e u s e f u l w h e n p o r t i n g t o p l a t f o r m s t h a t d o n ' t s u p p o r t U T F - 8 encoding ( e.g.
e m b e d d e d ) . " O N )
2024-08-21 08:48:53 -05:00
option ( LIBCXX_HAS_TERMINAL_AVAILABLE
" B u i l d l i b c + + w i t h s u p p o r t f o r c h e c k i n g w h e t h e r a s t r e a m i s a t e r m i n a l . " O N )
2021-08-23 15:32:36 -04:00
option ( LIBCXX_ENABLE_WIDE_CHARACTERS
" W h e t h e r t o i n c l u d e s u p p o r t f o r w i d e c h a r a c t e r s i n t h e l i b r a r y . D i s a b l i n g
w i d e c h a r a c t e r s u p p o r t c a n b e u s e f u l w h e n p o r t i n g t o p l a t f o r m s t h a t d o n ' t
s u p p o r t t h e C f u n c t i o n a l i t y f o r w i d e c h a r a c t e r s . W h e n w i d e c h a r a c t e r s a r e
n o t s u p p o r t e d , s e v e r a l p a r t s o f t h e l i b r a r y w i l l b e d i s a b l e d , n o t a b l y t h e
w i d e c h a r a c t e r s p e c i a l i z a t i o n s o f s t d : : b a s i c _ s t r i n g . " O N )
2024-11-14 13:06:43 +01:00
option ( LIBCXX_ENABLE_THREADS "Build libc++ with support for threads." ON )
option ( LIBCXX_ENABLE_MONOTONIC_CLOCK
" B u i l d l i b c + + w i t h s u p p o r t f o r a m o n o t o n i c c l o c k .
T h i s o p t i o n m a y o n l y b e s e t t o O F F w h e n L I B C X X _ E N A B L E _ T H R E A D S = O F F . " O N )
2022-09-23 18:33:20 +02:00
# To use time zone support in libc++ the platform needs to have the IANA
# database installed. Libc++ will fail to build if this is enabled on a
# platform that does not provide the IANA database. The default is set to the
# current implementation state on the different platforms.
#
# TODO TZDB make the default always ON when most platforms ship with the IANA
# database.
if ( ${ CMAKE_SYSTEM_NAME } MATCHES "Linux" )
set ( ENABLE_TIME_ZONE_DATABASE_DEFAULT ON )
else ( )
set ( ENABLE_TIME_ZONE_DATABASE_DEFAULT OFF )
endif ( )
option ( LIBCXX_ENABLE_TIME_ZONE_DATABASE
" W h e t h e r t o i n c l u d e s u p p o r t f o r t i m e z o n e s i n t h e l i b r a r y . D i s a b l i n g
t i m e z o n e s u p p o r t c a n b e u s e f u l w h e n p o r t i n g t o p l a t f o r m s t h a t d o n ' t
s h i p t h e I A N A t i m e z o n e d a t a b a s e . W h e n t i m e z o n e s a r e n o t s u p p o r t e d ,
t i m e z o n e s u p p o r t i n < c h r o n o > w i l l b e d i s a b l e d . " $ { E N A B L E _ T I M E _ Z O N E _ D A T A B A S E _ D E F A U L T } )
2020-11-04 15:01:25 -05:00
option ( LIBCXX_ENABLE_VENDOR_AVAILABILITY_ANNOTATIONS
" W h e t h e r t o t u r n o n v e n d o r a v a i l a b i l i t y a n n o t a t i o n s o n d e c l a r a t i o n s t h a t d e p e n d
o n d e f i n i t i o n s i n a s h a r e d l i b r a r y . B y d e f a u l t , w e a s s u m e t h a t w e ' r e n o t b u i l d i n g
l i b c + + f o r a n y s p e c i f i c v e n d o r , a n d w e d i s a b l e t h o s e a n n o t a t i o n s . V e n d o r s w i s h i n g
t o p r o v i d e c o m p i l e - t i m e e r r o r s w h e n u s i n g f e a t u r e s u n a v a i l a b l e o n s o m e v e r s i o n o f
2024-05-28 18:29:11 -07:00
t h e s h a r e d l i b r a r y t h e y s h i p p e d s h o u l d t u r n t h i s o n a n d s e e ` i n c l u d e / _ _ c o n f i g u r a t i o n / a v a i l a b i l i t y . h `
2020-11-04 15:01:25 -05:00
f o r m o r e d e t a i l s . " O F F )
2022-03-14 14:23:38 -04:00
if ( CMAKE_CXX_COMPILER_ID STREQUAL "GNU" )
set ( LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-shared-gcc.cfg.in" )
elseif ( MINGW )
2024-10-10 09:13:47 +03:00
set ( LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-mingw.cfg.in" )
2022-03-14 14:23:38 -04:00
elseif ( WIN32 ) # clang-cl
if ( LIBCXX_ENABLE_SHARED )
set ( LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-shared-clangcl.cfg.in" )
else ( )
set ( LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-static-clangcl.cfg.in" )
endif ( )
else ( )
if ( LIBCXX_ENABLE_SHARED )
set ( LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-shared.cfg.in" )
else ( )
set ( LIBCXX_DEFAULT_TEST_CONFIG "llvm-libc++-static.cfg.in" )
endif ( )
endif ( )
set ( LIBCXX_TEST_CONFIG "${LIBCXX_DEFAULT_TEST_CONFIG}" CACHE STRING
2021-09-29 15:26:05 -04:00
" T h e p a t h t o t h e L i t t e s t i n g c o n f i g u r a t i o n t o u s e w h e n r u n n i n g t h e t e s t s .
I f a r e l a t i v e p a t h i s p r o v i d e d , i t i s a s s u m e d t o b e r e l a t i v e t o ' < m o n o r e p o > / l i b c x x / t e s t / c o n f i g s ' . " )
if ( NOT IS_ABSOLUTE "${LIBCXX_TEST_CONFIG}" )
set ( LIBCXX_TEST_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/test/configs/${LIBCXX_TEST_CONFIG}" )
endif ( )
2022-03-14 14:23:38 -04:00
message ( STATUS "Using libc++ testing configuration: ${LIBCXX_TEST_CONFIG}" )
2020-07-09 11:54:09 -04:00
set ( LIBCXX_TEST_PARAMS "" CACHE STRING
" A l i s t o f p a r a m e t e r s t o r u n t h e L i t t e s t s u i t e w i t h . " )
2016-10-30 22:53:00 +00:00
2024-11-07 09:07:50 -05:00
# TODO: Figure out how to build GoogleBenchmark on those platforms, and how to build when exceptions or RTTI is disabled
if ( WIN32 OR MINGW OR ANDROID OR ${ CMAKE_SYSTEM_NAME } MATCHES "AIX"
O R N O T L I B C X X _ E N A B L E _ L O C A L I Z A T I O N
O R N O T L I B C X X _ E N A B L E _ T H R E A D S
O R N O T L I B C X X _ E N A B L E _ F I L E S Y S T E M
O R N O T L I B C X X _ E N A B L E _ R A N D O M _ D E V I C E
O R N O T L I B C X X _ E N A B L E _ E X C E P T I O N S
O R N O T L I B C X X _ E N A B L E _ R T T I )
set ( _include_benchmarks OFF )
else ( )
set ( _include_benchmarks ON )
endif ( )
option ( LIBCXX_INCLUDE_BENCHMARKS "Build the libc++ benchmarks and their dependencies" ${ _include_benchmarks } )
2018-11-14 20:38:46 +00:00
2015-08-22 19:40:49 +00:00
option ( LIBCXX_INCLUDE_DOCS "Build the libc++ documentation." ${ LLVM_INCLUDE_DOCS } )
2022-08-18 22:44:46 -04:00
set ( LIBCXX_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING
" D e f i n e s u f f i x o f l i b r a r y d i r e c t o r y name ( 32/64 ) " )
2015-07-30 22:30:34 +00:00
option ( LIBCXX_INSTALL_HEADERS "Install the libc++ headers." ON )
2015-08-26 20:18:21 +00:00
option ( LIBCXX_INSTALL_LIBRARY "Install the libc++ library." ON )
2024-01-21 12:16:22 +01:00
option ( LIBCXX_INSTALL_MODULES
2024-04-28 14:12:27 +02:00
" I n s t a l l t h e l i b c + + C + + 2 0 m o d u l e s o u r c e files ( experimental ) . " O N
2024-01-21 12:16:22 +01:00
)
2018-07-24 23:27:51 +00:00
cmake_dependent_option ( LIBCXX_INSTALL_STATIC_LIBRARY
" I n s t a l l t h e s t a t i c l i b c + + l i b r a r y . " O N
" L I B C X X _ E N A B L E _ S T A T I C ; L I B C X X _ I N S T A L L _ L I B R A R Y " O F F )
cmake_dependent_option ( LIBCXX_INSTALL_SHARED_LIBRARY
" I n s t a l l t h e s h a r e d l i b c + + l i b r a r y . " O N
" L I B C X X _ E N A B L E _ S H A R E D ; L I B C X X _ I N S T A L L _ L I B R A R Y " O F F )
Implement <filesystem>
This patch implements the <filesystem> header and uses that
to provide <experimental/filesystem>.
Unlike other standard headers, the symbols needed for <filesystem>
have not yet been placed in libc++.so. Instead they live in the
new libc++fs.a library. Users of filesystem are required to link this
library. (Also note that libc++experimental no longer contains the
definition of <experimental/filesystem>, which now requires linking libc++fs).
The reason for keeping <filesystem> out of the dylib for now is that
it's still somewhat experimental, and the possibility of requiring an
ABI breaking change is very real. In the future the symbols will likely
be moved into the dylib, or the dylib will be made to link libc++fs automagically).
Note that moving the symbols out of libc++experimental may break user builds
until they update to -lc++fs. This should be OK, because the experimental
library provides no stability guarantees. However, I plan on looking into
ways we can force libc++experimental to automagically link libc++fs.
In order to use a single implementation and set of tests for <filesystem>, it
has been placed in a special `__fs` namespace. This namespace is inline in
C++17 onward, but not before that. As such implementation is available
in C++11 onward, but no filesystem namespace is present "directly", and
as such name conflicts shouldn't occur in C++11 or C++14.
llvm-svn: 338093
2018-07-27 03:07:09 +00:00
2022-02-07 14:52:17 -05:00
option ( LIBCXX_ABI_UNSTABLE "Use the unstable ABI of libc++. This is equivalent to specifying LIBCXX_ABI_VERSION=n, where n is the not-yet-stable version." OFF )
if ( LIBCXX_ABI_UNSTABLE )
set ( abi_version "2" )
else ( )
set ( abi_version "1" )
endif ( )
2022-05-16 09:50:56 -04:00
set ( LIBCXX_ABI_VERSION "${abi_version}" CACHE STRING
" A B I v e r s i o n o f l i b c + + . C a n b e e i t h e r 1 o r 2 , w h e r e 2 i s c u r r e n t l y t h e u n s t a b l e A B I .
D e f a u l t s t o 1 u n l e s s L I B C X X _ A B I _ U N S T A B L E i s s p e c i f i e d , i n w h i c h c a s e t h i s i s 2 . " )
set ( LIBCXX_LIBRARY_VERSION "${LIBCXX_ABI_VERSION}.0" CACHE STRING
" V e r s i o n o f l i b c + + . T h i s w i l l b e r e f l e c t e d i n t h e n a m e o f t h e s h a r e d l i b r a r y p r o d u c e d .
F o r e x a m p l e , - D L I B C X X _ L I B R A R Y _ V E R S I O N = x . y w i l l r e s u l t i n t h e l i b r a r y b e i n g n a m e d
l i b c + + . x . y . d y l i b , a l o n g w i t h t h e u s u a l s y m l i n k s p o i n t i n g t o t h a t . O n A p p l e p l a t f o r m s ,
t h i s a l s o c o n t r o l s t h e l i n k e r ' s ' c u r r e n t _ v e r s i o n ' p r o p e r t y . " )
2022-02-07 14:52:17 -05:00
set ( LIBCXX_ABI_NAMESPACE "__${LIBCXX_ABI_VERSION}" CACHE STRING "The inline ABI namespace used by libc++. It defaults to __n where `n` is the current ABI version." )
if ( NOT LIBCXX_ABI_NAMESPACE MATCHES "__.*" )
2022-06-09 08:49:03 -07:00
message ( FATAL_ERROR "LIBCXX_ABI_NAMESPACE must be a reserved identifier, got '${LIBCXX_ABI_NAMESPACE}'." )
2022-02-07 14:52:17 -05:00
endif ( )
2017-10-05 02:18:08 +00:00
option ( LIBCXX_ABI_FORCE_ITANIUM "Ignore auto-detection and force use of the Itanium ABI." )
option ( LIBCXX_ABI_FORCE_MICROSOFT "Ignore auto-detection and force use of the Microsoft ABI." )
2019-05-29 02:21:37 +00:00
2020-11-16 18:13:43 -05:00
set ( LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION "default" CACHE STRING
" O v e r r i d e t h e i m p l e m e n t a t i o n t o u s e f o r c o m p a r i n g t y p e i n f o s . B y d e f a u l t , t h i s
i s d e t e c t e d a u t o m a t i c a l l y b y t h e l i b r a r y , b u t t h i s o p t i o n a l l o w s o v e r r i d i n g
w h i c h i m p l e m e n t a t i o n i s u s e d u n c o n d i t i o n a l l y .
S e e t h e d o c u m e n t a t i o n i n < l i b c x x / i n c l u d e / t y p e i n f o > f o r d e t a i l s o n w h a t e a c h
v a l u e m e a n s . " )
set ( TYPEINFO_COMPARISON_VALUES "default;1;2;3" )
if ( NOT ( "${LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION}" IN_LIST TYPEINFO_COMPARISON_VALUES ) )
2020-05-15 15:58:19 -04:00
message ( FATAL_ERROR " Value ' ${ LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION } ' is not a valid value for
2020-11-16 18:13:43 -05:00
L I B C X X _ T Y P E I N F O _ C O M P A R I S O N _ I M P L E M E N T A T I O N " )
2019-05-29 02:21:37 +00:00
endif ( )
2017-10-04 23:51:57 +00:00
set ( LIBCXX_ABI_DEFINES "" CACHE STRING "A semicolon separated list of ABI macros to define in the site config header." )
2023-08-14 18:14:02 -04:00
set ( LIBCXX_EXTRA_SITE_DEFINES "" CACHE STRING "Extra defines to add into __config_site" )
2016-08-24 04:22:52 +00:00
option ( LIBCXX_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF )
2015-07-30 22:30:34 +00:00
2024-07-18 22:17:42 -07:00
# C Library options -----------------------------------------------------------
set ( LIBCXX_SUPPORTED_C_LIBRARIES system llvm-libc )
set ( LIBCXX_LIBC "system" CACHE STRING "Specify C library to use. Supported values are ${LIBCXX_SUPPORTED_C_LIBRARIES}." )
if ( NOT "${LIBCXX_LIBC}" IN_LIST LIBCXX_SUPPORTED_C_LIBRARIES )
message ( FATAL_ERROR "Unsupported C library: '${LIBCXX_CXX_ABI}'. Supported values are ${LIBCXX_SUPPORTED_C_LIBRARIES}." )
endif ( )
2015-07-30 22:30:34 +00:00
# ABI Library options ---------------------------------------------------------
2023-07-07 09:55:36 +00:00
if ( MSVC )
2022-03-01 08:42:13 -05:00
set ( LIBCXX_DEFAULT_ABI_LIBRARY "vcruntime" )
else ( )
set ( LIBCXX_DEFAULT_ABI_LIBRARY "libcxxabi" )
endif ( )
2015-07-30 22:30:34 +00:00
2022-03-01 08:42:13 -05:00
set ( LIBCXX_SUPPORTED_ABI_LIBRARIES none libcxxabi system-libcxxabi libcxxrt libstdc++ libsupc++ vcruntime )
set ( LIBCXX_CXX_ABI "${LIBCXX_DEFAULT_ABI_LIBRARY}" CACHE STRING "Specify C++ ABI library to use. Supported values are ${LIBCXX_SUPPORTED_ABI_LIBRARIES}." )
if ( NOT "${LIBCXX_CXX_ABI}" IN_LIST LIBCXX_SUPPORTED_ABI_LIBRARIES )
message ( FATAL_ERROR "Unsupported C++ ABI library: '${LIBCXX_CXX_ABI}'. Supported values are ${LIBCXX_SUPPORTED_ABI_LIBRARIES}." )
2016-08-08 18:01:50 +00:00
endif ( )
2015-10-22 20:54:27 +00:00
2019-03-18 18:18:01 +00:00
option ( LIBCXX_ENABLE_STATIC_ABI_LIBRARY
" U s e a s t a t i c c o p y o f t h e A B I l i b r a r y w h e n l i n k i n g l i b c + + .
T h i s o p t i o n c a n n o t b e u s e d w i t h L I B C X X _ E N A B L E _ A B I _ L I N K E R _ S C R I P T . " O F F )
2015-07-30 22:30:34 +00:00
2022-09-26 15:42:35 +02:00
option ( LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY
" S t a t i c a l l y l i n k t h e A B I l i b r a r y t o s t a t i c l i b r a r y "
$ { L I B C X X _ E N A B L E _ S T A T I C _ A B I _ L I B R A R Y } )
2018-07-24 07:06:17 +00:00
2022-09-26 15:42:35 +02:00
option ( LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY
" S t a t i c a l l y l i n k t h e A B I l i b r a r y t o s h a r e d l i b r a r y "
$ { L I B C X X _ E N A B L E _ S T A T I C _ A B I _ L I B R A R Y } )
2018-07-24 07:06:17 +00:00
2015-10-14 19:54:03 +00:00
# Generate and install a linker script inplace of libc++.so. The linker script
2015-10-15 22:41:51 +00:00
# will link libc++ to the correct ABI library. This option is on by default
2023-12-01 12:37:04 -08:00
# on UNIX platforms other than Apple, and on the Fuchsia platform unless we
# statically link libc++abi inside libc++.so, we don't build libc++.so at all
# or we don't have any ABI library.
2023-11-23 05:15:03 -10:00
if ( LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY
O R N O T L I B C X X _ E N A B L E _ S H A R E D
O R L I B C X X _ C X X _ A B I S T R E Q U A L " n o n e " )
set ( ENABLE_LINKER_SCRIPT_DEFAULT_VALUE OFF )
2023-12-01 12:37:04 -08:00
elseif ( ( UNIX OR FUCHSIA ) AND NOT APPLE )
2023-11-23 05:15:03 -10:00
set ( ENABLE_LINKER_SCRIPT_DEFAULT_VALUE ON )
else ( )
set ( ENABLE_LINKER_SCRIPT_DEFAULT_VALUE OFF )
2015-10-15 22:41:51 +00:00
endif ( )
2015-10-14 19:54:03 +00:00
option ( LIBCXX_ENABLE_ABI_LINKER_SCRIPT
2015-10-15 22:41:51 +00:00
" U s e a n d i n s t a l l a l i n k e r s c r i p t f o r t h e g i v e n A B I l i b r a r y "
2015-10-15 23:04:54 +00:00
$ { E N A B L E _ L I N K E R _ S C R I P T _ D E F A U L T _ V A L U E } )
2015-10-14 19:54:03 +00:00
2017-03-02 19:35:33 +00:00
option ( LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS
[libc++] Define new/delete in libc++abi only by default
Previously, we would define new/delete in both libc++ and libc++abi.
Not only does this cause code bloat, but also it's technically an ODR
violation since we don't know which operator will be selected. Furthermore,
since those are weak definitions, we should strive to have as few of them
as possible (to improve load times).
My preferred choice would have been to put the operators in libc++ only
by default, however that would create a circular dependency between
libc++ and libc++abi, which GNU linkers don't handle.
Folks who want to ship new/delete in libc++ instead of libc++abi are
free to do so by turning on LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS at
CMake configure time.
On Apple platforms, this shouldn't be an ABI break because we re-export
the new/delete symbols from libc++abi. This change actually makes libc++
behave closer to the system libc++ shipped on Apple platforms.
On other platforms, this is an ABI break for people linking against libc++
but not libc++abi. However, vendors have been consulted in D68269 and no
objection was raised. Furthermore, the definitions can be controlled to
appear in libc++ instead with the CMake option.
Differential Revision: https://reviews.llvm.org/D68269
2019-10-01 09:34:58 -04:00
" B u i l d l i b c + + w i t h d e f i n i t i o n s f o r o p e r a t o r n e w / d e l e t e . T h e s e a r e n o r m a l l y
d e f i n e d i n l i b c + + a b i , b u t t h i s o p t i o n c a n b e u s e d t o d e f i n e t h e m i n l i b c + +
i n s t e a d . I f y o u d e f i n e t h e m i n l i b c + + , m a k e s u r e t h e y a r e N O T d e f i n e d i n
l i b c + + a b i . D o i n g o t h e r w i s e i s a n O D R v i o l a t i o n . " O F F )
2015-07-30 22:30:34 +00:00
# Build libc++abi with libunwind. We need this option to determine whether to
# link with libunwind or libgcc_s while running the test cases.
2024-01-11 10:13:21 -05:00
option ( LIBCXXABI_USE_LLVM_UNWINDER "Build and use the LLVM unwinder." ON )
2015-07-30 22:30:34 +00:00
# Target options --------------------------------------------------------------
2021-11-23 16:34:09 -05:00
option ( LIBCXX_BUILD_32_BITS "Build 32 bit multilib libc++. This option is not supported anymore when building the runtimes. Please specify a full triple instead." ${ LLVM_BUILD_32_BITS } )
if ( LIBCXX_BUILD_32_BITS )
2021-12-01 12:57:30 -05:00
message ( FATAL_ERROR "LIBCXX_BUILD_32_BITS is not supported anymore when building the runtimes, please specify a full triple instead." )
2021-11-23 16:34:09 -05:00
endif ( )
2021-10-12 15:59:08 -04:00
2015-07-30 22:30:34 +00:00
# Feature options -------------------------------------------------------------
2015-11-09 10:21:04 +00:00
option ( LIBCXX_HAS_MUSL_LIBC "Build libc++ with support for the Musl C library" OFF )
2016-05-25 17:40:09 +00:00
option ( LIBCXX_HAS_PTHREAD_API "Ignore auto-detection and force use of pthread API" OFF )
2018-01-05 20:48:29 +00:00
option ( LIBCXX_HAS_WIN32_THREAD_API "Ignore auto-detection and force use of win32 thread API" OFF )
[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
llvm-svn: 281179
2016-09-11 21:46:40 +00:00
option ( LIBCXX_HAS_EXTERNAL_THREAD_API
" B u i l d l i b c + + w i t h a n e x t e r n a l i z e d t h r e a d i n g A P I .
T h i s o p t i o n m a y o n l y b e s e t t o O N w h e n L I B C X X _ E N A B L E _ T H R E A D S = O N . " O F F )
2015-07-30 22:30:34 +00:00
2023-05-24 15:33:38 -07:00
if ( LIBCXX_ENABLE_THREADS )
2024-04-17 13:36:53 -04:00
set ( LIBCXX_PSTL_BACKEND "std_thread" CACHE STRING "Which PSTL backend to use" )
2023-05-24 15:33:38 -07:00
else ( )
2024-04-17 13:36:53 -04:00
set ( LIBCXX_PSTL_BACKEND "serial" CACHE STRING "Which PSTL backend to use" )
2023-05-24 15:33:38 -07:00
endif ( )
2015-07-30 22:30:34 +00:00
# Misc options ----------------------------------------------------------------
2015-10-10 03:34:52 +00:00
# FIXME: Turn -pedantic back ON. It is currently off because it warns
# about #include_next which is used everywhere.
option ( LIBCXX_ENABLE_PEDANTIC "Compile with pedantic enabled." OFF )
2015-07-30 22:30:34 +00:00
option ( LIBCXX_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF )
[runtimes] Default LIB*_HERMETIC_STATIC_LIBRARY to ON on Windows
(In the case of libunwind, the cmake option is called
LIBUNWIND_HIDE_SYMBOLS, but it has the same effect as
LIBCXX_HERMETIC_STATIC_LIBRARY and
LIBCXXABI_HERMETIC_STATIC_LIBRARY.)
Previously, the same issue was dealt with by setting a project wide
define (_LIBUNWIND_HIDE_SYMBOLS,
_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS and
_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) if only building a static
library. If building both static and shared at the same time, this
wasn't set, and the static library would contain dllexport directives.
The LIB*_HERMETIC_STATIC_LIBRARY and LIBUNWIND_HIDE_SYMBOLS cmake
options only apply the defines to the static library in the build,
even if building both static and shared at the same time.
(This could only be done use after the object libraries were
enabled, as a shared libcxx needs libcxxabi object files built
with dllexports included.)
This allows removing inelegant code for deciding how to build the
libcxxabi static library and a TODO comment that suggested that
users should need to start setting an option, which they shouldn't
need to. Finally, this gets rid of two XFAILs in tests.
Differential Revision: https://reviews.llvm.org/D125715
2022-04-09 23:40:07 +03:00
set ( LIBCXX_HERMETIC_STATIC_LIBRARY_DEFAULT OFF )
if ( WIN32 )
set ( LIBCXX_HERMETIC_STATIC_LIBRARY_DEFAULT ON )
endif ( )
2019-01-06 06:14:31 +00:00
option ( LIBCXX_HERMETIC_STATIC_LIBRARY
[runtimes] Default LIB*_HERMETIC_STATIC_LIBRARY to ON on Windows
(In the case of libunwind, the cmake option is called
LIBUNWIND_HIDE_SYMBOLS, but it has the same effect as
LIBCXX_HERMETIC_STATIC_LIBRARY and
LIBCXXABI_HERMETIC_STATIC_LIBRARY.)
Previously, the same issue was dealt with by setting a project wide
define (_LIBUNWIND_HIDE_SYMBOLS,
_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS and
_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) if only building a static
library. If building both static and shared at the same time, this
wasn't set, and the static library would contain dllexport directives.
The LIB*_HERMETIC_STATIC_LIBRARY and LIBUNWIND_HIDE_SYMBOLS cmake
options only apply the defines to the static library in the build,
even if building both static and shared at the same time.
(This could only be done use after the object libraries were
enabled, as a shared libcxx needs libcxxabi object files built
with dllexports included.)
This allows removing inelegant code for deciding how to build the
libcxxabi static library and a TODO comment that suggested that
users should need to start setting an option, which they shouldn't
need to. Finally, this gets rid of two XFAILs in tests.
Differential Revision: https://reviews.llvm.org/D125715
2022-04-09 23:40:07 +03:00
" D o n o t e x p o r t a n y s y m b o l s f r o m t h e s t a t i c l i b r a r y . " $ { L I B C X X _ H E R M E T I C _ S T A T I C _ L I B R A R Y _ D E F A U L T } )
2019-01-06 06:14:31 +00:00
2015-07-30 22:30:34 +00:00
#===============================================================================
# Check option configurations
#===============================================================================
# Ensure LIBCXX_ENABLE_MONOTONIC_CLOCK is set to ON only when
# LIBCXX_ENABLE_THREADS is on.
if ( LIBCXX_ENABLE_THREADS AND NOT LIBCXX_ENABLE_MONOTONIC_CLOCK )
message ( FATAL_ERROR "LIBCXX_ENABLE_MONOTONIC_CLOCK can only be set to OFF"
" w h e n L I B C X X _ E N A B L E _ T H R E A D S i s a l s o s e t t o O F F . " )
2015-07-29 21:07:28 +00:00
endif ( )
2017-01-03 12:59:50 +00:00
if ( NOT LIBCXX_ENABLE_THREADS )
if ( LIBCXX_HAS_PTHREAD_API )
message ( FATAL_ERROR "LIBCXX_HAS_PTHREAD_API can only be set to ON"
" w h e n L I B C X X _ E N A B L E _ T H R E A D S i s a l s o s e t t o O N . " )
endif ( )
if ( LIBCXX_HAS_EXTERNAL_THREAD_API )
message ( FATAL_ERROR "LIBCXX_HAS_EXTERNAL_THREAD_API can only be set to ON"
" w h e n L I B C X X _ E N A B L E _ T H R E A D S i s a l s o s e t t o O N . " )
endif ( )
2018-01-05 20:48:29 +00:00
if ( LIBCXX_HAS_WIN32_THREAD_API )
message ( FATAL_ERROR "LIBCXX_HAS_WIN32_THREAD_API can only be set to ON"
" w h e n L I B C X X _ E N A B L E _ T H R E A D S i s a l s o s e t t o O N . " )
endif ( )
2017-01-06 20:05:40 +00:00
endif ( )
2017-01-09 10:38:56 +00:00
if ( LIBCXX_HAS_EXTERNAL_THREAD_API )
if ( LIBCXX_HAS_PTHREAD_API )
message ( FATAL_ERROR "The options LIBCXX_HAS_EXTERNAL_THREAD_API"
2023-09-06 20:54:43 +02:00
" a n d L I B C X X _ H A S _ P T H R E A D _ A P I c a n n o t b e b o t h "
" s e t t o O N a t t h e s a m e t i m e . " )
2017-01-09 10:38:56 +00:00
endif ( )
2018-01-05 20:48:29 +00:00
if ( LIBCXX_HAS_WIN32_THREAD_API )
message ( FATAL_ERROR "The options LIBCXX_HAS_EXTERNAL_THREAD_API"
2023-09-06 20:54:43 +02:00
" a n d L I B C X X _ H A S _ W I N 3 2 _ T H R E A D _ A P I c a n n o t b e b o t h "
" s e t t o O N a t t h e s a m e t i m e . " )
2018-01-05 20:48:29 +00:00
endif ( )
endif ( )
if ( LIBCXX_HAS_PTHREAD_API )
if ( LIBCXX_HAS_WIN32_THREAD_API )
message ( FATAL_ERROR "The options LIBCXX_HAS_PTHREAD_API"
2023-09-06 20:54:43 +02:00
" a n d L I B C X X _ H A S _ W I N 3 2 _ T H R E A D _ A P I c a n n o t b e b o t h "
" s e t t o O N a t t h e s a m e t i m e . " )
2018-01-05 20:48:29 +00:00
endif ( )
[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
llvm-svn: 281179
2016-09-11 21:46:40 +00:00
endif ( )
2023-12-12 17:11:53 +01:00
if ( NOT LIBCXX_ENABLE_RTTI AND LIBCXX_ENABLE_EXCEPTIONS )
message ( FATAL_ERROR "Libc++ cannot be built with exceptions enabled but RTTI"
" d i s a b l e d , s i n c e t h a t c o n f i g u r a t i o n i s b r o k e n . S e e "
" h t t p s : / / g i t h u b . c o m / l l v m / l l v m - p r o j e c t / i s s u e s / 6 6 1 1 7 "
" f o r d e t a i l s . " )
endif ( )
2015-10-14 19:54:03 +00:00
if ( LIBCXX_ENABLE_ABI_LINKER_SCRIPT )
if ( APPLE )
message ( FATAL_ERROR "LIBCXX_ENABLE_ABI_LINKER_SCRIPT cannot be used on APPLE targets" )
endif ( )
2016-05-14 23:58:11 +00:00
if ( NOT LIBCXX_ENABLE_SHARED )
message ( FATAL_ERROR "LIBCXX_ENABLE_ABI_LINKER_SCRIPT is only available for shared library builds." )
endif ( )
2015-10-14 19:54:03 +00:00
endif ( )
2018-07-26 05:10:24 +00:00
if ( LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY AND LIBCXX_ENABLE_ABI_LINKER_SCRIPT )
2015-10-14 19:54:03 +00:00
message ( FATAL_ERROR " Conflicting options given.
2022-09-26 15:42:35 +02:00
L I B C X X _ S T A T I C A L L Y _ L I N K _ A B I _ I N _ S H A R E D _ L I B R A R Y c a n n o t b e s p e c i f i e d w i t h
2015-10-14 19:54:03 +00:00
L I B C X X _ E N A B L E _ A B I _ L I N K E R _ S C R I P T " )
endif ( )
2017-10-05 02:18:08 +00:00
if ( LIBCXX_ABI_FORCE_ITANIUM AND LIBCXX_ABI_FORCE_MICROSOFT )
message ( FATAL_ERROR "Only one of LIBCXX_ABI_FORCE_ITANIUM and LIBCXX_ABI_FORCE_MICROSOFT can be specified." )
2017-10-04 23:44:38 +00:00
endif ( )
2023-07-17 12:52:47 +03:00
if ( LIBCXX_ENABLE_SHARED AND CMAKE_MSVC_RUNTIME_LIBRARY AND
( N O T C M A K E _ M S V C _ R U N T I M E _ L I B R A R Y M A T C H E S " D L L $ " ) )
message ( WARNING "A static CRT linked into a shared libc++ doesn't work correctly." )
endif ( )
2010-12-10 19:47:54 +00:00
#===============================================================================
# Configure System
#===============================================================================
2020-06-26 12:08:59 -04:00
# TODO: Projects that depend on libc++ should use LIBCXX_GENERATED_INCLUDE_DIR
# instead of hard-coding include/c++/v1.
2022-01-11 03:03:21 +00:00
2023-08-14 18:14:02 -04:00
set ( LIBCXX_INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_INCLUDEDIR}/c++/v1" CACHE STRING
2022-01-11 03:03:21 +00:00
" P a t h w h e r e t a r g e t - a g n o s t i c l i b c + + h e a d e r s s h o u l d b e i n s t a l l e d . " )
2023-08-14 18:14:02 -04:00
set ( LIBCXX_INSTALL_RUNTIME_DIR "${CMAKE_INSTALL_BINDIR}" CACHE STRING
2022-01-11 03:03:21 +00:00
" P a t h w h e r e b u i l t l i b c + + r u n t i m e l i b r a r i e s s h o u l d b e i n s t a l l e d . " )
2024-01-21 12:16:22 +01:00
set ( LIBCXX_INSTALL_MODULES_DIR "share/libc++/v1" CACHE STRING
" P a t h w h e r e t a r g e t - a g n o s t i c l i b c + + m o d u l e s o u r c e f i l e s s h o u l d b e i n s t a l l e d . " )
2022-01-11 03:03:21 +00:00
2022-10-11 10:05:56 -04:00
set ( LIBCXX_SHARED_OUTPUT_NAME "c++" CACHE STRING "Output name for the shared libc++ runtime library." )
set ( LIBCXX_STATIC_OUTPUT_NAME "c++" CACHE STRING "Output name for the static libc++ runtime library." )
2022-10-03 16:41:58 -05:00
2018-06-28 03:11:52 +00:00
if ( LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE )
2024-05-31 11:48:45 -07:00
set ( LIBCXX_TARGET_SUBDIR ${ LLVM_DEFAULT_TARGET_TRIPLE } )
if ( LIBCXX_LIBDIR_SUBDIR )
string ( APPEND LIBCXX_TARGET_SUBDIR / ${ LIBCXX_LIBDIR_SUBDIR } )
endif ( )
set ( LIBCXX_LIBRARY_DIR ${ LLVM_LIBRARY_OUTPUT_INTDIR } / ${ LIBCXX_TARGET_SUBDIR } )
2025-01-14 18:23:07 +00:00
set ( LIBCXX_GENERATED_INCLUDE_DIR "${LLVM_BINARY_DIR}/include/c++/v1" )
set ( LIBCXX_GENERATED_MODULE_DIR "${LLVM_BINARY_DIR}/modules/c++/v1" )
set ( LIBCXX_GENERATED_INCLUDE_TARGET_DIR "${LLVM_BINARY_DIR}/include/${LIBCXX_TARGET_SUBDIR}/c++/v1" )
2024-05-31 11:48:45 -07:00
set ( LIBCXX_INSTALL_LIBRARY_DIR lib ${ LLVM_LIBDIR_SUFFIX } / ${ LIBCXX_TARGET_SUBDIR } CACHE STRING
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
" P a t h w h e r e b u i l t l i b c + + l i b r a r i e s s h o u l d b e i n s t a l l e d . " )
2024-05-31 11:48:45 -07:00
set ( LIBCXX_INSTALL_INCLUDE_TARGET_DIR "${CMAKE_INSTALL_INCLUDEDIR}/${LIBCXX_TARGET_SUBDIR}/c++/v1" CACHE STRING
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
" P a t h w h e r e t a r g e t - s p e c i f i c l i b c + + h e a d e r s s h o u l d b e i n s t a l l e d . " )
2024-05-31 11:48:45 -07:00
unset ( LIBCXX_TARGET_SUBDIR )
2017-05-04 06:02:50 +00:00
else ( )
2022-01-11 03:03:21 +00:00
if ( LLVM_LIBRARY_OUTPUT_INTDIR )
set ( LIBCXX_LIBRARY_DIR ${ LLVM_LIBRARY_OUTPUT_INTDIR } )
2025-01-14 18:23:07 +00:00
set ( LIBCXX_GENERATED_INCLUDE_DIR "${LLVM_BINARY_DIR}/include/c++/v1" )
set ( LIBCXX_GENERATED_MODULE_DIR "${LLVM_BINARY_DIR}/modules/c++/v1" )
2022-01-11 03:03:21 +00:00
else ( )
2022-08-18 22:44:46 -04:00
set ( LIBCXX_LIBRARY_DIR ${ CMAKE_BINARY_DIR } /lib ${ LIBCXX_LIBDIR_SUFFIX } )
2025-01-14 18:23:07 +00:00
set ( LIBCXX_GENERATED_INCLUDE_DIR "${CMAKE_BINARY_DIR}/include/c++/v1" )
set ( LIBCXX_GENERATED_MODULE_DIR "${CMAKE_BINARY_DIR}/modules/c++/v1" )
2022-01-11 03:03:21 +00:00
endif ( )
2020-07-15 14:10:56 -07:00
set ( LIBCXX_GENERATED_INCLUDE_TARGET_DIR "${LIBCXX_GENERATED_INCLUDE_DIR}" )
2023-08-14 18:14:02 -04:00
set ( LIBCXX_INSTALL_LIBRARY_DIR lib ${ LIBCXX_LIBDIR_SUFFIX } CACHE STRING
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
" P a t h w h e r e b u i l t l i b c + + l i b r a r i e s s h o u l d b e i n s t a l l e d . " )
2023-08-14 18:14:02 -04:00
set ( LIBCXX_INSTALL_INCLUDE_TARGET_DIR "${LIBCXX_INSTALL_INCLUDE_DIR}" CACHE STRING
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
" P a t h w h e r e t a r g e t - s p e c i f i c l i b c + + h e a d e r s s h o u l d b e i n s t a l l e d . " )
2017-05-04 06:02:50 +00:00
endif ( )
2018-06-28 03:11:52 +00:00
2015-07-30 22:30:34 +00:00
set ( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${ LIBCXX_LIBRARY_DIR } )
set ( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${ LIBCXX_LIBRARY_DIR } )
2017-04-13 16:27:38 +00:00
set ( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${ LIBCXX_LIBRARY_DIR } )
2015-07-30 22:30:34 +00:00
2014-11-15 06:26:30 +00:00
# Declare libc++ configuration variables.
# They are intended for use as follows:
# LIBCXX_CXX_FLAGS: General flags for both the compiler and linker.
# LIBCXX_COMPILE_FLAGS: Compile only flags.
# LIBCXX_LINK_FLAGS: Linker only flags.
2016-10-09 21:34:03 +00:00
# LIBCXX_LIBRARIES: libraries libc++ is linked to.
2014-11-15 06:26:30 +00:00
set ( LIBCXX_COMPILE_FLAGS "" )
set ( LIBCXX_LINK_FLAGS "" )
2015-07-30 22:30:34 +00:00
set ( LIBCXX_LIBRARIES "" )
2022-10-03 16:41:58 -05:00
set ( LIBCXX_ADDITIONAL_COMPILE_FLAGS "" CACHE STRING
2024-10-17 16:17:40 -04:00
" A d d i t i o n a l c o m p i l e f l a g s t o u s e w h e n b u i l d i n g l i b c + + . T h i s s h o u l d b e a C M a k e ; - d e l i m i t e d l i s t o f i n d i v i d u a l
c o m p i l e r o p t i o n s t o u s e . F o r o p t i o n s t h a t m u s t b e p a s s e d a s - i s t o t h e c o m p i l e r w i t h o u t deduplication ( e.g.
` - X c l a n g - f o o ` o p t i o n g r o u p s ) , c o n s i d e r u s i n g ` S H E L L : ` ( h t t p s : / / c m a k e . o r g / c m a k e / h e l p / l a t e s t / c o m m a n d / a d d _ c o m p i l e _ o p t i o n s . h t m l #option-de-duplication).")
2022-10-03 16:41:58 -05:00
set ( LIBCXX_ADDITIONAL_LIBRARIES "" CACHE STRING
" A d d i t i o n a l l i b r a r i e s l i b c + + i s l i n k e d t o w h i c h c a n b e p r o v i d e d i n c a c h e " )
2014-11-15 06:26:30 +00:00
2016-06-02 01:10:08 +00:00
# Include macros for adding and removing libc++ flags.
include ( HandleLibcxxFlags )
# Target flags ================================================================
# These flags get added to CMAKE_CXX_FLAGS and CMAKE_C_FLAGS so that
# 'config-ix' use them during feature checks. It also adds them to both
# 'LIBCXX_COMPILE_FLAGS' and 'LIBCXX_LINK_FLAGS'
[CMake] Support CMake variables for setting target, sysroot and toolchain
CMake has a standard way of setting target triple, sysroot and external
toolchain through CMAKE_<LANG>_COMPILER_TARGET, CMAKE_SYSROOT and
CMAKE_<LANG>_COMPILER_EXTERNAL_TOOLCHAIN. These are turned into
corresponding --target=, --sysroot= and --gcc-toolchain= variables add
included appended to CMAKE_<LANG>_FLAGS.
libunwind, libc++abi, libc++ provides their own mechanism through
<PROJECT>_TARGET_TRIPLE, <PROJECT>_SYSROOT and <PROJECT>_GCC_TOOLCHAIN
variables. These are also passed to lit via lit.site.cfg, and lit config
uses these to set the corresponding compiler flags when building tessts.
This means that there are two different ways of setting target, sysroot
and toolchain, but only one is properly supported in lit. This change
extends CMake build for libunwind, libc++abi and libc++ to also support
the CMake variables in addition to project specific ones in lit.
Differential Revision: https://reviews.llvm.org/D57670
llvm-svn: 353084
2019-02-04 20:02:26 +00:00
2022-06-13 21:44:58 -04:00
if ( ${ CMAKE_SYSTEM_NAME } MATCHES "AIX" )
2023-02-20 16:47:34 +01:00
add_flags_if_supported ( "-mdefault-visibility-export-mapping=explicit" )
2022-06-13 21:44:58 -04:00
set ( CMAKE_AIX_EXPORT_ALL_SYMBOLS OFF )
endif ( )
2014-11-15 17:25:23 +00:00
# Configure compiler.
include ( config-ix )
2015-07-30 22:30:34 +00:00
2014-11-15 17:25:23 +00:00
#===============================================================================
# Setup Compiler Flags
#===============================================================================
2024-07-18 22:17:42 -07:00
include ( HandleLibC ) # Setup the C library flags
2016-03-05 14:22:02 +00:00
include ( HandleLibCXXABI ) # Setup the ABI library flags
2015-07-29 00:03:51 +00:00
2017-03-25 03:42:20 +00:00
# FIXME(EricWF): See the FIXME on LIBCXX_ENABLE_PEDANTIC.
2015-10-15 20:27:15 +00:00
# Remove the -pedantic flag and -Wno-pedantic and -pedantic-errors
2017-03-25 03:42:20 +00:00
# so they don't get transformed into -Wno and -errors respectively.
2015-10-15 20:27:15 +00:00
remove_flags ( -Wno-pedantic -pedantic-errors -pedantic )
2015-10-13 23:56:33 +00:00
2015-07-30 22:30:34 +00:00
# Required flags ==============================================================
2019-10-02 20:07:01 +00:00
function ( cxx_add_basic_build_flags target )
2019-12-11 20:26:30 -05:00
2023-11-05 08:40:51 -05:00
# Use C++23 for all targets.
2019-12-11 20:26:30 -05:00
set_target_properties ( ${ target } PROPERTIES
2023-11-05 08:40:51 -05:00
C X X _ S T A N D A R D 2 3
2023-11-16 14:58:36 -05:00
C X X _ S T A N D A R D _ R E Q U I R E D O F F # TODO: Make this REQUIRED once we don't need to accommodate the LLVM documentation builders using an ancient CMake
2019-12-11 20:26:30 -05:00
C X X _ E X T E N S I O N S N O )
2015-07-30 22:30:34 +00:00
2020-07-23 11:05:47 -04:00
# When building the dylib, don't warn for unavailable aligned allocation
# functions based on the deployment target -- they are always available
2022-08-02 12:42:04 +02:00
# because they are provided by the dylib itself with the exception of z/OS.
2020-11-12 14:40:35 -05:00
if ( ZOS )
target_add_compile_flags_if_supported ( ${ target } PRIVATE -fno-aligned-allocation )
else ( )
target_add_compile_flags_if_supported ( ${ target } PRIVATE -faligned-allocation )
endif ( )
2020-07-23 11:05:47 -04:00
2019-10-02 20:07:01 +00:00
# On all systems the system c++ standard library headers need to be excluded.
# MSVC only has -X, which disables all default includes; including the crt.
# Thus, we do nothing and hope we don't accidentally include any of the C++
# headers
target_add_compile_flags_if_supported ( ${ target } PUBLIC -nostdinc++ )
# Hide all inline function definitions which have not explicitly been marked
# visible. This prevents new definitions for inline functions from appearing in
# the dylib when get ODR used by another function.
target_add_compile_flags_if_supported ( ${ target } PRIVATE -fvisibility-inlines-hidden )
2025-03-25 15:43:48 +01:00
target_add_compile_flags_if_supported ( ${ target } PRIVATE -fvisibility=hidden )
[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
llvm-svn: 285101
2016-10-25 19:43:44 +00:00
2024-06-24 17:26:03 -04:00
# Build with -fsized-deallocation, which is default in recent versions of Clang.
# TODO(LLVM 21): This can be dropped once we only support Clang >= 19.
target_add_compile_flags_if_supported ( ${ target } PRIVATE -fsized-deallocation )
2019-10-02 20:07:01 +00:00
# Let the library headers know they are currently being used to build the
# library.
target_compile_definitions ( ${ target } PRIVATE -D_LIBCPP_BUILDING_LIBRARY )
[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
llvm-svn: 281681
2016-09-16 00:00:48 +00:00
2023-03-10 17:31:58 +01:00
# Make sure the library can be build without transitive includes. This makes
# it easier to upgrade the library to a newer language standard without build
# errors.
target_compile_definitions ( ${ target } PRIVATE -D_LIBCPP_REMOVE_TRANSITIVE_INCLUDES )
2022-03-10 11:47:09 +02:00
if ( C_SUPPORTS_COMMENT_LIB_PRAGMA )
2019-12-02 11:49:20 +01:00
if ( LIBCXX_HAS_PTHREAD_LIB )
target_compile_definitions ( ${ target } PRIVATE -D_LIBCPP_LINK_PTHREAD_LIB )
endif ( )
if ( LIBCXX_HAS_RT_LIB )
target_compile_definitions ( ${ target } PRIVATE -D_LIBCPP_LINK_RT_LIB )
endif ( )
2019-10-02 20:07:01 +00:00
endif ( )
2022-10-03 16:41:58 -05:00
target_compile_options ( ${ target } PUBLIC "${LIBCXX_ADDITIONAL_COMPILE_FLAGS}" )
2019-10-02 20:07:01 +00:00
endfunction ( )
2019-05-30 04:40:21 +00:00
2015-07-30 22:30:34 +00:00
# Exception flags =============================================================
2019-10-04 18:03:17 +00:00
function ( cxx_add_exception_flags target )
if ( LIBCXX_ENABLE_EXCEPTIONS )
# Catches C++ exceptions only and tells the compiler to assume that extern C
# functions never throw a C++ exception.
target_add_compile_flags_if_supported ( ${ target } PUBLIC -EHsc )
else ( )
target_add_compile_flags_if_supported ( ${ target } PUBLIC -EHs- -EHa- )
target_add_compile_flags_if_supported ( ${ target } PUBLIC -fno-exceptions )
endif ( )
endfunction ( )
2015-07-30 22:30:34 +00:00
# RTTI flags ==================================================================
2019-10-04 18:03:17 +00:00
function ( cxx_add_rtti_flags target )
if ( NOT LIBCXX_ENABLE_RTTI )
2023-07-07 09:55:36 +00:00
if ( MSVC )
2023-07-06 08:49:33 +00:00
target_add_compile_flags_if_supported ( ${ target } PUBLIC -GR- )
else ( )
target_add_compile_flags_if_supported ( ${ target } PUBLIC -fno-rtti )
endif ( )
2019-10-04 18:03:17 +00:00
endif ( )
endfunction ( )
2015-07-30 22:30:34 +00:00
2016-10-14 12:56:52 +00:00
# Modules flags ===============================================================
# FIXME The libc++ sources are fundamentally non-modular. They need special
# versions of the headers in order to provide C++03 and legacy ABI definitions.
# NOTE: The public headers can be used with modules in all other contexts.
2019-10-04 18:03:17 +00:00
function ( cxx_add_module_flags target )
if ( LLVM_ENABLE_MODULES )
# Ignore that the rest of the modules flags are now unused.
2019-10-04 19:10:56 +00:00
target_add_compile_flags_if_supported ( ${ target } PUBLIC -Wno-unused-command-line-argument )
target_compile_options ( ${ target } PUBLIC -fno-modules )
2019-10-04 18:03:17 +00:00
endif ( )
endfunction ( )
2016-10-14 12:56:52 +00:00
2023-07-11 20:18:20 -07:00
string ( TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE )
2015-08-24 21:20:07 +00:00
# Sanitizer flags =============================================================
2010-12-10 19:47:54 +00:00
2018-11-13 23:08:31 +00:00
function ( get_sanitizer_flags OUT_VAR USE_SANITIZER )
set ( SANITIZER_FLAGS )
set ( USE_SANITIZER "${USE_SANITIZER}" )
2015-07-29 23:46:55 +00:00
# NOTE: LLVM_USE_SANITIZER checks for a UNIX like system instead of MSVC.
# But we don't have LLVM_ON_UNIX so checking for MSVC is the best we can do.
2018-11-13 23:08:31 +00:00
if ( USE_SANITIZER AND NOT MSVC )
append_flags_if_supported ( SANITIZER_FLAGS "-fno-omit-frame-pointer" )
append_flags_if_supported ( SANITIZER_FLAGS "-gline-tables-only" )
2015-07-30 22:30:34 +00:00
2015-07-29 23:46:55 +00:00
if ( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" AND
2018-11-13 23:08:31 +00:00
N O T u p p e r c a s e _ C M A K E _ B U I L D _ T Y P E S T R E Q U A L " R E L W I T H D E B I N F O " )
append_flags_if_supported ( SANITIZER_FLAGS "-gline-tables-only" )
2015-07-29 23:46:55 +00:00
endif ( )
2018-11-13 23:08:31 +00:00
if ( USE_SANITIZER STREQUAL "Address" )
append_flags ( SANITIZER_FLAGS "-fsanitize=address" )
2022-08-12 22:12:28 -07:00
elseif ( USE_SANITIZER STREQUAL "HWAddress" )
append_flags ( SANITIZER_FLAGS "-fsanitize=hwaddress" )
2018-11-13 23:08:31 +00:00
elseif ( USE_SANITIZER MATCHES "Memory(WithOrigins)?" )
2022-04-30 13:17:17 +02:00
append_flags ( SANITIZER_FLAGS -fsanitize=memory )
2018-11-13 23:08:31 +00:00
if ( USE_SANITIZER STREQUAL "MemoryWithOrigins" )
append_flags ( SANITIZER_FLAGS "-fsanitize-memory-track-origins" )
2015-07-29 23:46:55 +00:00
endif ( )
2018-11-13 23:08:31 +00:00
elseif ( USE_SANITIZER STREQUAL "Undefined" )
2023-11-29 09:29:44 -05:00
append_flags ( SANITIZER_FLAGS "-fsanitize=undefined" "-fno-sanitize=vptr,function" "-fno-sanitize-recover=all" )
libcxx 'LLVM_USE_SANITIZER=Address;Undefined'
Summary:
Allow users to simultaneously enable address and undefined behavior
sanitizers, in the same manner that LLVM's 'HandleLLVMOptions.cmake'
allows.
Prior to this patch, `cmake -DLLVM_USE_SANITIZER="Address;Undefined"`
would succeed and the build would build most of the LLVM project with
`-fsanitize=address,undefined`, but a warning would be printed by
libcxx's CMake, and the build would use neither sanitizer. This
patch results in no warning being printed, and both sanitizers are used
in building libcxx.
Reviewers: jroelofs, EricWF, ldionne, #libc!
Subscribers: mgorny, dexonsmith, llvm-commits, libcxx-commits
Tags: #libc
Differential Revision: https://reviews.llvm.org/D77466
2020-04-04 13:01:32 -04:00
elseif ( USE_SANITIZER STREQUAL "Address;Undefined" OR
U S E _ S A N I T I Z E R S T R E Q U A L " U n d e f i n e d ; A d d r e s s " )
2023-11-29 09:29:44 -05:00
append_flags ( SANITIZER_FLAGS "-fsanitize=address,undefined" "-fno-sanitize=vptr,function" "-fno-sanitize-recover=all" )
2018-11-13 23:08:31 +00:00
elseif ( USE_SANITIZER STREQUAL "Thread" )
append_flags ( SANITIZER_FLAGS -fsanitize=thread )
2020-04-17 10:15:58 -07:00
elseif ( USE_SANITIZER STREQUAL "DataFlow" )
append_flags ( SANITIZER_FLAGS -fsanitize=dataflow )
2015-07-29 23:46:55 +00:00
else ( )
2018-11-13 23:08:31 +00:00
message ( WARNING "Unsupported value of LLVM_USE_SANITIZER: ${USE_SANITIZER}" )
2015-07-29 23:46:55 +00:00
endif ( )
2018-11-13 23:08:31 +00:00
elseif ( USE_SANITIZER AND MSVC )
2015-07-30 22:30:34 +00:00
message ( WARNING "LLVM_USE_SANITIZER is not supported on this platform." )
2015-07-29 23:46:55 +00:00
endif ( )
2018-11-13 23:08:31 +00:00
set ( ${ OUT_VAR } "${SANITIZER_FLAGS}" PARENT_SCOPE )
endfunction ( )
get_sanitizer_flags ( SANITIZER_FLAGS "${LLVM_USE_SANITIZER}" )
2023-11-29 09:29:44 -05:00
add_library ( cxx-sanitizer-flags INTERFACE )
target_compile_options ( cxx-sanitizer-flags INTERFACE ${ SANITIZER_FLAGS } )
[libcxx] Capture configuration information when installing the libc++ headers
Summary:
Hi all,
This patch is a successor to D11963. However it has changed dramatically and I felt it would be best to start a new review thread.
Please read the design documentation added in this patch for a description of how it works.
Reviewers: mclow.lists, danalbert, jroelofs, EricWF
Subscribers: vkalintiris, rnk, ed, espositofulvio, asl, eugenis, cfe-commits
Differential Revision: http://reviews.llvm.org/D13407
llvm-svn: 250235
2015-10-13 22:12:02 +00:00
[ASan][libc++] std::basic_string annotations (#72677)
This commit introduces basic annotations for `std::basic_string`,
mirroring the approach used in `std::vector` and `std::deque`.
Initially, only long strings with the default allocator will be
annotated. Short strings (_SSO - short string optimization_) and strings
with non-default allocators will be annotated in the near future, with
separate commits dedicated to enabling them. The process will be similar
to the workflow employed for enabling annotations in `std::deque`.
**Please note**: these annotations function effectively only when libc++
and libc++abi dylibs are instrumented (with ASan). This aligns with the
prevailing behavior of Memory Sanitizer.
To avoid breaking everything, this commit also appends
`_LIBCPP_INSTRUMENTED_WITH_ASAN` to `__config_site` whenever libc++ is
compiled with ASan. If this macro is not defined, string annotations are
not enabled. However, linking a binary that does **not** annotate
strings with a dynamic library that annotates strings, is not permitted.
Originally proposed here: https://reviews.llvm.org/D132769
Related patches on Phabricator:
- Turning on annotations for short strings:
https://reviews.llvm.org/D147680
- Turning on annotations for all allocators:
https://reviews.llvm.org/D146214
This PR is a part of a series of patches extending AddressSanitizer C++
container overflow detection capabilities by adding annotations, similar
to those existing in `std::vector` and `std::deque` collections. These
enhancements empower ASan to effectively detect instances where the
instrumented program attempts to access memory within a collection's
internal allocation that remains unused. This includes cases where
access occurs before or after the stored elements in `std::deque`, or
between the `std::basic_string`'s size (including the null terminator)
and capacity bounds.
The introduction of these annotations was spurred by a real-world
software bug discovered by Trail of Bits, involving an out-of-bounds
memory access during the comparison of two strings using the
`std::equals` function. This function was taking iterators
(`iter1_begin`, `iter1_end`, `iter2_begin`) to perform the comparison,
using a custom comparison function. When the `iter1` object exceeded the
length of `iter2`, an out-of-bounds read could occur on the `iter2`
object. Container sanitization, upon enabling these annotations, would
effectively identify and flag this potential vulnerability.
This Pull Request introduces basic annotations for `std::basic_string`.
Long strings exhibit structural similarities to `std::vector` and will
be annotated accordingly. Short strings are already implemented, but
will be turned on separately in a forthcoming commit. Look at [a
comment](https://github.com/llvm/llvm-project/pull/72677#issuecomment-1850554465)
below to read about SSO issues at current moment.
Due to the functionality introduced in
[D132522](https://github.com/llvm/llvm-project/commit/dd1b7b797a116eed588fd752fbe61d34deeb24e4),
the `__sanitizer_annotate_contiguous_container` function now offers
compatibility with all allocators. However, enabling this support will
be done in a subsequent commit. For the time being, only strings with
the default allocator will be annotated.
If you have any questions, please email:
- advenam.tacet@trailofbits.com
- disconnect3d@trailofbits.com
2023-12-13 06:05:34 +01:00
# _LIBCPP_INSTRUMENTED_WITH_ASAN informs that library was built with ASan.
# Defining _LIBCPP_INSTRUMENTED_WITH_ASAN while building the library with ASan is required.
# Normally, the _LIBCPP_INSTRUMENTED_WITH_ASAN flag is used to keep information whether
# dylibs are built with AddressSanitizer. However, when building libc++,
# this flag needs to be defined so that the resulting dylib has all ASan functionalities guarded by this flag.
# If the _LIBCPP_INSTRUMENTED_WITH_ASAN flag is not defined, then parts of the ASan instrumentation code in libc++
# will not be compiled into it, resulting in false positives.
# For context, read: https://github.com/llvm/llvm-project/pull/72677#pullrequestreview-1765402800
string ( FIND "${LLVM_USE_SANITIZER}" "Address" building_with_asan )
if ( NOT "${building_with_asan}" STREQUAL "-1" )
config_define ( ON _LIBCPP_INSTRUMENTED_WITH_ASAN )
2024-11-06 10:39:19 +01:00
else ( )
config_define ( OFF _LIBCPP_INSTRUMENTED_WITH_ASAN )
[ASan][libc++] std::basic_string annotations (#72677)
This commit introduces basic annotations for `std::basic_string`,
mirroring the approach used in `std::vector` and `std::deque`.
Initially, only long strings with the default allocator will be
annotated. Short strings (_SSO - short string optimization_) and strings
with non-default allocators will be annotated in the near future, with
separate commits dedicated to enabling them. The process will be similar
to the workflow employed for enabling annotations in `std::deque`.
**Please note**: these annotations function effectively only when libc++
and libc++abi dylibs are instrumented (with ASan). This aligns with the
prevailing behavior of Memory Sanitizer.
To avoid breaking everything, this commit also appends
`_LIBCPP_INSTRUMENTED_WITH_ASAN` to `__config_site` whenever libc++ is
compiled with ASan. If this macro is not defined, string annotations are
not enabled. However, linking a binary that does **not** annotate
strings with a dynamic library that annotates strings, is not permitted.
Originally proposed here: https://reviews.llvm.org/D132769
Related patches on Phabricator:
- Turning on annotations for short strings:
https://reviews.llvm.org/D147680
- Turning on annotations for all allocators:
https://reviews.llvm.org/D146214
This PR is a part of a series of patches extending AddressSanitizer C++
container overflow detection capabilities by adding annotations, similar
to those existing in `std::vector` and `std::deque` collections. These
enhancements empower ASan to effectively detect instances where the
instrumented program attempts to access memory within a collection's
internal allocation that remains unused. This includes cases where
access occurs before or after the stored elements in `std::deque`, or
between the `std::basic_string`'s size (including the null terminator)
and capacity bounds.
The introduction of these annotations was spurred by a real-world
software bug discovered by Trail of Bits, involving an out-of-bounds
memory access during the comparison of two strings using the
`std::equals` function. This function was taking iterators
(`iter1_begin`, `iter1_end`, `iter2_begin`) to perform the comparison,
using a custom comparison function. When the `iter1` object exceeded the
length of `iter2`, an out-of-bounds read could occur on the `iter2`
object. Container sanitization, upon enabling these annotations, would
effectively identify and flag this potential vulnerability.
This Pull Request introduces basic annotations for `std::basic_string`.
Long strings exhibit structural similarities to `std::vector` and will
be annotated accordingly. Short strings are already implemented, but
will be turned on separately in a forthcoming commit. Look at [a
comment](https://github.com/llvm/llvm-project/pull/72677#issuecomment-1850554465)
below to read about SSO issues at current moment.
Due to the functionality introduced in
[D132522](https://github.com/llvm/llvm-project/commit/dd1b7b797a116eed588fd752fbe61d34deeb24e4),
the `__sanitizer_annotate_contiguous_container` function now offers
compatibility with all allocators. However, enabling this support will
be done in a subsequent commit. For the time being, only strings with
the default allocator will be annotated.
If you have any questions, please email:
- advenam.tacet@trailofbits.com
- disconnect3d@trailofbits.com
2023-12-13 06:05:34 +01:00
endif ( )
2019-10-08 16:26:24 +00:00
# Link system libraries =======================================================
function ( cxx_link_system_libraries target )
2023-10-13 11:53:57 -07:00
if ( NOT MSVC )
target_link_libraries ( ${ target } PRIVATE "-nostdlib++" )
2021-02-16 18:02:22 +00:00
endif ( )
2019-10-08 16:26:24 +00:00
2022-03-10 11:47:09 +02:00
if ( CXX_SUPPORTS_UNWINDLIB_EQ_NONE_FLAG AND LIBCXXABI_USE_LLVM_UNWINDER )
Reapply #2 of [runtimes] Fix building initial libunwind+libcxxabi+libcxx with compiler implied -lunwind
This does mostly the same as D112126, but for the runtimes cmake files.
Most of that is straightforward, but the interdependency between
libcxx and libunwind is tricky:
Libunwind is built at the same time as libcxx, but libunwind is not
installed yet. LIBCXXABI_USE_LLVM_UNWINDER makes libcxx link directly
against the just-built libunwind, but the compiler implicit -lunwind
isn't found. This patch avoids that by adding --unwindlib=none if
supported, if we are going to link explicitly against a newly built
unwinder anyway.
Since the previous attempt, this no longer uses
llvm_enable_language_nolink (and thus doesn't set
CMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY during the compiler
sanity checks). Setting CMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY
during compiler sanity checks makes cmake not learn about some
aspects of the compiler, which can make further find_library or
find_package fail. This caused OpenMP to not detect libelf and libffi,
disabling some OpenMP target plugins.
Instead, require the caller to set CMAKE_{C,CXX}_COMPILER_WORKS=YES
when building in a configuration with an incomplete toolchain.
Differential Revision: https://reviews.llvm.org/D113253
2021-10-24 01:11:20 +03:00
# If we're linking directly against the libunwind that we're building
# in the same invocation, don't try to link in the toolchain's
# default libunwind (which may be missing still).
target_add_link_flags_if_supported ( ${ target } PRIVATE "--unwindlib=none" )
endif ( )
2023-12-13 13:57:48 -05:00
if ( MSVC )
if ( LIBCXX_USE_COMPILER_RT )
find_compiler_rt_library ( builtins LIBCXX_BUILTINS_LIBRARY )
if ( LIBCXX_BUILTINS_LIBRARY )
target_link_libraries ( ${ target } PRIVATE "${LIBCXX_BUILTINS_LIBRARY}" )
endif ( )
elseif ( LIBCXX_HAS_GCC_LIB )
target_link_libraries ( ${ target } PRIVATE gcc )
elseif ( LIBCXX_HAS_GCC_S_LIB )
target_link_libraries ( ${ target } PRIVATE gcc_s )
2019-10-08 16:26:24 +00:00
endif ( )
endif ( )
[libc++] Link against libatomic when it is found
Before this patch, we tried detecting whether small atomics were available
without linking against libatomic. However, that's not really what we want
to know -- instead, we want to know what's required in order to support
atomics fully, which is to link against libatomic when it's provided.
That is both much simpler, and it doesn't suffer the problem that we would
not link against libatomic when small atomics didn't require it, which
lead to non-lockfree atomics never working.
Furthermore, because we understand that some platforms might not want to
(or be able to) ship non-lockfree atomics, we add that notion to the test
suite, independently of a potential extern library.
After this patch, we therefore:
(1) Link against libatomic when it is provided
(2) Independently detect whether non-lockfree atomics are supported in
the test suite, regardless of whether that means we're linking against
an external library or not (which is an implementation detail).
Differential Revision: https://reviews.llvm.org/D81190
2020-06-04 14:54:38 -04:00
if ( LIBCXX_HAS_ATOMIC_LIB )
2019-10-08 16:26:24 +00:00
target_link_libraries ( ${ target } PRIVATE atomic )
endif ( )
if ( MINGW )
target_link_libraries ( ${ target } PRIVATE "${MINGW_LIBRARIES}" )
endif ( )
2023-07-07 09:55:36 +00:00
if ( MSVC )
2023-07-17 12:50:35 +03:00
if ( ( NOT CMAKE_MSVC_RUNTIME_LIBRARY AND uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
OR ( CMAKE_MSVC_RUNTIME_LIBRARY MATCHES "Debug" ) )
2019-10-08 16:26:24 +00:00
set ( LIB_SUFFIX "d" )
else ( )
set ( LIB_SUFFIX "" )
endif ( )
2023-07-17 12:52:47 +03:00
if ( NOT CMAKE_MSVC_RUNTIME_LIBRARY OR CMAKE_MSVC_RUNTIME_LIBRARY MATCHES "DLL$" )
set ( CRT_LIB "msvcrt" )
set ( CXX_LIB "msvcprt" )
else ( )
set ( CRT_LIB "libcmt" )
set ( CXX_LIB "libcpmt" )
endif ( )
target_link_libraries ( ${ target } PRIVATE ${ CRT_LIB } ${ LIB_SUFFIX } ) # C runtime startup files
target_link_libraries ( ${ target } PRIVATE ${ CXX_LIB } ${ LIB_SUFFIX } ) # C++ standard library. Required for exception_ptr internals.
2019-10-08 16:26:24 +00:00
# Required for standards-complaint wide character formatting functions
# (e.g. `printfw`/`scanfw`)
target_link_libraries ( ${ target } PRIVATE iso_stdio_wide_specifiers )
endif ( )
2020-01-27 17:29:41 -08:00
if ( ANDROID AND ANDROID_PLATFORM_LEVEL LESS 21 )
target_link_libraries ( ${ target } PUBLIC android_support )
endif ( )
2022-10-03 16:41:58 -05:00
target_link_libraries ( ${ target } PUBLIC "${LIBCXX_ADDITIONAL_LIBRARIES}" )
2019-10-08 16:26:24 +00:00
endfunction ( )
2019-10-02 20:07:01 +00:00
# Windows-related flags =======================================================
function ( cxx_add_windows_flags target )
if ( WIN32 AND NOT MINGW )
target_compile_definitions ( ${ target } PRIVATE
# Ignore the -MSC_VER mismatch, as we may build
# with a different compatibility version.
_ A L L O W _ M S C _ V E R _ M I S M A T C H
# Don't check the msvcprt iterator debug levels
# as we will define the iterator types; libc++
# uses a different macro to identify the debug
# level.
_ A L L O W _ I T E R A T O R _ D E B U G _ L E V E L _ M I S M A T C H
# We are building the c++ runtime, don't pull in
# msvcprt.
_ C R T B L D
# Don't warn on the use of "deprecated"
# "insecure" functions which are standards
# specified.
_ C R T _ S E C U R E _ N O _ W A R N I N G S
# Use the ISO conforming behaviour for conversion
# in printf, scanf.
_ C R T _ S T D I O _ I S O _ W I D E _ S P E C I F I E R S )
endif ( )
endfunction ( )
[libcxx] Capture configuration information when installing the libc++ headers
Summary:
Hi all,
This patch is a successor to D11963. However it has changed dramatically and I felt it would be best to start a new review thread.
Please read the design documentation added in this patch for a description of how it works.
Reviewers: mclow.lists, danalbert, jroelofs, EricWF
Subscribers: vkalintiris, rnk, ed, espositofulvio, asl, eugenis, cfe-commits
Differential Revision: http://reviews.llvm.org/D13407
llvm-svn: 250235
2015-10-13 22:12:02 +00:00
# Configuration file flags =====================================================
2022-02-07 14:52:17 -05:00
config_define ( ${ LIBCXX_ABI_VERSION } _LIBCPP_ABI_VERSION )
config_define ( ${ LIBCXX_ABI_NAMESPACE } _LIBCPP_ABI_NAMESPACE )
2024-11-06 10:39:19 +01:00
config_define ( ${ LIBCXX_ABI_FORCE_ITANIUM } _LIBCPP_ABI_FORCE_ITANIUM )
config_define ( ${ LIBCXX_ABI_FORCE_MICROSOFT } _LIBCPP_ABI_FORCE_MICROSOFT )
config_define ( ${ LIBCXX_ENABLE_THREADS } _LIBCPP_HAS_THREADS )
config_define ( ${ LIBCXX_ENABLE_MONOTONIC_CLOCK } _LIBCPP_HAS_MONOTONIC_CLOCK )
config_define ( ${ LIBCXX_HAS_TERMINAL_AVAILABLE } _LIBCPP_HAS_TERMINAL )
2020-11-16 18:13:43 -05:00
if ( NOT LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION STREQUAL "default" )
2020-05-15 15:58:19 -04:00
config_define ( "${LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION}" _LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION )
2019-05-29 02:21:37 +00:00
endif ( )
2024-11-06 10:39:19 +01:00
config_define ( ${ LIBCXX_HAS_PTHREAD_API } _LIBCPP_HAS_THREAD_API_PTHREAD )
config_define ( ${ LIBCXX_HAS_EXTERNAL_THREAD_API } _LIBCPP_HAS_THREAD_API_EXTERNAL )
config_define ( ${ LIBCXX_HAS_WIN32_THREAD_API } _LIBCPP_HAS_THREAD_API_WIN32 )
config_define ( ${ LIBCXX_HAS_MUSL_LIBC } _LIBCPP_HAS_MUSL_LIBC )
2017-10-09 19:25:17 +00:00
config_define_if ( LIBCXX_NO_VCRUNTIME _LIBCPP_NO_VCRUNTIME )
2024-11-06 10:39:19 +01:00
config_define ( ${ LIBCXX_ENABLE_FILESYSTEM } _LIBCPP_HAS_FILESYSTEM )
config_define ( ${ LIBCXX_ENABLE_RANDOM_DEVICE } _LIBCPP_HAS_RANDOM_DEVICE )
config_define ( ${ LIBCXX_ENABLE_LOCALIZATION } _LIBCPP_HAS_LOCALIZATION )
config_define ( ${ LIBCXX_ENABLE_UNICODE } _LIBCPP_HAS_UNICODE )
config_define ( ${ LIBCXX_ENABLE_WIDE_CHARACTERS } _LIBCPP_HAS_WIDE_CHARACTERS )
config_define ( ${ LIBCXX_ENABLE_TIME_ZONE_DATABASE } _LIBCPP_HAS_TIME_ZONE_DATABASE )
config_define ( ${ LIBCXX_ENABLE_VENDOR_AVAILABILITY_ANNOTATIONS } _LIBCPP_HAS_VENDOR_AVAILABILITY_ANNOTATIONS )
2023-10-10 11:10:18 -07:00
2024-10-29 10:48:18 -04:00
# TODO: Remove in LLVM 21. We're leaving an error to make this fail explicitly.
2023-10-10 11:10:18 -07:00
if ( LIBCXX_ENABLE_ASSERTIONS )
2024-10-29 10:48:18 -04:00
message ( FATAL_ERROR "LIBCXX_ENABLE_ASSERTIONS has been removed. Please use LIBCXX_HARDENING_MODE instead." )
2023-10-10 11:10:18 -07:00
endif ( )
2023-11-08 09:10:00 -10:00
if ( LIBCXX_HARDENING_MODE STREQUAL "none" )
config_define ( 2 _LIBCPP_HARDENING_MODE_DEFAULT )
elseif ( LIBCXX_HARDENING_MODE STREQUAL "fast" )
config_define ( 4 _LIBCPP_HARDENING_MODE_DEFAULT )
elseif ( LIBCXX_HARDENING_MODE STREQUAL "extensive" )
config_define ( 16 _LIBCPP_HARDENING_MODE_DEFAULT )
2023-07-12 10:12:51 -07:00
elseif ( LIBCXX_HARDENING_MODE STREQUAL "debug" )
2023-11-08 09:10:00 -10:00
config_define ( 8 _LIBCPP_HARDENING_MODE_DEFAULT )
2023-07-12 10:12:51 -07:00
endif ( )
2015-11-09 10:21:04 +00:00
2024-04-17 13:36:53 -04:00
if ( LIBCXX_PSTL_BACKEND STREQUAL "serial" )
config_define ( 1 _LIBCPP_PSTL_BACKEND_SERIAL )
elseif ( LIBCXX_PSTL_BACKEND STREQUAL "std_thread" )
config_define ( 1 _LIBCPP_PSTL_BACKEND_STD_THREAD )
elseif ( LIBCXX_PSTL_BACKEND STREQUAL "libdispatch" )
config_define ( 1 _LIBCPP_PSTL_BACKEND_LIBDISPATCH )
2023-05-24 15:33:38 -07:00
else ( )
2024-04-17 13:36:53 -04:00
message ( FATAL_ERROR " LIBCXX_PSTL_BACKEND is set to ${ LIBCXX_PSTL_BACKEND } , which is not a valid backend.
2023-07-12 13:24:57 -07:00
V a l i d b a c k e n d s a r e : s e r i a l , s t d _ t h r e a d a n d l i b d i s p a t c h " )
2023-05-24 15:33:38 -07:00
endif ( )
2017-10-04 23:17:12 +00:00
if ( LIBCXX_ABI_DEFINES )
set ( abi_defines )
foreach ( abi_define ${ LIBCXX_ABI_DEFINES } )
if ( NOT abi_define MATCHES "^_LIBCPP_ABI_" )
message ( SEND_ERROR "Invalid ABI macro ${abi_define} in LIBCXX_ABI_DEFINES" )
endif ( )
list ( APPEND abi_defines "#define ${abi_define}" )
endforeach ( )
string ( REPLACE ";" "\n" abi_defines "${abi_defines}" )
config_define ( ${ abi_defines } _LIBCPP_ABI_DEFINES )
endif ( )
2021-12-21 01:19:34 +02:00
if ( LIBCXX_EXTRA_SITE_DEFINES )
set ( extra_site_defines )
foreach ( extra_site_define ${ LIBCXX_EXTRA_SITE_DEFINES } )
# Allow defines such as DEFINE=VAL, transformed into "#define DEFINE VAL".
string ( REPLACE "=" " " extra_site_define "${extra_site_define}" )
list ( APPEND extra_site_defines "#define ${extra_site_define}" )
endforeach ( )
string ( REPLACE ";" "\n" extra_site_defines "${extra_site_defines}" )
config_define ( ${ extra_site_defines } _LIBCPP_EXTRA_SITE_DEFINES )
endif ( )
2016-09-26 22:19:41 +00:00
# By default libc++ on Windows expects to use a shared library, which requires
# the headers to use DLL import/export semantics. However when building a
# static library only we modify the headers to disable DLL import/export.
if ( DEFINED WIN32 AND LIBCXX_ENABLE_STATIC AND NOT LIBCXX_ENABLE_SHARED )
message ( STATUS "Generating custom __config for non-DLL Windows build" )
2016-12-05 19:40:12 +00:00
config_define ( ON _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS )
2016-09-26 22:19:41 +00:00
endif ( )
2020-10-23 10:54:02 +03:00
if ( WIN32 AND LIBCXX_ENABLE_STATIC_ABI_LIBRARY )
# If linking libcxxabi statically into libcxx, skip the dllimport attributes
# on symbols we refer to from libcxxabi.
add_definitions ( -D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS )
endif ( )
2019-10-04 22:50:23 +00:00
# Setup all common build flags =================================================
function ( cxx_add_common_build_flags target )
cxx_add_basic_build_flags ( ${ target } )
2023-02-17 11:31:41 +01:00
cxx_add_warning_flags ( ${ target } ${ LIBCXX_ENABLE_WERROR } ${ LIBCXX_ENABLE_PEDANTIC } )
2019-10-04 22:50:23 +00:00
cxx_add_windows_flags ( ${ target } )
cxx_add_exception_flags ( ${ target } )
cxx_add_rtti_flags ( ${ target } )
cxx_add_module_flags ( ${ target } )
2019-10-08 16:26:24 +00:00
cxx_link_system_libraries ( ${ target } )
2023-11-29 09:29:44 -05:00
target_link_libraries ( ${ target } PRIVATE cxx-sanitizer-flags )
2019-10-04 22:50:23 +00:00
endfunction ( )
2010-12-10 19:47:54 +00:00
#===============================================================================
2015-07-30 22:30:34 +00:00
# Setup Source Code And Tests
2010-12-10 19:47:54 +00:00
#===============================================================================
2024-05-28 18:31:01 -07:00
add_custom_target ( cxx-test-depends
C O M M E N T " B u i l d d e p e n d e n c i e s r e q u i r e d t o r u n t h e l i b c + + t e s t s u i t e . " )
2013-11-15 17:18:57 +00:00
add_subdirectory ( include )
2019-05-01 06:40:36 +00:00
add_subdirectory ( src )
2021-07-15 10:19:39 -04:00
add_subdirectory ( utils )
2024-01-21 12:02:39 +01:00
add_subdirectory ( modules )
2015-08-22 19:40:49 +00:00
2015-07-30 22:30:34 +00:00
if ( LIBCXX_INCLUDE_TESTS )
2020-06-29 11:51:15 -04:00
add_subdirectory ( test )
2016-11-14 02:43:12 +00:00
add_subdirectory ( lib/abi )
2017-09-19 17:19:10 +00:00
endif ( )
2015-08-22 19:40:49 +00:00
if ( LIBCXX_INCLUDE_DOCS )
add_subdirectory ( docs )
endif ( )