leaningtech/webvm

Support for GHC

Closed this issue · 4 comments

I forked WebVM here and am trying to get GHC working. With this Dockerfile I'm getting errors like this after startup:

/opt/ghc/9.10.1/lib/ghc-9.10.1/bin/./ghc-9.10.1: error while loading shared libraries: libHShaskeline-0.8.2.1-161b-ghc9.10.1.so: cannot open shared object file: No such file or directory

And errors like this in the JavaScript console:

TODO: READLINK PATH /proc/self/exe LEN 4096

and finally

Fault addr 0, ip 556b9106

Thanks for reporting this, we'll investigate this when we can. The readlink message is most likely not the problem, so I'll update the title to reflect this.

Thanks for your patience, GHC is now working on the currently deployed version of WebVM, please be aware that due to CDN caching it might take a while for the updated version to be available everywhere.

/opt/ghc/9.10.1/lib/ghc-9.10.1/bin/./ghc-9.10.1: error while loading shared libraries: libHShaskeline-0.8.2.1-161b-ghc9.10.1.so: cannot open shared object file: No such file or directory

The initial problem is actually quite obvious and not a WebVM bug. The libraries for GHC are installed in /opt which is not part of the standard library path. The same error would happen in native. To fix this you need to add this environment variable

LD_LIBRARY_PATH=/opt/ghc/9.10.1/lib/ghc-9.10.1/lib/i386-linux-ghc-9.10.1/

A few additional fixes were also required to our syscalls implementation, but nothing major. Thanks for reporting this.

It's not obvious to me why I have to set LD_LIBRARY_PATH myself here, this seems like a WebVM-specific implementation detail. I don't agree that the same thing happens natively, since I have a similar setup using container2wasm and this Dockerfile, and I don't have to touch LD_LIBRARY_PATH anywhere to get that to work (you can see that here). In any case, thanks for your extremely helpful response!

You are right, LD_LIBRARY_PATH is not required since the executable uses RUNPATHs internally. These were not working correctly due to the missing /proc/self/exe symlink.

The problem is now fixed and the application can start correctly without defining any additional environment variable. Don't forget to rebase your fork on the updated webvm repo, proc was not previously mounted.

As usual take into account that the CDN might cache the older build for a few days.