简体   繁体   English

是否可以从程序集文件中获取 LLVM-IR?

[英]Is it possible to get LLVM-IR from Assembly file?

I compiled .S file using command:我使用命令编译了 .S 文件:

clang-8 -c funcs.s -o funcs.o -emit-llvm

I found, that .o file was generated in ELF format.我发现,.o 文件是以 ELF 格式生成的。 I was expected to see llvm-ir format (with "BC" characters at the beginning of resulting file).我预计会看到 llvm-ir 格式(在结果文件的开头带有“BC”字符)。

Seems, Clang ignores "-emit-llvm" flag.似乎,Clang 忽略了“-emit-llvm”标志。

Your question isn't fundamentally different from Is it possible to translate an assembly language to LLVM IR, optimize it and then recompile it to a different architecture?您的问题与Is it possible to translate an assembly language to LLVM IR, 优化它,然后将其重新编译为不同的体系结构并没有根本的不同 . .

asm source and binary executables / object files are basically equivalent for this problem. asm 源代码和二进制可执行文件/目标文件对于这个问题基本上是等价的。 You're still trying to decompile to LLVM-IR.您仍在尝试反编译为 LLVM-IR。 This is hard, and I don't know if a decompiler exists.这很难,我不知道是否存在反编译器。

Seems, Clang ignores "-emit-llvm" flag.似乎,Clang 忽略了“-emit-llvm”标志。

No, it just didn't affect any of the steps involved in the operation you asked it to do.不,它只是不影响您要求它执行的操作中涉及的任何步骤。

You asked your compiler to compile to a .o , so it did so.您要求编译器编译为.o ,所以它这样做了。

If the input had been .c and the output a .s , it would have been able to emit LLVM-IR, but in this case LLVM-IR wasn't part of the process of assembling a .s to a .o .如果输入是.c ,输出是.s ,它就可以发出 LLVM-IR,但在这种情况下,LLVM-IR 不是将.s组装到.o的过程的一部分。

So no LLVM-IR representation of the program ever existed while clang was running, so there was nothing to emit.因此,当clang运行时,程序的 LLVM-IR 表示不存在,所以没有任何东西可以发出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM