Merge pull request #1091 from yamt/mach-o

adapt the linker sections usage to mach-o
This commit is contained in:
Christopher Haster
2025-05-13 00:45:02 -05:00
committed by GitHub
4 changed files with 18 additions and 2 deletions

View File

@@ -123,8 +123,13 @@ typedef struct bench_id {
// bench suites are linked into a custom ld section
#if defined(__APPLE__)
extern struct bench_suite __start__bench_suites __asm("section$start$__DATA$_bench_suites");
extern struct bench_suite __stop__bench_suites __asm("section$end$__DATA$_bench_suites");
#else
extern struct bench_suite __start__bench_suites;
extern struct bench_suite __stop__bench_suites;
#endif
const struct bench_suite *bench_suites = &__start__bench_suites;
#define BENCH_SUITE_COUNT \

View File

@@ -136,8 +136,13 @@ typedef struct test_id {
// test suites are linked into a custom ld section
#if defined(__APPLE__)
extern struct test_suite __start__test_suites __asm("section$start$__DATA$_test_suites");
extern struct test_suite __stop__test_suites __asm("section$end$__DATA$_test_suites");
#else
extern struct test_suite __start__test_suites;
extern struct test_suite __stop__test_suites;
#endif
const struct test_suite *test_suites = &__start__test_suites;
#define TEST_SUITE_COUNT \

View File

@@ -404,12 +404,15 @@ def compile(bench_paths, **args):
f.writeln()
# create suite struct
#
f.writeln('#if defined(__APPLE__)')
f.writeln('__attribute__((section("__DATA,_bench_suites")))')
f.writeln('#else')
# note we place this in the custom bench_suites section with
# minimum alignment, otherwise GCC ups the alignment to
# 32-bytes for some reason
f.writeln('__attribute__((section("_bench_suites"), '
'aligned(1)))')
f.writeln('#endif')
f.writeln('const struct bench_suite __bench__%s__suite = {'
% suite.name)
f.writeln(4*' '+'.name = "%s",' % suite.name)

View File

@@ -412,12 +412,15 @@ def compile(test_paths, **args):
f.writeln()
# create suite struct
#
f.writeln('#if defined(__APPLE__)')
f.writeln('__attribute__((section("__DATA,_test_suites")))')
f.writeln('#else')
# note we place this in the custom test_suites section with
# minimum alignment, otherwise GCC ups the alignment to
# 32-bytes for some reason
f.writeln('__attribute__((section("_test_suites"), '
'aligned(1)))')
f.writeln('#endif')
f.writeln('const struct test_suite __test__%s__suite = {'
% suite.name)
f.writeln(4*' '+'.name = "%s",' % suite.name)