Skip to content

stage2: -fno-emit-bin crashes #7099

Open

Description

@xackus

zig build-exe stage2_test.zig -fno-LLVM -fno-emit-bin

stage2_test.zig is just export fn _start() noreturn {}

attempt to use null value
/home/mwa/code/zig/src/link/Elf.zig:2039:69: 0x55555690476c in link.Elf.allocateDeclIndexes (zig1)
    const phdr = &self.program_headers.items[self.phdr_load_re_index.?];
                                                                    ^
/home/mwa/code/zig/src/link.zig:279:82: 0x5555568c2b4b in link.File.allocateDeclIndexes (zig1)
            .elf => return @fieldParentPtr(Elf, "base", base).allocateDeclIndexes(decl),
                                                                                 ^
/home/mwa/code/zig/src/Module.zig:1181:59: 0x5555567eaf9b in Module.astGenAndAnalyzeDecl (zig1)
                try self.comp.bin_file.allocateDeclIndexes(decl);
                                                          ^
/home/mwa/code/zig/src/Module.zig:938:34: 0x55555665d6f9 in Module.ensureDeclAnalyzed (zig1)
        self.astGenAndAnalyzeDecl(decl) catch |err| switch (err) {
                                 ^
/home/mwa/code/zig/src/Compilation.zig:1275:38: 0x55555663251a in Compilation.performAllTheWork (zig1)
            module.ensureDeclAnalyzed(decl) catch |err| switch (err) {
                                     ^
/home/mwa/code/zig/src/Compilation.zig:1088:31: 0x55555662c317 in Compilation.update (zig1)
    try self.performAllTheWork();
                              ^
...

Activity

  1. g-w1 commented on Nov 14, 2020

    @g-w1
    Contributor

    Hi, just to note, export fn _start() noreturn {} is incorrect. {} returns void. You have to have an exit function that exits the code. This does not seem to change the outcome (it still crashes), but I thought it would be good to note.

  2. xackus commented on Nov 14, 2020

    @xackus
    ContributorAuthor

    I know, this is just a minimized example, but thanks anyway.

  3. added
    bug
    frontend
    on Nov 16, 2020
  4. added this to the 0.8.0 milestone on Nov 16, 2020
  5. modified the milestones: 0.8.0, 0.8.1 on Jun 4, 2021
  6. modified the milestones: 0.8.1, 0.9.1 on Aug 31, 2021
  7. modified the milestones: 0.9.1, 0.9.0, 0.10.0 on Nov 20, 2021
  8. modified the milestones: 0.10.0, 0.10.1 on Aug 24, 2022
  9. alichraghi commented on Nov 16, 2022

    @alichraghi
    Member

    i can't reproduce this anymore.

    $ cat z.zig
    pub fn main() void {}
    $ zig build-exe z.zig -fno-LLVM -fno-emit-bin
    $
    
    $ cat z.zig
    export fn _start() void {}
    $ zig build-obj z.zig -fno-LLVM -fno-emit-bin -target x86-freestanding-none
    $
    
  10. Vexu commented on Nov 16, 2022

    @Vexu
    Member

    The crash only happens in debug builds of the compiler.

  11. alichraghi commented on Nov 16, 2022

    @alichraghi
    Member

    im using a debug build

  12. Vexu commented on Nov 16, 2022

    @Vexu
    Member

    Hmm, I can't reproduce either using build-obj but with build-exe I get a crash somewhere else in the linker:

    thread 40117 panic: attempt to use null value
    link/Elf.zig:2322:17: 0x7d3c295 in getDeclPhdrIndex (zig)
    link/Elf.zig:2637:47: 0x7d4e718 in updateDeclExports (zig)
    
  13. alichraghi commented on Nov 16, 2022

    @alichraghi
    Member

    now i used a newer version (0.11.0-dev.4785+f5f1f8c66) and i get the same crash. but a bit older version (0.10.0-dev.4560+828735ac0) works fine

  14. modified the milestones: 0.10.1, 0.11.0 on Jan 10, 2023
  15. modified the milestones: 0.11.0, 0.12.0 on Apr 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugfrontend

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions