You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cannot compile Zig source for target armv7-linux-musleabi #2833
Thanks to fix #2437, cross-compiling C source for v7 arm target: armv7-linux-musleabi works great. But unfortunately cross-compiling Zig source for the same target produces errors.
zig1.zig source:
export fn answer() i32 {
return 42;
}
Command:
zig build-lib -dynamic zig1.zig --library c -fPIC -target armv7-linux-musleabi
Errors:
/Users/admin/Develop/zig/lib/zig/std/debug.zig:1025:48: error: expected type 'usize', found 'u64'
const self_exe_mmap_len = mem.alignForward(try S.self_exe_file.getEndPos(), mem.page_size);
^
/Users/admin/Develop/zig/lib/zig/std/os.zig:1738:35: error: use of undeclared identifier 'Stat'
pub fn fstat(fd: fd_t) FStatError!Stat {
^
/Users/admin/Develop/zig/lib/zig/std/fs/file.zig:44:25: error: container 'std.os' has no member called 'O_LARGEFILE'
const flags = os.O_LARGEFILE | os.O_RDONLY;
^
/Users/admin/Develop/zig/lib/zig/std/os/linux.zig:97:74: error: use of undeclared identifier 'timespec'
pub fn futex_wait(uaddr: *const i32, futex_op: u32, val: i32, timeout: ?*timespec) usize {
^
/Users/admin/Develop/zig/lib/zig/std/os/linux.zig:102:12: error: use of undeclared identifier 'syscall3'
return syscall3(SYS_futex, @ptrToInt(uaddr), futex_op, @bitCast(u32, val));
^
/Users/admin/Develop/zig/lib/zig/std/os.zig:2150:36: error: expected type 'isize', found 'i64'
switch (errno(system.lseek(fd, ipos, SEEK_SET))) {
^
The zig standard library needs some improvements for 32 bit ARM. Contributions are welcome, and that would be the best option to solve this.
As a workaround you can disable debug info with --strip. This gives up the ability to have stack traces and other nice things, but fixes most of the errors, leaving you with:
$ zig build-lib -dynamic zig1.zig --library c -target armv7-linux-musleabi --strip
/home/andy/dev/zig/build/lib/zig/std/os/linux.zig:97:74: error: use of undeclared identifier 'timespec'
pub fn futex_wait(uaddr: *const i32, futex_op: u32, val: i32, timeout: ?*timespec) usize {
^
/home/andy/dev/zig/build/lib/zig/std/os/linux.zig:102:12: error: use of undeclared identifier 'syscall3'
return syscall3(SYS_futex, @ptrToInt(uaddr), futex_op, @bitCast(u32, val));
^
The remaining errors have to do with zig's mutex implementation, which needs the arm-32 linux syscall definitions. This is a small patch to the std lib which would be welcome. However, if your application is single-threaded, you can avoid this with --single-threaded:
And then the build will succeed. If you need threads, then we'll need to improve the std lib implementation of mutex to support this target, or to use pthread mutex functions when linking libc.
BTW the -fPIC argument is redundant; I think you should leave it to the default.
Activity
andrewrk commentedon Jul 6, 2019
The zig standard library needs some improvements for 32 bit ARM. Contributions are welcome, and that would be the best option to solve this.
As a workaround you can disable debug info with
--strip. This gives up the ability to have stack traces and other nice things, but fixes most of the errors, leaving you with:The remaining errors have to do with zig's mutex implementation, which needs the arm-32 linux syscall definitions. This is a small patch to the std lib which would be welcome. However, if your application is single-threaded, you can avoid this with
--single-threaded:And then the build will succeed. If you need threads, then we'll need to improve the std lib implementation of mutex to support this target, or to use pthread mutex functions when linking libc.
BTW the
-fPICargument is redundant; I think you should leave it to the default.babelchips commentedon Jul 6, 2019
@andrewrk Thank you very much!
babelchips commentedon Jul 6, 2019
Sorry - I guess this should stay open?
andrewrk commentedon Jul 6, 2019
Yes, let's leave this open because it's currently the only issue tracking 32-bit arm linux support in the standard library.
andrewrk commentedon Sep 29, 2019
This works now thanks to a lot of work by several people