问题
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