lol lol
lol lol

Reputation: 491

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

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.

Upvotes: 4

Views: 5449

Answers (1)

Peter Cordes
Peter Cordes

Reputation: 364180

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.

Upvotes: 4

Related Questions