On Thu, 9 Feb 2023 at 13:54, John Paul Adrian Glaubitz
<glaub...@physik.fu-berlin.de> wrote:
>
> Hi!
>
> I usually build a static qemu-user binary from the git source using the 
> following
> configure line:
>
> export ARCH=m68k && ./configure --target-list=$ARCH-linux-user --static 
> --disable-rdma \
>                     --disable-pie --disable-system --disable-xen 
> --disable-pvrdma \
>                     --disable-libssh --disable-werror --disable-glusterfs
>
> However, that stopped working some time ago with the linker error below.
>
> Does anyone know how to fix this?

The "Using getpwuid in statically linked applications" etc warnings
are expected, so we can ignore those; this is the key error:

> /usr/bin/ld: /usr/lib/x86_64-linux-gnu/libdw.a(debuginfod-client.o): in 
> function `__libdwfl_debuginfod_init':
> (.text.startup+0x17): undefined reference to `dlopen'
> /usr/bin/ld: (.text.startup+0x32): undefined reference to `dlsym'
> /usr/bin/ld: (.text.startup+0x4b): undefined reference to `dlsym'
> /usr/bin/ld: (.text.startup+0x64): undefined reference to `dlsym'
> /usr/bin/ld: (.text.startup+0x7d): undefined reference to `dlsym'
> /usr/bin/ld: (.text.startup+0xdc): undefined reference to `dlclose'
> collect2: error: ld returned 1 exit status

We use pkg-config to find out what the libdw library needs on
the compiler/linker command line to link successfully, so
maybe your distro's pkg-config info isn't right. What does
"pkg-config --static --libs libdw" say ? If libdw needs libdl
then it ought to list it in that output, I think. IME pkg-config
information is often incorrect for static linking, though.
I guess this one happened to work previously because glibc didn't
actually mandate linking with '-ldl', and now on your system it
apparently does. On my system pkg-config says
-ldw -lbz2 -llzma -pthread -lpthread -lelf -lz
which looks like it's missing -ldl, but the link succeeds anyway,
presumably because the symbols are provided by the main glibc .a.

On the other hand, if libdw wants to use dlopen/dlsym then
I wonder if we should just suppress it for static linking:
on my (Ubuntu 22.04) ld warns:
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/libdw.a(debuginfod-client.o):
in function `__libdwfl_debuginfod_init':
(.text.startup+0x1b): warning: Using 'dlopen' in statically linked
applications requires at runtime the shared libraries from the glibc
version used for linking

so whatever libdw is trying to do will likely not work in most
statically-linked situations anyway.

I've cc'd the author of the commit that added the libdw
dependency.

thanks
-- PMM

Reply via email to