如何从 LLVM IR 交叉编译到 ARM Cortex M4 的汇编?
我正在尝试使用 llc 编译器将 llvm-ir 文件交叉编译为程序集,或者更好地生成目标文件,用于 ARM Cortex M4 微处理器。
为此我必须指定哪些参数? 我尝试过这个命令llc -mtriple=armv7m-eabi -mcpu=cortex-m4 file.ll -o file.s
它不会抛出任何错误,但生成的汇编代码仍然适用于 x86 机器。
特别是,尝试使用随机参数进行编译,例如llc -mtriple=randomwords -mcpu=cortex-m4 file.ll -o file.s
它运行得很顺利,为 x86 机器生成了汇编代码。它忽略我指定的内容。
I'm trying to cross-compile an llvm-ir file to assembly, or better generate an object file, for an ARM Cortex M4 microprocessor using llc compiler.
Which are the parameters that I have to specify in order to do so?
I have tried with this commandllc -mtriple=armv7m-eabi -mcpu=cortex-m4 file.ll -o file.s
It doesn't throw any error but the assembly code generated is still for an x86 machine.
In particular, trying to compiling with random parameters, e.g.llc -mtriple=randomwords -mcpu=cortex-m4 file.ll -o file.s
It goes smooth, producing an assembly code for the x86 machine. It ignores what I specify.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我找到了解决方案,或者更好地解决了这个问题。
我没有直接使用 llc,而是首先通过此命令获取了二进制代码
llvm-as file.ll -o file.bc
然后我使用 clang 交叉编译并使用此指令获取 ARM Cortex M4 的目标文件
clang --target=arm-none-eabi -march=armv7e-m -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -nostdlib file.bc -c -o文件.o
-c
仅用于编译。也可以通过以下命令行获取汇编代码
clang -S --target=arm-none-eabi -march=armv7e-m -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -nostdlib file.bc -o文件.s
I found a solution, or better a work around to this problem.
Instead of using directly llc, first I've obtained the binary code through this command
llvm-as file.ll -o file.bc
An than I used clang to crosscompile and obtain the object file for ARM Cortex M4 using this instruction
clang --target=arm-none-eabi -march=armv7e-m -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -nostdlib file.bc -c -o file.o
The
-c
is used to compile only.It is also possible to obtain the assembly code by using the following command line
clang -S --target=arm-none-eabi -march=armv7e-m -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -nostdlib file.bc -o file.s
llc(在 v9 之前不确定)似乎只关心架构。
我可以使用以下脚本进行交叉编译和链接(对于运行 Linux 的 RPI):
llc --version 将显示可用的架构
根据您的情况尝试以下操作(或者使用更具体的架构,如果它在列表中):
llc (not sure about prior to v9) seems to only care about the architecture.
I can cross compile and link with the following script (for a RPI running Linux):
llc --version will show the available architectures
Try the following for your case (or use a more specific architecture if it is in the list):