Skip to content

Commit 6de036a

Browse files
wgtmacdongjoon-hyun
authored andcommitted
ORC-1826: [C++][CI] Add ASAN support to CMake
### What changes were proposed in this pull request? Add a CMake option to enable ASan in the C++ build and enable it in the CI. ### Why are the changes needed? We are able to detect potential memory issues with the help of address sanitizer. ### How was this patch tested? Pass all CIs (including the new ASan CIs) ### Was this patch authored or co-authored using generative AI tooling? No. Closes #2097 from wgtmac/asan. Authored-by: Gang Wu <ustcwg@gmail.com> Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
1 parent a7aa293 commit 6de036a

File tree

3 files changed

+99
-0
lines changed

3 files changed

+99
-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/workflows/asan_test.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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: Address Sanitizer Tests
19+
20+
on:
21+
pull_request:
22+
paths-ignore:
23+
- 'site/**'
24+
- 'conan/**'
25+
branches:
26+
- main
27+
28+
concurrency:
29+
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.event.number || github.sha }}
30+
cancel-in-progress: true
31+
32+
jobs:
33+
asan-test:
34+
name: "ASAN with ${{ matrix.compiler }} on Ubuntu"
35+
runs-on: ubuntu-latest
36+
strategy:
37+
fail-fast: false
38+
matrix:
39+
compiler: [gcc, clang]
40+
include:
41+
- compiler: gcc
42+
cc: gcc
43+
cxx: g++
44+
- compiler: clang
45+
cc: clang
46+
cxx: clang++
47+
steps:
48+
- name: Checkout
49+
uses: actions/checkout@v4
50+
- name: Configure and Build with ASAN
51+
env:
52+
CC: ${{ matrix.cc }}
53+
CXX: ${{ matrix.cxx }}
54+
run: |
55+
mkdir build && cd build
56+
cmake .. -DCMAKE_BUILD_TYPE=Debug -DENABLE_ASAN=ON -DBUILD_JAVA=OFF
57+
make
58+
- name: Run Tests
59+
working-directory: build
60+
env:
61+
ASAN_OPTIONS: detect_leaks=1:symbolize=1:strict_string_checks=1:halt_on_error=0:detect_container_overflow=0
62+
LSAN_OPTIONS: suppressions=${{ github.workspace }}/.github/lsan-suppressions.txt
63+
run: |
64+
ctest --output-on-failure

CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ option(BUILD_ENABLE_AVX512
7777
"Enable build with AVX512 at compile time"
7878
OFF)
7979

80+
option(ENABLE_ASAN
81+
"Enable Address Sanitizer"
82+
OFF)
83+
8084
option(ORC_PACKAGE_KIND
8185
"Arbitrary string that identifies the kind of package"
8286
"")
@@ -152,6 +156,16 @@ elseif (MSVC)
152156
set (WARN_FLAGS "${WARN_FLAGS} -wd4521") # multiple copy constructors specified
153157
set (WARN_FLAGS "${WARN_FLAGS} -wd4146") # unary minus operator applied to unsigned type, result still unsigned
154158
endif ()
159+
# Configure Address Sanitizer if enabled
160+
if (ENABLE_ASAN)
161+
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
162+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer")
163+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fno-omit-frame-pointer")
164+
message(STATUS "Address Sanitizer enabled")
165+
else()
166+
message(WARNING "Address Sanitizer is only supported for GCC and Clang compilers")
167+
endif()
168+
endif()
155169

156170
enable_testing()
157171

0 commit comments

Comments
 (0)