In buildroot, forcing HAPROXY_CFLAGS on the haproxy build command line 
overrides CFLAGS
which were internally set by the package Makefile.

In such a way, a bunch of flags that were deduced by the package build script
in *_CFLAGS variables, specifically in SPEC_CFLAGS, are omitted. Compiling and
running haproxy without SPEC_CFLAGS taken into account results in runtime error:

$ haproxy
FATAL ERROR: invalid code detected -- cannot go further, please recompile!
The source code was miscompiled by the compiler, which usually indicates that
some of the CFLAGS needed to work around overzealous compiler optimizations
were overwritten at build time. Please do not force CFLAGS, and read Makefile
and INSTALL files to decide on the best way to pass your local build options.
...

This error is produced by haproxy.c [1] source which effectively ensures that 
INT_MAX+1
expression wraps around using twos-complement representation. It is only true 
when -fwrapv
gcc option is set in SPEC_CFLAGS.

To address this, append necessary *_CFLAGS variables to the CFLAGS in haproxy 
Makefile.

[1] 
https://git.haproxy.org/?p=haproxy.git;a=blob;f=src/haproxy.c;h=e1863255422459e806f7e50828e81976bb41c14c;hb=HEAD#l3304

Signed-off-by: Aleksandr Makarov <[email protected]>
---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index a66c9b69c..95fbb8a9c 100644
--- a/Makefile
+++ b/Makefile
@@ -289,7 +289,7 @@ ARCH_FLAGS        = $(ARCH_FLAGS.$(ARCH))
 # These CFLAGS contain general optimization options, CPU-specific optimizations
 # and debug flags. They may be overridden by some distributions which prefer to
 # set all of them at once instead of playing with the CPU and DEBUG variables.
-CFLAGS = $(ARCH_FLAGS) $(CPU_CFLAGS) $(DEBUG_CFLAGS) $(SPEC_CFLAGS)
+override CFLAGS += $(ARCH_FLAGS) $(CPU_CFLAGS) $(DEBUG_CFLAGS) $(SPEC_CFLAGS)
 
 #### Common LDFLAGS
 # These LDFLAGS are used as the first "ld" options, regardless of any library
-- 
2.39.2


Reply via email to