diff mbox series

package/haproxy: fix runtime 'FATAL ERROR: invalid code detected -- cannot go further'

Message ID 20240117180059.40265-1-aleksandr.o.makarov@gmail.com
State Superseded
Headers show
Series package/haproxy: fix runtime 'FATAL ERROR: invalid code detected -- cannot go further' | expand

Commit Message

Aleksandr Makarov Jan. 17, 2024, 6 p.m. UTC
Forcing HAPROXY_CFLAGS on the haproxy build command line overrides CFLAGS
which were internally set by the haproxy Makefile.

In such a way, a bunch of flags that were deduced by the Makefile 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 issue, include HAPROXY_CFLAGS in the DEFINE variable in haproxy.mk. This way,
the resulting CFLAGS in the haproxy Makefile will have the appended HAPROXY_CFLAGS instead of
being overridden.

[1] https://git.haproxy.org/?p=haproxy.git;a=blob;f=src/haproxy.c;h=e1863255422459e806f7e50828e81976bb41c14c;hb=HEAD#l3304
---
 package/haproxy/haproxy.mk | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/package/haproxy/haproxy.mk b/package/haproxy/haproxy.mk
index 63a92090f3..61a9ebebe4 100644
--- a/package/haproxy/haproxy.mk
+++ b/package/haproxy/haproxy.mk
@@ -82,7 +82,7 @@  endif
 
 define HAPROXY_BUILD_CMDS
 	$(TARGET_MAKE_ENV) $(MAKE) $(TARGET_CONFIGURE_OPTS) \
-		$(HAPROXY_MAKE_OPTS) CFLAGS="$(HAPROXY_CFLAGS)" -C $(@D)
+		$(HAPROXY_MAKE_OPTS) DEFINE="$(HAPROXY_CFLAGS)" -C $(@D)
 endef
 
 define HAPROXY_INSTALL_TARGET_CMDS