Adding a new build target - What is `adjust_for_foreign_abi` even supposed to do?

pub fn adjust_for_foreign_abi<C>(
        &mut self,
        cx: &C,
        abi: spec::abi::Abi,
    ) -> Result<(), AdjustForForeignAbiError>

Implementing this is necessary for supporting a new ISA's ABI. This is usually done via implementing isa_name::compute_abi_info(cx, self). However i found the documentation FnAbi in rustc_target::abi::call - Rust not very insightful in what exactly i need to specify. In my current understanding the application of Rust then LLVM which also tries to enure the calling convention https://github.com/llvm/llvm-project/blob/main/llvm/lib/Target/Hexagon/HexagonCallingConv.td together need to uphold the calling convention.

Any resources on adjust_for_foreign_abi or explanations and it's responsibilities would be very welcome.

Every ABI has rules on how to lower complex user facing types like structs into primitive types like integers and pointers. adjust_for_foreign_abi implements those rules. After that LLVM handles assigning those primitive values to the right registers and stack locations. While LLVM can lower complex types, it does so in a way not conforming to any C ABI. Every frontend has to implement this lowering. If you want a reference on how to implement it for your target you could look at the implementation in clang. I believe multiple of the rustc implementations link to their clang counterpart.

I have now understood pub fn compute_abi_info<Ty>(fn_abi: &mut FnAbi<'_, Ty>) gets a struct representing the return value and an array of argument structs. All of these need to have the .mode field set. This should respect the Conv field showing which convention is in force. The context is used to keep track of parts of complicated ISAs like SPARC.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.