Systemd/src/core/meson.build
Zbigniew Jędrzejewski-Szmek 22ce84de18 meson: do not link libsystemd_static into libcore (#8813)
(or in terms of the names of the actual files on disk, do not link
libsystemd-shared-238.a into libcore.a).

libsystemd_static is linked into libsystemd_shared, which in turn means that
anything that links to libcore and libsystemd_shared will get libsystemd_static
twice:

$ cc -o systemd 'systemd@exe/src_core_main.c.o' -Wl,--no-undefined -Wl,--as-needed -Wl,-z,relro -Wl,-z,now -pie -DVALGRIND -Wl,--start-group src/core/libcore.a src/shared/libsystemd-shared-238.a src/shared/libsystemd-shared-238.so -pthread -lrt -lseccomp -lselinux -lmount -lblkid -Wl,--end-group -lseccomp -lpam -L/lib64 -laudit -lkmod -lmount -lrt -lcap -lacl -lcryptsetup -lgcrypt -lip4tc -lip6tc -lseccomp -lselinux -lidn -llzma -llz4 -lblkid '-Wl,-rpath,$ORIGIN/src/shared' -Wl,-rpath-link,/home/zbyszek/src/systemd/build/src/shared

This propagation of the dependency seems correct (in the sense that meson is
doing the expected thing based on the given configuration). Linking was done
this way in the original meson conversion. I was probably trying to get
everything to compile and link, I'm not sure why this particular choice was
made. In the meantime, meson has gotten better at propagating dependencies, so
it's possible that this had slightly different effect in the original
conversion, but I did not verify this. Either way, I think we should drop this.

With the patch:
$ cc -o systemd 'systemd@exe/src_core_main.c.o' -Wl,--no-undefined -Wl,--as-needed -Wl,-z,relro -Wl,-z,now -pie -DVALGRIND -Wl,--start-group src/core/libcore.a src/shared/libsystemd-shared-238.so -pthread -lrt -lseccomp -lselinux -lmount -Wl,--end-group -lblkid -lrt -lseccomp -lpam -L/lib64 -laudit -lkmod -lselinux -lmount '-Wl,-rpath,$ORIGIN/src/shared' -Wl,-rpath-link,/home/zbyszek/src/systemd/build/src/shared

This is more correct because we're not linking the same code twice.
With the patch, libystemd_static is used in exactly four places:
- src/shared/libsystemd-shared-238.so
- src/udev/libudev.so.1.6.10
- pam_systemd.so
- test-bus-error
(compared to a bunch more executables before, including systemd,
systemd-analyze, test-hostname, test-ns, etc.)

Size savings are also noticable:

$ size /var/tmp/inst?/usr/lib/systemd/libsystemd-shared-238.so
   text	   data	    bss	    dec	    hex	filename
2397826	 578488	  15920	2992234	 2da86a	/var/tmp/inst1/usr/lib/systemd/libsystemd-shared-238.so
2397826	 578488	  15920	2992234	 2da86a	/var/tmp/inst2/usr/lib/systemd/libsystemd-shared-238.so

$ size /var/tmp/inst?/usr/lib/systemd/systemd
   text	   data	    bss	    dec	    hex	filename
1858790	 261688	   9320	2129798	 207f86	/var/tmp/inst1/usr/lib/systemd/systemd
1556358	 258704	   8072	1823134	 1bd19e	/var/tmp/inst2/usr/lib/systemd/systemd

$ du -s /var/tmp/inst?
52216	/var/tmp/inst1
50844	/var/tmp/inst2

https://github.com/google/oss-fuzz/issues/1330#issuecomment-384054530 might be related.
2018-04-25 13:47:18 +02:00

226 lines
5.9 KiB
Meson

# SPDX-License-Identifier: LGPL-2.1+
#
# Copyright 2017 Zbigniew Jędrzejewski-Szmek
libcore_la_sources = '''
audit-fd.c
audit-fd.h
automount.c
automount.h
bpf-firewall.c
bpf-firewall.h
cgroup.c
cgroup.h
chown-recursive.c
chown-recursive.h
dbus-automount.c
dbus-automount.h
dbus-cgroup.c
dbus-cgroup.h
dbus-device.c
dbus-device.h
dbus-execute.c
dbus-execute.h
dbus-job.c
dbus-job.h
dbus-kill.c
dbus-kill.h
dbus-manager.c
dbus-manager.h
dbus-mount.c
dbus-mount.h
dbus-path.c
dbus-path.h
dbus-scope.c
dbus-scope.h
dbus-service.c
dbus-service.h
dbus-slice.c
dbus-slice.h
dbus-socket.c
dbus-socket.h
dbus-swap.c
dbus-swap.h
dbus-target.c
dbus-target.h
dbus-timer.c
dbus-timer.h
dbus-unit.c
dbus-unit.h
dbus-util.c
dbus-util.h
dbus.c
dbus.h
device.c
device.h
dynamic-user.c
dynamic-user.h
emergency-action.c
emergency-action.h
execute.c
execute.h
hostname-setup.c
hostname-setup.h
ima-setup.c
ima-setup.h
ip-address-access.c
ip-address-access.h
job.c
job.h
kill.c
kill.h
killall.c
killall.h
kmod-setup.c
kmod-setup.h
load-dropin.c
load-dropin.h
load-fragment.c
load-fragment.h
locale-setup.c
locale-setup.h
loopback-setup.c
loopback-setup.h
machine-id-setup.c
machine-id-setup.h
manager.c
manager.h
mount-setup.c
mount-setup.h
mount.c
mount.h
namespace.c
namespace.h
path.c
path.h
scope.c
scope.h
selinux-access.c
selinux-access.h
selinux-setup.c
selinux-setup.h
service.c
service.h
show-status.c
show-status.h
slice.c
slice.h
smack-setup.c
smack-setup.h
socket.c
socket.h
swap.c
swap.h
target.c
target.h
timer.c
timer.h
transaction.c
transaction.h
unit-printf.c
unit-printf.h
unit.c
unit.h
'''.split()
load_fragment_gperf_gperf = custom_target(
'load-fragment-gperf.gperf',
input : 'load-fragment-gperf.gperf.m4',
output: 'load-fragment-gperf.gperf',
command : [m4, '-P'] + m4_defines + ['@INPUT@'],
capture : true)
load_fragment_gperf_c = custom_target(
'load-fragment-gperf.c',
input : load_fragment_gperf_gperf,
output : 'load-fragment-gperf.c',
command : [gperf, '@INPUT@', '--output-file', '@OUTPUT@'])
awkscript = 'load-fragment-gperf-nulstr.awk'
load_fragment_gperf_nulstr_c = custom_target(
'load-fragment-gperf-nulstr.c',
input : [awkscript, load_fragment_gperf_gperf],
output : 'load-fragment-gperf-nulstr.c',
command : [awk, '-f', '@INPUT0@', '@INPUT1@'],
capture : true)
libcore = static_library(
'core',
libcore_la_sources,
load_fragment_gperf_c,
load_fragment_gperf_nulstr_c,
include_directories : includes,
dependencies : [threads,
librt,
libseccomp,
libpam,
libaudit,
libkmod,
libapparmor,
libselinux,
libmount])
systemd_sources = files('main.c')
systemd_shutdown_sources = files('''
shutdown.c
umount.c
umount.h
mount-setup.c
mount-setup.h
killall.c
killall.h
'''.split())
in_files = [['macros.systemd', rpmmacrosdir],
['triggers.systemd', ''],
['systemd.pc', pkgconfigdatadir],
['system.conf', pkgsysconfdir]]
foreach item : in_files
file = item[0]
dir = item[1]
# If 'no', disable generation completely.
# If '', generate, but do not install.
if dir != 'no'
gen = configure_file(
input : file + '.in',
output : file,
configuration : substs)
if dir != ''
install_data(gen,
install_dir : dir)
endif
endif
endforeach
install_data('org.freedesktop.systemd1.conf',
install_dir : dbuspolicydir)
install_data('org.freedesktop.systemd1.service',
install_dir : dbussystemservicedir)
policy = configure_file(
input : 'org.freedesktop.systemd1.policy.in',
output : 'org.freedesktop.systemd1.policy',
configuration : substs)
install_data(policy,
install_dir : polkitpolicydir)
install_data('user.conf',
install_dir : pkgsysconfdir)
meson.add_install_script('sh', '-c', mkdir_p.format(systemshutdowndir))
meson.add_install_script('sh', '-c', mkdir_p.format(systemsleepdir))
meson.add_install_script('sh', '-c', mkdir_p.format(systemgeneratordir))
meson.add_install_script('sh', '-c', mkdir_p.format(usergeneratordir))
meson.add_install_script('sh', '-c',
mkdir_p.format(join_paths(pkgsysconfdir, 'system/multi-user.target.wants')))
meson.add_install_script('sh', '-c',
mkdir_p.format(join_paths(pkgsysconfdir, 'system/getty.target.wants')))
meson.add_install_script('sh', '-c',
mkdir_p.format(join_paths(pkgsysconfdir, 'user')))
meson.add_install_script('sh', '-c',
mkdir_p.format(join_paths(sysconfdir, 'xdg/systemd')))