Daniel P. Berrangé wrote:
On Thu, Sep 03, 2020 at 01:49:11PM +0200, Pavel Hrdina wrote:
> On Thu, Sep 03, 2020 at 03:21:51PM +0400, Roman Bogorodskiy wrote:
> > Daniel P. Berrangé wrote:
> >
> > > On Thu, Sep 03, 2020 at 02:52:41PM +0400, Roman Bogorodskiy wrote:
> > > > Daniel P. Berrangé wrote:
> > > >
> > > > > On Thu, Sep 03, 2020 at 02:21:37PM +0400, Roman Bogorodskiy
wrote:
> > > > > > Add some FreeBSD-specific libraries (-lutil, -lkvm) to
tests dependencies.
> > > > > >
> > > > > > Without that, FreeBSD 11.x, which uses the GNU ld, fails to
link tests.
> > > > > > Interestingly, newer FreeBSD versions that use LLVM ld
tolerate this
> > > > > > behaviour and builds successfully as is.
> > > > >
> > > > > Hmm, we need a CI job for FreeBSD 11 added
> > > > >
> > > > > Cirrus supports FreeBSD 11.4 so ought to be possible to add it
to our
> > > > > matrix.
> > > > >
> > > > > >
> > > > > > Signed-off-by: Roman Bogorodskiy
<bogorodskiy(a)gmail.com>
> > > > > > ---
> > > > > > tests/meson.build | 2 ++
> > > > > > 1 file changed, 2 insertions(+)
> > > > > >
> > > > > > diff --git a/tests/meson.build b/tests/meson.build
> > > > > > index ad13e2de60..ea2458efbc 100644
> > > > > > --- a/tests/meson.build
> > > > > > +++ b/tests/meson.build
> > > > > > @@ -10,11 +10,13 @@ tests_dep = declare_dependency(
> > > > > > dlopen_dep,
> > > > > > glib_dep,
> > > > > > gnutls_dep,
> > > > > > + kvm_dep,
> > > > >
> > > > > Makes sense, as we don't reference kvm_dep anywhere.
> > > > >
> > > > > > libnl_dep,
> > > > > > libxml_dep,
> > > > > > rpc_dep,
> > > > > > sasl_dep,
> > > > > > selinux_dep,
> > > > > > + util_dep,
> > > > >
> > > > > In the top level meson.build, we appear to add -lutil as a
linker
> > > > > arg to the entire project, so i'm surprised this was
needed.
> > > >
> > > > -lutil was actually the first issue spotted, and when fixed, -lkvm
> > > > showed up.
> > > >
> > > > Here's the original report I got:
> > > >
> > > >
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=249056
> > > >
> > > > It contains some initial thoughts on this issue; there I also
assumed
> > > > that add_global_link_arguments() could fix the issue, but was
satisfied
> > > > with the current solution.
> > >
> > > Hmm, this is all very strange if I'm reading the the
> > > add_project_link_arguments doc correctly it should apply to everything
> > > we have. The difference between add_project and add_global is just
> > > about meson subprojects, but the tests are in our main project.
> > >
> > > If add_project_link_arguments isn't working as we expect, we might be
> > > better removing its use entirely in favour of explicitly adding the
> > > _deps objects in the particular places they are needed.
> >
> > I've just tried this change:
> >
> > --- meson.build.orig 2020-09-03 11:14:20.233605000 +0000
> > +++ meson.build 2020-09-03 11:14:43.661313000 +0000
> > @@ -1405,7 +1405,7 @@
> >
> > util_dep = cc.find_library('util', required: false)
> > if util_dep.found()
> > - add_project_link_arguments('-lutil', language: 'c')
> > + add_global_link_arguments('-lutil', language: 'c')
> > endif
> >
> > if not get_option('virtualport').disabled()
> >
> > It doesn't work, the build is still failing with it.
>
> This is strange, after checking the freebsd bug there is -lutil and it
> still fails which I don't understand:
>
> [846/936] cc -o tests/domaincapstest
'tests/59830eb@@domaincapstest(a)exe/domaincapstest.c.o'
> -I/usr/local/include -L/usr/local/lib -Wl,--as-needed -Wl,--no-undefined -Wl,-O1
-Wl,-export-dynamic
> -pie -Wl,--whole-archive -Wl,--start-group tests/libtest_utils.a
tests/libtest_file_wrapper.a
> -Wl,--no-whole-archive -lkvm -lintl -lutil -O2 -pipe -fstack-protector-strong
-fno-strict-aliasing
> ^
> here you can see there is -lutil
>
> ^ and here we have -lkvm as well
>
> -fstack-protector -fstack-protector-strong src/libvirt.so.0.6007.0
src/bhyve/libvirt_driver_bhyve_impl.a
> -Wl,-export-dynamic -ldl /usr/local/lib/libglib-2.0.so /usr/local/lib/libintl.so
/usr/local/lib/libgobject-2.0.so
> /usr/local/lib/libgio-2.0.so /usr/local/lib/libgnutls.so /usr/local/lib/libxml2.so
-Wl,--end-group -Wl,-z,relro
> -Wl,-z,now -Wl,-export-dynamic -Wl,-export-dynamic -Wl,-export-dynamic
'-Wl,-rpath,$ORIGIN/../src:$ORIGIN/../src/bhyve'
> -Wl,-rpath-link,/wrkdirs/usr/ports/devel/libvirt/work/libvirt-6.7.0/_build/src
-Wl,-rpath-link,/wrkdirs/usr/ports/devel/libvirt/work/libvirt-6.7.0/_build/src/bhyve
> FAILED: tests/domaincapstest
> cc -o tests/domaincapstest
'tests/59830eb@@domaincapstest(a)exe/domaincapstest.c.o' -I/usr/local/include
> -L/usr/local/lib -Wl,--as-needed -Wl,--no-undefined -Wl,-O1 -Wl,-export-dynamic -pie
-Wl,--whole-archive
> -Wl,--start-group tests/libtest_utils.a tests/libtest_file_wrapper.a
-Wl,--no-whole-archive -lkvm -lintl
> -lutil -O2 -pipe -fstack-protector-strong -fno-strict-aliasing -fstack-protector
-fstack-protector-strong
> src/libvirt.so.0.6007.0 src/bhyve/libvirt_driver_bhyve_impl.a -Wl,-export-dynamic
-ldl /usr/local/lib/libglib-2.0.so
> /usr/local/lib/libintl.so /usr/local/lib/libgobject-2.0.so
/usr/local/lib/libgio-2.0.so /usr/local/lib/libgnutls.so
> /usr/local/lib/libxml2.so -Wl,--end-group -Wl,-z,relro -Wl,-z,now
-Wl,-export-dynamic -Wl,-export-dynamic
> -Wl,-export-dynamic '-Wl,-rpath,$ORIGIN/../src:$ORIGIN/../src/bhyve'
-Wl,-rpath-link,/wrkdirs/usr/ports/devel/libvirt/work/libvirt-6.7.0/_build/src
>
-Wl,-rpath-link,/wrkdirs/usr/ports/devel/libvirt/work/libvirt-6.7.0/_build/src/bhyve
> /usr/bin/ld: undefined reference to symbol `expand_number' (try adding -lutil)
> /usr/lib/libutil.so: could not read symbols: Bad value
> cc: error: linker command failed with exit code 1 (use -v to see invocation)
> ninja: build stopped: subcommand failed.
> *** Error code 1
>
> The fact that it compiles correctly on FreeBSD 12.x I'm not sure what's
> going on here.
IIUC, the only major difference between 11.x and later versions in this
context is that 11.x is using the GNU linker (ld.bfd),
and the later versions use the LLVM linker (ld.lld).
I'm not sure it's related, but it looks like it could...
I wonder if there is an ordering issue ? The -lutil/-lkvm args
are
quite early on the CLI. Adding them again as _deps might put them later
on the CLI ?
Yes, it looks like it's adding -lutil and -lkvm later on the CLI.
Command of the successful build with the patched tests/meson.build:
[841/962] cc -o tests/domaincapstest
'tests/59830eb@@domaincapstest(a)exe/domaincapstest.c.o' -I/usr/local/include
-L/usr/local/lib -Wl,--as-needed -Wl,--no-undefined -Wl,-O1 -Wl,-export-dynamic -pie
-Wl,--whole-archive -Wl,--start-group tests/libtest_utils.a tests/libtest_file_wrapper.a
-Wl,--no-whole-archive -lkvm -lintl -lutil -O2 -pipe -fstack-protector-strong
-fno-strict-aliasing -fstack-protector -fstack-protector-strong src/libvirt.so.0.6007.0
src/bhyve/libvirt_driver_bhyve_impl.a -Wl,-export-dynamic -ldl
/usr/local/lib/libglib-2.0.so /usr/local/lib/libintl.so /usr/local/lib/libgobject-2.0.so
/usr/local/lib/libgio-2.0.so /usr/local/lib/libgnutls.so -lkvm /usr/local/lib/libxml2.so
/usr/local/lib/libsasl2.so -lutil /usr/local/lib/libyajl.so -Wl,-z,relro -Wl,-z,now
-Wl,-export-dynamic -Wl,-export-dynamic -lkvm -lutil -Wl,-export-dynamic -lkvm -lutil
-Wl,--end-group '-Wl,-rpath,$ORIGIN/../src:$ORIGIN/../src/bhyve'
-Wl,-rpath-link,/wrkdirs/usr/ports/devel/libvirt/work/libvirt-6.7.0/_build/src
-Wl,-rpath-link,/wrkdirs/usr/ports/devel/libvirt/work/libvirt-6.7.0/_build/src/bhyve