-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
std.os.uefi: use std.os.uefi.cc instead of .C as calling convention #16339
Conversation
Well, I don't think On x86_64-linux with $ cat uefi.zig
pub fn main() void {
variadic(@as(u32, 1), @as(u8, 2), @as(i16, -3), @as([*:0]const u8, "hello"), false);
while (true) {}
}
fn variadic(...) callconv(.C) void {
var va_list = @cVaStart();
defer @cVaEnd(&va_list);
const h = @cVaArg(&va_list, u32);
const e = @cVaArg(&va_list, u8);
const l1 = @cVaArg(&va_list, i16);
const l2 = @cVaArg(&va_list, [*:0]const u8);
const o = @cVaArg(&va_list, bool);
@import("std").debug.panic("{} {} {} {s} {}\n", .{ h, e, l1, l2, o });
}
$ build/stage3/bin/zig run uefi.zig
thread 124435 panic: 1 2 -3 hello false Works. Change
Doesn't work (no panic output). Now as for the UEFI:
Doesn't work (no panic output). |
I tested this and this definitely compiles and these changes were done programmatically but if there's still anything wrong it shouldn't be hard to fix. With this change it's going to be very easy to make further adjustments to the calling conventions of all these external UEFI functions. Closes ziglang#16309
…c functions Now you can add new calling conventions that you confirmed to work with variadic functions simply in a single place and the rest will work automatically.
Does this correctly handle UEFI on ARM? ARM UEFI apparently uses the SMC calling convention, but Zig doesn't have such a calling convention. I haven't read enough of the spec PDF to know if that maps to another calling convention directly or if it's on LLVM to intuit the calling convention contextually. |
I don't think either LLVM or Zig has a calling convention called "SMC". This PR does not do any changes in that regard and for ARM it will keep using |
This change seems wrong. UEFI explicitly states that the Calling Convention used for ia32, x64, aarch32, aarch64, riscv and loongarch ("Intel Itanium-Based Platforms" use SAL) is the "the C language calling convention" (Sections 2.3.2 through 2.3.8). If the functions are not compiling correctly then the C calling convention is incorrect on UEFI. This shouldn't change anything because Win64 is the C calling convention for x86_64 UEFI. If the intent here was to make this work for OS stubs, then |
CC @oliver-giersch @billzez (if you got any input) Perhaps only the first commit of this PR could be reverted then. |
Please re-read the original issue #16309, where I tried to make sense of things as best I could and collected some references on what other languages/projects (including the Linux kernel) do. In the former case, this will produce incorrect assembly for any |
My argument is that this only fixes a very small part of the problem. Another thing to mention is that It may be easier for an EFI stub to actually target uefi and then link the stub into your kernel (like Linux without a compressed kernel) |
Ok I see. I guess it is at least some incremental progress and everything that is still broken was also broken before. I personally do not have the stomach right now to dive into various calling conventions for architectures I have no familiarity with. That said, I am not even sure, if there are any issues with other platforms. In #16309 I referenced the Linux definition for
Not sure what you mean, but in my test efi-stub kernel I've defined it as
Also not sure why that would be easier, I'd say it adds additional complexity to the build setup, but it may justified for other reasons that may not be obvious to me. |
std.os.uefi: use std.os.uefi.cc instead of .C as calling convention
I tested this and this definitely compiles and these
changes were done programmatically but if there's still anything wrong
it shouldn't be hard to fix.
With this change it's going to be very easy to make further adjustments
to the calling conventions of all these external UEFI functions.
Closes #16309