lib: fix error on MacOS

Sections use a different syntax for Mach-O executables.

Fixes:

lib/bfd.c:35: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
DEFINE_MTYPE_STATIC(LIB, BFD_INFO, "BFD info")
^
./lib/memory.h:140:2: note: expanded from macro 'DEFINE_MTYPE_STATIC'
        DEFINE_MTYPE_ATTR(group, name, static, desc)                           \
        ^
./lib/memory.h:110:26: note: expanded from macro 'DEFINE_MTYPE_ATTR'
                __attribute__((section(".data.mtypes"))) = { {                 \
                                       ^
1 error generated.

Signed-off-by: Ruben Kerkhof <ruben@rubenkerkhof.com>
Signed-off-by: Georgi Valkov <gvalkov@gmail.com>
This commit is contained in:
Ruben Kerkhof 2020-03-18 15:40:39 +01:00 committed by Georgi Valkov
parent 8deba1e48d
commit 9824f07b02
No known key found for this signature in database
2 changed files with 18 additions and 15 deletions

View file

@ -455,6 +455,12 @@ _Static_assert(sizeof(_uint64_t) == 8 && sizeof(_int64_t) == 8,
#define unlikely(_x) !!(_x) #define unlikely(_x) !!(_x)
#endif #endif
#ifdef __MACH__
#define _DATA_SECTION(name) __attribute__((section("__DATA," name)))
#else
#define _DATA_SECTION(name) __attribute__((section(".data." name)))
#endif
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View file

@ -69,14 +69,12 @@ struct memgroup {
#define DECLARE_MGROUP(name) extern struct memgroup _mg_##name #define DECLARE_MGROUP(name) extern struct memgroup _mg_##name
#define _DEFINE_MGROUP(mname, desc, ...) \ #define _DEFINE_MGROUP(mname, desc, ...) \
struct memgroup _mg_##mname \ struct memgroup _mg_##mname _DATA_SECTION("mgroups") = { \
__attribute__((section(".data.mgroups"))) = { \ .name = desc, \
.name = desc, \ .types = NULL, \
.types = NULL, \ .next = NULL, \
.next = NULL, \ .insert = NULL, \
.insert = NULL, \ .ref = NULL, \
.ref = NULL, \
__VA_ARGS__ \
}; \ }; \
static void _mginit_##mname(void) __attribute__((_CONSTRUCTOR(1000))); \ static void _mginit_##mname(void) __attribute__((_CONSTRUCTOR(1000))); \
static void _mginit_##mname(void) \ static void _mginit_##mname(void) \
@ -105,13 +103,12 @@ struct memgroup {
/* end */ /* end */
#define DEFINE_MTYPE_ATTR(group, mname, attr, desc) \ #define DEFINE_MTYPE_ATTR(group, mname, attr, desc) \
attr struct memtype MTYPE_##mname[1] \ attr struct memtype MTYPE_##mname[1] _DATA_SECTION("mtypes") = { { \
__attribute__((section(".data.mtypes"))) = { { \ .name = desc, \
.name = desc, \ .next = NULL, \
.next = NULL, \ .n_alloc = 0, \
.n_alloc = 0, \ .size = 0, \
.size = 0, \ .ref = NULL, \
.ref = NULL, \
} }; \ } }; \
static void _mtinit_##mname(void) __attribute__((_CONSTRUCTOR(1001))); \ static void _mtinit_##mname(void) __attribute__((_CONSTRUCTOR(1001))); \
static void _mtinit_##mname(void) \ static void _mtinit_##mname(void) \