Skip to content

Commit 64d18ac

Browse files
committed
ci make: support UBSAN
MariaDB bundles Groonga. With the recent UBSAN improvements in MariaDB, UBSAN errors are detected in the Groonga layer. To catch undefined behavior issues and ensure robust integration, this change adds a new UBSAN build configuration. ## For reviewers This UBSAN support is implemented only with Clang because GCC doesn't support the `-fno-sanitize=alignment` option, leading to numerous misalignment errors. And also, MariaDB is using this option too. ref: https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html#usage ref: https://github.com/MariaDB/server/blob/22efc2c784e1b7199fb5804e6330168277ea7dce/CMakeLists.txt#L239
1 parent 70d16b6 commit 64d18ac

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

.github/workflows/cmake.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,16 @@ jobs:
7777
mruby: "OFF"
7878
- cc: clang
7979
cxx: clang++
80+
- cc: clang
81+
cxx: clang++
82+
ubsan: "ON"
8083
runs-on: ubuntu-latest
8184
timeout-minutes: 90
8285
env:
8386
CC: ${{ matrix.cc }}
8487
CXX: ${{ matrix.cxx }}
8588
GRN_WITH_MRUBY: ${{ matrix.mruby }}
89+
GRN_WITH_UBSAN: ${{ matrix.ubsan }}
8690
steps:
8791
- uses: actions/checkout@v4
8892
with:
@@ -152,7 +156,8 @@ jobs:
152156
-DGRN_ALLOW_WARNING=OFF \
153157
-DGRN_WITH_APACHE_ARROW=ON \
154158
-DGRN_WITH_BLOSC=auto \
155-
-DGRN_WITH_MRUBY=${GRN_WITH_MRUBY:-ON}
159+
-DGRN_WITH_MRUBY=${GRN_WITH_MRUBY:-ON} \
160+
-DGRN_WITH_UBSAN=${GRN_WITH_UBSAN:-OFF}
156161
- name: Build
157162
run: |
158163
ninja -C ../groonga.build
@@ -164,6 +169,11 @@ jobs:
164169
run: |
165170
echo "COLUMNS=79" >> ${GITHUB_ENV}
166171
echo "LD_LIBRARY_PATH=$PWD/install/lib" >> ${GITHUB_ENV}
172+
if [ "${{ matrix.ubsan }}" == "ON" ] ; then
173+
CLANG_VER=$(clang -dumpversion | cut -d. -f1)
174+
CLANG_LIBRARY_PATH="/usr/lib/clang/${CLANG_VER}/lib/linux"
175+
echo "LD_LIBRARY_PATH=${CLANG_LIBRARY_PATH}:${env.LD_LIBRARY_PATH}" >> ${GITHUB_ENV}
176+
fi
167177
echo "PKG_CONFIG_PATH=$PWD/lib/pkgconfig" >> ${GITHUB_ENV}
168178
echo "TZ=Asia/Tokyo" >> ${GITHUB_ENV}
169179
if [ "${{ matrix.cc }}" == "gcc" -a \

CMakeLists.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,30 @@ option(GRN_WITH_NFKC "use NFKC based UTF8 normalization." ON)
521521

522522
option(GRN_WITH_MEMORY_DEBUG "use debug memory management" OFF)
523523

524+
option(GRN_WITH_UBSAN "Enable Undefined Behavior Sanitizer (UBSAN) checking"
525+
OFF)
526+
if(GRN_WITH_UBSAN)
527+
if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
528+
set(GRN_UBSAN_FLAGS "-fsanitize=undefined -fno-sanitize=alignment")
529+
string(APPEND CMAKE_C_FLAGS " ${GRN_UBSAN_FLAGS}")
530+
string(APPEND CMAKE_CXX_FLAGS " ${GRN_UBSAN_FLAGS}")
531+
message(STATUS "UBSAN flags: ${GRN_UBSAN_FLAGS}")
532+
execute_process(
533+
COMMAND ${CMAKE_C_COMPILER}
534+
-print-file-name=libclang_rt.ubsan_standalone-x86_64.so
535+
OUTPUT_VARIABLE GRN_UBSAN_LIB_PATH
536+
OUTPUT_STRIP_TRAILING_WHITESPACE)
537+
if(GRN_UBSAN_LIB_PATH)
538+
string(APPEND CMAKE_EXE_LINKER_FLAGS " ${GRN_UBSAN_LIB_PATH}")
539+
message(STATUS "Found UBSAN runtime library: ${GRN_UBSAN_LIB_PATH}")
540+
else()
541+
message(FATAL_ERROR "No UBSAN runtime library found")
542+
endif()
543+
else()
544+
message(FATAL_ERROR "UBSAN support is available only for Clang")
545+
endif()
546+
endif()
547+
524548
if(WIN32)
525549
target_link_libraries(grn_dependencies INTERFACE dbghelp.lib)
526550
target_link_libraries(grn_dependencies INTERFACE psapi.lib)

0 commit comments

Comments
 (0)