From 2d4ceca8a5f606beed5f11b0d307913727590c00 Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Tue, 19 Dec 2017 14:19:46 +0100 Subject: meson: link libbasic and libshared_static into libshared gcrypt_util_sources had to be moved because otherwise they appeared twice in libshared.so halfproducts, causing an error. -fvisibility=default is added to libbasic, libshared_static so that the symbols appear properly in the exported symbol list in libshared. The advantage is that files are not compiled twice. When configured with -Dman=false, the ninja target list is reduced from 1588 to 1347 targets. The difference in compilation time is small (<10%). I think this is because of -O0 and ccache and multiple cores, and in different settings the compilation time could be reduced. The main advantage is that errors and warnings are not reported twice. --- src/basic/meson.build | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/basic/meson.build') diff --git a/src/basic/meson.build b/src/basic/meson.build index a37e279e57..43a2e11356 100644 --- a/src/basic/meson.build +++ b/src/basic/meson.build @@ -15,7 +15,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with systemd; If not, see . -basic_sources_plain = files(''' +basic_sources = files(''' MurmurHash2.c MurmurHash2.h af-list.c @@ -294,7 +294,7 @@ foreach item : [['af', af_list_txt, 'af', ''], generated_gperf_headers += [target1, target2] endforeach -basic_sources = basic_sources_plain + [missing_h] + generated_gperf_headers +basic_sources += [missing_h] + generated_gperf_headers libbasic = static_library( 'basic', @@ -303,6 +303,6 @@ libbasic = static_library( dependencies : [threads, libcap, libblkid, - libselinux, - ], + libselinux], + c_args : ['-fvisibility=default'], install : false) -- cgit v1.2.3 From 34e221a58bb3f4d5d58fe238a6a5e5a5df30d4ff Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Tue, 19 Dec 2017 19:06:56 +0100 Subject: Move gcrypt-util to basic/ We were including gcrypt-util.[ch] by hand in the few places where it was used. Create a convenience library to avoid compiling the same files multiple times. v2: - use a separate static library instead of mergin into libbasic --- meson.build | 18 ++++-------- src/basic/gcrypt-util.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++ src/basic/gcrypt-util.h | 48 ++++++++++++++++++++++++++++++++ src/basic/meson.build | 10 +++++++ src/shared/gcrypt-util.c | 72 ------------------------------------------------ src/shared/gcrypt-util.h | 48 -------------------------------- src/shared/meson.build | 5 ++-- 7 files changed, 138 insertions(+), 135 deletions(-) create mode 100644 src/basic/gcrypt-util.c create mode 100644 src/basic/gcrypt-util.h delete mode 100644 src/shared/gcrypt-util.c delete mode 100644 src/shared/gcrypt-util.h (limited to 'src/basic/meson.build') diff --git a/meson.build b/meson.build index 8ea3c03788..fa0b0abf74 100644 --- a/meson.build +++ b/meson.build @@ -1235,9 +1235,6 @@ includes = include_directories('src/basic', add_project_arguments('-include', 'config.h', language : 'c') -gcrypt_util_sources = files('src/shared/gcrypt-util.h', - 'src/shared/gcrypt-util.c') - subdir('po') subdir('catalog') subdir('src/systemd') @@ -1258,15 +1255,14 @@ libsystemd_sym_path = '@0@/@1@'.format(meson.current_source_dir(), libsystemd_sy libsystemd = shared_library( 'systemd', journal_internal_sources, - gcrypt_util_sources, version : libsystemd_version, include_directories : includes, link_args : ['-shared', '-Wl,--version-script=' + libsystemd_sym_path], - link_with : libbasic, + link_with : [libbasic, + libbasic_gcrypt], link_whole : libsystemd_static, dependencies : [threads, - libgcrypt, librt, libxz, liblz4], @@ -1507,11 +1503,10 @@ endif if conf.get('ENABLE_RESOLVE') == 1 executable('systemd-resolved', systemd_resolved_sources, - gcrypt_util_sources, include_directories : includes, - link_with : [libshared], + link_with : [libshared, + libbasic_gcrypt], dependencies : [threads, - libgcrypt, libgpg_error, libm, libidn], @@ -1521,11 +1516,10 @@ if conf.get('ENABLE_RESOLVE') == 1 exe = executable('systemd-resolve', systemd_resolve_sources, - gcrypt_util_sources, include_directories : includes, - link_with : [libshared], + link_with : [libshared, + libbasic_gcrypt], dependencies : [threads, - libgcrypt, libgpg_error, libm, libidn], diff --git a/src/basic/gcrypt-util.c b/src/basic/gcrypt-util.c new file mode 100644 index 0000000000..1bfb776725 --- /dev/null +++ b/src/basic/gcrypt-util.c @@ -0,0 +1,72 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +/*** + This file is part of systemd. + + Copyright 2012 Lennart Poettering + + 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 . +***/ + +#if HAVE_GCRYPT +#include + +#include "gcrypt-util.h" +#include "hexdecoct.h" + +void initialize_libgcrypt(bool secmem) { + const char *p; + if (gcry_control(GCRYCTL_INITIALIZATION_FINISHED_P)) + return; + + p = gcry_check_version("1.4.5"); + assert(p); + + /* Turn off "secmem". Clients which wish to make use of this + * feature should initialize the library manually */ + if (!secmem) + gcry_control(GCRYCTL_DISABLE_SECMEM); + gcry_control(GCRYCTL_INITIALIZATION_FINISHED, 0); +} + +int string_hashsum(const char *s, size_t len, int md_algorithm, char **out) { + gcry_md_hd_t md = NULL; + size_t hash_size; + void *hash; + char *enc; + + initialize_libgcrypt(false); + + hash_size = gcry_md_get_algo_dlen(md_algorithm); + assert(hash_size > 0); + + gcry_md_open(&md, md_algorithm, 0); + if (!md) + return -EIO; + + gcry_md_write(md, s, len); + + hash = gcry_md_read(md, 0); + if (!hash) + return -EIO; + + enc = hexmem(hash, hash_size); + if (!enc) + return -ENOMEM; + + *out = enc; + return 0; +} +#endif diff --git a/src/basic/gcrypt-util.h b/src/basic/gcrypt-util.h new file mode 100644 index 0000000000..69faf08e56 --- /dev/null +++ b/src/basic/gcrypt-util.h @@ -0,0 +1,48 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +/*** + 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 + +#if HAVE_GCRYPT +#include + +void initialize_libgcrypt(bool secmem); +int string_hashsum(const char *s, size_t len, int md_algorithm, char **out); +#endif + +static inline int string_hashsum_sha224(const char *s, size_t len, char **out) { +#if HAVE_GCRYPT + return string_hashsum(s, len, GCRY_MD_SHA224, out); +#else + return -EOPNOTSUPP; +#endif +} + +static inline int string_hashsum_sha256(const char *s, size_t len, char **out) { +#if HAVE_GCRYPT + return string_hashsum(s, len, GCRY_MD_SHA256, out); +#else + return -EOPNOTSUPP; +#endif +} diff --git a/src/basic/meson.build b/src/basic/meson.build index 43a2e11356..fce1d218c0 100644 --- a/src/basic/meson.build +++ b/src/basic/meson.build @@ -306,3 +306,13 @@ libbasic = static_library( libselinux], c_args : ['-fvisibility=default'], install : false) + +# A convenience library that is separate from libbasic to avoid +# unnecessary linking to libgcrypt. +libbasic_gcrypt = static_library( + 'basic-gcrypt', + 'gcrypt-util.c', + 'gcrypt-util.h', + include_directories : includes, + dependencies : [libgcrypt], + c_args : ['-fvisibility=default']) diff --git a/src/shared/gcrypt-util.c b/src/shared/gcrypt-util.c deleted file mode 100644 index 1bfb776725..0000000000 --- a/src/shared/gcrypt-util.c +++ /dev/null @@ -1,72 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1+ */ -/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ - -/*** - This file is part of systemd. - - Copyright 2012 Lennart Poettering - - 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 . -***/ - -#if HAVE_GCRYPT -#include - -#include "gcrypt-util.h" -#include "hexdecoct.h" - -void initialize_libgcrypt(bool secmem) { - const char *p; - if (gcry_control(GCRYCTL_INITIALIZATION_FINISHED_P)) - return; - - p = gcry_check_version("1.4.5"); - assert(p); - - /* Turn off "secmem". Clients which wish to make use of this - * feature should initialize the library manually */ - if (!secmem) - gcry_control(GCRYCTL_DISABLE_SECMEM); - gcry_control(GCRYCTL_INITIALIZATION_FINISHED, 0); -} - -int string_hashsum(const char *s, size_t len, int md_algorithm, char **out) { - gcry_md_hd_t md = NULL; - size_t hash_size; - void *hash; - char *enc; - - initialize_libgcrypt(false); - - hash_size = gcry_md_get_algo_dlen(md_algorithm); - assert(hash_size > 0); - - gcry_md_open(&md, md_algorithm, 0); - if (!md) - return -EIO; - - gcry_md_write(md, s, len); - - hash = gcry_md_read(md, 0); - if (!hash) - return -EIO; - - enc = hexmem(hash, hash_size); - if (!enc) - return -ENOMEM; - - *out = enc; - return 0; -} -#endif diff --git a/src/shared/gcrypt-util.h b/src/shared/gcrypt-util.h deleted file mode 100644 index 69faf08e56..0000000000 --- a/src/shared/gcrypt-util.h +++ /dev/null @@ -1,48 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1+ */ -/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ - -/*** - 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 - -#if HAVE_GCRYPT -#include - -void initialize_libgcrypt(bool secmem); -int string_hashsum(const char *s, size_t len, int md_algorithm, char **out); -#endif - -static inline int string_hashsum_sha224(const char *s, size_t len, char **out) { -#if HAVE_GCRYPT - return string_hashsum(s, len, GCRY_MD_SHA224, out); -#else - return -EOPNOTSUPP; -#endif -} - -static inline int string_hashsum_sha256(const char *s, size_t len, char **out) { -#if HAVE_GCRYPT - return string_hashsum(s, len, GCRY_MD_SHA256, out); -#else - return -EOPNOTSUPP; -#endif -} diff --git a/src/shared/meson.build b/src/shared/meson.build index a9ad217fec..7402e75592 100644 --- a/src/shared/meson.build +++ b/src/shared/meson.build @@ -56,8 +56,6 @@ shared_sources = ''' firewall-util.h fstab-util.c fstab-util.h - gcrypt-util.c - gcrypt-util.h generator.c generator.h gpt.h @@ -175,7 +173,8 @@ libshared = shared_library( link_args : ['-shared', '-Wl,--version-script=' + libshared_sym_path], link_whole : [libshared_static, - libbasic], + libbasic, + libbasic_gcrypt], c_args : ['-fvisibility=default'], dependencies : libshared_deps, install : true, -- cgit v1.2.3