çABI与LLVM [英] C ABI with LLVM

查看:221
本文介绍了çABI与LLVM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经得到了与LLVM写一个编译器,我希望我的ABI的兼容性。例如,我发现很难找到真正的Windows的x86或Linux对于C ABI规范文件。而且我发现的那些解释在RAX / EAX /等​​方面,而不是我可以使用IR条款。

I've got a compiler written with LLVM and I'm looking to up my ABI compliance. For example, I've found it hard to actually find specification documents for C ABI on Windows x86 or Linux. And the ones I have found explain it in terms of RAX/EAX/etc, rather than IR terms that I can use.

到目前为止,我想我已经想通了LLVM对待invisibly-也就是说,它认为自己的成员每一个不同的参数聚集。因此,例如,在Windows 64,如果我要处理的集合类的文件说,我需要强制该大小的一个整数,如果8,16,32或64位。否则,指针传递。

So far, I think I've figured that LLVM treats aggregates invisibly- that is, it considers their members as a distinct parameter each. So for example, on Windows x64, if I want to handle an aggregate like the document says, I'll need to coerce to a single integer of that size, if 8, 16, 32, or 64 bits. Otherwise, pass by pointer.

对于Windows 86,好像__cdecl和所有的参数都在栈上传递__stdcall并不需要我做任何动作。 __fastcall说,前两个32位或更小的参数是寄存器传递,因此我需要胁迫该尺寸或更小的集合体。 __thiscall通过这个在寄存器中,并在栈上休息,所以好像我不需要在这里进行任何调整。

For Windows x86, it seems like __cdecl and __stdcall don't need any action from me as all parameters are passed on the stack. __fastcall says that the first two 32bit or smaller arguments are register-passed so I'll need to coerce aggregates of that size or less. __thiscall passes this in a register, and the rest on the stack, so it seems like I won't need to perform any adjustment here.

有关__vectorcall,通过聚集不超过的sizeof(无效*)由整数强制多。对于其他的集合体,如果是高速电弧喷涂然后按值传递;否则按值传递在x86或指针在x64上通过。

For __vectorcall, pass aggregates not more than sizeof(void*) by integer coercion. For other aggregates, if they are HVAs then pass by value; else pass by value on x86 or pass by pointer on x64.

这似乎很简单(当然,相对而言),但LLVM文档的六重峰明确规定这表明到code发生器参数或返回值被符号扩展到由目标的ABI(通常是32位)由呼叫者(为一个参数)或被叫方(为一个返回值)所要求的程度。针对x86调用约定的微软页面没有提及任何有关扩展到任何宽度。

This seems simple (well, relatively), but the LLVM docs for sext clearly state "This indicates to the code generator that the parameter or return value should be sign-extended to the extent required by the target’s ABI (which is usually 32-bits) by the caller (for a parameter) or the callee (for a return value).". The Microsoft pages for the x86 calling conventions mention nothing about extending anything to any width.

和我观察到锵产生的LLVM IR生成Wi​​ndows上的 BYVAL 属性。我从上面收集的认识从来没有要求 BYVAL 的使用情况。

And I've observed the LLVM IR generated by Clang that generates the byval attribute on Windows. The understanding I've gleaned from the above never calls for byval's usage.

我将如何降低各种平台的C的ABI到LLVM IR?

How would I lower the various platform C ABIs to LLVM IR?

推荐答案

我不能说我明白你的问题100%,但值得注意的是,LLVM IR根本无法再present平台的ABI的所有细微之处。因此,在锵工具链,这是这是负责执行ABI降低,如通过适当的值传递对象,功能等方面的前端。

I can't say I understand your question 100%, but it's worth noting that LLVM IR simply can not represent all the subtleties of platform ABIs. Therefore, in the Clang toolchain, it is the frontend that's responsible for performing ABI lowering, such as properly passing objects by value to functions, etc.

看看在锵源代码树中定义的lib /基本/ Targets.cpp 。血淋淋的细节进一步在的lib / codeGEN / TargetInfo.cpp

Take a look at lib/Basic/Targets.cpp in the Clang source tree for the definitions. The gory details are further in lib/CodeGen/TargetInfo.cpp

这篇关于çABI与LLVM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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