Gate -fno-rtti on BORINGSSL_ALLOW_CXX_RUNTIME
We used to have this toggle to control whether we passed -fno-rtti to
libssl, when libssl was not allowed to take a C++ runtime dependency.
This toggle is used by OSS-Fuzz because -fsanitize=vptr is incompatible
with -fno-rtti. Now that we're back to passing -fno-rtti, but this time
to libcrypto instead, restore this opt-out to unbreak OSS-Fuzz builds.
Bug: 377971745
Change-Id: I6058efdb020cbb5481d3d25551dbb2e986af8ccc
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/73387
Reviewed-by: Adam Langley <agl@google.com>
Auto-Submit: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f1814f8..a5e9ca4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -504,21 +504,25 @@
message(FATAL_ERROR "Can't set both delocate and shared mode for FIPS build")
endif()
+# OSS-Fuzz relies on BORINGSSL_ALLOW_CXX_RUNTIME because -fno-rtti and
+# -fsanitize=vptr are incompatible.
+set(NO_CXX_RUNTIME_FLAGS)
+if(NOT MSVC AND NOT BORINGSSL_ALLOW_CXX_RUNTIME)
+ # Without -fno-exceptions, use of std::unique_ptr emits a call to
+ # std::terminate.
+ set(NO_CXX_RUNTIME_FLAGS -fno-exceptions -fno-rtti)
+endif()
+
if(FIPS_DELOCATE)
add_library(bcm_c_generated_asm STATIC ${BCM_SOURCES})
- if(NOT MSVC)
- # The C++ code in libcrypto shouldn't depend on libstdc++. This requires
- # -fno-exceptions otherwise use of std::unique_ptr emits a call to
- # std::terminate.
- target_compile_options(bcm_c_generated_asm PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions -fno-rtti>)
- endif()
+ # The C++ code in libcrypto shouldn't depend on libstdc++.
+ target_compile_options(bcm_c_generated_asm PRIVATE $<$<COMPILE_LANGUAGE:CXX>:${NO_CXX_RUNTIME_FLAGS}> "-S")
add_dependencies(bcm_c_generated_asm boringssl_prefix_symbols)
target_include_directories(bcm_c_generated_asm PRIVATE ${PROJECT_SOURCE_DIR}/include)
- set_target_properties(bcm_c_generated_asm PROPERTIES COMPILE_OPTIONS "-S")
set_target_properties(bcm_c_generated_asm PROPERTIES POSITION_INDEPENDENT_CODE ON)
if(CLANG)
# Clang warns when passing both -c (from CMake) and -S.
- set_property(TARGET bcm_c_generated_asm APPEND PROPERTY COMPILE_OPTIONS "-Wno-unused-command-line-argument")
+ target_compile_options(bcm_c_generated_asm PRIVATE "-Wno-unused-command-line-argument")
endif()
set(TARGET_FLAG "")
@@ -562,12 +566,8 @@
endif()
add_library(bcm_library STATIC ${BCM_SOURCES} ${BCM_SOURCES_ASM_USED})
- if(NOT MSVC)
- # The C++ code in libcrypto shouldn't depend on libstdc++. This requires
- # -fno-exceptions otherwise use of std::unique_ptr emits a call to
- # std::terminate.
- target_compile_options(bcm_library PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions -fno-rtti>)
- endif()
+ # The C++ code in libcrypto shouldn't depend on libstdc++.
+ target_compile_options(bcm_library PRIVATE $<$<COMPILE_LANGUAGE:CXX>:${NO_CXX_RUNTIME_FLAGS}>)
add_dependencies(bcm_library boringssl_prefix_symbols)
target_include_directories(bcm_library PRIVATE ${PROJECT_SOURCE_DIR}/include)
@@ -580,24 +580,16 @@
set(CRYPTO_FIPS_OBJECTS bcm.o)
else()
add_library(fipsmodule OBJECT ${BCM_SOURCES} ${BCM_SOURCES_ASM_USED})
- if(NOT MSVC)
- # The C++ code in libcrypto shouldn't depend on libstdc++. This requires
- # -fno-exceptions otherwise use of std::unique_ptr emits a call to
- # std::terminate.
- target_compile_options(fipsmodule PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions -fno-rtti>)
- endif()
+ # The C++ code in libcrypto shouldn't depend on libstdc++.
+ target_compile_options(fipsmodule PRIVATE $<$<COMPILE_LANGUAGE:CXX>:${NO_CXX_RUNTIME_FLAGS}>)
add_dependencies(fipsmodule boringssl_prefix_symbols)
target_include_directories(fipsmodule PRIVATE ${PROJECT_SOURCE_DIR}/include)
set(CRYPTO_FIPS_OBJECTS $<TARGET_OBJECTS:fipsmodule>)
endif()
add_library(crypto ${CRYPTO_SOURCES} ${CRYPTO_FIPS_OBJECTS} ${CRYPTO_SOURCES_ASM_USED})
-if(NOT MSVC)
- # The C++ code in libcrypto shouldn't depend on libstdc++. This requires
- # -fno-exceptions otherwise use of std::unique_ptr emits a call to
- # std::terminate.
- target_compile_options(crypto PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions -fno-rtti>)
-endif()
+ # The C++ code in libcrypto shouldn't depend on libstdc++.
+target_compile_options(crypto PRIVATE $<$<COMPILE_LANGUAGE:CXX>:${NO_CXX_RUNTIME_FLAGS}>)
target_include_directories(crypto PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>