Skip to content

Commit e029de2

Browse files
committed
build: fix sanitizers usage
* Fix ENABLE_ASAN flag passing into CMakeLists.txt * Add UBSAN * Enable ASAN/UBSAN for librdkafka and lua module targets
1 parent abd1b3e commit e029de2

File tree

4 files changed

+29
-7
lines changed

4 files changed

+29
-7
lines changed

.github/workflows/asan_testing.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ jobs:
4343
cd tarantool
4444
git checkout release/2.11
4545
export LSAN_OPTIONS=suppressions=${PWD}/asan/lsan.supp
46-
cmake . -DENABLE_ASAN=ON -DENABLE_DIST=ON
46+
cmake . -DENABLE_ASAN=ON -DENABLE_UB_SANITIZER=ON -DENABLE_DIST=ON
4747
make -j16
4848
sudo make install
4949
cd ..
50-
tarantoolctl rocks STATIC_BUILD=ON ENABLE_ASAN=ON make
50+
tarantoolctl rocks STATIC_BUILD=ON ENABLE_ASAN=ON ENABLE_UBSAN=ON make
5151
5252
- name: Run tarantool application
5353
run: |

CMakeLists.txt

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
1+
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
22

33
project(kafka C)
44

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

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

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

25-
option(ENABLE_ASAN OFF)
2627
if (ENABLE_ASAN)
27-
set(LIBRDKAFKA_C_FLAGS "-fsanitize=address")
28-
set(LIBRDKAFKA_CXX_FLAGS "-fsanitize=address")
29-
set(LIBRDKAFKA_FLAGS "--enable-devel")
28+
list(APPEND SANITIZER_FLAGS -fsanitize=address)
29+
endif()
30+
31+
if (ENABLE_UBSAN)
32+
list(APPEND SANITIZER_FLAGS -fsanitize=undefined)
33+
endif()
34+
35+
if (SANITIZER_FLAGS)
36+
list(JOIN SANITIZER_FLAGS " " SANITIZER_FLAGS)
37+
set(LIBRDKAFKA_FLAGS --enable-devel --disable-optimization)
38+
set(CMAKE_BUILD_TYPE "Debug")
39+
set(LIBRDKAFKA_CXX_FLAGS "${SANITIZER_FLAGS}")
40+
set(LIBRDKAFKA_C_FLAGS "${SANITIZER_FLAGS}")
41+
set(LIBRDKAFKA_LD_FLAGS "${SANITIZER_FLAGS}")
3042
endif()
3143

3244
if (APPLE)
45+
set(LIBRDKAFKA_LD_FLAGS "${LIBRDKAFKA_LD_FLAGS} ${CMAKE_C_SYSROOT_FLAG} ${CMAKE_OSX_SYSROOT}")
3346
set(LIBRDKAFKA_CXX_FLAGS "${LIBRDKAFKA_CXX_FLAGS} ${CMAKE_C_SYSROOT_FLAG} ${CMAKE_OSX_SYSROOT}")
3447
set(LIBRDKAFKA_C_FLAGS "${LIBRDKAFKA_C_FLAGS} ${CMAKE_C_SYSROOT_FLAG} ${CMAKE_OSX_SYSROOT}")
3548
endif()
@@ -46,6 +59,7 @@ if(STATIC_BUILD)
4659
--cxx=${CMAKE_CXX_COMPILER}
4760
--CFLAGS=${LIBRDKAFKA_C_FLAGS}
4861
--CPPFLAGS=${LIBRDKAFKA_CXX_FLAGS}
62+
--LDFLAGS=${LIBRDKAFKA_LD_FLAGS}
4963
--prefix=<INSTALL_DIR>
5064
${LIBRDKAFKA_FLAGS}
5165

kafka-scm-1.rockspec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ build = {
2525
TARANTOOL_INSTALL_LIBDIR="$(LIBDIR)",
2626
TARANTOOL_INSTALL_LUADIR="$(LUADIR)",
2727
STATIC_BUILD="$(STATIC_BUILD)",
28+
ENABLE_ASAN="$(ENABLE_ASAN)",
29+
ENABLE_UBSAN="$(ENABLE_UBSAN)",
2830
WITH_OPENSSL_1_1="$(WITH_OPENSSL_1_1)"
2931
}
3032
}

kafka/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR})
33

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

6+
if (SANITIZER_FLAGS)
7+
separate_arguments(SANITIZER_FLAGS UNIX_COMMAND "${SANITIZER_FLAGS}")
8+
target_compile_options(tntkafka PRIVATE ${SANITIZER_FLAGS})
9+
target_link_options(tntkafka PRIVATE ${SANITIZER_FLAGS})
10+
endif()
11+
612
if (APPLE)
713
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} \
814
-undefined suppress -flat_namespace")

0 commit comments

Comments
 (0)