Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/topic/bbannier/asan-macos'
Browse files Browse the repository at this point in the history
  • Loading branch information
bbannier committed Jan 9, 2024
2 parents 10155ec + 84aa8e6 commit b237d86
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ environment:
CCACHE_MAXSIZE: "2G"

lint_task:
skip: $CIRRUS_CRON == '' && $CIRRUS_PR == ''
skip: $CIRRUS_PR == ''
container:
dockerfile: ci/Dockerfile
cpu: 4
Expand Down Expand Up @@ -56,7 +56,7 @@ lint_task:
path: build/ci

clang17_ubuntu_debug_task:
skip: $CIRRUS_BRANCH != 'main' && $CIRRUS_TAG == ''
skip: $CIRRUS_TAG == ''

container:
dockerfile: ci/Dockerfile
Expand Down
20 changes: 20 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
1.10.0-dev.103 | 2024-01-09 14:00:44 +0100

* Remove references to Cirrus cron task. (Benjamin Bannier, Corelight)

We do not schedule CI runs with cron anymore.

* Run CI ASAN task also for PRs. (Benjamin Bannier, Corelight)

* Skip tests around stack size on macos with ASAN. (Benjamin Bannier, Corelight)

These tests produce false positives on macos with ASAN which seem hard
to get rid of. Disable them on the smallest possible subset of setups.

* Fix ASAN false positives introduces with d332827aee7d70cdb642631d7a289751e1d8a36a. (Benjamin Bannier, Corelight)

Since the logging changes of d332827aee7d70cdb642631d7a289751e1d8a36a
ASAN reports false positives on e.g., macos-13.6.2 with its
clang-1500.0.40.1. This patch slightly reorganizes the code so these
false positiives are not triggered.

1.10.0-dev.98 | 2024-01-09 13:55:27 +0100

* Bump dependencies. (Benjamin Bannier, Corelight)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.10.0-dev.98
1.10.0-dev.103
16 changes: 13 additions & 3 deletions hilti/runtime/src/fiber.cc
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,12 @@ void __fiber_switch_trampoline(void* argsp) {

auto from = args->from;
auto to = args->to;
HILTI_RT_FIBER_DEBUG("stack-switcher", fmt("switching from %s to %s", *from, *to));
// Explicitly put the log message on the stack to work around ASAN false positives on macos.
if ( detail::unsafeGlobalState()->debug_logger &&
detail::unsafeGlobalState()->debug_logger->isEnabled(debug_stream_fibers) ) {
const auto msg = fmt("switching from %s to %s", from, to);
HILTI_RT_FIBER_DEBUG("stack-switcher", msg);
}

if ( from->_type == detail::Fiber::Type::SharedStack )
from->_stack_buffer.save();
Expand Down Expand Up @@ -351,8 +356,13 @@ void ASAN_NO_OPTIMIZE detail::Fiber::_finishSwitchFiber(const char* tag) {
size_t prev_size = 0;
__sanitizer_finish_switch_fiber(current->_asan.fake_stack, &prev_bottom, &prev_size);

HILTI_RT_FIBER_DEBUG(tag, fmt("asan-finish: prev-stack=%s/%zu fake-stack=%p", prev_bottom, prev_size,
current->_asan.fake_stack));
// Explicitly put the log message on the stack to work around ASAN false positives on macos.
if ( detail::unsafeGlobalState()->debug_logger &&
detail::unsafeGlobalState()->debug_logger->isEnabled(debug_stream_fibers) ) {
const auto msg =
fmt("asan-finish: prev-stack=%s/%zu fake-stack=%p", prev_bottom, prev_size, current->_asan.fake_stack);
HILTI_RT_FIBER_DEBUG(tag, msg);
}

// By construction, the very first time this method is called, we must just
// have finished switching over from the main fiber. Record its stack.
Expand Down
10 changes: 9 additions & 1 deletion hilti/runtime/src/tests/fiber.cc
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,16 @@ static int fibo(int i) {
return x;
}

bool isMacosAsan() {
#if defined(HILTI_HAVE_ASAN) && defined(__APPLE__)
return true;
#else
return false;
#endif
}

TEST_CASE("stack-size-check") {
// This test produces false positives on macos with ASAN.
TEST_CASE("stack-size-check" * doctest::skip(isMacosAsan())) {
hilti::rt::init();

auto f = [&](hilti::rt::resumable::Handle* r) {
Expand Down
2 changes: 1 addition & 1 deletion tests/Baseline/spicy.rt.stack-check/output
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
[error] terminating with uncaught exception of type hilti::rt::StackSizeExceeded: not enough stack space remaining (<...>/stack-check.spicy:18:5)
[error] terminating with uncaught exception of type hilti::rt::StackSizeExceeded: not enough stack space remaining (<...>/stack-check.spicy:21:5)
9 changes: 8 additions & 1 deletion tests/spicy/rt/stack-check.spicy
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# This test produces false positives on macos with ASAN.
# @TEST-REQUIRES: ! sh ./isMacosAsan.sh
#
# @TEST-EXEC-FAIL: echo . | spicy-driver %INPUT >output 2>&1
# @TEST-EXEC: btest-diff output
#
# Check that stack overflows are caught before we crash.
# @TEST-DOC: Check that stack overflows are caught before we crash.

module Foo;

Expand All @@ -23,3 +26,7 @@ function fibo(n: int64) : int64 {
public type X = unit() {
x: int8 { fibo(100000); }
};

# @TEST-START-FILE isMacosAsan.sh
have-sanitizer && [[ "$OSTYPE" == "darwin"* ]]
# @TEST-END-FILE

0 comments on commit b237d86

Please sign in to comment.