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

我与影子孤独终老i 提交于 2020-05-23 21:43:11

问题


I compiled .S file using command:

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

I found, that .o file was generated in ELF format. I was expected to see llvm-ir format (with "BC" characters at the beginning of resulting file).

Seems, Clang ignores "-emit-llvm" flag.


回答1:


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?.

asm source and binary executables / object files are basically equivalent for this problem. You're still trying to decompile to LLVM-IR. This is hard, and I don't know if a decompiler exists.

Seems, Clang ignores "-emit-llvm" flag.

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.

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.

So no LLVM-IR representation of the program ever existed while clang was running, so there was nothing to emit.



来源:https://stackoverflow.com/questions/56145015/is-it-possible-to-get-llvm-ir-from-assembly-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!