mirror of
https://github.com/XRPLF/rippled.git
synced 2026-04-29 15:37:57 +00:00
ASAN wasn't able to keep track of `boost::coroutine` context switches, and would lead to many false positives being detected. By switching to `boost::coroutine2` and `ucontext`, ASAN is able to know about the context switches advertised by the `boost::fiber` class, which in turn leads to more cleaner ASAN analysis.
87 lines
4.1 KiB
Plaintext
87 lines
4.1 KiB
Plaintext
include(default)
|
|
{% set compiler, version, compiler_exe = detect_api.detect_default_compiler() %}
|
|
{% set sanitizers = os.getenv("SANITIZERS") %}
|
|
|
|
[conf]
|
|
{% if sanitizers %}
|
|
{% if compiler == "gcc" %}
|
|
{% if "address" in sanitizers or "thread" in sanitizers or "undefinedbehavior" in sanitizers %}
|
|
{% set sanitizer_list = [] %}
|
|
{% set defines = [] %}
|
|
{% set model_code = "" %}
|
|
{% set extra_cxxflags = ["-fno-omit-frame-pointer", "-O1", "-Wno-stringop-overflow"] %}
|
|
|
|
{% if "address" in sanitizers %}
|
|
{% set _ = sanitizer_list.append("address") %}
|
|
{% set model_code = "-mcmodel=large" %}
|
|
{% set _ = defines.append("BOOST_USE_ASAN")%}
|
|
{% set _ = defines.append("BOOST_USE_UCONTEXT")%}
|
|
{% elif "thread" in sanitizers %}
|
|
{% set _ = sanitizer_list.append("thread") %}
|
|
{% set model_code = "-mcmodel=medium" %}
|
|
{% set _ = extra_cxxflags.append("-Wno-tsan") %}
|
|
{% set _ = defines.append("BOOST_USE_TSAN")%}
|
|
{% set _ = defines.append("BOOST_USE_UCONTEXT")%}
|
|
{% endif %}
|
|
|
|
{% if "undefinedbehavior" in sanitizers %}
|
|
{% set _ = sanitizer_list.append("undefined") %}
|
|
{% set _ = sanitizer_list.append("float-divide-by-zero") %}
|
|
{% endif %}
|
|
|
|
{% set sanitizer_flags = "-fsanitize=" ~ ",".join(sanitizer_list) ~ " " ~ model_code %}
|
|
|
|
tools.build:cxxflags+=['{{sanitizer_flags}} {{" ".join(extra_cxxflags)}}']
|
|
tools.build:sharedlinkflags+=['{{sanitizer_flags}}']
|
|
tools.build:exelinkflags+=['{{sanitizer_flags}}']
|
|
tools.build:defines+={{defines}}
|
|
{% endif %}
|
|
{% elif compiler == "apple-clang" or compiler == "clang" %}
|
|
{% if "address" in sanitizers or "thread" in sanitizers or "undefinedbehavior" in sanitizers %}
|
|
{% set sanitizer_list = [] %}
|
|
{% set defines = [] %}
|
|
{% set extra_cxxflags = ["-fno-omit-frame-pointer", "-O1"] %}
|
|
|
|
{% if "address" in sanitizers %}
|
|
{% set _ = sanitizer_list.append("address") %}
|
|
{% set _ = defines.append("BOOST_USE_ASAN")%}
|
|
{% set _ = defines.append("BOOST_USE_UCONTEXT")%}
|
|
{% elif "thread" in sanitizers %}
|
|
{% set _ = sanitizer_list.append("thread") %}
|
|
{% set _ = defines.append("BOOST_USE_TSAN")%}
|
|
{% set _ = defines.append("BOOST_USE_UCONTEXT")%}
|
|
{% endif %}
|
|
|
|
{% if "undefinedbehavior" in sanitizers %}
|
|
{% set _ = sanitizer_list.append("undefined") %}
|
|
{% set _ = sanitizer_list.append("float-divide-by-zero") %}
|
|
{% set _ = sanitizer_list.append("unsigned-integer-overflow") %}
|
|
{% endif %}
|
|
|
|
{% set sanitizer_flags = "-fsanitize=" ~ ",".join(sanitizer_list) %}
|
|
|
|
tools.build:cxxflags+=['{{sanitizer_flags}} {{" ".join(extra_cxxflags)}}']
|
|
tools.build:sharedlinkflags+=['{{sanitizer_flags}}']
|
|
tools.build:exelinkflags+=['{{sanitizer_flags}}']
|
|
tools.build:defines+={{defines}}
|
|
{% endif %}
|
|
{% endif %}
|
|
{% endif %}
|
|
|
|
tools.info.package_id:confs+=["tools.build:cxxflags", "tools.build:exelinkflags", "tools.build:sharedlinkflags", "tools.build:defines"]
|
|
|
|
[options]
|
|
{% if sanitizers %}
|
|
{% if "address" in sanitizers %}
|
|
# Build Boost.Context with ucontext backend (not fcontext) so that
|
|
# ASAN fiber-switching annotations (__sanitizer_start/finish_switch_fiber)
|
|
# are compiled into the library. fcontext (assembly) has no ASAN support.
|
|
# define=BOOST_USE_ASAN=1 is critical: it must be defined when building
|
|
# Boost.Context itself so the ucontext backend compiles in the ASAN annotations.
|
|
boost/*:extra_b2_flags=context-impl=ucontext address-sanitizer=on define=BOOST_USE_ASAN=1
|
|
boost/*:without_context=False
|
|
# Boost stacktrace fails to build with some sanitizers
|
|
boost/*:without_stacktrace=True
|
|
{% endif %}
|
|
{% endif %}
|