zig icon indicating copy to clipboard operation
zig copied to clipboard

Big `threadlocal` variables cause runtime panic when linking libc.

Open IntegratedQuantum opened this issue 2 years ago • 2 comments

Zig Version

0.11.0-dev.3602+387f9568a

Steps to Reproduce and Observed Behavior

The following code causes a runtime panic exclusively when linking libc:

const std = @import("std");

threadlocal var x: [32000000]u8 = undefined;

pub fn main() !void {
	@memset(&x, 0);
	_ = try std.Thread.spawn(.{}, main, .{});
	std.os.exit(0);
}
$ zig run test.zig                              // ← works without an error
$ zig run test.zig -lc
thread 8389 panic: reached unreachable code
/home/mint/zig/stage3/lib/zig/std/Thread.zig:707:23: 0x20e46c in spawn__anon_3835 (test)
            .INVAL => unreachable,
                      ^
/home/mint/zig/stage3/lib/zig/std/Thread.zig:340:32: 0x20c609 in spawn__anon_2677 (test)
    const impl = try Impl.spawn(config, function, args);
                               ^
/home/mint/Desktop/test.zig:7:26: 0x20c58b in main (test)
 _ = try std.Thread.spawn(.{}, main, .{});
                         ^
/home/mint/zig/stage3/lib/zig/std/start.zig:609:37: 0x20ccc4 in main (test)
            const result = root.main() catch |err| {
                                    ^
???:?:?: 0x7f841ff7a082 in ??? (???)
Aborted (core dumped)

Expected Behavior

threadlocal variables should behave consistently.

IntegratedQuantum avatar Jun 14 '23 10:06 IntegratedQuantum

I'm working on this

ghost avatar Jun 16 '23 01:06 ghost

Sorry, posted this on the wrong issue

ghost avatar Jun 16 '23 01:06 ghost