Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't get this to work with LLVM 16.0.4 #1

Open
TGMM opened this issue May 23, 2023 · 3 comments
Open

Can't get this to work with LLVM 16.0.4 #1

TGMM opened this issue May 23, 2023 · 3 comments

Comments

@TGMM
Copy link

TGMM commented May 23, 2023

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.

@soedirgo
Copy link
Owner

soedirgo commented Jun 3, 2023

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?

@TGMM
Copy link
Author

TGMM commented Jun 4, 2023

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.

@soedirgo
Copy link
Owner

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants