Skip to content

Commit d1ff03e

Browse files
author
lei.liu
committed
feat: add asan and ubsan support to cmake
1 parent cb44bdc commit d1ff03e

File tree

5 files changed

+140
-0
lines changed

5 files changed

+140
-0
lines changed

.github/lsan-suppressions.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
#
18+
# Add specific leak suppressions here if needed
19+
# Format:
20+
# leak:SymbolName
21+
# leak:source_file.cc

.github/ubsan-suppressions.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
#
18+
# Add specific undefined suppressions here if needed
19+
# Format:
20+
# signed-integer-overflow:source_file.cc
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
name: ASAN and UBSAN Tests
19+
20+
on:
21+
push:
22+
branches:
23+
- '**'
24+
- '!dependabot/**'
25+
tags:
26+
- '**'
27+
pull_request:
28+
29+
concurrency:
30+
group: ${{ github.repository }}-${{ github.head_ref || github.sha }}-${{ github.workflow }}
31+
cancel-in-progress: true
32+
33+
jobs:
34+
asan-test:
35+
name: "ASAN and UBSAN Tests"
36+
runs-on: ubuntu-24.04
37+
strategy:
38+
fail-fast: false
39+
steps:
40+
- name: Checkout iceberg-cpp
41+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
42+
- name: Configure and Build with ASAN & UBSAN
43+
env:
44+
CC: ${{ matrix.cc }}
45+
CXX: ${{ matrix.cxx }}
46+
run: |
47+
mkdir build && cd build
48+
cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DICEBERG_ENABLE_ASAN=ON -DICEBERG_ENABLE_UBSAN=ON
49+
cmake --build . --verbose
50+
- name: Run Tests
51+
working-directory: build
52+
env:
53+
ASAN_OPTIONS: log_path=out.log:detect_leaks=1:symbolize=1:strict_string_checks=1:halt_on_error=0:detect_container_overflow=0
54+
LSAN_OPTIONS: suppressions=${{ github.workspace }}/.github/lsan-suppressions.txt
55+
UBSAN_OPTIONS: log_path=out.log:print_stacktrace=1:suppressions=${{ github.workspace }}/.github/ubsan-suppressions.txt
56+
run: |
57+
ctest --output-on-failure

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ option(ICEBERG_BUILD_STATIC "Build static library" ON)
3737
option(ICEBERG_BUILD_SHARED "Build shared library" OFF)
3838
option(ICEBERG_BUILD_TESTS "Build tests" ON)
3939
option(ICEBERG_BUILD_BUNDLE "Build the battery included library" ON)
40+
option(ICEBERG_ENABLE_ASAN "Enable Address Sanitizer" OFF)
41+
option(ICEBERG_ENABLE_UBSAN "Enable Undefined Behavior Sanitizer" OFF)
4042

4143
include(GNUInstallDirs)
4244
include(FetchContent)
@@ -55,6 +57,7 @@ endif()
5557

5658
include(CMakeParseArguments)
5759
include(IcebergBuildUtils)
60+
include(IcebergSanitizer)
5861
include(IcebergThirdpartyToolchain)
5962
include(GenerateExportHeader)
6063

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
# Sanitize check for address and undefined.
19+
20+
if(ICEBERG_ENABLE_ASAN)
21+
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
22+
add_compile_options(-fsanitize=address -fno-omit-frame-pointer)
23+
add_link_options(-fsanitize=address)
24+
message(STATUS "Address Sanitizer enabled")
25+
else()
26+
message(WARNING "Address Sanitizer is only supported for GCC and Clang compilers")
27+
endif()
28+
endif()
29+
30+
if(ICEBERG_ENABLE_UBSAN)
31+
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
32+
add_compile_options(-fsanitize=undefined -fno-omit-frame-pointer)
33+
add_link_options(-fsanitize=undefined)
34+
message(STATUS "Undefined Behavior Sanitizer enabled")
35+
else()
36+
message(WARNING "Undefined Behavior Sanitizer is only supported for GCC and Clang compilers"
37+
)
38+
endif()
39+
endif()

0 commit comments

Comments
 (0)