Skip to content

state_exec: measure the native stack from the frame, not a local, so it works under ASan - #866

Merged
transfix merged 1 commit into
masterfrom
fix/native-stack-real-frame
Oct 28, 2026
Merged

transfix merged 1 commit into
masterfrom
fix/native-stack-real-frame

Conversation

@transfix

@transfix transfix commented Oct 28, 2026 •

Copy link
Copy Markdown
Owner

native_stack_left() is what detail::native_nesting checks before every nested native call, so a deep chain stops with an error before the stack overflows. It measured the stack from the address of a local variable. Under AddressSanitizer's use-after-return check, a function's locals live in a "fake stack" that the runtime allocates off the thread's stack, and gcc's and clang's runtimes turn that check on by default on Linux. So the measurement said no stack was left at all, and every native call a data job makes threw native calls nested too deeply (0 levels; ...).

The new sanitizers / asan-ubsan job in #858 showed it (run 40639662336, sanitizers-asan-ubsan-logs). Four StepDeadlineTest cases in state_exec_scheduler_test failed:

  • EveryEvaluatorCutsALoopInsideAStepAsATimeout threw that error.
  • TheSyncSchedulerKillsAProcessCutInsideAStep, TheSyncSchedulerLeavesADeadlineArmedOutsideItToItsCaller and TheAsyncSchedulerReportsATimeLimitWhereverItRanOut got a process that died of it, not the timeout they expect.

The fix is a new stack_here() that returns an address in its own frame, which stays on the real stack:

  • gcc and clang: __builtin_frame_address(0).
  • MSVC: _AddressOfReturnAddress(). MSVC's own use-after-return check is opt-in, but the same applies when it is on.
  • Emscripten: a local's address, as before. Its stack is in linear memory.

native_stack_left() and the Windows stack_low() now use it. Until this lands, #858 runs ASan with detect_stack_use_after_return=0, with a comment naming this PR.

On Windows (MSVC, the _AddressOfReturnAddress() path), state_exec_scheduler_test (165 tests), state_exec_deep_data_test (35) and pycvc_state_exec_data pass. The deep data tests include the ones that run native nesting on small fixed-size stacks until the guard refuses a level, so the measurement still finds the stack's end. The gcc path under ASan gets checked once #858's asan-ubsan job drops detect_stack_use_after_return=0.

…it works under ASan

native_stack_left(), which detail::native_nesting checks before every nested
native call, measured the stack from the address of a local. Under
AddressSanitizer's use-after-return check, which gcc's and clang's runtimes
turn on by default on Linux, a function's locals live in a "fake stack" the
runtime allocates off the thread's stack. The measurement then said no stack
was left at all, and every native call a data job makes threw "native calls
nested too deeply (0 levels; ...)".

The new asan-ubsan job (#858) showed it: four StepDeadlineTest
cases in state_exec_scheduler_test failed with that error, or with a process
that died of it instead of the timeout the test expected.

stack_here() now gives an address in its own frame on the real stack:
__builtin_frame_address(0) with gcc and clang, _AddressOfReturnAddress() with
MSVC (whose own use-after-return check is opt-in, but the same applies), and a
local's address only on Emscripten, whose stack is in linear memory.
native_stack_left() and the Windows stack_low() use it.
transfix added a commit that referenced this pull request Oct 28, 2026
…settles its first baseline

The asan-ubsan job's first full run (40639662336) found:
- Every pycvc script stopped at its first C++ throw on ASan's CHECK that it had
  found the real __cxa_throw. ASan looks it up when it starts, and the
  interpreter is C, so libstdc++ was not loaded yet. run.sh now preloads
  libstdc++ after the ASan runtime.
- Four StepDeadlineTest cases in state_exec_scheduler_test failed with "native
  calls nested too deeply (0 levels)": libcvc measured its stack from a local,
  which ASan's use-after-return check moves to a fake stack. Fixed in #866;
  until it lands the job runs with detect_stack_use_after_return=0.
- LeakSanitizer reported state_exec's reference cycles in
  state_exec_async_test and state_exec_integration_test, all indirect leaks:
  garbage only collect_cycles() frees, and these tests exit before any
  collection. lsan.supp hides them by fixture, with the reasons.

test_pycvc_state_exec_eval.py is not run under ASan until #864 lands: it would
stop at the heap-use-after-free that #864 fixes, and ASan can't suppress one.
run.sh's py_skip lists it, and the job summary shows it as skipped.
@transfix
transfix marked this pull request as ready for review October 28, 2026 19:42
@transfix
transfix merged commit 05bc9d0 into master Oct 28, 2026
23 of 25 checks passed
transfix added a commit that referenced this pull request Oct 28, 2026
transfix added a commit that referenced this pull request Oct 28, 2026
#866 (the native-stack guard measuring from the frame, not a local) is merged,
so asan-ubsan runs with ASan's default use-after-return check again, which also
checks #866 under gcc's ASan. No workaround for a fix in flight is left.
transfix added a commit that referenced this pull request Oct 28, 2026
… deep workflow (#858)

* ci: TSan and ASan+UBSan jobs over the threaded state_exec suites, and the locks deep workflow

The state_exec lock work (docs/STATE_EXEC_LOCKS.md) adds code that runs on
several threads, and no CI lane ran a race detector or an address checker. This
lands them before any lock code, so that the races and leaks already in the
tree get a baseline first.

- ci.yml `sanitizers` (tsan, asan-ubsan): gcc's -fsanitize=thread, or
  -fsanitize=address,undefined, over libcvc itself (the cvcpkg deps stay
  uninstrumented), RelWithDebInfo, building only the targets it runs. It runs
  the existing suites that use threads (state_exec_scheduler, _async,
  _integration and _coordinator tests, ariadne_runtime_test, thread_pool_test,
  async_lane_test) and pycvc's exec scripts, with the sanitizer runtime
  preloaded into the interpreter. Suppressions go in .github/sanitizers/, each
  with a comment naming what it hides. Each lock phase appends its suites.
- ci.yml's pull_request filter takes perf/** as well, so the lock phases'
  stacked drafts get the full set of jobs.
- locks-deep.yml (daily, and by hand on a branch): a Release Linux build of the
  lock test targets, running their deep sizes. A dispatchable workflow must be
  on the default branch, so it lands first; on a ref without the lock tests it
  stops after the checkout.

* ci: sanitizers / asan-ubsan without UBSan's vptr check, and TSan suppressions for the baseline's two bugs

The asan-ubsan job failed to link libcvc.so: UBSan's vptr check references the
typeinfo of every polymorphic class it checks, and Jolt is built without RTTI,
as are the two libcvc files that subclass its classes, so that typeinfo exists
nowhere ("undefined reference to `typeinfo for JPH::GroupFilter'"). The job now
builds with -fno-sanitize=vptr; the rest of UBSan stays on.

The tsan job's first run found two real bugs, each fixed in its own PR, and
suppressed here until those land:
- a lock-order inversion between exec_coordinator's leader_mu_ and the message
  bus's lock, from start() announcing its election under leader_mu_ (6 reports
  in state_exec_coordinator_test and state_exec_integration_test; #863);
- pycvc's evaluator.stats(), evaluator_state.stats and process.state not
  keeping their owner alive, because their %pythonappend was never generated
  (13 heap-use-after-free reports in test_pycvc_state_exec_eval.py; #864).

* ci: sanitizers / asan-ubsan runs pycvc with libstdc++ preloaded, and settles its first baseline

The asan-ubsan job's first full run (40639662336) found:
- Every pycvc script stopped at its first C++ throw on ASan's CHECK that it had
  found the real __cxa_throw. ASan looks it up when it starts, and the
  interpreter is C, so libstdc++ was not loaded yet. run.sh now preloads
  libstdc++ after the ASan runtime.
- Four StepDeadlineTest cases in state_exec_scheduler_test failed with "native
  calls nested too deeply (0 levels)": libcvc measured its stack from a local,
  which ASan's use-after-return check moves to a fake stack. Fixed in #866;
  until it lands the job runs with detect_stack_use_after_return=0.
- LeakSanitizer reported state_exec's reference cycles in
  state_exec_async_test and state_exec_integration_test, all indirect leaks:
  garbage only collect_cycles() frees, and these tests exit before any
  collection. lsan.supp hides them by fixture, with the reasons.

test_pycvc_state_exec_eval.py is not run under ASan until #864 lands: it would
stop at the heap-use-after-free that #864 fixes, and ASan can't suppress one.
run.sh's py_skip lists it, and the job summary shows it as skipped.

* ci: sanitizers drop the #864 workarounds now that it is on master

#864 (pycvc keep-alives for references into an evaluator, a state or a
process) is merged, so tsan.supp no longer hides its heap-use-after-free
reports and test_pycvc_state_exec_eval.py runs under ASan again. py_skip stays,
empty, for the next report ASan can't suppress.

* ci: sanitizers drop the #863 suppression now that it is on master

#863 (exec_coordinator::start() announcing its election without its leader
lock) is merged, so tsan.supp no longer hides the lock-order inversion it fixed.
tsan.supp is empty again.

* ci: sanitizers drop the #866 workaround now that it is on master

#866 (the native-stack guard measuring from the frame, not a local) is merged,
so asan-ubsan runs with ASan's default use-after-return check again, which also
checks #866 under gcc's ASan. No workaround for a fix in flight is left.
transfix added a commit that referenced this pull request Oct 29, 2026
…"laying out" note (#871)

TfOverlayTasks.CooperativeTaskSlicesAcrossFramesAndMatchesCompute records the
overlay status note each time it changes between frames and expected every one
to carry a percentage. Laying out the contour tree is a single step, so its note
("contour tree: laying out") has none, as
TfOverlaysVolume.JobSlicesEveryPhaseAndReportsProgress already expects. A frame
only sometimes lands on that step, so the test failed now and then: on
recipe / macos-latest / Debug in #866 (job 122924848877), with
the task otherwise finished and published normally. The loop now skips that
note; the other checks on the notes are unchanged.
@transfix
transfix deleted the fix/native-stack-real-frame branch October 29, 2026 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant