Skip to content

Commit

Permalink
Add test with ASAN enabled.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rot127 committed Apr 7, 2024
1 parent cda40c6 commit af12ea4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
17 changes: 16 additions & 1 deletion .github/workflows/CITest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jobs:
python-arch: x64,
python-version: '3.6',
build-system: 'cmake',
enable-asan: 'OFF'
}
- {
name: 'ubuntu-22.04 x64 python3.9 make',
Expand All @@ -44,6 +45,7 @@ jobs:
python-arch: x64,
python-version: '3.9',
build-system: 'make',
enable-asan: 'OFF'
}
- {
name: 'ubuntu-22.04 x64 python3.9 cmake',
Expand All @@ -52,6 +54,7 @@ jobs:
python-arch: x64,
python-version: '3.9',
build-system: 'cmake',
enable-asan: 'OFF'
}
- {
name: 'ubuntu-22.04 x64 python3.11 cmake',
Expand All @@ -60,6 +63,16 @@ jobs:
python-arch: x64,
python-version: '3.11',
build-system: 'cmake',
enable-asan: 'OFF'
}
- {
name: 'ubuntu-22.04 x64 python3.11 ASAN',
os: ubuntu-22.04,
arch: x64,
python-arch: x64,
python-version: '3.11',
build-system: 'cmake',
enable-asan: 'ON'
}

steps:
Expand Down Expand Up @@ -88,13 +101,15 @@ jobs:
- name: cmake
if: startsWith(matrix.config.build-system, 'cmake')
env: |
ENABLE_ASAN: ${{ matrix.config.enable_asan }}
run: |
mkdir build && cd build
# build static library
cmake -DCAPSTONE_INSTALL=1 -DCMAKE_INSTALL_PREFIX=/usr ..
cmake --build . --config Release
# build shared library
cmake -DCAPSTONE_INSTALL=1 -DBUILD_SHARED_LIBS=1 -DCMAKE_INSTALL_PREFIX=/usr ..
cmake -DCAPSTONE_INSTALL=1 -DBUILD_SHARED_LIBS=1 -DCMAKE_INSTALL_PREFIX=/usr -DENABLE_ASAN=${ENABLE_ASAN} ..
sudo cmake --build . --config Release --target install
cp libcapstone.* ../
cp libcapstone.* ../tests/
Expand Down
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ option(CAPSTONE_USE_ARCH_REGISTRATION "Use explicit architecture registration" O
option(CAPSTONE_ARCHITECTURE_DEFAULT "Whether architectures are enabled by default" ON)
option(CAPSTONE_DEBUG "Whether to enable extra debug assertions" OFF)
option(CAPSTONE_INSTALL "Generate install target" ${PROJECT_IS_TOP_LEVEL})
option(ENABLE_ASAN "Enable address sanitizer" OFF)

if (ENABLE_ASAN)
add_definitions(-DASAN_ENABLED)
add_compile_options(-fsanitize=address)
add_link_options(-fsanitize=address)
endif()

# If building for OSX it's best to allow CMake to handle building both architectures
if(APPLE AND NOT CAPSTONE_BUILD_MACOS_THIN)
Expand Down
1 change: 1 addition & 0 deletions COMPILE_CMAKE.TXT
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Get CMake for free from http://www.cmake.org.
- CAPSTONE_X86_REDUCE: change this to ON to make X86 binary smaller.
- CAPSTONE_X86_ATT_DISABLE: change this to ON to disable AT&T syntax on x86.
- CAPSTONE_DEBUG: change this to ON to enable extra debug assertions.
- ENABLE_ASAN: Compiles Capstone with the address sanitizer.

By default, Capstone use system dynamic memory management, and both DIET and X86_REDUCE
modes are disabled. To use your own memory allocations, turn ON both DIET &
Expand Down

0 comments on commit af12ea4

Please sign in to comment.