2015-04-25 01:46:35 +00:00
#===============================================================================
2015-08-06 23:31:37 +00:00
# Setup Project
2015-04-25 01:46:35 +00:00
#===============================================================================
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 16:12:32 +00:00
cmake_minimum_required ( VERSION 3.20.0 )
2015-04-25 01:46:35 +00:00
2022-01-01 07:03:31 +00:00
set ( LLVM_COMMON_CMAKE_UTILS "${CMAKE_CURRENT_SOURCE_DIR}/../cmake" )
2017-04-12 02:28:07 +00:00
# Add path for custom modules
2022-01-01 07:03:31 +00:00
list ( INSERT CMAKE_MODULE_PATH 0
2017-04-12 02:28:07 +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 15:26:19 +00: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 "
2017-04-12 02:28:07 +00:00
)
2020-08-24 09:01:05 +00:00
set ( LIBUNWIND_SOURCE_DIR ${ CMAKE_CURRENT_SOURCE_DIR } )
set ( LIBUNWIND_BINARY_DIR ${ CMAKE_CURRENT_BINARY_DIR } )
set ( LIBUNWIND_LIBCXX_PATH "${CMAKE_CURRENT_LIST_DIR}/../libcxx" CACHE PATH
" S p e c i f y p a t h t o l i b c + + s o u r c e . " )
2022-01-19 06:45:07 +00:00
include ( GNUInstallDirs )
MIPS/libunwind: Use -mfp64 if compiler is FPXX (#68521)
Libunwind supports FP64 and FP32 modes, but not FPXX. The reason is
that, FP64 and FP32 have different way to save/restore FPRs. If
libunwind is built as FPXX, we have no idea which one should we use.
It's not due to the code bug, but rather the nature of FPXX.
FPXX is an ABI which uses only a common subset of FR=1(FP64) and FR=0
(FP32).
So that FPXX binaries can link with both FP64 and FP32 ones, aka.
FPXX + FP32 -> FP32
FPXX + FP64 -> FP64
While for libunwind, we should save/restore all of FPRs. If we use FPXX,
we can only save/restore a common subset of FPRs, instead of superset.
If libunwind is built as FP64, it will interoperatable with FPXX/FP64
APPs, and if it is built as FP32, it will interoperatable with
FP32/FPXX. Currently most of O32 APPs are FPXX or FP64, while few are
FP32.
So if the compiler is FPXX, which is the default value of most
toolchain, let's switch it to FP64.
Co-authored-by: YunQiang Su <yunqiang.su@cipunited.com>
(cherry picked from commit 4520b478d2512b0f39764e0464dcb4cb961845b5)
2024-02-08 01:15:53 +00:00
include ( CheckSymbolExists )
2022-01-19 06:45:07 +00:00
2015-04-25 01:46:35 +00:00
#===============================================================================
# Setup CMake Options
#===============================================================================
2018-07-24 23:42:51 +00:00
include ( CMakeDependentOption )
2017-04-12 02:28:07 +00:00
include ( HandleCompilerRT )
2015-04-25 01:46:35 +00:00
# Define options.
2021-11-23 21:34:09 +00:00
option ( LIBUNWIND_BUILD_32_BITS "Build 32 bit multilib libunwind. This option is not supported anymore when building the runtimes. Please specify a full triple instead." ${ LLVM_BUILD_32_BITS } )
if ( LIBUNWIND_BUILD_32_BITS )
2021-12-01 17:57:30 +00:00
message ( FATAL_ERROR "LIBUNWIND_BUILD_32_BITS is not supported anymore when building the runtimes, please specify a full triple instead." )
2021-11-23 21:34:09 +00:00
endif ( )
[libunwind] Support stack unwind in CET environment
Control-flow Enforcement Technology (CET), published by Intel,
introduces shadow stack feature aiming to ensure a return from
a function is directed to where the function was called.
In a CET enabled system, each function call will push return
address into normal stack and shadow stack, when the function
returns, the address stored in shadow stack will be popped and
compared with the return address, program will fail if the 2
addresses don't match.
In exception handling, the control flow may skip some stack frames
and we must adjust shadow stack to avoid violating CET restriction.
In order to achieve this, we count the number of stack frames skipped
and adjust shadow stack by this number before jumping to landing pad.
Reviewed By: hjl.tools, compnerd, MaskRay
Differential Revision: https://reviews.llvm.org/D105968
Signed-off-by: gejin <ge.jin@intel.com>
2021-08-26 08:20:38 +00:00
option ( LIBUNWIND_ENABLE_CET "Build libunwind with CET enabled." OFF )
2015-04-25 01:46:35 +00:00
option ( LIBUNWIND_ENABLE_ASSERTIONS "Enable assertions independent of build mode." ON )
option ( LIBUNWIND_ENABLE_PEDANTIC "Compile with pedantic enabled." ON )
option ( LIBUNWIND_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF )
option ( LIBUNWIND_ENABLE_SHARED "Build libunwind as a shared library." ON )
2016-08-08 22:55:48 +00:00
option ( LIBUNWIND_ENABLE_STATIC "Build libunwind as a static library." ON )
2016-05-27 08:29:27 +00:00
option ( LIBUNWIND_ENABLE_CROSS_UNWINDING "Enable cross-platform unwinding support." OFF )
2016-07-07 10:55:39 +00:00
option ( LIBUNWIND_ENABLE_ARM_WMMX "Enable unwinding support for ARM WMMX registers." OFF )
2016-09-28 10:57:15 +00:00
option ( LIBUNWIND_ENABLE_THREADS "Build libunwind with threading support." ON )
2019-05-13 18:45:03 +00:00
option ( LIBUNWIND_WEAK_PTHREAD_LIB "Use weak references to refer to pthread functions." OFF )
2017-04-12 02:28:07 +00:00
option ( LIBUNWIND_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF )
2017-03-28 15:21:43 +00:00
option ( LIBUNWIND_INCLUDE_DOCS "Build the libunwind documentation." ${ LLVM_INCLUDE_DOCS } )
2021-02-13 10:49:47 +00:00
option ( LIBUNWIND_INCLUDE_TESTS "Build the libunwind tests." ${ LLVM_INCLUDE_TESTS } )
2020-07-29 10:39:41 +00:00
option ( LIBUNWIND_IS_BAREMETAL "Build libunwind for baremetal targets." OFF )
2020-08-18 19:05:07 +00:00
option ( LIBUNWIND_USE_FRAME_HEADER_CACHE "Cache frame headers for unwinding. Requires locking dl_iterate_phdr." OFF )
2020-11-11 09:58:41 +00:00
option ( LIBUNWIND_REMEMBER_HEAP_ALLOC "Use heap instead of the stack for .cfi_remember_state." OFF )
2022-10-11 13:19:55 +00:00
option ( LIBUNWIND_INSTALL_HEADERS "Install the libunwind headers." ON )
Make _LIBUNWIND_SUPPORT_FRAME_APIS a build-time option
Previously this was based on target architecture, but
that makes very little sense--frame API availability is generally
for libgcc compatibility and that is dependent on runtime
needs rather than target architecture.
Default this to on, so as not to remove the apis from
environments that already have them.
The functions this macro protects are stubs for libgcc-compatibility.
Today, libunwind as a drop-in replacement for libgcc_eh links on x86,
x86_64, and powerpc, but not aarch64, which doesn't really make
sense. As there is nothing architecture specific about these, they
should be provided everywhere or nowhere.
The target-specific protection goes all the way back to the original
code contribution in 312fcd0e1cf14482b2ae8eee8234541dcc3bc2c4 from
2013, so the original reason is lost to history, and probably not
relevant today.
Differential Revision: https://reviews.llvm.org/D158011
2023-08-15 18:36:30 +00:00
option ( LIBUNWIND_ENABLE_FRAME_APIS "Include libgcc-compatible frame apis." OFF )
2015-04-25 01:46:35 +00:00
2022-08-19 02:44:46 +00:00
set ( LIBUNWIND_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 ) " )
2017-11-17 23:29:46 +00:00
option ( LIBUNWIND_INSTALL_LIBRARY "Install the libunwind library." ON )
2018-07-24 23:27:51 +00:00
cmake_dependent_option ( LIBUNWIND_INSTALL_STATIC_LIBRARY
" I n s t a l l t h e s t a t i c l i b u n w i n d l i b r a r y . " O N
" L I B U N W I N D _ E N A B L E _ S T A T I C ; L I B U N W I N D _ I N S T A L L _ L I B R A R Y " O F F )
cmake_dependent_option ( LIBUNWIND_INSTALL_SHARED_LIBRARY
" I n s t a l l t h e s h a r e d l i b u n w i n d l i b r a r y . " O N
" L I B U N W I N D _ E N A B L E _ S H A R E D ; L I B U N W I N D _ I N S T A L L _ L I B R A R Y " O F F )
2021-10-12 18:10:02 +00:00
2023-03-29 21:36:51 +00:00
if ( MINGW )
set ( LIBUNWIND_DEFAULT_TEST_CONFIG "llvm-libunwind-mingw.cfg.in" )
elseif ( LIBUNWIND_ENABLE_SHARED )
2021-10-12 18:10:02 +00:00
set ( LIBUNWIND_DEFAULT_TEST_CONFIG "llvm-libunwind-shared.cfg.in" )
else ( )
set ( LIBUNWIND_DEFAULT_TEST_CONFIG "llvm-libunwind-static.cfg.in" )
endif ( )
set ( LIBUNWIND_TEST_CONFIG "${LIBUNWIND_DEFAULT_TEST_CONFIG}" CACHE STRING
2021-09-29 19:26:05 +00: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 .
2021-10-12 16:46:21 +00:00
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 u n w i n d / t e s t / c o n f i g s ' . " )
2021-09-29 19:26:05 +00:00
if ( NOT IS_ABSOLUTE "${LIBUNWIND_TEST_CONFIG}" )
2021-10-12 16:46:21 +00:00
set ( LIBUNWIND_TEST_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/test/configs/${LIBUNWIND_TEST_CONFIG}" )
2021-09-29 19:26:05 +00:00
endif ( )
2022-05-11 14:16:29 +00:00
message ( STATUS "Using libunwind testing configuration: ${LIBUNWIND_TEST_CONFIG}" )
2020-08-24 09:01:05 +00:00
set ( LIBUNWIND_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 . " )
2015-04-25 01:46:35 +00:00
2016-08-08 22:55:48 +00:00
if ( NOT LIBUNWIND_ENABLE_SHARED AND NOT LIBUNWIND_ENABLE_STATIC )
message ( FATAL_ERROR "libunwind must be built as either a shared or static library." )
endif ( )
[libunwind] Support stack unwind in CET environment
Control-flow Enforcement Technology (CET), published by Intel,
introduces shadow stack feature aiming to ensure a return from
a function is directed to where the function was called.
In a CET enabled system, each function call will push return
address into normal stack and shadow stack, when the function
returns, the address stored in shadow stack will be popped and
compared with the return address, program will fail if the 2
addresses don't match.
In exception handling, the control flow may skip some stack frames
and we must adjust shadow stack to avoid violating CET restriction.
In order to achieve this, we count the number of stack frames skipped
and adjust shadow stack by this number before jumping to landing pad.
Reviewed By: hjl.tools, compnerd, MaskRay
Differential Revision: https://reviews.llvm.org/D105968
Signed-off-by: gejin <ge.jin@intel.com>
2021-08-26 08:20:38 +00:00
if ( LIBUNWIND_ENABLE_CET AND MSVC )
message ( FATAL_ERROR "libunwind CET support is not available for MSVC!" )
endif ( )
[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 20:40:07 +00:00
if ( WIN32 )
set ( LIBUNWIND_DEFAULT_HIDE_SYMBOLS TRUE )
else ( )
set ( LIBUNWIND_DEFAULT_HIDE_SYMBOLS FALSE )
endif ( )
[libunwind] unw_* alias fixes for ELF and Mach-O
Rename the CMake option, LIBUNWIND_HERMETIC_STATIC_LIBRARY, to
LIBUNWIND_HIDE_SYMBOLS. Rename the C macro define,
_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS, to _LIBUNWIND_HIDE_SYMBOLS,
because now the macro adds a .hidden directive rather than merely
suppress visibility annotations.
For ELF, when LIBUNWIND_HIDE_SYMBOLS is enabled, mark unw_getcontext as
hidden. This symbol is the only one defined using src/assembly.h's
WEAK_ALIAS macro. Other unw_* weak aliases are defined in C++ and are
already hidden.
Mach-O doesn't support weak aliases, so remove .weak_reference and
weak_import. When LIBUNWIND_HIDE_SYMBOLS is enabled, output
.private_extern for the unw_* aliases.
In assembly.h, add missing SYMBOL_NAME macro invocations, which are
used to prefix symbol names with '_' on some targets.
Fixes PR46709.
Reviewed By: #libunwind, phosek, compnerd, steven_wu
Differential Revision: https://reviews.llvm.org/D93003
2021-02-23 00:35:38 +00:00
option ( LIBUNWIND_HIDE_SYMBOLS
[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 20:40:07 +00: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 U N W I N D _ D E F A U L T _ H I D E _ S Y M B O L S } )
2019-01-29 23:01:08 +00:00
MIPS/libunwind: Use -mfp64 if compiler is FPXX (#68521)
Libunwind supports FP64 and FP32 modes, but not FPXX. The reason is
that, FP64 and FP32 have different way to save/restore FPRs. If
libunwind is built as FPXX, we have no idea which one should we use.
It's not due to the code bug, but rather the nature of FPXX.
FPXX is an ABI which uses only a common subset of FR=1(FP64) and FR=0
(FP32).
So that FPXX binaries can link with both FP64 and FP32 ones, aka.
FPXX + FP32 -> FP32
FPXX + FP64 -> FP64
While for libunwind, we should save/restore all of FPRs. If we use FPXX,
we can only save/restore a common subset of FPRs, instead of superset.
If libunwind is built as FP64, it will interoperatable with FPXX/FP64
APPs, and if it is built as FP32, it will interoperatable with
FP32/FPXX. Currently most of O32 APPs are FPXX or FP64, while few are
FP32.
So if the compiler is FPXX, which is the default value of most
toolchain, let's switch it to FP64.
Co-authored-by: YunQiang Su <yunqiang.su@cipunited.com>
(cherry picked from commit 4520b478d2512b0f39764e0464dcb4cb961845b5)
2024-02-08 01:15:53 +00:00
# If toolchain is FPXX, we switch to FP64 to save the full FPRs. See:
# https://web.archive.org/web/20180828210612/https://dmz-portal.mips.com/wiki/MIPS_O32_ABI_-_FR0_and_FR1_Interlinking
check_symbol_exists ( __mips_hard_float "" __MIPSHF )
check_symbol_exists ( _ABIO32 "" __MIPS_O32 )
if ( __MIPSHF AND __MIPS_O32 )
file ( WRITE ${ CMAKE_BINARY_DIR } ${ CMAKE_FILES_DIRECTORY } /CMakeTmp/mips_is_fpxx.c
" #if __mips_fpr != 0\n"
" # error\n"
" #endif\n")
try_compile ( MIPS_FPABI_FPXX ${ CMAKE_BINARY_DIR }
$ { C M A K E _ B I N A R Y _ D I R } $ { C M A K E _ F I L E S _ D I R E C T O R Y } / C M a k e T m p / m i p s _ i s _ f p x x . c
C M A K E _ F L A G S - D C M A K E _ C _ L I N K _ E X E C U T A B L E = ' e c h o ' )
endif ( )
2015-04-25 01:46:35 +00:00
#===============================================================================
# Configure System
#===============================================================================
# Add path for custom modules
set ( CMAKE_MODULE_PATH
" $ { 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 _ M O D U L E _ P A T H } )
2024-01-10 09:25:17 +00:00
set ( LIBUNWIND_INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_INCLUDEDIR}" 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 u n w i n d 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-01-10 09:25:17 +00:00
set ( LIBUNWIND_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 u n w i n d 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 . " )
2022-10-11 14:05:56 +00:00
set ( LIBUNWIND_SHARED_OUTPUT_NAME "unwind" CACHE STRING "Output name for the shared libunwind runtime library." )
set ( LIBUNWIND_STATIC_OUTPUT_NAME "unwind" CACHE STRING "Output name for the static libunwind runtime library." )
2018-06-29 20:27:40 +00:00
if ( LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE )
2022-12-05 22:20:51 +00:00
set ( LIBUNWIND_LIBRARY_DIR ${ LLVM_LIBRARY_OUTPUT_INTDIR } / ${ LLVM_DEFAULT_TARGET_TRIPLE } )
2024-01-10 09:25:17 +00:00
set ( LIBUNWIND_INSTALL_LIBRARY_DIR lib ${ LLVM_LIBDIR_SUFFIX } / ${ LLVM_DEFAULT_TARGET_TRIPLE } 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 u n w i n d 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 . " )
2019-05-22 21:08:33 +00:00
if ( LIBCXX_LIBDIR_SUBDIR )
string ( APPEND LIBUNWIND_LIBRARY_DIR / ${ LIBUNWIND_LIBDIR_SUBDIR } )
string ( APPEND LIBUNWIND_INSTALL_LIBRARY_DIR / ${ LIBUNWIND_LIBDIR_SUBDIR } )
endif ( )
2017-07-18 21:30:18 +00:00
else ( )
2022-01-09 00:08:15 +00:00
if ( LLVM_LIBRARY_OUTPUT_INTDIR )
set ( LIBUNWIND_LIBRARY_DIR ${ LLVM_LIBRARY_OUTPUT_INTDIR } )
else ( )
2022-08-19 02:44:46 +00:00
set ( LIBUNWIND_LIBRARY_DIR ${ CMAKE_BINARY_DIR } /lib ${ LIBUNWIND_LIBDIR_SUFFIX } )
2022-01-09 00:08:15 +00:00
endif ( )
2024-01-10 09:25:17 +00:00
set ( LIBUNWIND_INSTALL_LIBRARY_DIR lib ${ LIBUNWIND_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 u n w i n d 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 . " )
2017-07-18 21:30:18 +00:00
endif ( )
set ( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${ LIBUNWIND_LIBRARY_DIR } )
set ( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${ LIBUNWIND_LIBRARY_DIR } )
set ( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${ LIBUNWIND_LIBRARY_DIR } )
2015-04-25 01:46:35 +00:00
2016-06-02 01:02:10 +00:00
set ( LIBUNWIND_C_FLAGS "" )
set ( LIBUNWIND_CXX_FLAGS "" )
set ( LIBUNWIND_COMPILE_FLAGS "" )
set ( LIBUNWIND_LINK_FLAGS "" )
2023-06-29 07:41:08 +00:00
set ( LIBUNWIND_ADDITIONAL_COMPILE_FLAGS "" CACHE STRING
" A d d i t i o n a l C o m p i l e o n l y f l a g s 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 " )
set ( LIBUNWIND_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 u n w i n d 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 " )
2015-04-25 01:46:35 +00:00
2019-10-11 22:22:29 +00:00
# Include macros for adding and removing libunwind flags.
include ( HandleLibunwindFlags )
#===============================================================================
# Setup Compiler Flags
#===============================================================================
2016-06-02 01:02:10 +00:00
# Configure compiler.
include ( config-ix )
2018-09-04 20:57:50 +00:00
if ( LIBUNWIND_USE_COMPILER_RT AND NOT LIBUNWIND_HAS_NODEFAULTLIBS_FLAG )
2017-04-12 02:28:07 +00:00
list ( APPEND LIBUNWIND_LINK_FLAGS "-rtlib=compiler-rt" )
endif ( )
2019-10-11 22:22:29 +00:00
add_compile_flags_if_supported ( -Werror=return-type )
2015-04-25 01:46:35 +00:00
[libunwind] Support stack unwind in CET environment
Control-flow Enforcement Technology (CET), published by Intel,
introduces shadow stack feature aiming to ensure a return from
a function is directed to where the function was called.
In a CET enabled system, each function call will push return
address into normal stack and shadow stack, when the function
returns, the address stored in shadow stack will be popped and
compared with the return address, program will fail if the 2
addresses don't match.
In exception handling, the control flow may skip some stack frames
and we must adjust shadow stack to avoid violating CET restriction.
In order to achieve this, we count the number of stack frames skipped
and adjust shadow stack by this number before jumping to landing pad.
Reviewed By: hjl.tools, compnerd, MaskRay
Differential Revision: https://reviews.llvm.org/D105968
Signed-off-by: gejin <ge.jin@intel.com>
2021-08-26 08:20:38 +00:00
if ( LIBUNWIND_ENABLE_CET )
add_compile_flags_if_supported ( -fcf-protection=full )
add_compile_flags_if_supported ( -mshstk )
2022-10-18 22:00:09 +00:00
if ( NOT CXX_SUPPORTS_FCF_PROTECTION_EQ_FULL_FLAG )
[libunwind] Support stack unwind in CET environment
Control-flow Enforcement Technology (CET), published by Intel,
introduces shadow stack feature aiming to ensure a return from
a function is directed to where the function was called.
In a CET enabled system, each function call will push return
address into normal stack and shadow stack, when the function
returns, the address stored in shadow stack will be popped and
compared with the return address, program will fail if the 2
addresses don't match.
In exception handling, the control flow may skip some stack frames
and we must adjust shadow stack to avoid violating CET restriction.
In order to achieve this, we count the number of stack frames skipped
and adjust shadow stack by this number before jumping to landing pad.
Reviewed By: hjl.tools, compnerd, MaskRay
Differential Revision: https://reviews.llvm.org/D105968
Signed-off-by: gejin <ge.jin@intel.com>
2021-08-26 08:20:38 +00:00
message ( SEND_ERROR "Compiler doesn't support CET -fcf-protection option!" )
endif ( )
2022-10-18 22:00:09 +00:00
if ( NOT CXX_SUPPORTS_MSHSTK_FLAG )
[libunwind] Support stack unwind in CET environment
Control-flow Enforcement Technology (CET), published by Intel,
introduces shadow stack feature aiming to ensure a return from
a function is directed to where the function was called.
In a CET enabled system, each function call will push return
address into normal stack and shadow stack, when the function
returns, the address stored in shadow stack will be popped and
compared with the return address, program will fail if the 2
addresses don't match.
In exception handling, the control flow may skip some stack frames
and we must adjust shadow stack to avoid violating CET restriction.
In order to achieve this, we count the number of stack frames skipped
and adjust shadow stack by this number before jumping to landing pad.
Reviewed By: hjl.tools, compnerd, MaskRay
Differential Revision: https://reviews.llvm.org/D105968
Signed-off-by: gejin <ge.jin@intel.com>
2021-08-26 08:20:38 +00:00
message ( SEND_ERROR "Compiler doesn't support CET -mshstk option!" )
endif ( )
endif ( )
2020-10-23 19:51:21 +00:00
if ( WIN32 )
# The headers lack matching dllexport attributes (_LIBUNWIND_EXPORT);
# silence the warning instead of cluttering the headers (which aren't
# necessarily the ones that the callers will use anyway) with the
# attributes.
add_compile_flags_if_supported ( -Wno-dll-attribute-on-redeclaration )
endif ( )
MIPS/libunwind: Use -mfp64 if compiler is FPXX (#68521)
Libunwind supports FP64 and FP32 modes, but not FPXX. The reason is
that, FP64 and FP32 have different way to save/restore FPRs. If
libunwind is built as FPXX, we have no idea which one should we use.
It's not due to the code bug, but rather the nature of FPXX.
FPXX is an ABI which uses only a common subset of FR=1(FP64) and FR=0
(FP32).
So that FPXX binaries can link with both FP64 and FP32 ones, aka.
FPXX + FP32 -> FP32
FPXX + FP64 -> FP64
While for libunwind, we should save/restore all of FPRs. If we use FPXX,
we can only save/restore a common subset of FPRs, instead of superset.
If libunwind is built as FP64, it will interoperatable with FPXX/FP64
APPs, and if it is built as FP32, it will interoperatable with
FP32/FPXX. Currently most of O32 APPs are FPXX or FP64, while few are
FP32.
So if the compiler is FPXX, which is the default value of most
toolchain, let's switch it to FP64.
Co-authored-by: YunQiang Su <yunqiang.su@cipunited.com>
(cherry picked from commit 4520b478d2512b0f39764e0464dcb4cb961845b5)
2024-02-08 01:15:53 +00:00
if ( MIPS_FPABI_FPXX )
add_compile_flags ( -mfp64 )
endif ( )
2015-04-25 01:46:35 +00:00
# Get feature flags.
# Exceptions
# Catches C++ exceptions only and tells the compiler to assume that extern C
# functions never throw a C++ exception.
2019-10-11 22:22:29 +00:00
add_cxx_compile_flags_if_supported ( -fstrict-aliasing )
add_cxx_compile_flags_if_supported ( -EHsc )
2015-04-25 01:46:35 +00:00
2019-12-06 14:26:35 +00:00
# Don't run the linker in this CMake check.
#
# The reason why this was added is that when building libunwind for
# ARM Linux, we need to pass the -funwind-tables flag in order for it to
# work properly with ARM EHABI.
#
# However, when performing CMake checks, adding this flag causes the check
# to produce a false negative, because the compiler generates calls
# to __aeabi_unwind_cpp_pr0, which is defined in libunwind itself,
# which isn't built yet, so the linker complains about undefined symbols.
#
# This leads to libunwind not being built with this flag, which makes
# libunwind quite useless in this setup.
set ( _previous_CMAKE_TRY_COMPILE_TARGET_TYPE ${ CMAKE_TRY_COMPILE_TARGET_TYPE } )
set ( CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY )
2019-10-12 01:50:57 +00:00
add_compile_flags_if_supported ( -funwind-tables )
2019-12-06 14:26:35 +00:00
set ( CMAKE_TRY_COMPILE_TARGET_TYPE ${ _previous_CMAKE_TRY_COMPILE_TARGET_TYPE } )
2022-03-10 09:47:09 +00:00
if ( LIBUNWIND_USES_ARM_EHABI AND NOT CXX_SUPPORTS_FUNWIND_TABLES_FLAG )
2019-12-06 14:26:35 +00:00
message ( SEND_ERROR "The -funwind-tables flag must be supported "
" b e c a u s e t h i s t a r g e t u s e s A R M E x c e p t i o n H a n d l i n g A B I " )
endif ( )
2019-10-11 22:22:29 +00:00
add_cxx_compile_flags_if_supported ( -fno-exceptions )
add_cxx_compile_flags_if_supported ( -fno-rtti )
2015-04-25 01:46:35 +00:00
2019-01-29 22:26:18 +00:00
# Ensure that we don't depend on C++ standard library.
2022-03-10 09:47:09 +00:00
if ( CXX_SUPPORTS_NOSTDINCXX_FLAG )
2019-10-11 22:22:29 +00:00
list ( APPEND LIBUNWIND_COMPILE_FLAGS -nostdinc++ )
# Remove -stdlib flags to prevent them from causing an unused flag warning.
2020-10-13 14:05:00 +00:00
string ( REPLACE "--stdlib=libc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" )
string ( REPLACE "--stdlib=libstdc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" )
2019-10-11 22:22:29 +00:00
string ( REPLACE "-stdlib=libc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" )
string ( REPLACE "-stdlib=libstdc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" )
endif ( )
2019-01-29 22:26:18 +00:00
2015-04-25 01:46:35 +00:00
# Assert
string ( TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE )
if ( LIBUNWIND_ENABLE_ASSERTIONS )
# MSVC doesn't like _DEBUG on release builds. See PR 4379.
if ( NOT MSVC )
2019-10-11 22:22:29 +00:00
add_compile_flags ( -D_DEBUG )
2016-08-08 17:56:28 +00:00
endif ( )
2015-04-25 01:46:35 +00:00
# On Release builds cmake automatically defines NDEBUG, so we
# explicitly undefine it:
2022-05-04 09:52:20 +00:00
if ( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
2019-10-11 22:22:29 +00:00
add_compile_flags ( -UNDEBUG )
2016-08-08 17:56:28 +00:00
endif ( )
2015-04-25 01:46:35 +00:00
else ( )
2022-05-04 09:52:20 +00:00
if ( uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
2019-10-11 22:22:29 +00:00
add_compile_flags ( -DNDEBUG )
2016-08-08 17:56:28 +00:00
endif ( )
endif ( )
2015-04-25 01:46:35 +00:00
2016-05-25 12:36:34 +00:00
# Cross-unwinding
if ( NOT LIBUNWIND_ENABLE_CROSS_UNWINDING )
2019-10-11 22:22:29 +00:00
add_compile_flags ( -D_LIBUNWIND_IS_NATIVE_ONLY )
2016-08-08 17:56:28 +00:00
endif ( )
2016-05-25 12:36:34 +00:00
Make _LIBUNWIND_SUPPORT_FRAME_APIS a build-time option
Previously this was based on target architecture, but
that makes very little sense--frame API availability is generally
for libgcc compatibility and that is dependent on runtime
needs rather than target architecture.
Default this to on, so as not to remove the apis from
environments that already have them.
The functions this macro protects are stubs for libgcc-compatibility.
Today, libunwind as a drop-in replacement for libgcc_eh links on x86,
x86_64, and powerpc, but not aarch64, which doesn't really make
sense. As there is nothing architecture specific about these, they
should be provided everywhere or nowhere.
The target-specific protection goes all the way back to the original
code contribution in 312fcd0e1cf14482b2ae8eee8234541dcc3bc2c4 from
2013, so the original reason is lost to history, and probably not
relevant today.
Differential Revision: https://reviews.llvm.org/D158011
2023-08-15 18:36:30 +00:00
# Include stubs for __register_frame_info_bases and related
if ( LIBUNWIND_ENABLE_FRAME_APIS )
add_compile_flags ( -D_LIBUNWIND_SUPPORT_FRAME_APIS )
endif ( )
2016-09-28 10:57:15 +00:00
# Threading-support
if ( NOT LIBUNWIND_ENABLE_THREADS )
2019-10-11 22:22:29 +00:00
add_compile_flags ( -D_LIBUNWIND_HAS_NO_THREADS )
2016-09-28 10:57:15 +00:00
endif ( )
2016-07-07 10:55:39 +00:00
# ARM WMMX register support
if ( LIBUNWIND_ENABLE_ARM_WMMX )
# __ARM_WMMX is a compiler pre-define (as per the ACLE 2.0). Clang does not
# define this macro for any supported target at present. Therefore, here we
# provide the option to explicitly enable support for WMMX registers in the
# unwinder.
2019-10-11 22:22:29 +00:00
add_compile_flags ( -D__ARM_WMMX )
2016-08-08 17:56:28 +00:00
endif ( )
2016-07-07 10:55:39 +00:00
2020-07-29 10:39:41 +00:00
if ( LIBUNWIND_IS_BAREMETAL )
add_compile_definitions ( _LIBUNWIND_IS_BAREMETAL )
endif ( )
2020-08-18 19:05:07 +00:00
if ( LIBUNWIND_USE_FRAME_HEADER_CACHE )
add_compile_definitions ( _LIBUNWIND_USE_FRAME_HEADER_CACHE )
endif ( )
2020-11-11 09:58:41 +00:00
if ( LIBUNWIND_REMEMBER_HEAP_ALLOC )
add_compile_definitions ( _LIBUNWIND_REMEMBER_HEAP_ALLOC )
endif ( )
2015-04-25 01:46:35 +00:00
# This is the _ONLY_ place where add_definitions is called.
if ( MSVC )
add_definitions ( -D_CRT_SECURE_NO_WARNINGS )
2016-08-08 17:56:28 +00:00
endif ( )
2015-04-25 01:46:35 +00:00
2022-03-10 09:47:09 +00:00
if ( C_SUPPORTS_COMMENT_LIB_PRAGMA )
2019-11-30 14:13:56 +00:00
if ( LIBUNWIND_HAS_DL_LIB )
add_definitions ( -D_LIBUNWIND_LINK_DL_LIB )
endif ( )
if ( LIBUNWIND_HAS_PTHREAD_LIB )
add_definitions ( -D_LIBUNWIND_LINK_PTHREAD_LIB )
endif ( )
2019-05-30 04:40:21 +00:00
endif ( )
2015-04-25 01:46:35 +00:00
#===============================================================================
# Setup Source Code
#===============================================================================
2021-12-16 18:32:12 +00:00
add_subdirectory ( include )
2015-04-25 01:46:35 +00:00
add_subdirectory ( src )
2017-03-28 15:21:43 +00:00
if ( LIBUNWIND_INCLUDE_DOCS )
add_subdirectory ( docs )
endif ( )
2017-07-06 15:20:12 +00:00
2021-09-16 16:27:53 +00:00
if ( LIBUNWIND_INCLUDE_TESTS AND EXISTS ${ LLVM_CMAKE_DIR } )
2018-08-03 05:51:31 +00:00
add_subdirectory ( test )
endif ( )