Skip to content

Commit 65db595

Browse files
YunQiang Suwzssyqa
authored andcommitted
MIPS/libunwind: Use -mfp64 if compiler is FPXX
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. 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.
1 parent 78b4e7c commit 65db595

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

libunwind/CMakeLists.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ set(LIBUNWIND_LIBCXX_PATH "${CMAKE_CURRENT_LIST_DIR}/../libcxx" CACHE PATH
2121
"Specify path to libc++ source.")
2222

2323
include(GNUInstallDirs)
24+
include(CheckSymbolExists)
2425

2526
#===============================================================================
2627
# Setup CMake Options
@@ -96,6 +97,20 @@ endif()
9697
option(LIBUNWIND_HIDE_SYMBOLS
9798
"Do not export any symbols from the static library." ${LIBUNWIND_DEFAULT_HIDE_SYMBOLS})
9899

100+
# If toolchain is FPXX, we switch to FP64 to save the full FPRs. See:
101+
# https://web.archive.org/web/20180828210612/https://dmz-portal.mips.com/wiki/MIPS_O32_ABI_-_FR0_and_FR1_Interlinking
102+
check_symbol_exists(__mips_hard_float "" __MIPSHF)
103+
check_symbol_exists(_ABIO32 "" __MIPS_O32)
104+
if (__MIPSHF AND __MIPS_O32)
105+
file(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/mips_is_fpxx.c
106+
"#if __mips_fpr != 0\n"
107+
"# error\n"
108+
"#endif\n")
109+
try_compile(MIPS_FPABI_FPXX ${CMAKE_BINARY_DIR}
110+
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/mips_is_fpxx.c
111+
CMAKE_FLAGS -DCMAKE_C_LINK_EXECUTABLE='echo')
112+
endif()
113+
99114
#===============================================================================
100115
# Configure System
101116
#===============================================================================
@@ -179,6 +194,10 @@ if (WIN32)
179194
add_compile_flags_if_supported(-Wno-dll-attribute-on-redeclaration)
180195
endif()
181196

197+
if (MIPS_FPABI_FPXX)
198+
add_compile_flags(-mfp64)
199+
endif()
200+
182201
# Get feature flags.
183202
# Exceptions
184203
# Catches C++ exceptions only and tells the compiler to assume that extern C

0 commit comments

Comments
 (0)