Hacker News new | ask | show | jobs
by goalieca 3036 days ago
Follow-up question, why can't LLVM -> Web Assembly solve the problem?
5 comments

The regular Go compiler doesn't use LLVM. It is derived from Plan9 compiler toolchain. There has been work on a LLVM Go compiler. There is also Gccgo, Go frontend for GCC, that could use GCC WebAssembly backend.
Could use dragonegg[1] to run gccgo through llvm and then through emscripten.

1: https://dragonegg.llvm.org/

It can, emscripten supports this, however the primary Go compiler doesn't use LLVM so this doesn't help really.
Emscripten does, but LLVM does without emscripten too.
This is kind of what I was getting at... other languages seem to have a webasm pipeline that includes LLVM. I wanted to know what what the difference was between go and these languages that require one to use something other than LLVM.
Besides the issue of Go main compilers not using LLVM, that would only be about the instructions.

There is no way around porting the runtime as well.

x86 elf -> wasm could solve this problem.
No, it wouldn't. At that point you already lost lots of information and your only option is to faithfully reproduce the behaviour of the x86 machine.

You can still do it, of course and performance isn't even that bad. See Fabrice Bellard's x86 emulator using asm.js.

https://bellard.org/jslinux/tech.html

Ok, pick a better ISA, like RISC-V.
That would take quite the effort to build, but I bet lifting to LLVM first might work: https://github.com/trailofbits/mcsema