From 9eba910f92dfc81ed509bdf40a3ebdcc92e8b0479d7d7cd26dffe3a4c92d58b5 Mon Sep 17 00:00:00 2001 From: Aleksa Sarai Date: Wed, 16 Jun 2021 03:13:50 +0000 Subject: [PATCH] Accepting request 900295 from home:cyphar:lxc - Build lxd-agent and lxd-p2c statically to match upstream LXD build scripts (and to make VMs work properly -- lxd-agent is injected into the VM). - Update lxd-rpmlintrc to match this. OBS-URL: https://build.opensuse.org/request/show/900295 OBS-URL: https://build.opensuse.org/package/show/Virtualization:containers/lxd?expand=0&rev=95 --- lxd-rpmlintrc | 4 ++++ lxd.changes | 7 +++++++ lxd.spec | 50 +++++++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 56 insertions(+), 5 deletions(-) diff --git a/lxd-rpmlintrc b/lxd-rpmlintrc index 0e5cd9b..24c85cb 100644 --- a/lxd-rpmlintrc +++ b/lxd-rpmlintrc @@ -2,3 +2,7 @@ # our shared libraries are internal and aren't meant to be used outside LXD. # This error only appears in old SLE versions. addFilter ("^lxd.* E: invalid-filepath-dependency .* /usr/lib(32|64)?/lxd/") + +# We need lxd-agent and lxd-p2c to be statically linked. +addFilter ("^lxd.*: W: statically-linked-binary /usr/bin/lxd-(agent|p2c)") +addFilter ("^lxd.*: W: position-independent-executable-suggested /usr/bin/lxd-(agent|p2c)") diff --git a/lxd.changes b/lxd.changes index 1e57a5c..e85bb80 100644 --- a/lxd.changes +++ b/lxd.changes @@ -1,3 +1,10 @@ +------------------------------------------------------------------- +Tue Jun 8 02:25:02 UTC 2021 - Aleksa Sarai + +- Build lxd-agent and lxd-p2c statically to match upstream LXD build scripts + (and to make VMs work properly -- lxd-agent is injected into the VM). +- Update lxd-rpmlintrc to match this. + ------------------------------------------------------------------- Sun Jun 6 07:03:53 UTC 2021 - Aleksa Sarai diff --git a/lxd.spec b/lxd.spec index cab63a5..64ca413 100644 --- a/lxd.spec +++ b/lxd.spec @@ -196,12 +196,34 @@ do then binary="lxd-$binary" fi + case "$binary" in + lxd-agent) + build_static=1 + build_tags="agent,netgo" + ;; + lxd-p2c) + build_static=1 + build_tags="netgo" + ;; + *) + build_static= + build_tags="libsqlite3" + ;; + esac ( # We need to link against our particular dylib deps. export \ CGO_CFLAGS="-I $INSTALL_INCLUDEDIR" \ CGO_LDFLAGS="-L $INSTALL_LIBDIR" ||: - go build -buildmode=pie -tags "libsqlite3" -o "bin/$binary" "$mainpkg" + + if [ -n "$build_static" ] + then + CGO_ENABLED=0 go build -ldflags "-extldflags -static" \ + -tags "$build_tags" -o "bin/$binary" "$mainpkg" + else + go build -buildmode=pie \ + -tags "$build_tags" -o "bin/$binary" "$mainpkg" + fi ) done @@ -253,6 +275,16 @@ done # chain-loading problems. for target in bin/* "$INSTALL_LIBDIR"/lib*.so do + case "$(basename "$target")" in + lxd-agent|lxd-p2c) + # Cannot patch static binaries, and the patching isn't necessary + # for them anyway. + continue + ;; + *) + ;; + esac + # Drop RPATH in case it got included during builds. patchelf --remove-rpath "$target" # And now replace all the possible DT_NEEDEDs to absolute paths. @@ -272,10 +304,18 @@ mkdir man pushd bin/ for bin in * do - # Ensure that all our binaries are dynamic. boo#1138769 - file "$bin" | grep 'dynamically linked' - # Check what they are linked against. - ldd "$bin" + # Ensure that all our binaries are dynamic (except for lxd-p2c and + # lxd-agent, which must be static). boo#1138769 + case "$(basename $bin)" in + lxd-agent|lxd-p2c) + file "$bin" | grep 'statically linked' + ;; + *) + file "$bin" | grep 'dynamically linked' + # Check what they are linked against. + ldd "$bin" + ;; + esac done popd