]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
Always define and use ENABLE_ELFDBG
authorEmil Velikov <emil.l.velikov@gmail.com>
Tue, 15 Oct 2024 19:36:50 +0000 (20:36 +0100)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Thu, 17 Oct 2024 14:27:15 +0000 (09:27 -0500)
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 <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/173
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
configure.ac
libkmod/libkmod-elf.c
meson.build

index 96749f4b3f0da2660cefa1691fdba5d8b5a818e3..486795eeb4d98cee2f92dc63d4c7e58e67147c9f 100644 (file)
@@ -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@:>@]),
index 23ae76d73de7fa9ebe6ab4bab52bf47a9a52d89e..3e97aaa25bd83d1f1aee0e4bde54cef1519a4d06 100644 (file)
@@ -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)
 {
index aac442f13abc90e6970a6523062bb87c0d15b43f..39ac3f07047ca2157e2dda0aed812a6709b131ef 100644 (file)
@@ -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')