basic/dlfcn-util: deobfuscate macro definitions

When looking at how dlopen for various libs is implemented, I found that the
macros hide too much. I find it much easier to see what is going on if 'extern'
and '= NULL' are written explicitly. After all, we don't hide those for other
definitions, e.g. our style guide says that static variables should be
initialized with '= NULL'. With that change, it's much more obvious what is
a variable declaration and what is a variable initialization.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2024-06-12 15:21:15 +02:00
parent 726fc7ae69
commit 5c672e90a6
31 changed files with 619 additions and 621 deletions
+35 -35
View File
@@ -31,20 +31,20 @@
#if HAVE_LZ4
static void *lz4_dl = NULL;
static DLSYM_FUNCTION(LZ4F_compressBegin);
static DLSYM_FUNCTION(LZ4F_compressBound);
static DLSYM_FUNCTION(LZ4F_compressEnd);
static DLSYM_FUNCTION(LZ4F_compressUpdate);
static DLSYM_FUNCTION(LZ4F_createCompressionContext);
static DLSYM_FUNCTION(LZ4F_createDecompressionContext);
static DLSYM_FUNCTION(LZ4F_decompress);
static DLSYM_FUNCTION(LZ4F_freeCompressionContext);
static DLSYM_FUNCTION(LZ4F_freeDecompressionContext);
static DLSYM_FUNCTION(LZ4F_isError);
DLSYM_FUNCTION(LZ4_compress_default);
DLSYM_FUNCTION(LZ4_decompress_safe);
DLSYM_FUNCTION(LZ4_decompress_safe_partial);
DLSYM_FUNCTION(LZ4_versionNumber);
static DLSYM_PROTOTYPE(LZ4F_compressBegin) = NULL;
static DLSYM_PROTOTYPE(LZ4F_compressBound) = NULL;
static DLSYM_PROTOTYPE(LZ4F_compressEnd) = NULL;
static DLSYM_PROTOTYPE(LZ4F_compressUpdate) = NULL;
static DLSYM_PROTOTYPE(LZ4F_createCompressionContext) = NULL;
static DLSYM_PROTOTYPE(LZ4F_createDecompressionContext) = NULL;
static DLSYM_PROTOTYPE(LZ4F_decompress) = NULL;
static DLSYM_PROTOTYPE(LZ4F_freeCompressionContext) = NULL;
static DLSYM_PROTOTYPE(LZ4F_freeDecompressionContext) = NULL;
static DLSYM_PROTOTYPE(LZ4F_isError) = NULL;
DLSYM_PROTOTYPE(LZ4_compress_default) = NULL;
DLSYM_PROTOTYPE(LZ4_decompress_safe) = NULL;
DLSYM_PROTOTYPE(LZ4_decompress_safe_partial) = NULL;
DLSYM_PROTOTYPE(LZ4_versionNumber) = NULL;
DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(LZ4F_compressionContext_t, sym_LZ4F_freeCompressionContext, NULL);
DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(LZ4F_decompressionContext_t, sym_LZ4F_freeDecompressionContext, NULL);
@@ -53,22 +53,22 @@ DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(LZ4F_decompressionContext_t, sym_LZ4F_freeDecom
#if HAVE_ZSTD
static void *zstd_dl = NULL;
static DLSYM_FUNCTION(ZSTD_CCtx_setParameter);
static DLSYM_FUNCTION(ZSTD_compress);
static DLSYM_FUNCTION(ZSTD_compressStream2);
static DLSYM_FUNCTION(ZSTD_createCCtx);
static DLSYM_FUNCTION(ZSTD_createDCtx);
static DLSYM_FUNCTION(ZSTD_CStreamInSize);
static DLSYM_FUNCTION(ZSTD_CStreamOutSize);
static DLSYM_FUNCTION(ZSTD_decompressStream);
static DLSYM_FUNCTION(ZSTD_DStreamInSize);
static DLSYM_FUNCTION(ZSTD_DStreamOutSize);
static DLSYM_FUNCTION(ZSTD_freeCCtx);
static DLSYM_FUNCTION(ZSTD_freeDCtx);
static DLSYM_FUNCTION(ZSTD_getErrorCode);
static DLSYM_FUNCTION(ZSTD_getErrorName);
static DLSYM_FUNCTION(ZSTD_getFrameContentSize);
static DLSYM_FUNCTION(ZSTD_isError);
static DLSYM_PROTOTYPE(ZSTD_CCtx_setParameter) = NULL;
static DLSYM_PROTOTYPE(ZSTD_compress) = NULL;
static DLSYM_PROTOTYPE(ZSTD_compressStream2) = NULL;
static DLSYM_PROTOTYPE(ZSTD_createCCtx) = NULL;
static DLSYM_PROTOTYPE(ZSTD_createDCtx) = NULL;
static DLSYM_PROTOTYPE(ZSTD_CStreamInSize) = NULL;
static DLSYM_PROTOTYPE(ZSTD_CStreamOutSize) = NULL;
static DLSYM_PROTOTYPE(ZSTD_decompressStream) = NULL;
static DLSYM_PROTOTYPE(ZSTD_DStreamInSize) = NULL;
static DLSYM_PROTOTYPE(ZSTD_DStreamOutSize) = NULL;
static DLSYM_PROTOTYPE(ZSTD_freeCCtx) = NULL;
static DLSYM_PROTOTYPE(ZSTD_freeDCtx) = NULL;
static DLSYM_PROTOTYPE(ZSTD_getErrorCode) = NULL;
static DLSYM_PROTOTYPE(ZSTD_getErrorName) = NULL;
static DLSYM_PROTOTYPE(ZSTD_getFrameContentSize) = NULL;
static DLSYM_PROTOTYPE(ZSTD_isError) = NULL;
DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(ZSTD_CCtx*, sym_ZSTD_freeCCtx, NULL);
DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(ZSTD_DCtx*, sym_ZSTD_freeDCtx, NULL);
@@ -88,11 +88,11 @@ static int zstd_ret_to_errno(size_t ret) {
#if HAVE_XZ
static void *lzma_dl = NULL;
static DLSYM_FUNCTION(lzma_code);
static DLSYM_FUNCTION(lzma_easy_encoder);
static DLSYM_FUNCTION(lzma_end);
static DLSYM_FUNCTION(lzma_stream_buffer_encode);
static DLSYM_FUNCTION(lzma_stream_decoder);
static DLSYM_PROTOTYPE(lzma_code) = NULL;
static DLSYM_PROTOTYPE(lzma_easy_encoder) = NULL;
static DLSYM_PROTOTYPE(lzma_end) = NULL;
static DLSYM_PROTOTYPE(lzma_stream_buffer_encode) = NULL;
static DLSYM_PROTOTYPE(lzma_stream_decoder) = NULL;
/* We can't just do _cleanup_(sym_lzma_end) because a compiler bug makes
* this fail with:
+4 -4
View File
@@ -71,10 +71,10 @@ int decompress_stream_lz4(int fdf, int fdt, uint64_t max_size);
int decompress_stream_zstd(int fdf, int fdt, uint64_t max_size);
#if HAVE_LZ4
DLSYM_PROTOTYPE(LZ4_compress_default);
DLSYM_PROTOTYPE(LZ4_decompress_safe);
DLSYM_PROTOTYPE(LZ4_decompress_safe_partial);
DLSYM_PROTOTYPE(LZ4_versionNumber);
extern DLSYM_PROTOTYPE(LZ4_compress_default);
extern DLSYM_PROTOTYPE(LZ4_decompress_safe);
extern DLSYM_PROTOTYPE(LZ4_decompress_safe_partial);
extern DLSYM_PROTOTYPE(LZ4_versionNumber);
int dlopen_lz4(void);
#endif
+2 -4
View File
@@ -25,10 +25,8 @@ int dlopen_many_sym_or_warn_sentinel(void **dlp, const char *filename, int log_l
#define dlopen_many_sym_or_warn(dlp, filename, log_level, ...) \
dlopen_many_sym_or_warn_sentinel(dlp, filename, log_level, __VA_ARGS__, NULL)
#define DLSYM_PROTOTYPE(symbol) \
extern typeof(symbol)* sym_##symbol
#define DLSYM_FUNCTION(symbol) \
typeof(symbol)* sym_##symbol = NULL
#define DLSYM_PROTOTYPE(symbol) \
typeof(symbol)* sym_##symbol
/* Macro useful for putting together variable/symbol name pairs when calling dlsym_many_or_warn(). Assumes
* that each library symbol to resolve will be placed in a variable with the "sym_" prefix, i.e. a symbol
+32 -32
View File
@@ -7,38 +7,38 @@
static void *gcrypt_dl = NULL;
static DLSYM_FUNCTION(gcry_control);
static DLSYM_FUNCTION(gcry_check_version);
DLSYM_FUNCTION(gcry_md_close);
DLSYM_FUNCTION(gcry_md_copy);
DLSYM_FUNCTION(gcry_md_ctl);
DLSYM_FUNCTION(gcry_md_get_algo_dlen);
DLSYM_FUNCTION(gcry_md_open);
DLSYM_FUNCTION(gcry_md_read);
DLSYM_FUNCTION(gcry_md_reset);
DLSYM_FUNCTION(gcry_md_setkey);
DLSYM_FUNCTION(gcry_md_write);
DLSYM_FUNCTION(gcry_mpi_add);
DLSYM_FUNCTION(gcry_mpi_add_ui);
DLSYM_FUNCTION(gcry_mpi_cmp);
DLSYM_FUNCTION(gcry_mpi_cmp_ui);
DLSYM_FUNCTION(gcry_mpi_get_nbits);
DLSYM_FUNCTION(gcry_mpi_invm);
DLSYM_FUNCTION(gcry_mpi_mod);
DLSYM_FUNCTION(gcry_mpi_mul);
DLSYM_FUNCTION(gcry_mpi_mulm);
DLSYM_FUNCTION(gcry_mpi_new);
DLSYM_FUNCTION(gcry_mpi_powm);
DLSYM_FUNCTION(gcry_mpi_print);
DLSYM_FUNCTION(gcry_mpi_release);
DLSYM_FUNCTION(gcry_mpi_scan);
DLSYM_FUNCTION(gcry_mpi_set_ui);
DLSYM_FUNCTION(gcry_mpi_sub);
DLSYM_FUNCTION(gcry_mpi_subm);
DLSYM_FUNCTION(gcry_mpi_sub_ui);
DLSYM_FUNCTION(gcry_prime_check);
DLSYM_FUNCTION(gcry_randomize);
DLSYM_FUNCTION(gcry_strerror);
static DLSYM_PROTOTYPE(gcry_control) = NULL;
static DLSYM_PROTOTYPE(gcry_check_version) = NULL;
DLSYM_PROTOTYPE(gcry_md_close) = NULL;
DLSYM_PROTOTYPE(gcry_md_copy) = NULL;
DLSYM_PROTOTYPE(gcry_md_ctl) = NULL;
DLSYM_PROTOTYPE(gcry_md_get_algo_dlen) = NULL;
DLSYM_PROTOTYPE(gcry_md_open) = NULL;
DLSYM_PROTOTYPE(gcry_md_read) = NULL;
DLSYM_PROTOTYPE(gcry_md_reset) = NULL;
DLSYM_PROTOTYPE(gcry_md_setkey) = NULL;
DLSYM_PROTOTYPE(gcry_md_write) = NULL;
DLSYM_PROTOTYPE(gcry_mpi_add) = NULL;
DLSYM_PROTOTYPE(gcry_mpi_add_ui) = NULL;
DLSYM_PROTOTYPE(gcry_mpi_cmp) = NULL;
DLSYM_PROTOTYPE(gcry_mpi_cmp_ui) = NULL;
DLSYM_PROTOTYPE(gcry_mpi_get_nbits) = NULL;
DLSYM_PROTOTYPE(gcry_mpi_invm) = NULL;
DLSYM_PROTOTYPE(gcry_mpi_mod) = NULL;
DLSYM_PROTOTYPE(gcry_mpi_mul) = NULL;
DLSYM_PROTOTYPE(gcry_mpi_mulm) = NULL;
DLSYM_PROTOTYPE(gcry_mpi_new) = NULL;
DLSYM_PROTOTYPE(gcry_mpi_powm) = NULL;
DLSYM_PROTOTYPE(gcry_mpi_print) = NULL;
DLSYM_PROTOTYPE(gcry_mpi_release) = NULL;
DLSYM_PROTOTYPE(gcry_mpi_scan) = NULL;
DLSYM_PROTOTYPE(gcry_mpi_set_ui) = NULL;
DLSYM_PROTOTYPE(gcry_mpi_sub) = NULL;
DLSYM_PROTOTYPE(gcry_mpi_subm) = NULL;
DLSYM_PROTOTYPE(gcry_mpi_sub_ui) = NULL;
DLSYM_PROTOTYPE(gcry_prime_check) = NULL;
DLSYM_PROTOTYPE(gcry_randomize) = NULL;
DLSYM_PROTOTYPE(gcry_strerror) = NULL;
static int dlopen_gcrypt(void) {
ELF_NOTE_DLOPEN("gcrypt",
+30 -30
View File
@@ -12,36 +12,36 @@
#include "dlfcn-util.h"
#include "macro.h"
DLSYM_PROTOTYPE(gcry_md_close);
DLSYM_PROTOTYPE(gcry_md_copy);
DLSYM_PROTOTYPE(gcry_md_ctl);
DLSYM_PROTOTYPE(gcry_md_get_algo_dlen);
DLSYM_PROTOTYPE(gcry_md_open);
DLSYM_PROTOTYPE(gcry_md_read);
DLSYM_PROTOTYPE(gcry_md_reset);
DLSYM_PROTOTYPE(gcry_md_setkey);
DLSYM_PROTOTYPE(gcry_md_write);
DLSYM_PROTOTYPE(gcry_mpi_add);
DLSYM_PROTOTYPE(gcry_mpi_add_ui);
DLSYM_PROTOTYPE(gcry_mpi_cmp);
DLSYM_PROTOTYPE(gcry_mpi_cmp_ui);
DLSYM_PROTOTYPE(gcry_mpi_get_nbits);
DLSYM_PROTOTYPE(gcry_mpi_invm);
DLSYM_PROTOTYPE(gcry_mpi_mod);
DLSYM_PROTOTYPE(gcry_mpi_mul);
DLSYM_PROTOTYPE(gcry_mpi_mulm);
DLSYM_PROTOTYPE(gcry_mpi_new);
DLSYM_PROTOTYPE(gcry_mpi_powm);
DLSYM_PROTOTYPE(gcry_mpi_print);
DLSYM_PROTOTYPE(gcry_mpi_release);
DLSYM_PROTOTYPE(gcry_mpi_scan);
DLSYM_PROTOTYPE(gcry_mpi_set_ui);
DLSYM_PROTOTYPE(gcry_mpi_sub);
DLSYM_PROTOTYPE(gcry_mpi_subm);
DLSYM_PROTOTYPE(gcry_mpi_sub_ui);
DLSYM_PROTOTYPE(gcry_prime_check);
DLSYM_PROTOTYPE(gcry_randomize);
DLSYM_PROTOTYPE(gcry_strerror);
extern DLSYM_PROTOTYPE(gcry_md_close);
extern DLSYM_PROTOTYPE(gcry_md_copy);
extern DLSYM_PROTOTYPE(gcry_md_ctl);
extern DLSYM_PROTOTYPE(gcry_md_get_algo_dlen);
extern DLSYM_PROTOTYPE(gcry_md_open);
extern DLSYM_PROTOTYPE(gcry_md_read);
extern DLSYM_PROTOTYPE(gcry_md_reset);
extern DLSYM_PROTOTYPE(gcry_md_setkey);
extern DLSYM_PROTOTYPE(gcry_md_write);
extern DLSYM_PROTOTYPE(gcry_mpi_add);
extern DLSYM_PROTOTYPE(gcry_mpi_add_ui);
extern DLSYM_PROTOTYPE(gcry_mpi_cmp);
extern DLSYM_PROTOTYPE(gcry_mpi_cmp_ui);
extern DLSYM_PROTOTYPE(gcry_mpi_get_nbits);
extern DLSYM_PROTOTYPE(gcry_mpi_invm);
extern DLSYM_PROTOTYPE(gcry_mpi_mod);
extern DLSYM_PROTOTYPE(gcry_mpi_mul);
extern DLSYM_PROTOTYPE(gcry_mpi_mulm);
extern DLSYM_PROTOTYPE(gcry_mpi_new);
extern DLSYM_PROTOTYPE(gcry_mpi_powm);
extern DLSYM_PROTOTYPE(gcry_mpi_print);
extern DLSYM_PROTOTYPE(gcry_mpi_release);
extern DLSYM_PROTOTYPE(gcry_mpi_scan);
extern DLSYM_PROTOTYPE(gcry_mpi_set_ui);
extern DLSYM_PROTOTYPE(gcry_mpi_sub);
extern DLSYM_PROTOTYPE(gcry_mpi_subm);
extern DLSYM_PROTOTYPE(gcry_mpi_sub_ui);
extern DLSYM_PROTOTYPE(gcry_prime_check);
extern DLSYM_PROTOTYPE(gcry_randomize);
extern DLSYM_PROTOTYPE(gcry_strerror);
int initialize_libgcrypt(bool secmem);