ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
35.37k stars 2.58k forks source link

Zig 0.11.0 Regression: callconv(.Interrupt) on x86_64 causes ToDo error message #16635

Open ethindp opened 1 year ago

ethindp commented 1 year ago

Zig Version

0.11.0-dev.4321+235e6ac05

Steps to Reproduce and Observed Behavior

This is quite strange, but for whatever reason, the following two function declarations cause a todo (llvm) error (duplicate asm input name 'rax'):

fn handleDebug(frame: InterruptStackFrame) callconv(.Interrupt) void {

And:

fn handleBreakpoint(frame: InterruptStackFrame) callconv(.Interrupt) void {

This doesn't appear to happen on any other interrupt, according to the compile log:

zig build-exe kernel Debug x86_64-freestanding-none: error: the following command failed with 3 compilation errors:
C:\Users\ethin\scoop\apps\zig\current\zig.exe build-exe C:\Users\ethin\source\kernel\src\main.zig C:\Users\ethin\source\kernel\src\arch\x86.s --cache-dir C:\Users\ethin\source\kernel\zig-cache --global-cache-dir C:\Users\ethin\AppData\Local\zig --name kernel -mcmodel kernel -target x86_64-freestanding-none -mcpu x86_64-mmx+soft_float-sse-sse2 --script C:\Users\ethin\source\kernel\src\link.ld --listen=-
Build Summary: 0/3 steps succeeded; 1 failed (disable with --summary none)
install transitive failure
+- install kernel transitive failure
   +- zig build-exe kernel Debug x86_64-freestanding-none 3 errors
src\arch.zig:305:1: error: TODO (LLVM): duplicate asm input name 'rax'
fn handleDebug(frame: InterruptStackFrame) callconv(.Interrupt) void {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src\arch.zig:310:1: error: TODO (LLVM): duplicate asm input name 'rax'
fn handleBreakpoint(frame: InterruptStackFrame) callconv(.Interrupt) void {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src\terminal.zig:47:13: error: root struct of file 'arch' has no member named 'hault'
        arch.hault();
        ~~~~^~~~~~

Expected Behavior

This should correctly generate interrupt functions.

jacobly0 commented 1 year ago

The error suggests that you have an asm somewhere in the functions with duplicate input [name]s.

ethindp commented 1 year ago

@jacobly0 I fixed that but I still get the "unsupported x86 interrupt prototype" bug. Will have to look into LLVM's code apparently.

ethindp commented 1 year ago

Regardless, I think the error message should be a bit more helpful; as it currently stands, it makes it look like it's not actually a problem with my code but a problem in Zig.

david4r4 commented 1 year ago

Kind of offtopic, but I am pretty sure you never want to rely on the compiler for interrupt handler assembly and instead you want to write your own (it's not that hard).

ethindp commented 1 year ago

@davidgm94 Point taken

jacobly0 commented 1 year ago

This should be checked in Sema/AstGen where a better error message can be produced, so using this issue to track that.

@jacobly0 I fixed that but I still get the "unsupported x86 interrupt prototype" bug. Will have to look into LLVM's code apparently.

For this aspect of the issue, see #11661