Hi Olivier,

On Wed, Jan 09, 2019 at 07:23:42PM +0100, Olivier D wrote:
> Hello folks,
> 
> Just wanted to raise an issue with a compilation error on HAProxy that I
> was able to solve by myself. Just wanted to know if this issue is
> haproxy-related or compiler-related (and if a fix should be provided in the
> future)
> 
> Compiling haproxy (1.8.17) failed with this error :
(...)
> /usr/src/haproxy/opensslbin/lib/libcrypto.a(threads_pthread.o): In function
> `fork_once_func':
> threads_pthread.c:(.text+0x16): undefined reference to `pthread_atfork'
> collect2: error: ld returned 1 exit status

It's been a while since we've got such linking issues. Usually they come
from libpthread or libdl, which are most always shared. Can you please
try the attached patch ?

Thanks,
Willy
diff --git a/Makefile b/Makefile
index 94e0473..24bd87a 100644
--- a/Makefile
+++ b/Makefile
@@ -574,17 +574,6 @@ OPTIONS_CFLAGS += -DCONFIG_REGPARM=3
 BUILD_OPTIONS  += $(call ignore_implicit,USE_REGPARM)
 endif
 
-ifneq ($(USE_DL),)
-BUILD_OPTIONS   += $(call ignore_implicit,USE_DL)
-OPTIONS_LDFLAGS += -ldl
-endif
-
-ifneq ($(USE_THREAD),)
-BUILD_OPTIONS   += $(call ignore_implicit,USE_THREAD)
-OPTIONS_CFLAGS  += -DUSE_THREAD
-OPTIONS_LDFLAGS += -lpthread
-endif
-
 # report DLMALLOC_SRC only if explicitly specified
 ifneq ($(DLMALLOC_SRC),)
 BUILD_OPTIONS += DLMALLOC_SRC=$(DLMALLOC_SRC)
@@ -618,20 +607,6 @@ endif
 OPTIONS_OBJS  += src/ssl_sock.o
 endif
 
-# The private cache option affect the way the shctx is built
-ifneq ($(USE_PRIVATE_CACHE),)
-OPTIONS_CFLAGS  += -DUSE_PRIVATE_CACHE
-else
-ifneq ($(USE_PTHREAD_PSHARED),)
-OPTIONS_CFLAGS  += -DUSE_PTHREAD_PSHARED
-OPTIONS_LDFLAGS += -lpthread
-else
-ifneq ($(USE_FUTEX),)
-OPTIONS_CFLAGS  += -DUSE_SYSCALL_FUTEX
-endif
-endif
-endif
-
 ifneq ($(USE_LUA),)
 check_lua_lib = $(shell echo "int main(){}" | $(CC) -o /dev/null -x c - $(2) 
-l$(1) 2>/dev/null && echo $(1))
 check_lua_inc = $(shell if [ -d $(2)$(1) ]; then echo $(2)$(1); fi;)
@@ -838,6 +813,33 @@ OPTIONS_CFLAGS += -DCONFIG_HAP_NS
 BUILD_OPTIONS  += $(call ignore_implicit,USE_NS)
 endif
 
+# -ldl and -lpthread should appear last otherwise some systems may face
+# some build issues.
+ifneq ($(USE_DL),)
+BUILD_OPTIONS   += $(call ignore_implicit,USE_DL)
+OPTIONS_LDFLAGS += -ldl
+endif
+
+ifneq ($(USE_THREAD),)
+BUILD_OPTIONS   += $(call ignore_implicit,USE_THREAD)
+OPTIONS_CFLAGS  += -DUSE_THREAD
+OPTIONS_LDFLAGS += -lpthread
+endif
+
+# The private cache option affect the way the shctx is built
+ifneq ($(USE_PRIVATE_CACHE),)
+OPTIONS_CFLAGS  += -DUSE_PRIVATE_CACHE
+else
+ifneq ($(USE_PTHREAD_PSHARED),)
+OPTIONS_CFLAGS  += -DUSE_PTHREAD_PSHARED
+OPTIONS_LDFLAGS += -lpthread
+else
+ifneq ($(USE_FUTEX),)
+OPTIONS_CFLAGS  += -DUSE_SYSCALL_FUTEX
+endif
+endif
+endif
+
 #### Global link options
 # These options are added at the end of the "ld" command line. Use LDFLAGS to
 # add options at the beginning of the "ld" command line if needed.

Reply via email to