返回结构在寄存器 - 在GCC ARM ABI [英] Returning structs in registers - ARM ABI in GCC

查看:309
本文介绍了返回结构在寄存器 - 在GCC ARM ABI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ARM ABI文档我遇到像定义函数:

In the ARM ABI documentation I come across functions defined like:

__value_in_regs struct bar foo(int a, int b) {
    ...
}

但GCC( 4.3.3 的)不允许它和所有我能找到的都在一定的的RealView 的编译器引用。
有没有从GCC这样做的方法吗?

but GCC(4.3.3) doesn't allow it and all I could find are references to some RealView compiler. Is there any way of doing this from GCC?

我曾尝试-freg-结构回报,但它不会有所作为。由于这是一个ABI我不能改变原来的计划,并返回一个常规结构轧液堆栈。

I have tried -freg-struct-return but it doesn't make a difference. As it is an ABI I can't change the original programs, and returning a regular struct mangles the stack.

我宁可不使用汇编本,如果可以避免的,因为它没有其他必要的。

I would rather not using assembly for this if avoidable as it isn't otherwise necessary.

谢谢!

推荐答案

发帖按要求回答:

如果您需要生成二进制,将与ABI工作中的编译器不支持,你是在一些麻烦。有什么可以在C做在这种情况下,你需要求助于汇编语言编程和咚必要的电话。有两种可能性:

If you have to generate a binary that will work with an ABI your compiler doesn't support, you're in for some trouble. There's nothing you can do in C. In this case, you'll need to fall back on assembly language programming and thunk the necessary calls. There are two possibilities:


  1. 从二进制文件到其他二进制的ABI呼叫。

  2. 从其他二进制到二进制的ABI呼叫。

这两个问题被类似地解决。若要从code叫唤,你就需要在装配,围绕调用约定相匹配的外部ABI调酒垫片的功能,然后从那里调用外部函数。到C code不同的是,现在做外部呼叫,你打电话给你的内部汇编程序,它也不管它需要从外部调出,然后把返回值回来格式的C $ C $按c理解和回报。

Both of these problems are solved similarly. To call out from your code, you'll need to make shim functions in assembly that swizzle around the calling convention to match the external ABI, and then call the external functions from there. The difference to your C code is that now to make external calls, you call your internal assembly routine, and it does whatever it needs to to call out externally, then puts the return value back in a format your C code will understand, and returns.

要支持从外部的二进制调用的的您code,你做同样的事情,但在相反。入口点到你的二进制文件将小组装例程调酒外部ABI到C code能理解,请与内部函数的格式,然后将返回值回一个格式外部code了解到,而归。

To support calls from the external binary into your code, you do the same thing, but in reverse. The entry points to your binary will be little assembly routines that swizzle the external ABI into a format your C code can understand, call your internal function, then put the return values back into a format the external code understands, and return.

有时只是没有很好的解决方案,我害怕。

Sometimes there's just no good solution, I'm afraid.

这篇关于返回结构在寄存器 - 在GCC ARM ABI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆