Skip to content

Enhance WAMR_BUILD_SANITIZER to support multiple sanitizers #4489

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kylo5aby
Copy link
Contributor

Support combining compatible sanitizers,
Usage examples:
cmake -DWAMR_BUILD_SANITIZER=ubsan,posan ../
cmake -DWAMR_BUILD_SANITIZER=ubsan ../

@lum1n0us lum1n0us added the enhancement Check if this issue/PR enhances a feature; scripts will use this info. label Jul 14, 2025
@lum1n0us
Copy link
Collaborator

A list in cmake is a ; separated group of strings.

I'm not entirely sure if we're following the same approach with command line options, but it seems that ";" is more commonly used than "," in the CMake world for representing a list. I mean -DWAMR_BUILD_SANITIZER=ubsan;posan is more natural and preferable than -DWAMR_BUILD_SANITIZER=ubsan,posan.

https://cmake.org/cmake/help/v3.14/command/list.html#introduction

@kylo5aby
Copy link
Contributor Author

A list in cmake is a ; separated group of strings.

I'm not entirely sure if we're following the same approach with command line options, but it seems that ";" is more commonly used than "," in the CMake world for representing a list. I mean -DWAMR_BUILD_SANITIZER=ubsan;posan is more natural and preferable than -DWAMR_BUILD_SANITIZER=ubsan,posan.

https://cmake.org/cmake/help/v3.14/command/list.html#introduction

I think while ";" is cmake's internal list separator, "," provides better user experience as it doesn't require shell escaping or quotes. moreover, comma-delimited parameters align with industry conventions used by compilers like gcc/clang: gcc -fsanitize=address,undefined

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 -fno-omit-frame-pointer -fsanitize=undefined -fno-sanitize-recover=all -fno-sanitize=alignment")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=undefined")
endif()
if(sanitizer STREQUAL "asan")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(sanitizer STREQUAL "asan")
elseif(sanitizer STREQUAL "asan")

set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
endif()
endif()
if(sanitizer STREQUAL "tsan")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(sanitizer STREQUAL "tsan")
elseif(sanitizer STREQUAL "tsan")

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 -fno-omit-frame-pointer -fsanitize=thread -fno-sanitize-recover=all")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=thread")
endif()
if(sanitizer STREQUAL "posan")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(sanitizer STREQUAL "posan")
elseif(sanitizer STREQUAL "posan")

if(NOT sanitizer IN_LIST SUPPORTED_SANITIZERS)
list(APPEND INVALID_SANITIZERS "${sanitizer}")
endif()
if(sanitizer STREQUAL "ubsan")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(sanitizer STREQUAL "ubsan")
elseif(sanitizer STREQUAL "ubsan")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Check if this issue/PR enhances a feature; scripts will use this info.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants