From: Emil Velikov Date: Tue, 15 Oct 2024 19:36:50 +0000 (+0100) Subject: Always define and use ENABLE_ELFDBG X-Git-Tag: v34~222 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=eea5278df7fa6e3e20aebdd42df9368f40a21694;p=thirdparty%2Fkmod.git Always define and use ENABLE_ELFDBG Convert the "if defined FOO" pre-processor checks for compiler ones "if (FOO == 1)". This makes things easier to reason with and ensures both code-paths are build-tested. In case, the option is disabled DCE will kick in (assuming you're not force disabling all optimisations) and remove the respective code. Signed-off-by: Emil Velikov Link: https://github.com/kmod-project/kmod/pull/173 Signed-off-by: Lucas De Marchi --- diff --git a/configure.ac b/configure.ac index 96749f4b..486795ee 100644 --- a/configure.ac +++ b/configure.ac @@ -219,6 +219,7 @@ AS_IF([test "x$enable_debug" = "xyes"], [ ], [ AC_DEFINE(ENABLE_DEBUG, [0], [Debug messages.]) ]) +AC_DEFINE(ENABLE_ELFDBG, [0], [Debug elf parsing messages.]) AC_ARG_ENABLE([coverage], AS_HELP_STRING([--enable-coverage], [enable test coverage @<:@default=disabled@:>@]), diff --git a/libkmod/libkmod-elf.c b/libkmod/libkmod-elf.c index 23ae76d7..3e97aaa2 100644 --- a/libkmod/libkmod-elf.c +++ b/libkmod/libkmod-elf.c @@ -53,10 +53,14 @@ struct kmod_elf { } header; }; +//#undef ENABLE_ELFDBG //#define ENABLE_ELFDBG 1 -#if (ENABLE_LOGGING == 1) && defined(ENABLE_ELFDBG) -#define ELFDBG(elf, ...) _elf_dbg(elf, __FILE__, __LINE__, __func__, __VA_ARGS__); +#define ELFDBG(elf, ...) \ + do { \ + if (ENABLE_LOGGING == 1 && ENABLE_ELFDBG == 1) \ + _elf_dbg(elf, __FILE__, __LINE__, __func__, __VA_ARGS__); \ + } while (0); static inline void _elf_dbg(const struct kmod_elf *elf, const char *fname, unsigned line, const char *func, const char *fmt, ...) @@ -69,9 +73,6 @@ static inline void _elf_dbg(const struct kmod_elf *elf, const char *fname, unsig vfprintf(stderr, fmt, args); va_end(args); } -#else -#define ELFDBG(elf, ...) -#endif static int elf_identify(const void *memory, uint64_t size) { diff --git a/meson.build b/meson.build index aac442f1..39ac3f07 100644 --- a/meson.build +++ b/meson.build @@ -20,6 +20,7 @@ cdata.set_quoted('VERSION', meson.project_version()) cdata.set10('ENABLE_LOGGING', get_option('logging')) cdata.set10('ENABLE_DEBUG', get_option('debug-messages')) +cdata.set10('ENABLE_ELFDBG', false) pkg = import('pkgconfig') cc = meson.get_compiler('c')