diff mbox series

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

Message ID 20220727221055.1838031-1-james.hilliard1@gmail.com
State Rejected
Headers show
Series [1/1] package/systemd: use statically linked host tools | expand

Commit Message

James Hilliard July 27, 2022, 10:10 p.m. UTC
This lets us remove the HOST_SYSTEMD_FIX_RPATH hack.

Signed-off-by: James Hilliard <james.hilliard1@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

Comments

Norbert Lange July 28, 2022, 8:33 a.m. UTC | #1
Am Do., 28. Juli 2022 um 00:11 Uhr schrieb James Hilliard
<james.hilliard1@gmail.com>:
>
> This lets us remove the HOST_SYSTEMD_FIX_RPATH hack.
>
> Signed-off-by: James Hilliard <james.hilliard1@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@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@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.

Makes sense for example the bootctl tool when you want to re-use that
in an initramfs,
but thats not buildroot's concern AFAIK.

Norbert
James Hilliard July 28, 2022, 9:01 a.m. UTC | #2
On Thu, Jul 28, 2022 at 2:33 AM Norbert Lange <nolange79@gmail.com> wrote:
>
> Am Do., 28. Juli 2022 um 00:11 Uhr schrieb James Hilliard
> <james.hilliard1@gmail.com>:
> >
> > This lets us remove the HOST_SYSTEMD_FIX_RPATH hack.
> >
> > Signed-off-by: James Hilliard <james.hilliard1@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@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@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.

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).

>
> Makes sense for example the bootctl tool when you want to re-use that
> in an initramfs,
> but thats not buildroot's concern AFAIK.
>
> Norbert
Yann E. MORIN July 30, 2022, 10:22 a.m. UTC | #3
James, All,

On 2022-07-27 16:10 -0600, James Hilliard spake thusly:
> This lets us remove the HOST_SYSTEMD_FIX_RPATH hack.

This will require a lot more explanations than just that.

Please, compare the length of the explanations in 35c11a027c88
(package/systemd: add host variant), that went to extra details about
the issue, with your patch that has just one terse line that does not
explain anything.

The commit log is not about stating _what_ is done, but _why_ it is.
A small note about the _what_ can be needed to summarise it, and what
you wrote is enough. But you need to really extend the explanations on
_why_ it is correct to now do so.

Which it is not entirely either:

    $ readelf -d host/bin/systemctl
    [--SNIP--]
     0x000000000000001d (RUNPATH)            Library runpath: [/usr/lib/systemd:/home/ymorin/dev/buildroot/O/misc/per-package/host-systemd/host/lib]

So, this is wrong, because it is going to use my system's systemd libs,
not the host ones. Also, it still looks into the per-package directory
instead of $(HOST_DIR). This does not prevent it to work, but is
semantically incorrect. It will however break in a system that does not
have the systemd libraries installed, or has incompatible libraries
(e.g. too old or too recent). So, the rpath fixup hook is stil needed.

Maybe you can do for systemctl as was done for the other tools? Or maybe
upstream should have a global option to build everything shared or
static, instead of one such option for each tool...

> Signed-off-by: James Hilliard <james.hilliard1@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@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@gmail.com>
> +[Upstream status:
> +https://github.com/systemd/systemd/pull/24140]

That has been accepted now.

We are usually not too fond of feature backports, except maybe when they
fix a build/run breakage that we can't easily fix otherwise. But in this
case, we do not have a breakage, just ugly code, and the build succeeds,
and the system runs. So, I think that this cleanup can very well wait
for after we update to an upstream version that has this feature.

> @@ -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 \

What is this new 'standalone' mode, and how is it related to statically
linking tools?

>  	-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

That we will eventually be able to drop this hook, is very good news,
though. But I think that is not urgent, and that we can wait for the
next version bump.

Regards,
Yann E. MORIN.

>  $(eval $(meson-package))
>  $(eval $(host-meson-package))
> -- 
> 2.34.1
> 
> _______________________________________________
> buildroot mailing list
> buildroot@buildroot.org
> https://lists.buildroot.org/mailman/listinfo/buildroot
Norbert Lange July 30, 2022, 7:04 p.m. UTC | #4
James Hilliard <james.hilliard1@gmail.com> schrieb am Do., 28. Juli 2022,
11:01:

> On Thu, Jul 28, 2022 at 2:33 AM Norbert Lange <nolange79@gmail.com> wrote:
> >
> > Am Do., 28. Juli 2022 um 00:11 Uhr schrieb James Hilliard
> > <james.hilliard1@gmail.com>:
> > >
> > > This lets us remove the HOST_SYSTEMD_FIX_RPATH hack.
> > >
> > > Signed-off-by: James Hilliard <james.hilliard1@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@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@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
Yann E. MORIN Aug. 29, 2022, 3:37 p.m. UTC | #5
James, All,

On 2022-07-27 16:10 -0600, James Hilliard spake thusly:
> This lets us remove the HOST_SYSTEMD_FIX_RPATH hack.
> 
> Signed-off-by: James Hilliard <james.hilliard1@gmail.com>

Given the feedback from Norbert and I, I have now marked this change as
rejected in Patchwork.

Regards,
Yann E. MORIN.
diff mbox series

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@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@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))