Skip to content

Commit

Permalink
build: fix sanitizers usage
Browse files Browse the repository at this point in the history
  * Fix ENABLE_ASAN flag passing into CMakeLists.txt
  * Add UBSAN
  * Enable ASAN/UBSAN for librdkafka and lua module targets
  • Loading branch information
olegrok committed May 14, 2024
1 parent abd1b3e commit e029de2
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/asan_testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ jobs:
cd tarantool
git checkout release/2.11
export LSAN_OPTIONS=suppressions=${PWD}/asan/lsan.supp
cmake . -DENABLE_ASAN=ON -DENABLE_DIST=ON
cmake . -DENABLE_ASAN=ON -DENABLE_UB_SANITIZER=ON -DENABLE_DIST=ON
make -j16
sudo make install
cd ..
tarantoolctl rocks STATIC_BUILD=ON ENABLE_ASAN=ON make
tarantoolctl rocks STATIC_BUILD=ON ENABLE_ASAN=ON ENABLE_UBSAN=ON make
- name: Run tarantool application
run: |
Expand Down
24 changes: 19 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)

project(kafka C)

Expand All @@ -14,6 +14,8 @@ find_package(Tarantool REQUIRED)

set(STATIC_BUILD "OFF" CACHE BOOL "Link dependencies statically?")
set(WITH_OPENSSL_1_1 "OFF" CACHE BOOL "Require openssl version >= 1.1?")
set(ENABLE_ASAN "OFF" CACHE BOOL "Enable ASAN")
set(ENABLE_UBSAN "OFF" CACHE BOOL "Enable UBSAN")

if (WITH_OPENSSL_1_1)
find_package(OpenSSL 1.1 REQUIRED)
Expand All @@ -22,14 +24,25 @@ else()
endif()
message("Found OPENSSL version: ${OPENSSL_VERSION}")

option(ENABLE_ASAN OFF)
if (ENABLE_ASAN)
set(LIBRDKAFKA_C_FLAGS "-fsanitize=address")
set(LIBRDKAFKA_CXX_FLAGS "-fsanitize=address")
set(LIBRDKAFKA_FLAGS "--enable-devel")
list(APPEND SANITIZER_FLAGS -fsanitize=address)
endif()

if (ENABLE_UBSAN)
list(APPEND SANITIZER_FLAGS -fsanitize=undefined)
endif()

if (SANITIZER_FLAGS)
list(JOIN SANITIZER_FLAGS " " SANITIZER_FLAGS)
set(LIBRDKAFKA_FLAGS --enable-devel --disable-optimization)
set(CMAKE_BUILD_TYPE "Debug")
set(LIBRDKAFKA_CXX_FLAGS "${SANITIZER_FLAGS}")
set(LIBRDKAFKA_C_FLAGS "${SANITIZER_FLAGS}")
set(LIBRDKAFKA_LD_FLAGS "${SANITIZER_FLAGS}")
endif()

if (APPLE)
set(LIBRDKAFKA_LD_FLAGS "${LIBRDKAFKA_LD_FLAGS} ${CMAKE_C_SYSROOT_FLAG} ${CMAKE_OSX_SYSROOT}")
set(LIBRDKAFKA_CXX_FLAGS "${LIBRDKAFKA_CXX_FLAGS} ${CMAKE_C_SYSROOT_FLAG} ${CMAKE_OSX_SYSROOT}")
set(LIBRDKAFKA_C_FLAGS "${LIBRDKAFKA_C_FLAGS} ${CMAKE_C_SYSROOT_FLAG} ${CMAKE_OSX_SYSROOT}")
endif()
Expand All @@ -46,6 +59,7 @@ if(STATIC_BUILD)
--cxx=${CMAKE_CXX_COMPILER}
--CFLAGS=${LIBRDKAFKA_C_FLAGS}
--CPPFLAGS=${LIBRDKAFKA_CXX_FLAGS}
--LDFLAGS=${LIBRDKAFKA_LD_FLAGS}
--prefix=<INSTALL_DIR>
${LIBRDKAFKA_FLAGS}

Expand Down
2 changes: 2 additions & 0 deletions kafka-scm-1.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ build = {
TARANTOOL_INSTALL_LIBDIR="$(LIBDIR)",
TARANTOOL_INSTALL_LUADIR="$(LUADIR)",
STATIC_BUILD="$(STATIC_BUILD)",
ENABLE_ASAN="$(ENABLE_ASAN)",
ENABLE_UBSAN="$(ENABLE_UBSAN)",
WITH_OPENSSL_1_1="$(WITH_OPENSSL_1_1)"
}
}
6 changes: 6 additions & 0 deletions kafka/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR})

add_library(tntkafka SHARED tnt_kafka.c callbacks.c consumer.c consumer_msg.c producer.c queue.c common.c)

if (SANITIZER_FLAGS)
separate_arguments(SANITIZER_FLAGS UNIX_COMMAND "${SANITIZER_FLAGS}")
target_compile_options(tntkafka PRIVATE ${SANITIZER_FLAGS})
target_link_options(tntkafka PRIVATE ${SANITIZER_FLAGS})
endif()

if (APPLE)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} \
-undefined suppress -flat_namespace")
Expand Down

0 comments on commit e029de2

Please sign in to comment.