ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
33.83k stars 2.47k forks source link

`zig libc` crashes with out of memory error on loongarch64 #21468

Open yxd-ym opened 15 hours ago

yxd-ym commented 15 hours ago

Zig Version

0.14.0-dev.1622+2ac543388

Steps to Reproduce and Observed Behavior

  1. Bootstrap a loongarch64 linux zig with https://github.com/ziglang/zig-bootstrap/commit/1ad232c5a2e1ebbdad2cfbb86ad8fe7f73c7e4d4 , either musl or gnu.
  2. Run zig libc on a loongarch64 linux machine with the bootstrapped zig
  3. The error occurs like this:
$ ~/opt/zig/musl/zig libc
error: OutOfMemory

Expected Behavior

zig libc returns correct libc related information on loongarch64 like x86_64 or aarch64 ones

yxd-ym commented 15 hours ago

also see: https://github.com/ziglang/zig-bootstrap/issues/164#issuecomment-2363160440

alexrp commented 14 hours ago

Does it happen under QEMU?

yxd-ym commented 14 minutes ago

I bootstrapped another version with ReleaseSafe mode and the error is different

 $ ~/opt/zig/musl/zig libc
thread 59547 panic: incorrect alignment
Aborted (core dumped)

Here is the backtrace output.

(gdb) r libc
Starting program: /home/yxd/opt/zig/musl/zig libc
[New LWP 59504]
[New LWP 59505]
[New LWP 59506]
[New LWP 59507]
[New LWP 59508]
thread 59502 panic: incorrect alignment

Thread 1 "zig" received signal SIGABRT, Aborted.
raise (sig=<optimized out>) at /Users/yxd/playspace/zig-bootstrap/out/host/lib/zig/libc/musl/src/signal/raise.c:12
warning: 12     /Users/yxd/playspace/zig-bootstrap/out/host/lib/zig/libc/musl/src/signal/raise.c: No such file or directory
(gdb) bt
#0  raise (sig=<optimized out>) at /Users/yxd/playspace/zig-bootstrap/out/host/lib/zig/libc/musl/src/signal/raise.c:12
#1  0x000000000a8dc530 in abort () at /Users/yxd/playspace/zig-bootstrap/out/host/lib/zig/libc/musl/src/exit/abort.c:11
#2  0x0000000009e04490 in posix.abort () at /Users/yxd/playspace/zig-bootstrap/out/host/lib/zig/std/posix.zig:706
#3  0x000000000a840068 in debug.panicImpl (trace=0x0, first_trace_addr=...) at /Users/yxd/playspace/zig-bootstrap/out/host/lib/zig/std/io/Writer.zig:19
#4  0x00000000099fef58 in builtin.default_panic (error_return_trace=0x0, ret_addr=...) at /Users/yxd/playspace/zig-bootstrap/out/host/lib/zig/std/builtin.zig:885
#5  0x0000000009c247c4 in posix.mmap (ptr=<optimized out>, length=528, prot=<optimized out>, flags=<optimized out>, fd=<optimized out>, offset=0)
    at /Users/yxd/playspace/zig-bootstrap/out/host/lib/zig/std/posix.zig:4706
#6  0x0000000009bc1a58 in crypto.tlcsprng.tlsCsprngFill () at /Users/yxd/playspace/zig-bootstrap/out/host/lib/zig/std/crypto/tlcsprng.zig:64
#7  0x0000000009c89488 in Random.bytes () at /Users/yxd/playspace/zig-bootstrap/out/host/lib/zig/std/Random.zig:55
#8  Random.int__anon_48074 () at /Users/yxd/playspace/zig-bootstrap/out/host/lib/zig/std/Random.zig:109
#9  Compilation.update (comp=0x7ffff7f9d350, main_progress_node=...) at Compilation.zig:2122
#10 0x0000000009c8fc14 in main.updateModule (comp=0x7ffff7f9d350, color=auto, prog_node=...) at main.zig:4499
#11 0x0000000009a2af0c in main.jitCmd (gpa=..., arena=..., options=...) at main.zig:5586
#12 0x00000000099feb7c in main.mainArgs (arena=...) at main.zig:303
#13 main.main () at main.zig:199
#14 start.callMain () at /Users/yxd/playspace/zig-bootstrap/out/host/lib/zig/std/start.zig:619
#15 start.callMainWithArgs () at /Users/yxd/playspace/zig-bootstrap/out/host/lib/zig/std/start.zig:579
#16 start.main (c_argc=<optimized out>, c_argv=<optimized out>, c_envp=<optimized out>) at /Users/yxd/playspace/zig-bootstrap/out/host/lib/zig/std/start.zig:594

update

I got the reason of this problem, my loongarch64 machine's memory page size is not 16KiB but 4KiB.

yxd@derp ~/tmp/test_zig $ getconf PAGESIZE
4096

I will check this with linux distribution's packagers.