Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error: NoSpaceLeft on a program built with the x86_64 backend #23099

Open
amarz45 opened this issue Mar 5, 2025 · 0 comments
Open

error: NoSpaceLeft on a program built with the x86_64 backend #23099

amarz45 opened this issue Mar 5, 2025 · 0 comments
Labels
arch-x86_64 64-bit x86 backend-self-hosted bug Observed behavior contradicts documented or intended behavior
Milestone

Comments

@amarz45
Copy link

amarz45 commented Mar 5, 2025

Zig Version

0.14.0-dev.3462+edabcf619

Steps to Reproduce and Observed Behavior

The following program runs fine when built with LLVM enabled but gives an error when using the x86_64 backend:

const std = @import("std");

const linux = std.os.linux;

const statfs = extern struct {
    f_type:    __fsword_t,
    f_bsize:   __fsword_t,
    f_blocks:  blkcnt_t,
    f_bfree:   blkcnt_t,
    f_bavail:  blkcnt_t,

    f_files:   fsfilcnt_t,
    f_ffree:   fsfilcnt_t,
    f_fsid:    fsid_t,
    f_namelen: __fsword_t,
    f_frsize:  __fsword_t,
    f_flags:   __fsword_t,

    const __fsword_t = isize;
    const blkcnt_t = linux.blkcnt_t;
    const fsfilcnt_t = u64;
    const fsid_t = linux.fsid_t;
};

pub fn main() ! void {
    var buf: [1024]u8 = undefined;
    std.debug.print("{s}\n", .{try get_storage(&buf)});
}

fn get_storage(buf: []u8) ! []const u8 {
    var stat: statfs = undefined;
    if (linux.syscall2(.statfs, @intFromPtr("/"), @intFromPtr(&stat)) != 0)
        std.process.exit(1);

    const total_bytes = stat.f_blocks * stat.f_bsize;
    return std.fmt.bufPrint(buf, "{} B", .{total_bytes});
}

When adding .use_llvm = false in the executable options of build.zig and trying to run the program, I get the following output:

error: NoSpaceLeft
/usr/local/lib/zig/std/io/fixed_buffer_stream.zig:63:46: 0x1053db5 in write (std.zig)
            if (self.pos >= self.buffer.len) return error.NoSpaceLeft;
                                             ^
/usr/local/lib/zig/std/io.zig:348:13: 0x103463f in typeErasedWriteFn (std.zig)
            return writeFn(ptr.*, bytes);
            ^
/usr/local/lib/zig/std/io/Writer.zig:13:5: 0x1055af4 in write (std.zig)
    return self.writeFn(self.context, bytes);
    ^
/usr/local/lib/zig/std/io/Writer.zig:19:18: 0x1034c43 in writeAll (std.zig)
        index += try self.write(bytes[index..]);
                 ^
/usr/local/lib/zig/std/fmt.zig:1068:9: 0x1055679 in formatBuf__anon_6771 (std.zig)
        try writer.writeAll(buf);
        ^
/usr/local/lib/zig/std/fmt.zig:1246:5: 0x1153735 in formatInt__anon_23546 (std.zig)
    return formatBuf(buf[index..], options, writer);
    ^
/usr/local/lib/zig/std/fmt.zig:780:5: 0x1153ada in formatIntValue__anon_23542 (std.zig)
    return formatInt(int_value, base, case, options, writer);
    ^
/usr/local/lib/zig/std/fmt.zig:729:32: 0x1153ba4 in formatValue__anon_23512 (std.zig)
        .int, .comptime_int => return formatIntValue(value, fmt, options, writer),
                               ^
/usr/local/lib/zig/std/fmt.zig:520:13: 0x1152a84 in formatType__anon_23402 (std.zig)
            return formatValue(value, actual_fmt, options, writer);
            ^
/usr/local/lib/zig/std/fmt.zig:193:9: 0x115102a in format__anon_23384 (std.zig)
        try formatType(
        ^
/usr/local/lib/zig/std/fmt.zig:1805:30: 0x11512df in bufPrint__anon_23254 (std.zig)
        error.NoSpaceLeft => return error.NoSpaceLeft,
                             ^
/home/amaral/source/new/src/main.zig:27:32: 0x114f941 in main (main.zig)
    std.debug.print("{s}\n", .{try get_storage(&buf)});

Expected Behavior

Here is an example of expected output:

254985371648 B
@amarz45 amarz45 added the bug Observed behavior contradicts documented or intended behavior label Mar 5, 2025
@alexrp alexrp added this to the 0.15.0 milestone Mar 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-x86_64 64-bit x86 backend-self-hosted bug Observed behavior contradicts documented or intended behavior
Projects
None yet
Development

No branches or pull requests

2 participants