From: Lucas De Marchi Date: Fri, 3 Jan 2025 19:01:14 +0000 (-0600) Subject: testsuite: Fix build when linking with lld X-Git-Tag: v34~20 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0396fc239ddacb6d774b5d4e315721d0aa022f5b;p=thirdparty%2Fkmod.git testsuite: Fix build when linking with lld When building with clang and linking with lld there is an issue with keeping the kmod_tests sections: On ELF targets, __attribute__((used)) prevents compiler discarding, but does not affect linker --gc-sections, according to https://lld.llvm.org/ELF/start-stop-gc. Make sure the _start/_stop symbols are not weak and add the "retain" attribute. Closes: https://github.com/kmod-project/kmod/issues/269 Signed-off-by: Lucas De Marchi Link: https://github.com/kmod-project/kmod/pull/274 --- diff --git a/testsuite/testsuite.h b/testsuite/testsuite.h index 161817e7..9486622a 100644 --- a/testsuite/testsuite.h +++ b/testsuite/testsuite.h @@ -126,19 +126,20 @@ int test_run(const struct test *t); } while (false) /* Test definitions */ -#define DEFINE_TEST_WITH_FUNC(_name, _func, ...) \ - static const struct test UNIQ(s##_name) \ - __attribute__((used, section("kmod_tests"), aligned(8))) = { \ - .name = #_name, .func = _func, ##__VA_ARGS__ \ - }; +// 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))) = { \ + .name = #_name, .func = _func, ##__VA_ARGS__ \ + }; +// clang-format on #define DEFINE_TEST(_name, ...) DEFINE_TEST_WITH_FUNC(_name, _name, __VA_ARGS__) #define TESTSUITE_MAIN() \ - extern struct test __start_kmod_tests[] \ - __attribute__((weak, visibility("hidden"))); \ - extern struct test __stop_kmod_tests[] \ - __attribute__((weak, visibility("hidden"))); \ + extern struct test __start_kmod_tests[] __attribute__((visibility("hidden"))); \ + extern struct test __stop_kmod_tests[] __attribute__((visibility("hidden"))); \ int main(int argc, char *argv[]) \ { \ const struct test *t; \