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

Call functions in naked function #18183

Open
xtexx opened this issue Dec 2, 2023 · 3 comments
Open

Call functions in naked function #18183

xtexx opened this issue Dec 2, 2023 · 3 comments
Labels
bug Observed behavior contradicts documented or intended behavior

Comments

@xtexx
Copy link
Contributor

xtexx commented Dec 2, 2023

Zig Version

0.12.0-dev.1769+bf5ab5451

Steps to Reproduce and Observed Behavior

In #7286, it is said that function calls in naked functions must have explictly-specified stack.
However, the stack option was removed in #13907.
Now, there are no way to call functions in naked functions but inline assembly.

src/main.zig:48:5: error: runtime @call not allowed in naked function
    @call(.auto, main, .{});
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expected Behavior

someway to call functions

@xtexx xtexx added the bug Observed behavior contradicts documented or intended behavior label Dec 2, 2023
@xtexx
Copy link
Contributor Author

xtexx commented Dec 2, 2023

To set stack manually:

    asm volatile (
        \\ movl %[stk], %esp
        \\ movl %esp, %ebp
        :
        : [stk] "{ecx}" (@intFromPtr(&stack) + @sizeOf(@TypeOf(stack))),
    );

@Ev1lT3rm1nal
Copy link

@andrewrk Is there zig way to set the stack?

@jiacai2050
Copy link
Contributor

For zig version >= 0.13, I use this code to setup the stack(use rbp for 64 bit OS).

export fn _start() callconv(.Naked) noreturn {
    asm volatile (
        \\ push %ebp
        \\ jmp %[start:P]
        :
        : [start] "X" (&main),
    );
}

pub fn main() void {
  ... 
}

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
Projects
None yet
Development

No branches or pull requests

3 participants