Skip to content

Commit

Permalink
Fix ASAN false positive with GCC.
Browse files Browse the repository at this point in the history
GCC reported false positives during stack switching for strings that
were created for debug logging. This moves the affected string into a
pre-allocated global constant.

Closes #1310.
  • Loading branch information
rsmmr committed Feb 11, 2023
1 parent 9823e9f commit 17ee047
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions hilti/runtime/src/fiber.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,25 @@ static const auto FiberGuardFlags = 0; // leak sanitizer may abort with "Tracer

#endif

// Pre-allocate this so that we don't need to create a std::string on the fly
// when HILTI_RT_FIBER_DEBUG executes. That avoids a false positive with
// ASAN during fiber switching when using GCC/libc++.
static const std::string debug_stream_fibers = "fibers";

// Wrapper similar to HILTI_RT_DEBUG that adds the current fiber to the message.
#define HILTI_RT_FIBER_DEBUG(tag, msg) \
{ \
if ( ::hilti::rt::detail::globalState()->debug_logger && \
::hilti::rt::detail::globalState()->debug_logger->isEnabled("fibers") ) \
::hilti::rt::debug::detail::print("fibers", \
::hilti::rt::detail::globalState()->debug_logger->isEnabled(debug_stream_fibers) ) \
::hilti::rt::debug::detail::print(debug_stream_fibers, \
fmt("[%s/%s] %s", *context::detail::get()->fiber.current, tag, msg)); \
}

#define HILTI_RT_FIBER_DEBUG_NO_CONTEXT(tag, msg) \
{ \
if ( ::hilti::rt::detail::globalState()->debug_logger && \
::hilti::rt::detail::globalState()->debug_logger->isEnabled("fibers") ) \
::hilti::rt::debug::detail::print("fibers", fmt("[none/%s] %s", tag, msg)); \
::hilti::rt::detail::globalState()->debug_logger->isEnabled(debug_stream_fibers) ) \
::hilti::rt::debug::detail::print(debug_stream_fibers, fmt("[none/%s] %s", tag, msg)); \
}

extern "C" {
Expand Down

0 comments on commit 17ee047

Please sign in to comment.