]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
meson: create new libsystemd-core.so private shared library
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 14 Dec 2021 12:20:28 +0000 (13:20 +0100)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 25 Dec 2021 06:18:47 +0000 (15:18 +0900)
The scheme is very similar to libsystemd-shared.so: instead of building a
static library, we build a shared library from the same objects and link the
two users to it. Both systemd and systemd-analyze consist mostly of the fairly
big code in libcore, so we save a bit on the installation:

(-0g, no strip)
-rwxr-xr-x 5238864 Dec 14 12:52 /var/tmp/inst1/usr/lib/systemd/systemd
-rwxr-xr-x 5399600 Dec 14 12:52 /var/tmp/inst1/usr/bin/systemd-analyze
-rwxr-xr-x  244912 Dec 14 13:17 /var/tmp/inst2/usr/lib/systemd/systemd
-rwxr-xr-x  461224 Dec 14 13:17 /var/tmp/inst2/usr/bin/systemd-analyze
-rwxr-xr-x 5271568 Dec 14 13:17 /var/tmp/inst2/usr/lib/systemd/libsystemd-core-250.so

(-0g, strip)
-rwxr-xr-x 2522080 Dec 14 13:19 /var/tmp/inst1/usr/lib/systemd/systemd
-rwxr-xr-x 2604160 Dec 14 13:19 /var/tmp/inst1/usr/bin/systemd-analyze
-rwxr-xr-x  113304 Dec 14 13:19 /var/tmp/inst2/usr/lib/systemd/systemd
-rwxr-xr-x  207656 Dec 14 13:19 /var/tmp/inst2/usr/bin/systemd-analyze
-rwxr-xr-x 2648520 Dec 14 13:19 /var/tmp/inst2/usr/lib/systemd/libsystemd-core-250.so

So for systemd itself we grow a bit (2522080 → 2648520+113304=2761824), but
overall we save. The most is saved on all the test files that link to libcore,
if they are installed, because there's 15 of them:

$ du -s /var/tmp/inst?
220096 /var/tmp/inst1
122960 /var/tmp/inst2

I also considered making systemd-analyze a symlink to /usr/lib/systemd/systemd
and turning systemd into a multicall binary. We did something like this with
udevd and udevadm. But that solution doesn't fit well in this case.
systemd-analyze has a bunch of functionality that is not used in systemd,
so the systemd binary would need to grow quite a bit. And we're likely to
add new types of verification or introspection features in analyze, and this
baggage would only grow. In addition, there are the test binaries which also
benefit from this.

meson.build
src/core/meson.build
src/shared/meson.build
src/test/meson.build
tools/oss-fuzz.sh

index 2665024426dd26ed6594c1c605c772eff2520919..146c95a478fd64aa3f30bb38626c9276e6c2e5a1 100644 (file)
@@ -2021,12 +2021,7 @@ dbus_programs += executable(
         link_with : [libcore,
                      libshared],
         dependencies : [versiondep,
-                        threads,
-                        librt,
-                        libseccomp,
-                        libselinux,
-                        libmount,
-                        libblkid],
+                        libseccomp],
         install_rpath : rootlibexecdir,
         install : true,
         install_dir : rootlibexecdir)
@@ -2042,12 +2037,7 @@ public_programs += executable(
         link_with : [libcore,
                      libshared],
         dependencies : [versiondep,
-                        threads,
-                        librt,
-                        libseccomp,
-                        libselinux,
-                        libmount,
-                        libblkid],
+                        libseccomp],
         install_rpath : rootlibexecdir,
         install : conf.get('ENABLE_ANALYZE'))
 
index d229d46779a6e63711ebfa0858fd994ce058b535..87456712131507b66a3bf2781adc18ee11dbb320 100644 (file)
@@ -167,12 +167,18 @@ load_fragment_gperf_nulstr_c = custom_target(
         command : [awk, '-f', '@INPUT0@', '@INPUT1@'],
         capture : true)
 
-libcore = static_library(
-        'core',
+libcore_name = 'systemd-core-@0@'.format(meson.project_version())
+
+libcore = shared_library(
+        libcore_name,
         libcore_sources,
         load_fragment_gperf_c,
         load_fragment_gperf_nulstr_c,
         include_directories : includes,
+        c_args : ['-fvisibility=default'],
+        link_args : ['-shared',
+                     '-Wl,--version-script=' + libshared_sym_path],
+        link_with : libshared,
         dependencies : [versiondep,
                         threads,
                         libdl,
@@ -184,8 +190,10 @@ libcore = static_library(
                         libapparmor,
                         libselinux,
                         libmount,
+                        libblkid,
                         libacl],
-        build_by_default : false)
+        install : true,
+        install_dir : rootlibexecdir)
 
 core_includes = [includes, include_directories('.')]
 
index 5dc58a863d4768ad611b7d64873e383ecacc9c60..c2e02339746e1543afd153fb07ad97af496cc411 100644 (file)
@@ -465,13 +465,13 @@ libshared_static = static_library(
 libshared = shared_library(
         libshared_name,
         include_directories : includes,
+        c_args : ['-fvisibility=default'],
         link_args : ['-shared',
                      '-Wl,--version-script=' + libshared_sym_path],
         link_whole : [libshared_static,
                       libbasic,
                       libbasic_gcrypt,
                       libsystemd_static],
-        c_args : ['-fvisibility=default'],
         dependencies : libshared_deps,
         install : true,
         install_dir : rootlibexecdir)
index 9a1c481f226c24662655afc7a32f2b75586eceb3..364cd3dd3fd6b463fcb21b600983ab54c68a5f94 100644 (file)
@@ -419,7 +419,8 @@ tests += [
           libmount,
           libxz,
           liblz4,
-          libblkid],
+          libblkid,
+          libselinux],
          [core_includes, journal_includes, udev_includes]],
 
         [['src/test/test-prioq.c']],
index 8a19da665eb568dff9c2c01471b2937896ce92d8..244eb83906b55728fb3e66c99c086fe2542818bd 100755 (executable)
@@ -67,7 +67,9 @@ df="$build/dns-fuzzing"
 git clone --depth 1 https://github.com/CZ-NIC/dns-fuzzing "$df"
 zip -jqr "$OUT/fuzz-dns-packet_seed_corpus.zip" "$df/packet"
 
-install -Dt "$OUT/src/shared/" "$build"/src/shared/libsystemd-shared-*.so
+install -Dt "$OUT/src/shared/" \
+        "$build"/src/shared/libsystemd-shared-*.so \
+        "$build"/src/core/libsystemd-core-*.so
 
 wget -O "$OUT/fuzz-json.dict" https://raw.githubusercontent.com/rc0r/afl-fuzz/master/dictionaries/json.dict