Proposal: Access pre-mangled program symbols from inline assembly #5211
Labels
proposal
This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone
(UPDATED, AGAIN AND AGAIN AND AGAIN -- syntax is from #5241)
Currently, inline assembly is limited by its dependence on surrounding code to integrate with the rest of the program. This means certain functions that would make more sense as external assembly programs, such as those that run in stackless contexts, need inelegant hacks to work, such as using globals to pass values between them. Much tighter integration could be achieved if inline assembly had facilities to safely refer to program symbols directly.
I propose we do this with
@
, like@[variable]
and@(function)
, to fit with the local/global convention employed in ZIR (and escape a literal@
with@@
, just like we do for%
). The compiler can mangle the symbols and perform any optimisations it likes, and any@
's will point to the correct location for the expected behaviour. For instance, here's a simple bare metal OS entry point on RISC-V:With this, you can mix and match assembly and Zig however you like. There is very little friction to just writing pure assembly functions in a Zig wrapper, or writing your own callsite-controlled "calling conventions" for naked functions, or whatever else.
The text was updated successfully, but these errors were encountered: