--static build fails in v5.0 (since 5010cec2bc87dafab39b3913c8ca91f88df9c540)

Bug #1878348 reported by Christophe Lyon
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
QEMU
Fix Released
Undecided
Unassigned

Bug Description

Hi,

Since commit 5010cec2bc87dafab39b3913c8ca91f88df9c540, building qemu fails when configured with --static (eg ../configure --target-list=x86_64-softmmu,x86_64-linux-user --enable-debug --static).

On ubuntu 16.04, it fails to find -lffi and -lselinux.

After I apt-get install libffi-dev libselinux1-dev, the build still fails:
../backends/dbus-vmstate.o: In function `_nocheck__trace_dbus_vmstate_pre_save':
/home/christophe.lyon/src/qemu/build-static/backends/trace.h:29: undefined reference to `_TRACE_DBUS_VMSTATE_PRE_SAVE_DSTATE'
../backends/dbus-vmstate.o: In function `_nocheck__trace_dbus_vmstate_post_load':
/home/christophe.lyon/src/qemu/build-static/backends/trace.h:52: undefined reference to `_TRACE_DBUS_VMSTATE_POST_LOAD_DSTATE'
../backends/dbus-vmstate.o: In function `_nocheck__trace_dbus_vmstate_loading':
/home/christophe.lyon/src/qemu/build-static/backends/trace.h:75: undefined reference to `_TRACE_DBUS_VMSTATE_LOADING_DSTATE'
../backends/dbus-vmstate.o: In function `_nocheck__trace_dbus_vmstate_saving':
/home/christophe.lyon/src/qemu/build-static/backends/trace.h:98: undefined reference to `_TRACE_DBUS_VMSTATE_SAVING_DSTATE'
collect2: error: ld returned 1 exit status

Revision history for this message
Laurent Vivier (laurent-vivier) wrote :

I'm not able to reproduce your problem.

Are you able to reproduce the problem if you cleanup your build directory (make distclean)?

Revision history for this message
Christophe Lyon (christophe-lyon) wrote :

Right, after a make distclean + configure, I managed to complete the build after installing libffi-dev libselinux1-dev.

However, I think there's a bug in configure: it should either complain when these packages are missing, or disable the module that needs them.

Without libffi-dev and libselinux1-dev, the build fails with:
  LINK x86_64-softmmu/qemu-system-x86_64
/usr/bin/ld: cannot find -lselinux
/usr/bin/ld: cannot find -lffi

Revision history for this message
Daniel Berrange (berrange) wrote :

Semi-officially, QEMU only aims to support static linking with usermode emulators, not system mode emulators. I'm not sure we make that clear anywhere in the docs, or configure script. We should probably print a warning from configure if using --static in combination with system emulators, that this is an untested scenario and users are responsible for figuring out any problems they hit such as missing libraries at link time.

In particular it is a known limitation that the configure checks for pre-requisite libraries only validate existence of the shared libraries, and make no attempt to look for the static variant, and it was decided not to fix that.

Revision history for this message
Peter Maydell (pmaydell) wrote :

I think it's largely that many distros ship pkg-config files which are just broken for the static linking case -- so configure tests "does pkg-config say this will work for static linking", and pkg-config says "yes, that will work", and then it doesn't. If you care about trying to get this to be more reliable you'd want to investigate all of these and file bugs upstream with your distro and get them fixed...

Revision history for this message
Christophe Lyon (christophe-lyon) wrote :

OK I wasn't aware that static linking was not supported by system emulators, thanks for the heads-up. I've updated our build scripts not to use static link, so you can close this PR unless you want to keep track that configure needs improvements.

Thanks.

Revision history for this message
Philippe Mathieu-Daudé (philmd) wrote :

For the record, previous attempt to fix:
https://<email address hidden>/msg624142.html
and identical conclusion:
https://<email address hidden>/msg624164.html

Revision history for this message
Christophe Lyon (christophe-lyon) wrote :

Maybe --static should be ignored for system emulators and accepted for user-mode emulators?
That would enable to have a single build, otherwise if we want both, we'd need to configure & build QEMU twice.

Revision history for this message
Peter Maydell (pmaydell) wrote :

Some people want the system emulation to be statically linked, which is why we don't refuse to do it entirely; and static vs not changes a bunch of stuff like CFLAGS which we assume to be common across the whole build. So if you want some statically linked binaries and some not statically linked, then yes, you should configure and build twice. (Use separate build directories, one for each config.)

Revision history for this message
Thomas Huth (th-huth) wrote :

The QEMU project is currently moving its bug tracking to another system.
For this we need to know which bugs are still valid and which could be
closed already. Thus we are setting older bugs to "Incomplete" now.

If the bug has already been fixed in the latest upstream version of QEMU,
then please close this ticket as "Fix released".

If it is not fixed yet and you think that this bug report here is still
valid, then you have two options:

1) If you already have an account on gitlab.com, please open a new ticket
for this problem in our new tracker here:

    https://gitlab.com/qemu-project/qemu/-/issues

and then close this ticket here on Launchpad (or let it expire auto-
matically after 60 days). Please mention the URL of this bug ticket on
Launchpad in the new ticket on GitLab.

2) If you don't have an account on gitlab.com and don't intend to get
one, but still would like to keep this ticket opened, then please switch
the state back to "New" within the next 60 days (otherwise it will get
closed as "Expired"). We will then eventually migrate the ticket auto-
matically to the new system.

Thank you and sorry for the inconvenience.

Changed in qemu:
status: New → Incomplete
Revision history for this message
Peter Maydell (pmaydell) wrote :

FWIW, a configure line that works for me for static system-emulation builds on Ubuntu 18.04 with QEMU 6.0 is:

'../../configure' '--target-list=arm-softmmu' '--enable-debug' '--static' '--disable-tools' '--disable-sdl' '--disable-gtk' '--disable-vnc' '--disable-virtfs' '--disable-attr' '--disable-libiscsi' '--disable-libnfs' '--disable-libusb' '--disable-opengl' '--disable-numa' '--disable-usb-redir' '--disable-bzip2' '--audio-drv-list=' '--disable-guest-agent' '--disable-vte' '--disable-mpath' '--disable-libudev' '--disable-vhost-user' '--disable-curl'

Revision history for this message
Christophe Lyon (christophe-lyon) wrote :

I have re-tested at commit d45a5270d075ea589f0b0ddcf963a5fea1f500ac, and the build succeeded, so it looks like the problem has been fixed.

Changed in qemu:
status: Incomplete → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.