From 276a28afd188f8e0bfe321d1de4239f5189509cc Mon Sep 17 00:00:00 2001 From: Jeremy Huddleston Sequoia Date: Fri, 27 Jan 2023 23:25:36 -0800 Subject: [PATCH] tests: Specify the test section as __RODATA on darwin Addresses build failures on darwin such as: tests/os-wrappers-test.c:413:1: error: argument to 'section' attribute is not valid for this target: mach-o section specifier requires a segment and section separated by a comma TEST(os_wrappers_epoll_create_cloexec_fallback) ^ ../tests/test-runner.h:44:35: note: expanded from macro 'TEST' __attribute__ ((used, section ("test_section"))) = { \ ^ Signed-off-by: Jeremy Huddleston Sequoia --- tests/test-runner.c | 5 +++++ tests/test-runner.h | 10 ++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/test-runner.c b/tests/test-runner.c index 868e1ff5..7a61ecba 100644 --- a/tests/test-runner.c +++ b/tests/test-runner.c @@ -63,7 +63,12 @@ static int timeouts_enabled = 1; /* set to one if the output goes to the terminal */ static int is_atty = 0; +#ifdef __APPLE__ +extern const struct test __start_test_section __asm("section$start$__RODATA$test_section"); +extern const struct test __stop_test_section __asm("section$end$__RODATA$test_section"); +#else extern const struct test __start_test_section, __stop_test_section; +#endif static const struct test * find_test(const char *name) diff --git a/tests/test-runner.h b/tests/test-runner.h index d0734009..2024fa13 100644 --- a/tests/test-runner.h +++ b/tests/test-runner.h @@ -31,6 +31,12 @@ #include +#ifdef __APPLE__ +#define TEST_SECTION "__RODATA,test_section" +#else +#define TEST_SECTION "test_section" +#endif + struct test { const char *name; void (*run)(void); @@ -41,7 +47,7 @@ struct test { static void name(void); \ \ const struct test test##name \ - __attribute__ ((used, section ("test_section"))) = { \ + __attribute__ ((used, section (TEST_SECTION))) = { \ #name, name, 0 \ }; \ \ @@ -51,7 +57,7 @@ struct test { static void name(void); \ \ const struct test test##name \ - __attribute__ ((used, section ("test_section"))) = { \ + __attribute__ ((used, section (TEST_SECTION))) = { \ #name, name, 1 \ }; \ \