From d7e7c4c49951bd8384640bbd7fb13e1484101af5 Mon Sep 17 00:00:00 2001 From: Lucas De Marchi Date: Fri, 3 Jan 2025 14:32:00 -0600 Subject: [PATCH] shared/macro: Add macros for more attributes Move attributes from test definition to a wrapper macro. Signed-off-by: Lucas De Marchi Link: https://github.com/kmod-project/kmod/pull/274 --- shared/macro.h | 4 ++++ testsuite/testsuite.h | 7 +++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/shared/macro.h b/shared/macro.h index 4cbdc7aa..3e8143f8 100644 --- a/shared/macro.h +++ b/shared/macro.h @@ -45,6 +45,10 @@ #define _printf_format_(a, b) __attribute__((format(printf, a, b))) #define _always_inline_ __inline__ __attribute__((always_inline)) #define _sentinel_ __attribute__((sentinel)) +#define _used_ __attribute((used)) +#define _retain_ __attribute((retain)) +#define _section_(a) __attribute((section(a))) +#define _aligned_(a) __attribute((aligned(a))) #if defined(__clang_analyzer__) #define _clang_suppress_ __attribute__((suppress)) diff --git a/testsuite/testsuite.h b/testsuite/testsuite.h index 9486622a..eca276d5 100644 --- a/testsuite/testsuite.h +++ b/testsuite/testsuite.h @@ -129,8 +129,11 @@ int test_run(const struct test *t); // clang-format off: At least up to version 18, it just makes a mess with _Pragma() #define DEFINE_TEST_WITH_FUNC(_name, _func, ...) \ _Pragma("GCC diagnostic ignored \"-Wattributes\"") \ - static const struct test UNIQ(s##_name) \ - __attribute__((retain, used, section("kmod_tests"), aligned(8))) = { \ + _used_ \ + _retain_ \ + _section_("kmod_tests") \ + _aligned_(8) \ + static const struct test UNIQ(s##_name) = { \ .name = #_name, .func = _func, ##__VA_ARGS__ \ }; // clang-format on -- 2.47.2