Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 990
lol lol Avatar asked Sep 12 '25 12:09

lol lol


1 Answers

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.

like image 183
Peter Cordes Avatar answered Sep 16 '25 00:09

Peter Cordes