llvm-wasm
llvm-wasm copied to clipboard
Can't get this to work with LLVM 16.0.4
First of all thanks for this repository. This has been pretty informative and interesting.
I'm trying to replicate this repo using LLVM 16.0.4 instead of 14.0.6. I've successfully cross-compiled llc and lld. And i've got the resulting binary files. The issue arises when I try to compile the example LLVM IR, I get the following error:
this.program: error: /lib/wasm32-wasi/libc.a(__main_void.o): undefined symbol: main
Comparing the resulting main.o files from the 14 and 16 version respectively with wasm2wat I get the following:
14
(type (;0;) (func (result i32)))
(type (;1;) (func (param i32 i32) (result i32)))
(import "env" "__linear_memory" (memory (;0;) 1))
(import "env" "printf" (func (;0;) (type 1)))
(import "env" "__indirect_function_table" (table (;0;) 0 funcref))
(func $__original_main (type 0) (result i32)
i32.const 0
i32.const 0
call 0
drop
i32.const 0)
(func $main (type 1) (param i32 i32) (result i32)
call $__original_main)
(data $.L.str (i32.const 0) "Hello wasm!\0a\00"))
16
(type (;0;) (func (result i32)))
(type (;1;) (func (param i32 i32) (result i32)))
(import "env" "__linear_memory" (memory (;0;) 1))
(import "env" "printf" (func (;0;) (type 1)))
(func $__original_main (type 0) (result i32)
i32.const 0
i32.const 0
call 0
drop
i32.const 0)
(func $main (type 1) (param i32 i32) (result i32)
call $__original_main)
(data $.L.str (i32.const 0) "Hello wasm!\0a\00"))
The only noticeable difference I can see is the lack of the (import "env" "__indirect_function_table" (table (;0;) 0 funcref)) instruction on the 16 version. But I don't know how to tell the compiler to add that instruction.
Searching for an answer I found that that __original_main main should no longer be generated with the new LLVM versions (from 14 onwards), but yours is 14 and still has it, so I don't know what that means.
You can try it on my fork, here, in case you have time and want to take a look.
Hey @TGMM, thanks for checking this out!
I was able to get it to work with the existing instructions, though I also had to update emsdk (3.1.21 -> 3.1.40) and WASI (15 -> 20).
I've updated the README with the updated versions - can you try it again?
Hello, thank you for your response.
I forgot to mention I also updated the emsdk and WASI versions when I compiled mine. I used 3.1.39 I believe (since 3.1.40 wasn't out yet).
I tried following the instructions again (which were almost exactly what I did the first time). But I continue getting the same error this.program: error: /lib/wasm32-wasi/libc.a(__main_void.o): undefined symbol: main when trying to run the demo.
Is there a way you could share your resulting files so I can compare them with mine? Could there be anything in my environment that's different to yours that's causing this issue? In the meantime, I'll try to make a Docker image following your steps and see if that works.
EDIT: I forgot to mention I'm compiling this on a Windows machine using WSL2.
Hey, sorry for the late response!
So it turns out that I was also having the undefined symbol: main issue - I couldn't reproduce it previously because I didn't properly replace the llc/lld build assets.
I was able to nail down the cause to a missing symbol in the LLVM IR placeholder, so it had nothing to do with the build steps after all. Let me know if that works!