Skip to content

lib/std/start.zig ignores entry option #21763

@ghost

Description

There is std.Build.Step.Compile.Entry

pub const Entry = union(enum) {
    /// Let the compiler decide whether to make an entry point and what to name
    /// it.
    default,
    /// The executable will have no entry point.
    disabled,
    /// The executable will have an entry point with the default symbol name.
    enabled,
    /// The executable will have an entry point with the specified symbol name.
    symbol_name: []const u8,
};

and the CLI flags -fentry and -fno-entry for specifying the name of the entry symbol of the executable or omitting an entry function altogether.
In lib/std/start.zig it assumes the name of the entry function:

const start_sym_name = if (native_arch.isMIPS()) "__start" else "_start";

The issue:

$ cat x.zig
pub export fn _start() void {}
$ zig build-exe x.zig # works

Now change _start to start and tell the compiler about it:

$ cat x.zig
pub export fn start() void {}
$ zig build-exe x.zig -fentry=start
zig-linux-x86_64/lib/std/start.zig:607:46: error: root struct of file 'x' has no member named 'main'

It should compile successfully.

Perhaps to fix this the Entry struct above should be moved into lib/std/builtin.zig (as std.builtin.Entry) and the entry option should be exposed through @import("builtin").
lib/std/start.zig then looks at @import("builtin").entry instead of assuming anything.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions