Zbigniew Jędrzejewski-Szmek 1cc4f8
From 66df80d8c37dce4b597dfa26e1050856a610cf7f Mon Sep 17 00:00:00 2001
Zbigniew Jędrzejewski-Szmek 1cc4f8
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
Zbigniew Jędrzejewski-Szmek 1cc4f8
Date: Wed, 3 Jul 2024 17:05:31 +0200
Zbigniew Jędrzejewski-Szmek 1cc4f8
Subject: [PATCH 3/3] meson: add option to build systemd-executor "statically"
Zbigniew Jędrzejewski-Szmek 1cc4f8
Zbigniew Jędrzejewski-Szmek 1cc4f8
The new link-executor-shared option is similar to the existing
Zbigniew Jędrzejewski-Szmek 1cc4f8
link-udev-shared: when set to false, we link to the static versions of our
Zbigniew Jędrzejewski-Szmek 1cc4f8
internal libraries.
Zbigniew Jędrzejewski-Szmek 1cc4f8
Zbigniew Jędrzejewski-Szmek 1cc4f8
The resulting exuctor binary is fairly large, about as large as libsystemd-core
Zbigniew Jędrzejewski-Szmek 1cc4f8
(14 MB without lto, 8 with lto).
Zbigniew Jędrzejewski-Szmek 1cc4f8
Zbigniew Jędrzejewski-Szmek 1cc4f8
This is intended as a workaround for the fuckup with the pinned executor
Zbigniew Jędrzejewski-Szmek 1cc4f8
binary:
Zbigniew Jędrzejewski-Szmek 1cc4f8
when an upgrade is performed, the package manager will install new version of
Zbigniew Jędrzejewski-Szmek 1cc4f8
the libraries and new version of the code, and some time later reexecute the
Zbigniew Jędrzejewski-Szmek 1cc4f8
managers. This creates a window when the pinned executor binary will fail to
Zbigniew Jędrzejewski-Szmek 1cc4f8
execute. There are two factors which make the issue easier to hit:
Zbigniew Jędrzejewski-Szmek 1cc4f8
Zbigniew Jędrzejewski-Szmek 1cc4f8
- when the distribution uses a finely-grained shared-lib-tag. E.g. Fedora
Zbigniew Jędrzejewski-Szmek 1cc4f8
  uses version-release as the tag, which means that the issue occurs on
Zbigniew Jędrzejewski-Szmek 1cc4f8
  every package upgrade. This is the right thing to do, because the
Zbigniew Jędrzejewski-Szmek 1cc4f8
  ABI of our internal libraries is not stable at all, so replacing the
Zbigniew Jędrzejewski-Szmek 1cc4f8
  library from a different version in place creates a window where our
Zbigniew Jędrzejewski-Szmek 1cc4f8
  programs may crash or misbehave.
Zbigniew Jędrzejewski-Szmek 1cc4f8
Zbigniew Jędrzejewski-Szmek 1cc4f8
- when the distribution doesn't immediately reexec all the managers after
Zbigniew Jędrzejewski-Szmek 1cc4f8
  upgrade. In early versions of systemd, we used to hammer the machine during
Zbigniew Jędrzejewski-Szmek 1cc4f8
  upgrade, doing daemon-reexecs repeatedly. This works, but is ugly and
Zbigniew Jędrzejewski-Szmek 1cc4f8
  wasteful. Doing the reexecs while the upgrade is in progres also creates a
Zbigniew Jędrzejewski-Szmek 1cc4f8
  window where a mix of old and new configs or both is loaded. Users are
Zbigniew Jędrzejewski-Szmek 1cc4f8
  particularly annoyed by those reloads if there is some issue in the
Zbigniew Jędrzejewski-Szmek 1cc4f8
  configuration causing us to emit warnings on every reexec. Doing the
Zbigniew Jędrzejewski-Szmek 1cc4f8
  reexecs once after the new configuration and libraries have been put
Zbigniew Jędrzejewski-Szmek 1cc4f8
  in place is nicer.
Zbigniew Jędrzejewski-Szmek 1cc4f8
Zbigniew Jędrzejewski-Szmek 1cc4f8
The pinning of the executor binary breaks upgrades and in particular
Zbigniew Jędrzejewski-Szmek 1cc4f8
it penalizes the distributions which make use of the features which
Zbigniew Jędrzejewski-Szmek 1cc4f8
were previously added to avoid bugs and inefficiency during upgrades.
Zbigniew Jędrzejewski-Szmek 1cc4f8
Zbigniew Jędrzejewski-Szmek 1cc4f8
When the executor is linked statically, there is a smaller chance that it'll
Zbigniew Jędrzejewski-Szmek 1cc4f8
fail to load libraries. The issue can still occur because other libraries, not
Zbigniew Jędrzejewski-Szmek 1cc4f8
our own, are linked dynamically.
Zbigniew Jędrzejewski-Szmek 1cc4f8
Zbigniew Jędrzejewski-Szmek 1cc4f8
(cherry picked from commit d59cae6cebd0fc25a16a020bd28e5303901f1b19)
Zbigniew Jędrzejewski-Szmek 1cc4f8
---
Zbigniew Jędrzejewski-Szmek 1cc4f8
 meson_options.txt    |  2 ++
Zbigniew Jędrzejewski-Szmek 1cc4f8
 src/core/meson.build | 16 ++++++++++++----
Zbigniew Jędrzejewski-Szmek 1cc4f8
 2 files changed, 14 insertions(+), 4 deletions(-)
Zbigniew Jędrzejewski-Szmek 1cc4f8
Zbigniew Jędrzejewski-Szmek 1cc4f8
diff --git a/meson_options.txt b/meson_options.txt
Zbigniew Jędrzejewski-Szmek 1cc4f8
index d52ca4e4b5..3cce818392 100644
Zbigniew Jędrzejewski-Szmek 1cc4f8
--- a/meson_options.txt
Zbigniew Jędrzejewski-Szmek 1cc4f8
+++ b/meson_options.txt
Zbigniew Jędrzejewski-Szmek 1cc4f8
@@ -21,6 +21,8 @@ option('rootprefix', type : 'string', deprecated: true,
Zbigniew Jędrzejewski-Szmek 1cc4f8
        description : '''This option is deprecated and will be removed in a future release''')
Zbigniew Jędrzejewski-Szmek 1cc4f8
 option('link-udev-shared', type : 'boolean',
Zbigniew Jędrzejewski-Szmek 1cc4f8
        description : 'link systemd-udevd and its helpers to libsystemd-shared.so')
Zbigniew Jędrzejewski-Szmek 1cc4f8
+option('link-executor-shared', type : 'boolean',
Zbigniew Jędrzejewski-Szmek 1cc4f8
+       description : 'link systemd-executor to libsystemd-shared.so and libsystemd-core.so')
Zbigniew Jędrzejewski-Szmek 1cc4f8
 option('link-systemctl-shared', type: 'boolean',
Zbigniew Jędrzejewski-Szmek 1cc4f8
        description : 'link systemctl against libsystemd-shared.so')
Zbigniew Jędrzejewski-Szmek 1cc4f8
 option('link-networkd-shared', type: 'boolean',
Zbigniew Jędrzejewski-Szmek 1cc4f8
diff --git a/src/core/meson.build b/src/core/meson.build
Zbigniew Jędrzejewski-Szmek 1cc4f8
index 1ef31cc529..dbeb752977 100644
Zbigniew Jędrzejewski-Szmek 1cc4f8
--- a/src/core/meson.build
Zbigniew Jędrzejewski-Szmek 1cc4f8
+++ b/src/core/meson.build
Zbigniew Jędrzejewski-Szmek 1cc4f8
@@ -156,6 +156,17 @@ systemd_executor_sources = files(
Zbigniew Jędrzejewski-Szmek 1cc4f8
         'exec-invoke.c',
Zbigniew Jędrzejewski-Szmek 1cc4f8
 )
Zbigniew Jędrzejewski-Szmek 1cc4f8
 
Zbigniew Jędrzejewski-Szmek 1cc4f8
+executor_libs = get_option('link-executor-shared') ? \
Zbigniew Jędrzejewski-Szmek 1cc4f8
+        [
Zbigniew Jędrzejewski-Szmek 1cc4f8
+                libcore,
Zbigniew Jędrzejewski-Szmek 1cc4f8
+                libshared,
Zbigniew Jędrzejewski-Szmek 1cc4f8
+        ] : [
Zbigniew Jędrzejewski-Szmek 1cc4f8
+                libcore_static,
Zbigniew Jędrzejewski-Szmek 1cc4f8
+                libshared_static,
Zbigniew Jędrzejewski-Szmek 1cc4f8
+                libbasic_static,
Zbigniew Jędrzejewski-Szmek 1cc4f8
+                libsystemd_static,
Zbigniew Jędrzejewski-Szmek 1cc4f8
+        ]
Zbigniew Jędrzejewski-Szmek 1cc4f8
+
Zbigniew Jędrzejewski-Szmek 1cc4f8
 executables += [
Zbigniew Jędrzejewski-Szmek 1cc4f8
         libexec_template + {
Zbigniew Jędrzejewski-Szmek 1cc4f8
                 'name' : 'systemd',
Zbigniew Jędrzejewski-Szmek 1cc4f8
@@ -173,10 +184,7 @@ executables += [
Zbigniew Jędrzejewski-Szmek 1cc4f8
                 'public' : true,
Zbigniew Jędrzejewski-Szmek 1cc4f8
                 'sources' : systemd_executor_sources,
Zbigniew Jędrzejewski-Szmek 1cc4f8
                 'include_directories' : core_includes,
Zbigniew Jędrzejewski-Szmek 1cc4f8
-                'link_with' : [
Zbigniew Jędrzejewski-Szmek 1cc4f8
-                        libcore,
Zbigniew Jędrzejewski-Szmek 1cc4f8
-                        libshared,
Zbigniew Jędrzejewski-Szmek 1cc4f8
-                ],
Zbigniew Jędrzejewski-Szmek 1cc4f8
+                'link_with' : executor_libs,
Zbigniew Jędrzejewski-Szmek 1cc4f8
                 'dependencies' : [
Zbigniew Jędrzejewski-Szmek 1cc4f8
                         libapparmor,
Zbigniew Jędrzejewski-Szmek 1cc4f8
                         libpam,