0

I have a problem with clang and compiling/linking/preprocessing several files together.

Working situation:

If all of them are .c files, then I can use

clang -c -g -emit-llvm myfile1.c myfile2.c myfile3.c
# outputs myfile1.bc myfile2.bc myfile3.bc

Then, I'm linking with

llvm-link myfile1.bc myfile2.bc myfile3.bc -o merged.bc

However, I cannot do the same, if one of my files is an x86 assembly file.

clang -c -g -emit-llvm myfile4.s

Produces myfile4.o as an output. When I try to link them using llvm-link, I have the following output:

llvm-link: myfile4.o:1:1: error: expected top-level entity
ELF SOME GIBBERISH...

I need those .s files and I don't know how can I use this method. I have looked at this link and also to this link too.

Is there any method, way to achieve what I want to do?

  • 1
    You can't assemble x86 asm into LLVM-IR / bytecode. That would basically be a decompiler and LLVM doesn't include that. – Peter Cordes Feb 04 '20 at 13:37
  • Is there any decompiler that does such a thing? I am assuming that I need to decompile it to `.c` first –  Feb 04 '20 at 13:42
  • Yes there are decompilers that can produce C. Google it. IDK if there are any that are good and free. If your file was written in asm for a reason like needing to do non-standard stuff, it might not be possible. – Peter Cordes Feb 04 '20 at 14:01
  • I was trying to do fuzzing and injecting instructions into the assembly file. I want to see whether any injected instructions have any effect on the code or not. –  Feb 04 '20 at 14:16
  • Ok, so why don't you just compile it into an executable for that machine, instead of trying to make portable bytecode out of it? Doesn't `clang -g -O2 *.c *.s -o testprog` work? – Peter Cordes Feb 04 '20 at 14:29

0 Answers0