From 5517e214c8e6a18decf54884c9a5566fd7236764 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 3 Dec 2020 20:21:11 +0100 Subject: [PATCH] tree-wide: make use of new DLSYM_ARG() macro everywhere --- src/journal/pcre2-dlopen.c | 22 +++++++++++++++------- src/shared/cryptsetup-util.c | 34 +++++++++++++++++----------------- src/shared/idn-util.c | 14 +++++++------- src/shared/pwquality-util.c | 16 ++++++++-------- src/shared/qrcode-util.c | 4 ++-- 5 files changed, 49 insertions(+), 41 deletions(-) diff --git a/src/journal/pcre2-dlopen.c b/src/journal/pcre2-dlopen.c index fbe81f99eb..5f78f76672 100644 --- a/src/journal/pcre2-dlopen.c +++ b/src/journal/pcre2-dlopen.c @@ -27,16 +27,24 @@ int dlopen_pcre2(void) { return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "PCRE2 support is not installed: %s", dlerror()); + /* So here's something weird: PCRE2 actually renames the symbols exported by the library via C + * macros, so that the exported symbols carry a suffix "_8" but when used from C the suffix is + * gone. In the argument list below we ignore this mangling. Surprisingly (at least to me), we + * actually get away with that. That's because DLSYM_ARG() useses STRINGIFY() to generate a string + * version of the symbol name, and that resolves the macro mapping implicitly already, so that the + * string actually contains the "_8" suffix already due to that and we don't have to append it + * manually anymore. C is weird. 🤯 */ + r = dlsym_many_and_warn( dl, LOG_ERR, - &sym_pcre2_match_data_create, "pcre2_match_data_create_8", - &sym_pcre2_match_data_free, "pcre2_match_data_free_8", - &sym_pcre2_code_free, "pcre2_code_free_8", - &sym_pcre2_compile, "pcre2_compile_8", - &sym_pcre2_get_error_message, "pcre2_get_error_message_8", - &sym_pcre2_match, "pcre2_match_8", - &sym_pcre2_get_ovector_pointer, "pcre2_get_ovector_pointer_8", + DLSYM_ARG(pcre2_match_data_create), + DLSYM_ARG(pcre2_match_data_free), + DLSYM_ARG(pcre2_code_free), + DLSYM_ARG(pcre2_compile), + DLSYM_ARG(pcre2_get_error_message), + DLSYM_ARG(pcre2_match), + DLSYM_ARG(pcre2_get_ovector_pointer), NULL); if (r < 0) return r; diff --git a/src/shared/cryptsetup-util.c b/src/shared/cryptsetup-util.c index 34a078e7e7..b02d95ac55 100644 --- a/src/shared/cryptsetup-util.c +++ b/src/shared/cryptsetup-util.c @@ -43,25 +43,25 @@ int dlopen_cryptsetup(void) { r = dlsym_many_and_warn( dl, LOG_DEBUG, - &sym_crypt_activate_by_passphrase, "crypt_activate_by_passphrase", + DLSYM_ARG(crypt_activate_by_passphrase), #if HAVE_CRYPT_ACTIVATE_BY_SIGNED_KEY - &sym_crypt_activate_by_signed_key, "crypt_activate_by_signed_key", + DLSYM_ARG(crypt_activate_by_signed_key), #endif - &sym_crypt_activate_by_volume_key, "crypt_activate_by_volume_key", - &sym_crypt_deactivate_by_name, "crypt_deactivate_by_name", - &sym_crypt_format, "crypt_format", - &sym_crypt_free, "crypt_free", - &sym_crypt_get_dir, "crypt_get_dir", - &sym_crypt_get_verity_info, "crypt_get_verity_info", - &sym_crypt_init, "crypt_init", - &sym_crypt_init_by_name, "crypt_init_by_name", - &sym_crypt_keyslot_add_by_volume_key, "crypt_keyslot_add_by_volume_key", - &sym_crypt_load, "crypt_load", - &sym_crypt_resize, "crypt_resize", - &sym_crypt_set_data_device, "crypt_set_data_device", - &sym_crypt_set_debug_level, "crypt_set_debug_level", - &sym_crypt_set_log_callback, "crypt_set_log_callback", - &sym_crypt_volume_key_get, "crypt_volume_key_get", + DLSYM_ARG(crypt_activate_by_volume_key), + DLSYM_ARG(crypt_deactivate_by_name), + DLSYM_ARG(crypt_format), + DLSYM_ARG(crypt_free), + DLSYM_ARG(crypt_get_dir), + DLSYM_ARG(crypt_get_verity_info), + DLSYM_ARG(crypt_init), + DLSYM_ARG(crypt_init_by_name), + DLSYM_ARG(crypt_keyslot_add_by_volume_key), + DLSYM_ARG(crypt_load), + DLSYM_ARG(crypt_resize), + DLSYM_ARG(crypt_set_data_device), + DLSYM_ARG(crypt_set_debug_level), + DLSYM_ARG(crypt_set_log_callback), + DLSYM_ARG(crypt_volume_key_get), NULL); if (r < 0) return r; diff --git a/src/shared/idn-util.c b/src/shared/idn-util.c index 83c4b3c530..1c4472dc66 100644 --- a/src/shared/idn-util.c +++ b/src/shared/idn-util.c @@ -35,9 +35,9 @@ int dlopen_idn(void) { r = dlsym_many_and_warn( dl, LOG_DEBUG, - &sym_idn2_lookup_u8, "idn2_lookup_u8", - &sym_idn2_strerror, "idn2_strerror", - &sym_idn2_to_unicode_8z8z, "idn2_to_unicode_8z8z", + DLSYM_ARG(idn2_lookup_u8), + DLSYM_ARG(idn2_strerror), + DLSYM_ARG(idn2_to_unicode_8z8z), NULL); if (r < 0) return r; @@ -76,10 +76,10 @@ int dlopen_idn(void) { r = dlsym_many_and_warn( dl, LOG_DEBUG, - &sym_idna_to_ascii_4i, "idna_to_ascii_4i", - &sym_idna_to_unicode_44i, "idna_to_unicode_44i", - &sym_stringprep_ucs4_to_utf8, "stringprep_ucs4_to_utf8", - &sym_stringprep_utf8_to_ucs4, "stringprep_utf8_to_ucs4", + DLSYM_ARG(idna_to_ascii_4i), + DLSYM_ARG(idna_to_unicode_44i), + DLSYM_ARG(stringprep_ucs4_to_utf8), + DLSYM_ARG(stringprep_utf8_to_ucs4), NULL); if (r < 0) return r; diff --git a/src/shared/pwquality-util.c b/src/shared/pwquality-util.c index 4000bef89e..5bd33eee4c 100644 --- a/src/shared/pwquality-util.c +++ b/src/shared/pwquality-util.c @@ -38,14 +38,14 @@ int dlopen_pwquality(void) { r = dlsym_many_and_warn( dl, LOG_DEBUG, - &sym_pwquality_check, "pwquality_check", - &sym_pwquality_default_settings, "pwquality_default_settings", - &sym_pwquality_free_settings, "pwquality_free_settings", - &sym_pwquality_generate, "pwquality_generate", - &sym_pwquality_get_str_value, "pwquality_get_str_value", - &sym_pwquality_read_config, "pwquality_read_config", - &sym_pwquality_set_int_value, "pwquality_set_int_value", - &sym_pwquality_strerror, "pwquality_strerror", + DLSYM_ARG(pwquality_check), + DLSYM_ARG(pwquality_default_settings), + DLSYM_ARG(pwquality_free_settings), + DLSYM_ARG(pwquality_generate), + DLSYM_ARG(pwquality_get_str_value), + DLSYM_ARG(pwquality_read_config), + DLSYM_ARG(pwquality_set_int_value), + DLSYM_ARG(pwquality_strerror), NULL); if (r < 0) return r; diff --git a/src/shared/qrcode-util.c b/src/shared/qrcode-util.c index 7050e186b7..f7d2d984c9 100644 --- a/src/shared/qrcode-util.c +++ b/src/shared/qrcode-util.c @@ -84,8 +84,8 @@ int print_qrcode(FILE *out, const char *header, const char *string) { r = dlsym_many_and_warn( dl, LOG_DEBUG, - &sym_QRcode_encodeString, "QRcode_encodeString", - &sym_QRcode_free, "QRcode_free", + DLSYM_ARG(QRcode_encodeString), + DLSYM_ARG(QRcode_free), NULL); if (r < 0) return r;