vnmakarov / mir

A lightweight JIT compiler based on MIR (Medium Internal Representation) and C11 JIT compiler and interpreter based on MIR
MIT License
2.24k stars 147 forks source link

Disabling red-zone when using system-v abi #301

Closed Itay2805 closed 1 year ago

Itay2805 commented 1 year ago

We are using mir on a bare-metal application and we just found out that when using the sysv abi it will use the red-zone, sadly on bare-metal using red-zone is not supported (the cpu does not know of red-zone and when an interrupt jumps it will override the area after the stack pointer, corrupting the red-zone).

Is there a way to make MIR not use the red-zone?

Btw we tried using MSABI as a workaround for now but we rely on using multiple-return arg, so that plan does not work...

Also it would be nice to know what mir uses the red-zone for exactly, we saw that for Long-Double it uses it explicitly, but is there anything else that it uses it for?

vnmakarov commented 1 year ago

Yes, I guess it is possible. But it will result in less efficient prologue code generation.

I can introduce a macro to generate prologue w/o using red-zone but still I'd like to use red zone by default.

I'll try to implement this on the next week.

Itay2805 commented 1 year ago

Yeah I think red-zone should be used by default, but having a macro to disable it would be perfect 😄

vnmakarov commented 1 year ago

I've added macro MIR_NO_RED_ZONE_API. Defining it results in no usage of red zone in x86-64 generated code:

https://github.com/vnmakarov/mir/commit/7528f3fdeffc2db2dbc581f64c57f43a105c5047

I did not find that other targets use red zone (some of them even have no red zone notion in their ABI).

Itay2805 commented 1 year ago

Thank you very much! Will try it out ASAP.

And yeah in general I think red-zone is only an x86 abi thing, never seen it on any other arch.