[Buildroot] [PATCH 1/1] package/systemd: use statically linked host tools

Norbert Lange nolange79 at gmail.com
Sat Jul 30 19:04:09 UTC 2022


James Hilliard <james.hilliard1 at gmail.com> schrieb am Do., 28. Juli 2022,
11:01:

> On Thu, Jul 28, 2022 at 2:33 AM Norbert Lange <nolange79 at gmail.com> wrote:
> >
> > Am Do., 28. Juli 2022 um 00:11 Uhr schrieb James Hilliard
> > <james.hilliard1 at gmail.com>:
> > >
> > > This lets us remove the HOST_SYSTEMD_FIX_RPATH hack.
> > >
> > > Signed-off-by: James Hilliard <james.hilliard1 at gmail.com>
> > > ---
> > >  ...nalctl-allow-statically-linked-build.patch | 68 +++++++++++++++++++
> > >  package/systemd/systemd.mk                    | 28 +++-----
> > >  2 files changed, 76 insertions(+), 20 deletions(-)
> > >  create mode 100644
> package/systemd/0002-journalctl-allow-statically-linked-build.patch
> > >
> > > diff --git
> a/package/systemd/0002-journalctl-allow-statically-linked-build.patch
> b/package/systemd/0002-journalctl-allow-statically-linked-build.patch
> > > new file mode 100644
> > > index 0000000000..98ffb72cca
> > > --- /dev/null
> > > +++
> b/package/systemd/0002-journalctl-allow-statically-linked-build.patch
> > > @@ -0,0 +1,68 @@
> > > +From d2dadbdc5618776e07e98baf8795cc8adebf05a1 Mon Sep 17 00:00:00 2001
> > > +From: James Hilliard <james.hilliard1 at gmail.com>
> > > +Date: Wed, 27 Jul 2022 15:28:09 -0600
> > > +Subject: [PATCH] journalctl: allow statically linked build
> > > +
> > > +The journalctl tool may be needed on cross compilation hosts in order
> > > +to run --update-catalog against a target rootfs.
> > > +
> > > +To avoid reliability issues caused by shared linking allow journalctl
> > > +to be linked statically.
> > > +
> > > +Signed-off-by: James Hilliard <james.hilliard1 at gmail.com>
> > > +[Upstream status:
> > > +https://github.com/systemd/systemd/pull/24140]
> > > +---
> > > + meson.build       | 11 ++++++++++-
> > > + meson_options.txt |  2 ++
> > > + 2 files changed, 12 insertions(+), 1 deletion(-)
> > > +
> > > +diff --git a/meson.build b/meson.build
> > > +index 692ee1ed4d..8cce19dce6 100644
> > > +--- a/meson.build
> > > ++++ b/meson.build
> > > +@@ -2263,11 +2263,19 @@ public_programs += executable(
> > > +         install_rpath : rootpkglibdir,
> > > +         install : true)
> > > +
> > > ++if get_option('link-journalctl-shared')
> > > ++        journalctl_link_with = [libshared]
> > > ++else
> > > ++        journalctl_link_with = [libsystemd_static,
> > > ++                                libshared_static,
> > > ++                                libbasic_gcrypt]
> > > ++endif
> > > ++
> > > + public_programs += executable(
> > > +         'journalctl',
> > > +         journalctl_sources,
> > > +         include_directories : includes,
> > > +-        link_with : [libshared],
> > > ++        link_with : [journalctl_link_with],
> > > +         dependencies : [threads,
> > > +                         libdl,
> > > +                         libxz,
> > > +@@ -4357,6 +4365,7 @@ foreach tuple : [
> > > +         ['link-systemctl-shared',
> get_option('link-systemctl-shared')],
> > > +         ['link-networkd-shared',
> get_option('link-networkd-shared')],
> > > +         ['link-timesyncd-shared',
> get_option('link-timesyncd-shared')],
> > > ++
> ['link-journalctl-shared',get_option('link-journalctl-shared')],
> > > +         ['link-boot-shared',      get_option('link-boot-shared')],
> > > +         ['first-boot-full-preset'],
> > > +         ['fexecve'],
> > > +diff --git a/meson_options.txt b/meson_options.txt
> > > +index 628ca1d797..d8c0c581c2 100644
> > > +--- a/meson_options.txt
> > > ++++ b/meson_options.txt
> > > +@@ -25,6 +25,8 @@ option('link-networkd-shared', type: 'boolean',
> > > +        description : 'link systemd-networkd and its helpers to
> libsystemd-shared.so')
> > > + option('link-timesyncd-shared', type: 'boolean',
> > > +        description : 'link systemd-timesyncd and its helpers to
> libsystemd-shared.so')
> > > ++option('link-journalctl-shared', type: 'boolean',
> > > ++       description : 'link journalctl against libsystemd-shared.so')
> > > + option('link-boot-shared', type: 'boolean',
> > > +        description : 'link bootctl and systemd-bless-boot against
> libsystemd-shared.so')
> > > + option('first-boot-full-preset', type: 'boolean', value: false,
> > > +--
> > > +2.34.1
> > > +
> > > diff --git a/package/systemd/systemd.mk b/package/systemd/systemd.mk
> > > index 47aaddf849..13348f9358 100644
> > > --- a/package/systemd/systemd.mk
> > > +++ b/package/systemd/systemd.mk
> > > @@ -738,7 +738,7 @@ endef
> > >  SYSTEMD_ROOTFS_PRE_CMD_HOOKS += SYSTEMD_RM_CATALOG_UPDATE_SERVICE
> > >
> > >  define SYSTEMD_CREATE_TMPFILES_HOOK
> > > -       HOST_SYSTEMD_TMPFILES=$(HOST_DIR)/bin/systemd-tmpfiles \
> > > +
>  HOST_SYSTEMD_TMPFILES=$(HOST_DIR)/bin/systemd-tmpfiles.standalone \
> > >                 $(SYSTEMD_PKGDIR)/fakeroot_tmpfiles.sh $(TARGET_DIR)
> > >  endef
> > >  SYSTEMD_ROOTFS_PRE_CMD_HOOKS += SYSTEMD_CREATE_TMPFILES_HOOK
> > > @@ -781,6 +781,13 @@ HOST_SYSTEMD_CONF_OPTS = \
> > >         --libdir=lib \
> > >         --sysconfdir=/etc \
> > >         --localstatedir=/var \
> > > +       -Dlink-udev-shared=false \
> > > +       -Dlink-systemctl-shared=false \
> > > +       -Dlink-networkd-shared=false \
> > > +       -Dlink-timesyncd-shared=false \
> > > +       -Dlink-journalctl-shared=false \
> > > +       -Dlink-boot-shared=false \
> > > +       -Dstandalone-binaries=true \
> > >         -Dmode=release \
> > >         -Dutmp=false \
> > >         -Dhibernate=false \
> > > @@ -854,24 +861,5 @@ HOST_SYSTEMD_DEPENDENCIES = \
> > >
> > >  HOST_SYSTEMD_NINJA_ENV = DESTDIR=$(HOST_DIR)
> > >
> > > -# Fix RPATH After installation
> > > -# * systemd provides a install_rpath instruction to meson because the
> binaries
> > > -#   need to link with libsystemd which is not in a standard path
> > > -# * meson can only replace the RPATH, not append to it
> > > -# * the original rpath is thus lost.
> > > -# * the original path had been tweaked by buildroot via LDFLAGS to add
> > > -#   $(HOST_DIR)/lib
> > > -# * thus re-tweak rpath after the installation for all binaries that
> need it
> > > -HOST_SYSTEMD_HOST_TOOLS = busctl journalctl systemctl systemd-*
> udevadm
> > > -
> > > -define HOST_SYSTEMD_FIX_RPATH
> > > -       for f in $(addprefix
> $(HOST_DIR)/bin/,$(HOST_SYSTEMD_HOST_TOOLS)); do \
> > > -               [ -e $$f ] || continue; \
> > > -               $(HOST_DIR)/bin/patchelf --set-rpath
> $(HOST_DIR)/lib:$(HOST_DIR)/lib/systemd $${f} \
> > > -               || exit 1; \
> > > -       done
> > > -endef
> > > -HOST_SYSTEMD_POST_INSTALL_HOOKS += HOST_SYSTEMD_FIX_RPATH
> > > -
> > >  $(eval $(meson-package))
> > >  $(eval $(host-meson-package))
> > > --
> > > 2.34.1
> > >
> >
> > Hello James,
> >
> > what issues are you trying to prevent here? buildroot's host tools
> > generally use the rpath to work,
> > static tools will just blow up filesize, and would only make sense if
> > you want to copy a few of them
> > to another location.
>
> We don't normally need to use patchelf for host tools, figured it would
> be nice to drop that hack.
>


The issue is meson not doing the right thing,
Unless you fix or drop meson (whatever is less unlikely), whatever you do
is a workaround.

Size shouldn't really matter much for small host tools like these IMO,
> and we should be able to avoid having to install a host libsystemd-shared
> this way down the line(static binaries are often smaller than shared in
> aggregate if only a subset of the library functions get used).
>

I believe systemctl uses almost the entire shared lib, so there aren't any
savings likely.

As said I don't consider the patchelf step terrible, and way less intrusive.

Norbert
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.buildroot.org/pipermail/buildroot/attachments/20220730/23365c5f/attachment-0001.html>


More information about the buildroot mailing list