ziglang/zig
262
5.9k
Fork
You've already forked zig
763

LLVM emits broken TLS access sequence on aarch64-windows for private thread_locals mixed with non-private ones #31865

Open
opened 2026年04月15日 00:43:33 +02:00 by alexrp · 9 comments

As far as I can tell, literally any invocation results in this:

"C:\a\zig-sdk\zig-sdk\out\dep\vezel.zig.toolsets.win-arm640円.16.0.1\tools\zig.exe" exited with code -1073741819.
As far as I can tell, literally any invocation results in this: ``` "C:\a\zig-sdk\zig-sdk\out\dep\vezel.zig.toolsets.win-arm640円.16.0.1\tools\zig.exe" exited with code -1073741819. ```
alexrp added this to the 0.17.0 milestone 2026年04月15日 00:43:33 +02:00
Author
Owner
Copy link

We are working on acquiring AArch64 hardware that, among other platform coverage, will allow us to resurrect aarch64-windows CI. But until then, I don't have access to a machine I can debug this on, so would appreciate any help in fixing this.

We are working on acquiring AArch64 hardware that, among other platform coverage, will allow us to resurrect `aarch64-windows` CI. But until then, I don't have access to a machine I can debug this on, so would appreciate any help in fixing this.

x86_64 cross-compiling to aarch64 works correctly.

- uses:mlugg/setup-zig@v2if:matrix.os != 'windows-11-arm'- name:Setup zig (Windows ARM workaround)if:matrix.os == 'windows-11-arm'run:| curl -fsSLo zig.zip https://ziglang.org/download/0.16.0/zig-x86_64-windows-0.16.0.zip
 unzip -q zig.zip -d zig-sdk
 echo "$PWD/zig-sdk/zig-x86_64-windows-0.16.0" >> $GITHUB_PATH

Probably aarch64-windows bootstrap package needs to be rebuilt from x86_64.

x86_64 cross-compiling to aarch64 works correctly. ```yaml - uses: mlugg/setup-zig@v2 if: matrix.os != 'windows-11-arm' - name: Setup zig (Windows ARM workaround) if: matrix.os == 'windows-11-arm' run: | curl -fsSLo zig.zip https://ziglang.org/download/0.16.0/zig-x86_64-windows-0.16.0.zip unzip -q zig.zip -d zig-sdk echo "$PWD/zig-sdk/zig-x86_64-windows-0.16.0" >> $GITHUB_PATH ``` Probably aarch64-windows bootstrap package needs to be rebuilt from x86_64.

src/codegen/llvm.zig

- .internal => if (o.builder.strip) .private else .internal,
+ .internal => if (o.builder.strip and !resolved.@"threadlocal") .private else .internal,
- llvm_global.ptr(&o.builder).linkage = if (o.builder.strip) .private else .internal;
+ llvm_global.ptr(&o.builder).linkage = if (o.builder.strip and !resolved.@"threadlocal") .private else .internal;

this worked for me. rebuilt from source with this edit, no errors using new binary on aarch64-windows to compile my projects

src/codegen/llvm.zig ```diff - .internal => if (o.builder.strip) .private else .internal, + .internal => if (o.builder.strip and !resolved.@"threadlocal") .private else .internal, ``` ```diff - llvm_global.ptr(&o.builder).linkage = if (o.builder.strip) .private else .internal; + llvm_global.ptr(&o.builder).linkage = if (o.builder.strip and !resolved.@"threadlocal") .private else .internal; ``` this worked for me. rebuilt from source with this edit, no errors using new binary on aarch64-windows to compile my projects

I've been using this patched version of the compiler for a couple of weeks now without any issue. Builds DVUI and other projects successfully.

I've been using this patched version of the compiler for a couple of weeks now without any issue. Builds DVUI and other projects successfully.
Author
Owner
Copy link
threadlocalvarx:u32=undefined;pubexportfnfoo()u32{returnx;}

zig4 build-lib -dynamic repro.zig -target aarch64-windows-gnu -lc:

0010fdf0 uint32_t foo()
0010fdf0 fd7bbfa9 stp fp, lr, [sp, #-0x10]! {__saved_fp} {__saved_lr}
0010fdf4 fd030091 mov fp, sp {__saved_fp}
0010fdf8 482e40f9 ldr x8, [x18, #0x58]
0010fdfc c90400f0 adrp x9, global_single_threaded_instance.csprng.rng.__offset(0x190)
0010fe00 294d42b9 ldr w9, [x9, #0x24c] {_tls_index}
0010fe04 087969f8 ldr x8, [x8, x9, lsl #0x3]
0010fe08 08014091 add x8, x8, #0, lsl #0xc
0010fe0c 001940b9 ldr w0, [x8, #0x18]
0010fe10 fd7bc1a8 ldp fp, lr, [sp], #0x10 {__saved_fp} {__saved_lr}
0010fe14 c0035fd6 ret 

zig4 build-lib -dynamic repro.zig -target aarch64-windows-gnu -lc -fstrip:

0009c9e8 uint32_t foo()
0009c9e8 fd7bbfa9 stp fp, lr, [sp, #-0x10]! {__saved_fp} {__saved_lr}
0009c9ec fd030091 mov fp, sp {__saved_fp}
0009c9f0 482e40f9 ldr x8, [x18, #0x58]
0009c9f4 090300b0 adrp x9, data_fd000
0009c9f8 29e541b9 ldr w9, [x9, #0x1e4] {data_fd1e4}
0009c9fc 087969f8 ldr x8, [x8, x9, lsl #0x3]
0009ca00 08414091 add x8, x8, #0x10, lsl #0xc
0009ca04 001940b9 ldr w0, [x8, #0x18]
0009ca08 fd7bc1a8 ldp fp, lr, [sp], #0x10 {__saved_fp} {__saved_lr}
0009ca0c c0035fd6 ret 

That add x8, x8, #0x10, lsl #0xc is very wrong; both DLLs have a .tls section that's 40 bytes in size, and x should be at offset zero in that section in both cases.

Still no idea why this is happening.

```zig threadlocal var x: u32 = undefined; pub export fn foo() u32 { return x; } ``` `zig4 build-lib -dynamic repro.zig -target aarch64-windows-gnu -lc`: ```asm 0010fdf0 uint32_t foo() 0010fdf0 fd7bbfa9 stp fp, lr, [sp, #-0x10]! {__saved_fp} {__saved_lr} 0010fdf4 fd030091 mov fp, sp {__saved_fp} 0010fdf8 482e40f9 ldr x8, [x18, #0x58] 0010fdfc c90400f0 adrp x9, global_single_threaded_instance.csprng.rng.__offset(0x190) 0010fe00 294d42b9 ldr w9, [x9, #0x24c] {_tls_index} 0010fe04 087969f8 ldr x8, [x8, x9, lsl #0x3] 0010fe08 08014091 add x8, x8, #0, lsl #0xc 0010fe0c 001940b9 ldr w0, [x8, #0x18] 0010fe10 fd7bc1a8 ldp fp, lr, [sp], #0x10 {__saved_fp} {__saved_lr} 0010fe14 c0035fd6 ret ``` `zig4 build-lib -dynamic repro.zig -target aarch64-windows-gnu -lc -fstrip`: ```asm 0009c9e8 uint32_t foo() 0009c9e8 fd7bbfa9 stp fp, lr, [sp, #-0x10]! {__saved_fp} {__saved_lr} 0009c9ec fd030091 mov fp, sp {__saved_fp} 0009c9f0 482e40f9 ldr x8, [x18, #0x58] 0009c9f4 090300b0 adrp x9, data_fd000 0009c9f8 29e541b9 ldr w9, [x9, #0x1e4] {data_fd1e4} 0009c9fc 087969f8 ldr x8, [x8, x9, lsl #0x3] 0009ca00 08414091 add x8, x8, #0x10, lsl #0xc 0009ca04 001940b9 ldr w0, [x8, #0x18] 0009ca08 fd7bc1a8 ldp fp, lr, [sp], #0x10 {__saved_fp} {__saved_lr} 0009ca0c c0035fd6 ret ``` That `add x8, x8, #0x10, lsl #0xc` is very wrong; both DLLs have a `.tls` section that's 40 bytes in size, and `x` should be at offset zero in that section in both cases. Still no idea why this is happening.

AArch64AsmBackend.cpp

rebuilt LLVM 22.1.3 with this and reprods compile clean:

 case AArch64::fixup_aarch64_add_imm12:
 case AArch64::fixup_aarch64_ldst_imm12_scale1:
- if (TheTriple.isOSBinFormatCOFF() && !IsResolved)
+ if (TheTriple.isOSBinFormatCOFF() && !IsResolved) {
+ if (AArch64::getAddressFrag(static_cast<AArch64::Specifier>(
+ Target.getSpecifier())) == AArch64::S_HI12)
+ Value >>= 12;
 Value &= 0xfff;
+ }

i have a snapdragon x2ee laptop if you want me to test anything else on my hardware, let me know

AArch64AsmBackend.cpp rebuilt LLVM 22.1.3 with this and reprods compile clean: ```diff case AArch64::fixup_aarch64_add_imm12: case AArch64::fixup_aarch64_ldst_imm12_scale1: - if (TheTriple.isOSBinFormatCOFF() && !IsResolved) + if (TheTriple.isOSBinFormatCOFF() && !IsResolved) { + if (AArch64::getAddressFrag(static_cast<AArch64::Specifier>( + Target.getSpecifier())) == AArch64::S_HI12) + Value >>= 12; Value &= 0xfff; + } ``` i have a snapdragon x2ee laptop if you want me to test anything else on my hardware, let me know
Author
Owner
Copy link

Reduction:

; ModuleID = 'reduced.bc'
target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-p:64:64-i32:32-i64:64-i128:128-n32:64-S128-Fn32"
target triple = "aarch64-unknown-windows-gnu"
@debug.panic_stage = thread_local global i64 0
@repro.x = private thread_local global i32 undef
@foo = alias i32 (), ptr @repro.foo
define i32 @repro.foo() {
 %1 = load i32, ptr @repro.x, align 4
 ret i32 %1
}
❯ llc reduced.bc -filetype obj
❯ llvm-objdump --disassemble-symbols=foo reduced.obj
reduced.obj: file format coff-arm64
Disassembly of section .text:
0000000000000000 <foo>:
 0: 90000008 adrp x8, 0x0 <repro.foo>
 4: f9402e49 ldr x9, [x18, #0x58]
 8: b9400108 ldr w8, [x8]
 c: f8687928 ldr x8, [x9, x8, lsl #3]
 10: 91402108 add x8, x8, #0x8, lsl #12 // =0x8000
 14: b9400900 ldr w0, [x8, #0x8]
 18: d65f03c0 ret
Reduction: ```llvm ; ModuleID = 'reduced.bc' target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-p:64:64-i32:32-i64:64-i128:128-n32:64-S128-Fn32" target triple = "aarch64-unknown-windows-gnu" @debug.panic_stage = thread_local global i64 0 @repro.x = private thread_local global i32 undef @foo = alias i32 (), ptr @repro.foo define i32 @repro.foo() { %1 = load i32, ptr @repro.x, align 4 ret i32 %1 } ``` ``` ❯ llc reduced.bc -filetype obj ❯ llvm-objdump --disassemble-symbols=foo reduced.obj reduced.obj: file format coff-arm64 Disassembly of section .text: 0000000000000000 <foo>: 0: 90000008 adrp x8, 0x0 <repro.foo> 4: f9402e49 ldr x9, [x18, #0x58] 8: b9400108 ldr w8, [x8] c: f8687928 ldr x8, [x9, x8, lsl #3] 10: 91402108 add x8, x8, #0x8, lsl #12 // =0x8000 14: b9400900 ldr w0, [x8, #0x8] 18: d65f03c0 ret ```
Author
Owner
Copy link
https://github.com/llvm/llvm-project/issues/199581
alexrp modified the milestone from 0.17.0 to Unplanned 2026年05月26日 00:50:40 +02:00
alexrp removed their assignment 2026年05月26日 00:58:44 +02:00
alexrp changed title from (削除) 0.16.0 aarch64-windows binary is broken (削除ここまで) to LLVM emits broken TLS access sequence on aarch64-windows for private thread_locals mixed with non-private ones 2026年05月28日 04:59:19 +02:00

this issue was resolved on the LLVM side with two commits, see https://github.com/llvm/llvm-project/issues/199581

this issue was resolved on the LLVM side with two commits, see https://github.com/llvm/llvm-project/issues/199581
alexrp modified the milestone from Unplanned to 0.18.0 2026年06月09日 23:17:16 +02:00
Sign in to join this conversation.
No Branch/Tag specified
master
std.zig.Ast.ParseOptions
elfv2
spork8
restricted
0.16.x
panic-rewrite
parking-futex-lockfree
windows-Io-cleanup
Io-watch
ParseCommandLineOptions
windows-async-files
poll-ring
debug-file-leaks-differently
debug-file-leaks
ProcessPrng
elfv2-dyn
jobserver
threadtheft
io-threaded-no-queue
0.15.x
Io.net
comptime-allocator
restricted-function-pointers
cli
wasm-linker-writer
wrangle-writer-buffering
sha1-stream
async-await-demo
fixes
0.14.x
ast-node-methods
macos-debug-info
make-vs-configure
fuzz-macos
sans-aro
ArrayList-reserve
incr-bug
llvm-ir-nosanitize-metadata
ci-tarballs
ci-scripts
threadpool
0.12.x
new-pkg-hash
json-diagnostics
more-doctests
rework-comptime-mutation
0.11.x
ci-perf-comment
stage2-async
0.10.x
autofix
0.9.x
aro
hcs
0.8.x
0.7.x
0.16.0
0.15.2
0.15.1
0.15.0
0.14.1
0.14.0
0.12.1
0.13.0
0.12.0
0.11.0
0.10.1
0.10.0
0.9.1
0.9.0
0.8.1
0.8.0
0.7.1
0.7.0
0.6.0
0.5.0
0.4.0
0.3.0
0.2.0
0.1.1
0.1.0
Labels
Clear labels
abi/f32
abi/ilp32
abi/sf
accepted
This proposal is planned.
arch/21k
arch/6502
arch/aarch64
arch/alpha
arch/amdgcn
arch/arc
arch/arc32
arch/arc64
arch/arm
arch/avr
arch/bfin
arch/bpf
arch/colossus
arch/cris
arch/csky
arch/dlx
arch/epiphany
arch/fr30
arch/frv
arch/hexagon
arch/hppa
arch/hppa64
arch/ia64
arch/kalimba
arch/kvx
arch/lanai
arch/lm32
arch/loongarch32
arch/loongarch64
arch/m32r
arch/m68k
arch/m88k
arch/mcore
arch/microblaze
arch/mips
arch/mips64
arch/mmix
arch/moxie
arch/mrisc32
arch/msp430
arch/nds32
arch/ns32k
arch/nvptx
arch/or1k
arch/powerpc
arch/powerpc64
arch/propeller
arch/riscv32
arch/riscv64
arch/rl78
arch/rx
arch/s390x
arch/sh
arch/sparc
arch/sparc64
arch/spirv
arch/spu
arch/tricore
arch/v850
arch/vax
arch/vc4
arch/ve
arch/wasm
arch/x86
arch/x86_64
arch/xcore
arch/xtensa
autodoc
The web application for interactive documentation and generation of its assets.
backend/c
The C backend outputs C source code.
backend/llvm
The LLVM backend outputs an LLVM bitcode module.
backend/self-hosted
The self-hosted backends produce machine code directly.
binutils
Zig's included binary utilities: zig ar, zig dlltool, zig lib, zig ranlib, zig objcopy, and zig rc.
breaking
Implementing this issue could cause existing code to no longer compile or have different behavior.
build system
The Zig build system - zig build, std.Build, the build runner, and package management.
debug info
An issue related to debug information (e.g. DWARF) produced by the Zig compiler.
docs
An issue with documentation, e.g. the language reference or standard library doc comments.
error message
This issue points out an error message that is unhelpful and should be improved.
frontend
Tokenization, parsing, AstGen, ZonGen, Sema, Legalize, and Liveness.
fuzzing
An issue related to Zig's integrated fuzz testing.
incremental
Reuse of internal compiler state for faster compilation.
lib/c
This issue relates to Zig's libc implementation and/or vendored libcs.
lib/compiler-rt
This issue relates to Zig's compiler-rt library.
lib/cxx
This issue relates to Zig's vendored libc++ and/or libc++abi.
lib/std
This issue relates to Zig's standard library.
lib/tsan
This issue relates to Zig's vendored libtsan.
lib/ubsan-rt
This issue relates to Zig's ubsan-rt library.
lib/unwind
This issue relates to Zig's vendored libunwind.
linking
Zig's integrated object file and incremental linker.
miscompilation
The compiler reports success but produces semantically incorrect code.
os/android
os/contiki
os/dragonfly
os/driverkit
os/emscripten
os/freebsd
os/fuchsia
os/haiku
os/hermit
os/hurd
os/illumos
os/ios
os/linux
os/maccatalyst
os/macos
os/managarm
os/netbsd
os/ohos
os/openbsd
os/plan9
os/redox
os/rtems
os/serenity
os/tvos
os/uefi
os/visionos
os/wasi
os/watchos
os/windows
proposal
This issue suggests language modifications. If it also has the "accepted" label then it is planned.
release notes
This issue or pull request should be mentioned in the release notes.
testing
This issue is related to testing the compiler, standard library, or other parts of Zig.
zig cc
Zig as a drop-in C-family compiler.
zig fmt
The Zig source code formatter.
zig reduce
The Zig source code reduction tool.
bounty
https://ziglang.org/news/announcing-donor-bounties
bug
Observed behavior contradicts documented or intended behavior.
contributor-friendly
This issue is limited in scope and/or knowledge of project internals.
downstream
An issue with a third-party project that uses this project.
enhancement
Solving this issue will likely involve adding new logic or components to the codebase.
infra
An issue related to project infrastructure, e.g. continuous integration.
optimization
A task to improve performance and/or resource usage.
question
No questions on the issue tracker; use a community space instead.
regression
Something that used to work in a previous version stopped working
upstream
An issue with a third-party project that this project uses.
use case
Describes a real use case that is difficult or impossible, but does not propose a solution.
No labels
abi/f32
abi/ilp32
abi/sf
accepted
arch/21k
arch/6502
arch/aarch64
arch/alpha
arch/amdgcn
arch/arc
arch/arc32
arch/arc64
arch/arm
arch/avr
arch/bfin
arch/bpf
arch/colossus
arch/cris
arch/csky
arch/dlx
arch/epiphany
arch/fr30
arch/frv
arch/hexagon
arch/hppa
arch/hppa64
arch/ia64
arch/kalimba
arch/kvx
arch/lanai
arch/lm32
arch/loongarch32
arch/loongarch64
arch/m32r
arch/m68k
arch/m88k
arch/mcore
arch/microblaze
arch/mips
arch/mips64
arch/mmix
arch/moxie
arch/mrisc32
arch/msp430
arch/nds32
arch/ns32k
arch/nvptx
arch/or1k
arch/powerpc
arch/powerpc64
arch/propeller
arch/riscv32
arch/riscv64
arch/rl78
arch/rx
arch/s390x
arch/sh
arch/sparc
arch/sparc64
arch/spirv
arch/spu
arch/tricore
arch/v850
arch/vax
arch/vc4
arch/ve
arch/wasm
arch/x86
arch/x86_64
arch/xcore
arch/xtensa
autodoc
backend/c
backend/llvm
backend/self-hosted
binutils
breaking
build system
debug info
docs
error message
frontend
fuzzing
incremental
lib/c
lib/compiler-rt
lib/cxx
lib/std
lib/tsan
lib/ubsan-rt
lib/unwind
linking
miscompilation
os/android
os/contiki
os/dragonfly
os/driverkit
os/emscripten
os/freebsd
os/fuchsia
os/haiku
os/hermit
os/hurd
os/illumos
os/ios
os/linux
os/maccatalyst
os/macos
os/managarm
os/netbsd
os/ohos
os/openbsd
os/plan9
os/redox
os/rtems
os/serenity
os/tvos
os/uefi
os/visionos
os/wasi
os/watchos
os/windows
proposal
release notes
testing
zig cc
zig fmt
zig reduce
bounty
bug
contributor-friendly
downstream
enhancement
infra
optimization
question
regression
upstream
use case
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
4 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ziglang/zig#31865
Reference in a new issue
ziglang/zig
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?