Compiling to LLVM IR

237 views
Skip to first unread message

Yugesh Kothari

unread,
Nov 3, 2020, 7:36:22 PM11/3/20
to emscripten-discuss
Hi,

I am trying to look for a way to compile C/C++ source written with emsripten headers to LLVM IR (.ll or .bc) and then subsequently use smack (https://github.com/smackers/smack) to get it to boogie. I use the command :

emsdk/upstream/bin/clang++ --target=wasm64 `em++ --cflags` -emit-llvm -S <file>.cpp -o <file>.ll

which runs. But then when I try to use smack I get this error:
"Exception: Problem reading input bitcode/IR: Invalid record".

I run into the same problem if I try to compile down the above llvm to an executable using llc.

I suspect this has something to do with how I originally compiled my C++ source. Can someone suggest what is the "right" way to get LLVM IR and .js+.wasm instead of just the latter?

Thanks!

Thomas Lively

unread,
Nov 3, 2020, 7:51:46 PM11/3/20
to emscripte...@googlegroups.com
What version of LLVM does Smack support? Since Emscripten uses tip-of-tree LLVM, my guess is that the LLVM IR you're getting is too new for Smack to read. It's hard to say from just that error message, though.

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/003bfb97-7658-4291-93b0-46f8ec3cd03cn%40googlegroups.com.

Yugesh Kothari

unread,
Nov 3, 2020, 10:58:55 PM11/3/20
to emscripten-discuss
Ah yes. This could be the reason as well.
smack uses LLVM 10.0.1 and i just saw that my emsdk has llvm version 12.0.0git.

How can I install emsdk for a specific version of LLVM? Are particular versions of the sdk tied to particular versions of LLVM?

Sam Clegg

unread,
Nov 5, 2020, 11:25:30 AM11/5/20
to emscripte...@googlegroups.com
Firstly you won't want to be using `--target=wasm64` at all right now, it is experimental and not supported by any engines yet.    Lucky `em++ --cflags` is going to contain its own `--target=wasm32-unknown-emscripten` so that is probably unrelated to your current failure.

Secondly, if you want emcc to produce bitcode you can simply add `-emit-llvm` to you normal emcc command:
  em++ -c -emit-llvm -S <file>.cpp -o <file>.ll
or 
  em++ -c -emit-llvm <file>.cpp -o <file>.bc

If you want to combine the bitcode files into a single large bitcode file we do also still have legacy support for that via the `-r` + `-flto` flags.

  em++ -r -flto  <file1>.bc <file2>.bc -o whole-program.bc

But this kind of bitcode linking has some caveats and I would not recommend it.  Avoid it if you can.

cheers,
sam



On Tue, Nov 3, 2020 at 4:36 PM Yugesh Kothari <kothar...@gmail.com> wrote:
--
Reply all
Reply to author
Forward
0 new messages