Regression `-Zsanitizer=thread` crashes any program on arm64 in nightly.

未关闭
#166,163 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
48/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
rust
领域
compilers

调研方向

Start by checking the compiler-builtins update and the AArch64 outlined atomic helpers mentioned in the issue, then reproduce with the supplied -Zsanitizer=thread -Zbuild-std command on aarch64. The backtrace points to __aarch64_swp1_acq during ThreadSanitizer initialization; verify whether that helper is instrumented and whether disabling its instrumentation addresses the crash. Done means the minimal program runs without a segmentation fault on nightly.

由索引模型根据 Issue 内容生成。

描述

A-sanitizers C-bug I-prioritize needs-triage O-AArch64 regression-from-stable-to-nightly T-compiler T-libs

-Zsanitizer=thread crashes any program on arm64 in nightly.

I found this while using Claude Code with Opus 5.5/Sonnet 5.5/Fable 5.2, output from the LLM will be clearly marked, other output is tested and verified by myself, every text here is written by myself if not otherwise marked :-)

Code

I tried this code with latest nightly:

fn main() {
    println!("Hello, world!");
}

I expected to see this output when running the program:

Hello, world!

Instead, this happened:

Segmentation fault         (core dumped) RUSTFLAGS=-Zsanitizer=thread cargo +nightly run -Zbuild-std --target aarch64-unknown-linux-gnu
Version it worked on

stable 1.100.0 (0ef1bc386 2026-11-09)

Claude Codes bisection for this, rewritten by myself

  • stable 1.100.0 (0ef1bc386 2026-11-09) -> ok
  • nightly-2026-09-01 (0dfb098f3) -> ok
  • nightly-2026-10-13 (e9bbadf68) -> ok
  • nightly-2026-10-15 (7df81381d) -> ok (last good)
  • nightly-2026-10-16 (4ebd25825) -> Error (first bad)
  • nightly-2026-10-28 (41089d07a) -> Error
  • nightly-2026-11-17 (59cbdee2e) -> Error

It most recently worked on (by bisection by Claude Code): stable 1.100.0 (0ef1bc386 2026-11-09) and nightly-2026-10-15 (7df81381d)

Version with regression (by bisection by Claude Code):

nightly-2026-10-16 (4ebd25825), nightly-2026-10-28 (41089d07a), nightly-2026-11-17 (59cbdee2e)
checked myself: 1.102.0-nightly (59cbdee2e 2026-11-17)

rustc --version --verbose:

rustup run nightly rustc --version --verbose
rustc 1.102.0-nightly (59cbdee2e 2026-11-17)
binary: rustc
commit-hash: 59cbdee2e7b3ee50e44b460561c43c9e3023d9f0
commit-date: 2026-11-17
host: aarch64-unknown-linux-gnu
release: 1.102.0-nightly
LLVM version: 23.1.5

Setting vm.mmap_rnd_bits to either 28 or 32 did not change any output.

The compiler did not crash, the program produced did crash:

Backtrace of running the programm
gdb -batch -ex run -ex bt target/aarch64-unknown-linux-gnu/debug/tsan-repo
warning: Missing auto-load script at offset 0 in section .debug_gdb_scripts
of file [...]./target/aarch64-unknown-linux-gnu/debug/tsan-repo.
Use `info auto-load python-scripts [REGEXP]' to list them.

This GDB supports auto-downloading debuginfo from the following URLs:
  <https://debuginfod.ubuntu.com>
Enable debuginfod for this session? (y or [n]) [answered N; input not from terminal]
Debuginfod has been disabled.
To make this setting permanent, add 'set debuginfod enabled off' to .gdbinit.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/aarch64-linux-gnu/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
0x0000aaaaaab314a8 in __tsan::TraceSwitchPart(__tsan::ThreadState*) ()
#0  0x0000aaaaaab314a8 in __tsan::TraceSwitchPart(__tsan::ThreadState*) ()
#1  0x0000aaaaaab3363c in __tsan::TraceRestartFuncEntry(__tsan::ThreadState*, unsigned long) ()
#2  0x0000aaaaaad18c78 in __aarch64_swp1_acq () at src/macros.rs:435
#3  0x0000aaaaaab51e78 in __sanitizer::MemoryMappingLayout::MemoryMappingLayout(bool) ()
#4  0x0000aaaaaab4693c in __tsan::CheckAndProtect(bool, bool, bool) ()
#5  0x0000aaaaaab45ff8 in __tsan::ReExecIfNeeded(bool) ()
#6  0x0000aaaaaab3053c in __tsan::Initialize(__tsan::ThreadState*) ()
#7  0x0000fffff7fc2e9c in _dl_init (main_map=0xfffff7fff340, argc=1, argv=0xffffffffe6c8, env=0xffffffffe6d8) at ./elf/dl-init.c:106
#8  0x0000fffff7fda648 in _start () at ../sysdeps/aarch64/dl-start.S:81

Claude Codes idea how it works currently:

Linking libgcc whole-archive makes it work:

Verified by me on that arm64:

RUSTFLAGS="-Zsanitizer=thread -Clink-arg=-Wl,--whole-archive -Clink-arg=$(cc -print-libgcc-file-name) -Clink-arg=-Wl,--no-whole-archive"  cargo +nightly run -Zbuild-std --target aarch64-unknown-linux-gnu

outputs:

Hello, world!
LLM analysis (unverified by me beyond everything above)

The following is LLM-generated analysis, quoted as such.

The only change in the range touching the affected code is #164333 (compiler-builtins subtree update), which brings in rust-lang/compiler-builtins#1321 ("Rewrite AArch64 outlined atomic functions with asm"). Before it, the __aarch64_{cas,swp,ldadd,…}* helpers were #[unsafe(naked)] functions, so sanitizer instrumentation never touched them. Now they are ordinary functions containing asm! plus a Rust load of HAVE_LSE_ATOMICS. With -Zbuild-std, compiler_builtins is compiled with -Zsanitizer=thread, so the helpers get __tsan_func_entry/__tsan_func_exit:

$ objdump -d --no-show-raw-insn target/aarch64-unknown-linux-gnu/debug/tsan-repro | grep -A12 '<__aarch64_swp1_acq>:'
<__aarch64_swp1_acq>:
  ...
  bl  <__tsan_func_entry>
  bl  <_RNvNtCs..._17compiler_builtins23aarch64_outline_atomics18___aarch64_swp1_acq>
  bl  <__tsan_func_exit>

The TSan runtime calls these helpers from __tsan::Initialize before its per-thread state exists, so the instrumented helper faults. rust-lang/compiler-builtins#1354 makes these the only implementation. A fix would be to keep the helpers uninstrumented again (naked, or #[sanitize(thread = "off")]).

Claude found related issues, didn't grasp those in their entirety:

Possibly related, but different: #151486, #161855.

@rustbot modify labels: +regression-from-stable-to-nightly -regression-untriaged

主要语言
Rust
星标
122k
派生
16.7k
平均合并
2 天 16 小时
30 天内合并 PR
515

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

rust-lang/rust 的其他 Issue

查看 rust-lang/rust 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。