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

crash with x86_64 hello world with assembly #12365

Open
andrewrk opened this issue Aug 8, 2022 · 2 comments
Open

crash with x86_64 hello world with assembly #12365

andrewrk opened this issue Aug 8, 2022 · 2 comments
Labels
bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Milestone

Comments

@andrewrk
Copy link
Member

andrewrk commented Aug 8, 2022

This example from the language reference is crashing stage2:

stage3/bin/zig build-exe test.zig
thread 1564356 panic: reached unreachable code
???:?:?: 0x6a455c3 in ??? (???)
???:?:?: 0x7220050 in ??? (???)
???:?:?: 0x73cc5d9 in ??? (???)
???:?:?: 0x71931ab in ??? (???)
???:?:?: 0x701c448 in ??? (???)
???:?:?: 0x701acfb in ??? (???)
???:?:?: 0x73cbef9 in ??? (???)
???:?:?: 0x71e1218 in ??? (???)
???:?:?: 0x70228a6 in ??? (???)
???:?:?: 0x701acfb in ??? (???)
???:?:?: 0x6ed3c77 in ??? (???)
???:?:?: 0x6d50795 in ??? (???)
???:?:?: 0x6d4effd in ??? (???)
???:?:?: 0x6c86e2a in ??? (???)
???:?:?: 0x6c83fa1 in ??? (???)
???:?:?: 0x6ca9329 in ??? (???)
???:?:?: 0x6aacd79 in ??? (???)
???:?:?: 0x6a4463d in ??? (???)
???:?:?: 0x6a43eb7 in ??? (???)
Aborted (core dumped)
pub fn main() noreturn {
    const msg = "hello world\n";
    _ = syscall3(SYS_write, STDOUT_FILENO, @ptrToInt(msg), msg.len);
    _ = syscall1(SYS_exit, 0);
    unreachable;
}

pub const SYS_write = 1;
pub const SYS_exit = 60;

pub const STDOUT_FILENO = 1;

pub fn syscall1(number: usize, arg1: usize) usize {
    return asm volatile ("syscall"
        : [ret] "={rax}" (-> usize),
        : [number] "{rax}" (number),
          [arg1] "{rdi}" (arg1),
        : "rcx", "r11"
    );
}

pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize {
    return asm volatile ("syscall"
        : [ret] "={rax}" (-> usize),
        : [number] "{rax}" (number),
          [arg1] "{rdi}" (arg1),
          [arg2] "{rsi}" (arg2),
          [arg3] "{rdx}" (arg3),
        : "rcx", "r11"
    );
}

Bonus points if you fix the missing stage3 stack traces before fixing the underlying issue.

@andrewrk andrewrk added bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness. labels Aug 8, 2022
@andrewrk andrewrk added this to the 0.10.0 milestone Aug 8, 2022
@davidgm94
Copy link
Contributor

This hello world is no longer crashing

@davidgm94
Copy link
Contributor

How can I make this into a regression test? Where should I put it?

@andrewrk andrewrk modified the milestones: 0.10.0, 0.10.1 Oct 12, 2022
@andrewrk andrewrk modified the milestones: 0.10.1, 0.11.0 Jan 10, 2023
@andrewrk andrewrk modified the milestones: 0.11.0, 0.11.1 Jul 20, 2023
@andrewrk andrewrk modified the milestones: 0.11.1, 0.12.0, 0.13.0 Jan 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Projects
None yet
Development

No branches or pull requests

2 participants