From: Olivier Houchard Date: Wed, 13 Feb 2019 15:22:17 +0000 (+0100) Subject: BUILD/MEDIUM: initcall: Fix build on MacOS. X-Git-Tag: v2.0-dev1~35 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9efa7b8ba8885ae796de62e079d4fd0ae259c11c;p=thirdparty%2Fhaproxy.git BUILD/MEDIUM: initcall: Fix build on MacOS. MacOS syntax for sections is a bit different, so implement it. (see issue #42). This should be backported to 1.9. --- diff --git a/include/common/initcall.h b/include/common/initcall.h index 35d237fddc..9e7059262d 100644 --- a/include/common/initcall.h +++ b/include/common/initcall.h @@ -32,6 +32,11 @@ /* List of known init stages. If others are added, please declare their * section at the end of the file below. */ +/* + * Please keep those names short enough, they are used to generate section + * names, Mac OS X accepts section names up to 16 characters, and we prefix + * them with i_, so stage name can't be more than 14 characters. + */ enum init_stage { STG_PREPARE = 0, // preset variables, tables, list heads STG_LOCK, // pre-initialize locks @@ -50,6 +55,12 @@ struct initcall { void *arg3; }; +#ifdef __APPLE__ +#define HA_SECTION(s) __section__("__DATA, i_" # s) +#else +#define HA_SECTION(s) __section__("init_" # s) +#endif + /* Declare a static variable in the init section dedicated to stage , * with an element referencing function and arguments . * is needed to deduplicate entries created from a same file. The @@ -62,7 +73,7 @@ struct initcall { */ #define __DECLARE_INITCALL(stg, linenum, function, a1, a2, a3) \ static const struct initcall *__initcb_##linenum \ - __attribute__((__used__,__section__("init_"#stg))) = \ + __attribute__((__used__,HA_SECTION(stg))) = \ (stg < STG_SIZE) ? &(const struct initcall) { \ .fct = (void (*)(void *,void *,void *))function, \ .arg1 = (void *)(a1), \ @@ -113,9 +124,16 @@ struct initcall { * empty. The corresponding sections must contain exclusively pointers to * make sure each location may safely be visited by incrementing a pointer. */ +#ifdef __APPLE__ +#define DECLARE_INIT_SECTION(stg) \ + extern __attribute__((__weak__)) const struct initcall *__start_init_##stg __asm("section$start$__DATA$i_" # stg); \ + extern __attribute__((__weak__)) const struct initcall *__stop_init_##stg __asm("section$end$__DATA$i_" # stg) + +#else #define DECLARE_INIT_SECTION(stg) \ extern __attribute__((__weak__)) const struct initcall *__start_init_##stg; \ extern __attribute__((__weak__)) const struct initcall *__stop_init_##stg +#endif /* Declare all initcall sections here */ DECLARE_INIT_SECTION(STG_PREPARE);