Skip to content

Commit

Permalink
GH-43688: [C++] Prevent Snappy from disabling RTTI when bundled (#43706)
Browse files Browse the repository at this point in the history
### Rationale for this change

Snappy's CMakeLists.txt unconditionally disables RTTI. This is incompatible with some other options, such as activating UBSAN for a fuzzing build:
google/snappy#189

### What changes are included in this PR?

Add `-frtti` at the end of compiler options when compiling a bundled Snappy build.

### Are these changes tested?

On CI; also manually checked that this allows enabling Snappy on OSS-Fuzz builds.

### Are there any user-facing changes?

No.

* GitHub Issue: #43688

Lead-authored-by: Antoine Pitrou <[email protected]>
Co-authored-by: Antoine Pitrou <[email protected]>
Co-authored-by: Sutou Kouhei <[email protected]>
Co-authored-by: Sutou Kouhei <[email protected]>
Signed-off-by: Sutou Kouhei <[email protected]>
  • Loading branch information
3 people authored Aug 16, 2024
1 parent a50ad42 commit a970fd7
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions cpp/cmake_modules/ThirdpartyToolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1355,16 +1355,24 @@ macro(build_snappy)
"-DCMAKE_INSTALL_PREFIX=${SNAPPY_PREFIX}")
# Snappy unconditionally enables -Werror when building with clang this can lead
# to build failures by way of new compiler warnings. This adds a flag to disable
# Werror to the very end of the invocation to override the snappy internal setting.
# -Werror to the very end of the invocation to override the snappy internal setting.
set(SNAPPY_ADDITIONAL_CXX_FLAGS "")
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
foreach(CONFIG DEBUG MINSIZEREL RELEASE RELWITHDEBINFO)
list(APPEND
SNAPPY_CMAKE_ARGS
"-DCMAKE_CXX_FLAGS_${UPPERCASE_BUILD_TYPE}=${EP_CXX_FLAGS_${CONFIG}} -Wno-error"
)
endforeach()
string(APPEND SNAPPY_ADDITIONAL_CXX_FLAGS " -Wno-error")
endif()
# Snappy unconditionally disables RTTI, which is incompatible with some other
# build settings (https://github.com/apache/arrow/issues/43688).
if(NOT MSVC)
string(APPEND SNAPPY_ADDITIONAL_CXX_FLAGS " -frtti")
endif()

foreach(CONFIG DEBUG MINSIZEREL RELEASE RELWITHDEBINFO)
list(APPEND
SNAPPY_CMAKE_ARGS
"-DCMAKE_CXX_FLAGS_${CONFIG}=${EP_CXX_FLAGS_${CONFIG}} ${SNAPPY_ADDITIONAL_CXX_FLAGS}"
)
endforeach()

if(APPLE AND CMAKE_HOST_SYSTEM_VERSION VERSION_LESS 20)
# On macOS 10.13 we need to explicitly add <functional> to avoid a missing include error
# This can be removed once CRAN no longer checks on macOS 10.13
Expand Down

0 comments on commit a970fd7

Please sign in to comment.