Skip to content

Commit

Permalink
fix: address/undefined/leak sanitizer for builder (except cppparser) …
Browse files Browse the repository at this point in the history
…&& undefined sanitizer for ros2_control_py
  • Loading branch information
VokunGahrotLaas authored and olivier-stasse committed Feb 17, 2024
1 parent 9daad65 commit 2a98a60
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
1 change: 1 addition & 0 deletions .lsan.supp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
leak:yyparse
22 changes: 11 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,11 @@ if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
endif()
# Default to C11
if(NOT CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 11)
endif()
# Warnings for gcc/clang
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# sanitize address gcc/clang
if(SANITIZE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer -fsanitize=address,undefined,leak")
set(CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} -fno-omit-frame-pointer -fsanitize=address,undefined,leak")
endif()

# ros2_control modules to parse
set(_ros2_py_modules
controller_interface
Expand Down Expand Up @@ -56,7 +47,7 @@ set(_ros2_py_src ${_ros2_py_src_dir}/impl_ros2_control_py.cpp)
# calls builder
add_custom_command(
OUTPUT ${_ros2_py_src}
COMMAND builder "${_ros2_py_src_dir}" "$ENV{AMENT_PREFIX_PATH}" "$ENV{ROS_DISTRO}" ${_ros2_py_modules}
COMMAND ${CMAKE_COMMAND} -E env "LSAN_OPTIONS=suppressions=${CMAKE_CURRENT_LIST_DIR}/.lsan.supp" $<TARGET_FILE:builder> "${_ros2_py_src_dir}" "$ENV{AMENT_PREFIX_PATH}" "$ENV{ROS_DISTRO}" ${_ros2_py_modules}
DEPENDS builder
)
add_custom_target(run_builder
Expand All @@ -73,6 +64,15 @@ pybind11_add_module(${_ros2_py_impl}
set_target_properties(${_ros2_py_impl}
PROPERTIES OUTPUT_NAME ${PROJECT_NAME}/${_ros2_py_impl}
)
# sanitize address gcc/clang
if(SANITIZE)
target_compile_options(${_ros2_py_impl} PRIVATE
"-fsanitize=undefined"
)
target_link_options(${_ros2_py_impl} PRIVATE
"-fsanitize=undefined"
)
endif()
add_dependencies(${_ros2_py_impl} run_builder)
target_include_directories(${_ros2_py_impl} PRIVATE
${_ros2_py_src_dir}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ colcon build

```sh
cd ~/ros2_control_py_ws
colcon build --cmake-args ' -DCMAKE_BUILD_TYPE=Debug -DSANITIZE'
colcon build --cmake-args ' -DCMAKE_BUILD_TYPE=Debug' ' -DSANITIZE=True'
colcon test
```

Expand Down
11 changes: 11 additions & 0 deletions builder/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,14 @@ target_link_libraries(builder
PRIVATE
cppparser
)
# sanitize address gcc/clang
if(SANITIZE)
target_compile_options(builder PRIVATE
"-fno-omit-frame-pointer"
"-fsanitize=address,undefined,leak"
)
target_link_options(builder PRIVATE
"-fno-omit-frame-pointer"
"-fsanitize=address,undefined,leak"
)
endif()

0 comments on commit 2a98a60

Please sign in to comment.