Merge pull request #7445 from sfc-gh-anoyes/anoyes/fix-ubsan

Fix UBSAN build when statically linking libcxx
This commit is contained in:
Markus Pilman 2022-07-11 17:27:37 -06:00 committed by GitHub
commit 4ece33a0a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 3 deletions

View File

@ -53,6 +53,15 @@ add_dependencies(fdb_c fdb_c_generated fdb_c_options)
add_dependencies(fdbclient fdb_c_options) add_dependencies(fdbclient fdb_c_options)
add_dependencies(fdbclient_sampling fdb_c_options) add_dependencies(fdbclient_sampling fdb_c_options)
target_link_libraries(fdb_c PRIVATE $<BUILD_INTERFACE:fdbclient>) target_link_libraries(fdb_c PRIVATE $<BUILD_INTERFACE:fdbclient>)
if(USE_UBSAN)
# The intent of this hack is to force c targets that depend on fdb_c to use
# c++ as their linker language. Otherwise you see undefined references to c++
# specific ubsan symbols.
add_library(force_cxx_linker STATIC IMPORTED)
set_property(TARGET force_cxx_linker PROPERTY IMPORTED_LOCATION /dev/null)
set_target_properties(force_cxx_linker PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES CXX)
target_link_libraries(fdb_c PUBLIC $<BUILD_INTERFACE:force_cxx_linker>)
endif()
if(APPLE) if(APPLE)
set(symbols ${CMAKE_CURRENT_BINARY_DIR}/fdb_c.symbols) set(symbols ${CMAKE_CURRENT_BINARY_DIR}/fdb_c.symbols)
add_custom_command(OUTPUT ${symbols} add_custom_command(OUTPUT ${symbols}
@ -67,7 +76,12 @@ if(APPLE)
target_link_options(fdb_c PRIVATE "LINKER:-no_weak_exports,-exported_symbols_list,${symbols}") target_link_options(fdb_c PRIVATE "LINKER:-no_weak_exports,-exported_symbols_list,${symbols}")
elseif(WIN32) elseif(WIN32)
else() else()
target_link_options(fdb_c PRIVATE "LINKER:--version-script=${CMAKE_CURRENT_SOURCE_DIR}/fdb_c.map,-z,nodelete,-z,noexecstack") if (NOT USE_UBSAN)
# For ubsan we need to export type information for the vptr check to work.
# Otherwise we only want to export fdb symbols in the fdb c api.
target_link_options(fdb_c PRIVATE "LINKER:--version-script=${CMAKE_CURRENT_SOURCE_DIR}/fdb_c.map")
endif()
target_link_options(fdb_c PRIVATE "LINKER:-z,nodelete,-z,noexecstack")
endif() endif()
target_include_directories(fdb_c PUBLIC target_include_directories(fdb_c PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}> $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>

View File

@ -479,8 +479,12 @@ private:
uint8_t* plaintext = new uint8_t[sizeof(int) + v1.size() + v2.size()]; uint8_t* plaintext = new uint8_t[sizeof(int) + v1.size() + v2.size()];
*(int*)plaintext = op; *(int*)plaintext = op;
memcpy(plaintext + sizeof(int), v1.begin(), v1.size()); if (v1.size()) {
memcpy(plaintext + sizeof(int) + v1.size(), v2.begin(), v2.size()); memcpy(plaintext + sizeof(int), v1.begin(), v1.size());
}
if (v2.size()) {
memcpy(plaintext + sizeof(int) + v1.size(), v2.begin(), v2.size());
}
ASSERT(cipherKeys.cipherTextKey.isValid()); ASSERT(cipherKeys.cipherTextKey.isValid());
ASSERT(cipherKeys.cipherHeaderKey.isValid()); ASSERT(cipherKeys.cipherHeaderKey.isValid());

View File

@ -2221,6 +2221,10 @@ ACTOR Future<Void> commitQueue(TLogData* self) {
break; break;
} }
if (logData->queueCommittedVersion.get() == std::numeric_limits<Version>::max()) {
break;
}
choose { choose {
when(wait(logData->version.whenAtLeast( when(wait(logData->version.whenAtLeast(
std::max(logData->queueCommittingVersion, logData->queueCommittedVersion.get()) + 1))) { std::max(logData->queueCommittingVersion, logData->queueCommittedVersion.get()) + 1))) {