Bug#1010932: wasm-ld-13: unable to find library -lgcc

Faidon Liambotis paravoid at debian.org
Fri Jul 8 00:59:52 BST 2022


Hi Jérémy,

On Sat, May 14, 2022 at 02:44:25PM +0200, Jérémy Lal wrote:
> > Addendum:
> >  "/usr/bin/wasm-ld-13" -m wasm32 -L/usr/lib/wasm32-wasi
> > /usr/lib/wasm32-wasi/crt1-reactor.o --entry _initialize -error-limit=0 -O3
> > --lto-O3 --strip-all --allow-undefined --export-dynamic --export-table
> > --export=malloc --export=free /tmp/api-1a4e87.o /tmp/http-f5ff3b.o
> > /tmp/llhttp-f86505.o -lc -lgcc -o
> > /home/dev/Software/debian/node-undici/js-team/lib/llhttp/llhttp.wasm
> > wasm-ld-13: error: unable to find library -lgcc
> >
> > does not fail if I just remove the "-lgcc" flag.
> > However, that line is generated by clang.
> 
> To workaround that issue, I found out that a combination of
> -nodefaultlibs -Wl,-lc
> flags work.
> 
> Still, something's wrong.

I'm not one of the LLVM maintainers, but I was debugging something
related today and came across your bug, so thought I'd do a drive-by
comment that would perhaps be helpful.

A few different things are going on here:

* The compiler requires a low-level compiler runtime, as it often emits
  code that would need to use it. This can either be libgcc, or LLVM's
  compiler-rt. Clang's default is conditional on the platform, but
  Debian sets this unconditionally to libgcc (see
  -DCLANG_DEFAULT_RTLIB=libgcc in llvm's debian/rules).

  One can set this at runtime, regardless of default, by passing the
  --rtlib option, such as --rtlib=compiler-rt or --rtlib=libgcc (the
  latter will always be a no-op on a Debian system, as that is always
  the default)

  See https://gcc.gnu.org/onlinedocs/gccint/Libgcc.html for more
  information about libgcc, and more importantly, clang's reference:
  https://clang.llvm.org/docs/Toolchain.html#compiler-runtime

* I don't believe anyone has ever built gcc/libgcc for a wasm32-wasi
  target. So the only option to my knowledge here is to use compiler-rt,
  by passing --rtlib=compiler-rt.

* Unfortunately, I don't believe that a wasm32 build of compiler-rt
  (filename: libclang_rt.builtins-wasm32.a) is shipped by any package in
  any architecture in Debian. 

  In general, it looks like libclang-common-${version}-dev just ships
  the architecture-native build, and that no "cross" package exists.

  For libgcc, cross packages exist, e.g. one can install
  libgcc-s1-arm64-cross on an amd64 system and get an arm64
  binary. (But again, no wasm32 port for libgcc...)

* The wasi-sdk project ships libclang_rt.builtins-wasm32.a as part of
  the SDK tarball, but also separately, in a libclang_rt tarball. For
  example, with wasi-sdk-16, this can be downloaded here:
  https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-16/libclang_rt.builtins-wasm32-wasi-16.0.tar.gz

  This should be extracted under /usr/lib/llvm-14/lib/clang/14.0.6,
  which would make this file available:
  /usr/lib/llvm-14/lib/clang/14.0.6/lib/wasi/libclang_rt.builtins-wasm32.a

After downloading this file as above, and passing --rtlib=compiler-rt to
CFLAGS, the problem you are seeing should be fixed.

This bug can probably be retitled/repurposed to request for a way for
ship libclang_rt.builtins-wasm32-wasi to be shipped in Debian. (I suspect
this may be quite a large endeavor and especially if one were to include
the generic case of cross-compiling into this.)

Hope this helps!

Best,
Faidon



More information about the Pkg-llvm-team mailing list