linux – 编写LLVM后端编译的代码时,架构是否重要?

前端之家收集整理的这篇文章主要介绍了linux – 编写LLVM后端编译的代码时,架构是否重要?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我的问题实际上比标题更通用:

在编写最终将编译为LLVM中间代码,然后从那里到机器语言的代码时,架构在什么时候起作用?

>假设我正在编写Rust(它使用LLVM作为后端).我是否能自动将Rust代码编译为LLVM可以定位的每个体系结构(假设该机器上有可以运行它的操作系统)?
>或者可能是Rust标准库还没有“ARM兼容”,所以即使LLVM以它为目标我也无法编译到ARM?
>如果我不使用任何标准库,我的整个程序只是一个立即返回的程序怎么办?可能是这样的情况,即使没有任何库,Rust(或者你有什么)也无法编译到ARM(或者你有什么),即使LLVM以它为目标?
>如果以上所有示例都编译得很好,我需要做些什么来使我的代码在一个架构上打破而不编译到某个架构?

相同品种的奖金问题:

>假设标准库使用OS系统调用(肯定会这样).在进行系统调用时,您是否需要关心架构?或者OS(例如Linux)是否也抽象了架构呢?

谢谢.

解决方法

TL; DR

根据我的理解,你可以编译到任何目标LLVM支持(这里可能仍有一些注意事项使用inline assemblermodule level inline assembly前端),但是,你不能保证它实际上会正确执行.前端负责在作者支持的平台上进行可移植的工作.

另请注意,作为前端开发人员,您负责提供data layouttarget triple.

也可以看看:

> llvm-bitcode-cross-platform
> llvm
FAQ

> Implementing Portable
sizeof

> Cross Compile with Clang

你的问题:

Let’s say I’m writing Rust (which uses LLVM as a backend). Am I
automatically capable of compiling my Rust code to every architecture
that LLVM can target (assuming there’s an OS on that machine that can
run it)?

这取决于Rust前端的作者.

Or could it be that the Rust standard library hasn’t been made “ARM
compatible” yet,so I couldn’t compile to ARM even if the LLVM targets
it?

我很确定LLVM能够发出指令,但在寻址方面可能不正确.

我自己没有使用上面提到的内联汇编程序设备,但我认为如果它允许特定于平台的程序集,那么这也会破坏平台不可知的编译.

What if I don’t use any of the standard library,my entire program is
just a program that returns right away? Could it be the case that even
without any libraries,Rust (or what have you) can’t compile to ARM
(or what have you) even if the LLVM targets it?

这又取决于Rust前端发出的内容.甚至在它发出逻辑指令之前,它可能会发出一些样板设置逻辑.

我在LLVM中编写自己的语言,在称为“main”的特殊函数的情况下执行此操作.我的目标是C ABI,因此它将使用适当的C样式main来包装此main,并使用更严格的参数集调用它.

If all the above examples compile just fine,what do I have to do to
get my code to break on one architecture not compile to a certain
architecture?

考虑使用Clang中的C/C++,如llvm FAQ中所述.Clang是LLVM的前端,可能是最受欢迎的,并且编写C/C++的用户负责#included-ing适当的平台特定功能.

有些语言可能设计得更加独立于平台,而前端可以为您处理工作.

Let’s say the standard library makes use of OS system calls (which is
surely does). Do you have to care about architecture when making
system calls? Or does the OS (Linux,for example) abstract away
architecture as well?

我假设您正在讨论前端针对C标准库的情况,在这种情况下,LLVM具有可由前端使用的standard C library intrinsics.但是,这不是唯一的方法,因为如果在Kaleidoscope example中定位C ABI,则可以使用call instruction直接调用C函数.

最后,标准库可能是一个可移植性问题,必须由前端开发人员解决.

原文链接:https://www.f2er.com/linux/394804.html

猜你在找的Linux相关文章