From 83b6af36d1ea1d1250ad2836c00193021e908cef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Fri, 14 Apr 2017 20:10:28 -0400 Subject: [PATCH] meson: add test-dlopen test-dlopen is a very simple binary that is only linked with libc and libdl. From it we do dlopen() on the nss and pam modules to check that they are linked to all necessary libs. (meson-compiled nss modules are linked to less libraries, for whatever reason. I suspected that some deps are missing, but it turns out that my suspicions weren't justified, and the modules load just fine. Let's keep the test though, it is very quick, and might detect missing linkage in the future.) --- meson.build | 99 +++++++++++++++++++++++++----------------- src/test/meson.build | 2 + src/test/test-dlopen.c | 32 ++++++++++++++ 3 files changed, 93 insertions(+), 40 deletions(-) create mode 100644 src/test/test-dlopen.c diff --git a/meson.build b/meson.build index 2b719ec257..86a04a70ed 100644 --- a/meson.build +++ b/meson.build @@ -1046,45 +1046,6 @@ libsystemd = shared_library( ############################################################ -foreach tuple : [['myhostname', 'HAVE_MYHOSTNAME', []], - ['systemd', '', []], - ['mymachines', 'ENABLE_MACHINED', []], - ['resolve', 'ENABLE_RESOLVED', [libdl]]] - - condition = tuple[1] == '' or conf.get(tuple[1], 0) == 1 - if condition - module = tuple[0] - extra_deps = tuple[2] - - sym = 'src/nss-@0@/nss-@0@.sym'.format(module) - version_script_arg = join_paths(meson.current_source_dir(), sym) - - shared_library( - 'nss_' + module, - 'src/nss-@0@/nss-@0@.c'.format(module), - version : '2', - include_directories : includes, - link_args : ['-shared', - '-Wl,--version-script=' + version_script_arg, - '-Wl,--undefined'], - link_with : [libsystemd_internal, - libbasic], - dependencies : [threads, - librt] + extra_deps, - link_depends : sym, - install : true, - install_dir : rootlibdir) - - # We cannot use shared_module because it does not support version suffix. - # Unfortunately shared_library insists on creating the symlink… - meson.add_install_script('sh', '-c', - 'rm $DESTDIR@0@/libnss_@1@.so' - .format(rootlibdir, module)) - endif -endforeach - -############################################################ - # binaries that have --help and are intended for use by humans, # usually, but not always, installed in /bin. public_programs = [] @@ -1114,6 +1075,60 @@ subdir('src/boot/efi') subdir('src/test') subdir('test') +############################################################ + +# only static linking apart from libdl, to make sure that the +# module is linked to all libraries that it uses. +test_dlopen = executable( + 'test-dlopen', + test_dlopen_c, + include_directories : includes, + link_with : [libbasic], + dependencies : [libdl]) + +foreach tuple : [['myhostname', 'HAVE_MYHOSTNAME', []], + ['systemd', '', []], + ['mymachines', 'ENABLE_MACHINED', []], + ['resolve', 'ENABLE_RESOLVED', [libdl]]] + + condition = tuple[1] == '' or conf.get(tuple[1], 0) == 1 + if condition + module = tuple[0] + extra_deps = tuple[2] + + sym = 'src/nss-@0@/nss-@0@.sym'.format(module) + version_script_arg = join_paths(meson.current_source_dir(), sym) + + nss = shared_library( + 'nss_' + module, + 'src/nss-@0@/nss-@0@.c'.format(module), + version : '2', + include_directories : includes, + link_args : ['-shared', + '-Wl,--version-script=' + version_script_arg, + '-Wl,--undefined'], + link_with : [libsystemd_internal, + libbasic], + dependencies : [threads, + librt] + extra_deps, + link_depends : sym, + install : true, + install_dir : rootlibdir) + + # We cannot use shared_module because it does not support version suffix. + # Unfortunately shared_library insists on creating the symlink… + meson.add_install_script('sh', '-c', + 'rm $DESTDIR@0@/libnss_@1@.so' + .format(rootlibdir, module)) + + test('dlopen-nss_' + module, + test_dlopen, + args : [nss.full_path()]) # path to dlopen must include a slash + endif +endforeach + +############################################################ + executable('systemd', systemd_sources, include_directories : includes, @@ -1325,7 +1340,7 @@ if conf.get('ENABLE_LOGIND', 0) == 1 if conf.get('HAVE_PAM', 0) == 1 version_script_arg = join_paths(meson.current_source_dir(), pam_systemd_sym) - shared_library( + pam_systemd = shared_library( 'pam_systemd', pam_systemd_c, name_prefix : '', @@ -1340,6 +1355,10 @@ if conf.get('ENABLE_LOGIND', 0) == 1 link_depends : pam_systemd_sym, install : true, install_dir : pamlibdir) + + test('dlopen-pam_systemd', + test_dlopen, + args : [pam_systemd.full_path()]) # path to dlopen must include a slash endif endif diff --git a/src/test/meson.build b/src/test/meson.build index 17fda96af0..59a51d857e 100644 --- a/src/test/meson.build +++ b/src/test/meson.build @@ -35,6 +35,8 @@ test_libudev_sym_c = custom_target( command : [generate_sym_test_py, '@INPUT0@', '@INPUT1@'], capture : true) +test_dlopen_c = files('test-dlopen.c') + ############################################################ tests += [ diff --git a/src/test/test-dlopen.c b/src/test/test-dlopen.c new file mode 100644 index 0000000000..9f5343a7ea --- /dev/null +++ b/src/test/test-dlopen.c @@ -0,0 +1,32 @@ +/*** + This file is part of systemd. + + Copyright 2016 Zbigniew Jędrzejewski-Szmek + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with systemd; If not, see . +***/ + +#include +#include + +#include "macro.h" + +int main(int argc, char **argv) { + void *handle; + + assert_se((handle = dlopen(argv[1], RTLD_NOW))); + assert_se(dlclose(handle) == 0); + + return EXIT_SUCCESS; +}