llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.92k stars 11.52k forks source link

Surface better error information for “function named more than once” in Wasm linking #61555

Open j-f1 opened 1 year ago

j-f1 commented 1 year ago

I’m trying to debug an issue where wasm-ld from emscripten fails with the error error: ../lib/.libs/libosp.dylib: function named more than once. That error is raised here:

https://github.com/llvm/llvm-project/blob/72073fc95cd4793a853925ddc8cc3fb2118808a5/llvm/lib/Object/WasmObjectFile.cpp#L481-L482

It’s really hard to debug what’s going wrong without more detail — would it be possible to surface some information about what the name of the function is, where in the file the issue is occurring, and where the previous naming occurred in this error message?

llvmbot commented 1 year ago

@llvm/issue-subscribers-lld-wasm

sbc100 commented 1 year ago

IIUC this would be an invalid object file, so its not something normal users should ever see.

Using wasm-objdump -x (this tools is part of wabt) is probably the best way to take a look at the name section. Within the name section each function should have exactly one name. In this case it seems like you have function with more than one name, which is illegal. How did you create this object file?

Actually object files should not have a name section at all... so something odd is going on. What type of file is libosp.dylib and how did you create it? Could you attach the file perhaps?

j-f1 commented 1 year ago

How did you create this object file?

I’m trying to build this package for Wasm and I pretty much ran autoconf and then make and have been working through the various errors.

Attached the output of wasm-objdump -x ../lib/.libs/libosp.dylib and the file itself.

file ../lib/.libs/libosp.dylib outputs WebAssembly (wasm) binary module version 0x1 (MVP).

objdump.txt.zip libosp.5.0.0.dylib.zip

EDIT: wasm-objdump outputs this to stderr: 074b63a: warning: unable to read u32 leb128: function index

sbc100 commented 1 year ago

Yes I noticed that warning too.. that is worrying.

From the looks of it that dylib file is actually a single object file created by emcc -shared. With the emscripten toolchain shared libraries are kind of "faked" by default and are in fact just normal object file produced by linking objects together using wasm-ld -r. In this case the combined object file seems to have issues, and its probably worth investigating more.

In them mean time, and in general, my advice to you would be to pass --disable-shared to your configure step and just use normal .a archive. This normally works much better, since emscripten doesn't really support traditional shared libraries, whereas it has good support for .a archive.

j-f1 commented 1 year ago

Thanks for the help! That seemed to fix the issue, but I’m now hitting https://github.com/emscripten-core/emscripten/issues/10719 and am thinking that getting this thing to build might be more than I can handle 😅