Hi Patrick,

On Wed, Feb 13, 2019 at 10:01:01AM -0500, Patrick Hemmer wrote:
> 
> 
> On 2019/2/13 09:40, Aleksandar Lazic wrote:
> > Am 13.02.2019 um 14:45 schrieb Patrick Hemmer:
> >> Trying to compile haproxy on my local machine for testing purposes and am
> >> running into the following:
> > Which compiler do you use?
> 
>       # gcc -v
>       Configured with: 
> --prefix=/Applications/Xcode.app/Contents/Developer/usr 
> --with-gxx-include-dir=/usr/include/c++/4.2.1
>       Apple LLVM version 9.0.0 (clang-900.0.39.2)
>       Target: x86_64-apple-darwin17.7.0
>       Thread model: posix
>       InstalledDir: 
> /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
> 
> >>         # make TARGET=osx
> >>         src/proto_http.c:293: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
> >>         DECLARE_POOL(pool_head_http_txn, "http_txn", sizeof(struct 
> >> http_txn));
> >>         ^
> >>         include/common/memory.h:128:2: note: expanded from macro 
> >> 'DECLARE_POOL'
> >>                         REGISTER_POOL(&ptr, name, size)
> >>                         ^
> >>         include/common/memory.h:123:2: note: expanded from macro 
> >> 'REGISTER_POOL'
> >>                         INITCALL3(STG_POOL, create_pool_callback, (ptr), 
> >> (name),
> >> (size))
> >>                         ^
> >>         include/common/initcall.h:102:2: note: expanded from macro 
> >> 'INITCALL3'
> >>                         _DECLARE_INITCALL(stage, __LINE__, function, arg1, 
> >> arg2,
> >> arg3)
> >>                         ^
> >>         include/common/initcall.h:78:2: note: expanded from macro
> >> '_DECLARE_INITCALL'
> >>                         __DECLARE_INITCALL(__VA_ARGS__)
> >>                         ^
> >>         include/common/initcall.h:65:42: note: expanded from macro
> >> '__DECLARE_INITCALL'
> >>                                
> >> __attribute__((__used__,__section__("init_"#stg))) =   \
> >>
> >>
> >>
> >> Issue occurs on master, and the 1.9 branch
> >>
> >> -Patrick
> 

Does the (totally untested, because I have no Mac to test) patch works for
you ?

Thanks !

Olivier
>From 2f68108ae32a66782b4c7518f8830896732be64d Mon Sep 17 00:00:00 2001
From: Olivier Houchard <ohouch...@haproxy.com>
Date: Wed, 13 Feb 2019 16:22:17 +0100
Subject: [PATCH] BUILD/MEDIUM: initcall: Fix build on MacOS.

MacOS syntax for sections is a bit different, so implement it.

This should be backported to 1.9.
---
 include/common/initcall.h | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/include/common/initcall.h b/include/common/initcall.h
index 35d237fd..95e488ba 100644
--- a/include/common/initcall.h
+++ b/include/common/initcall.h
@@ -50,6 +50,12 @@ struct initcall {
        void *arg3;
 };
 
+#ifdef __APPLE__
+#define HA_SECTION(s) __section__("__DATA, " s)
+#else
+#define HA_SECTION(s) __section__((s))
+#endif
+
 /* Declare a static variable in the init section dedicated to stage <stg>,
  * with an element referencing function <function> and arguments <a1..a3>.
  * <linenum> is needed to deduplicate entries created from a same file. The
@@ -62,7 +68,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("init_"#stg))) =    \
                (stg < STG_SIZE) ? &(const struct initcall) {      \
                .fct = (void (*)(void *,void *,void *))function,   \
                .arg1 = (void *)(a1),                              \
@@ -113,9 +119,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$" stg); \
+       extern __attribute__((__weak__)) const struct initcall 
*__stop_init_##stg __asm("section$end$__DATA$" 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);
-- 
2.20.1

Reply via email to