From 947e5fdfcaea5fa2037b370b8d3b6457fa7a99ec Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Wed, 10 Apr 2024 18:48:20 +0200 Subject: [PATCH] BUILD: makefile: move the fwrapv option to STD_CFLAGS We now have a separate CFLAGS variable for sensitive options that affect code generation and/or standard compliance. This one must not be mixed with the warnings auto-detection because changing such warnings can result in losing the options. Now it's easier to affect them separately. The option was not listed in the series of variables useful to packagers because they're not supposed to touch it. --- Makefile | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index c308a8fdeb..af4a04a49d 100644 --- a/Makefile +++ b/Makefile @@ -192,17 +192,22 @@ ERR = REG_TEST_FILES = REG_TEST_SCRIPT=./scripts/run-regtests.sh -#### Compiler-specific flags that may be used to disable some negative over- -# optimization or to silence some warnings. -# We rely on signed integer wraparound on overflow, however clang think it -# can do whatever it wants since it's an undefined behavior, so use -fwrapv -# to be sure we get the intended behavior. +#### Standard C definition +# Compiler-specific flags that may be used to set the standard behavior we +# rely on and to disable some negative over-optimization. More specifically, +# we rely on signed integer wraparound on overflow, however recently clang and +# gcc decided to change their code generation regarding this and abuse the +# undefined behavior to silently produce invalid code. For this reason we have +# to use -fwrapv or -fno-strict-overflow to guarantee the intended behavior. +# It is preferable not to change this option in order to avoid breakage. +STD_CFLAGS := $(call cc-opt-alt,-fwrapv,-fno-strict-overflow) + +#### Compiler-specific flags to enable/disable certain classes of warnings. WARN_CFLAGS := -Wtype-limits -Wshift-negative-value -Wshift-overflow=2 \ -Wduplicated-cond -Wnull-dereference SPEC_CFLAGS := -Wall -Wextra -Wundef -Wdeclaration-after-statement -Wfatal-errors SPEC_CFLAGS += $(call cc-all-fast,$(WARN_CFLAGS)) -SPEC_CFLAGS += $(call cc-opt-alt,-fwrapv,-fno-strict-overflow) SPEC_CFLAGS += $(cc-wnouwo) SPEC_CFLAGS += $(call cc-nowarn,address-of-packed-member) SPEC_CFLAGS += $(call cc-nowarn,unused-label) @@ -471,7 +476,7 @@ $(set_target_defaults) # linking with it by default as it's not always available nor deployed # (especially on archs which do not need it). ifneq ($(USE_THREAD:0=),) - ifneq ($(shell $(CC) $(OPT_CFLAGS) $(ARCH_FLAGS) $(CPU_CFLAGS) $(DEBUG_CFLAGS) $(SPEC_CFLAGS) $(CFLAGS) -dM -E -xc - /dev/null | grep -c 'LOCK_FREE.*1'),0) + ifneq ($(shell $(CC) $(OPT_CFLAGS) $(ARCH_FLAGS) $(CPU_CFLAGS) $(DEBUG_CFLAGS) $(STD_CFLAGS) $(SPEC_CFLAGS) $(CFLAGS) -dM -E -xc - /dev/null | grep -c 'LOCK_FREE.*1'),0) USE_LIBATOMIC = implicit endif endif @@ -840,10 +845,10 @@ endif $(collect_opts_flags) #### Global compile options -VERBOSE_CFLAGS = $(OPT_CFLAGS) $(ARCH_FLAGS) $(CPU_CFLAGS) $(DEBUG_CFLAGS) $(SPEC_CFLAGS) $(TARGET_CFLAGS) $(CFLAGS) $(DEFINE) +VERBOSE_CFLAGS = $(OPT_CFLAGS) $(ARCH_FLAGS) $(CPU_CFLAGS) $(DEBUG_CFLAGS) $(STD_CFLAGS) $(SPEC_CFLAGS) $(TARGET_CFLAGS) $(CFLAGS) $(DEFINE) COPTS = -Iinclude -COPTS += $(OPT_CFLAGS) $(ARCH_FLAGS) $(CPU_CFLAGS) $(DEBUG_CFLAGS) $(SPEC_CFLAGS) $(TARGET_CFLAGS) $(DEFINE) $(SILENT_DEFINE) +COPTS += $(OPT_CFLAGS) $(ARCH_FLAGS) $(CPU_CFLAGS) $(DEBUG_CFLAGS) $(STD_CFLAGS) $(SPEC_CFLAGS) $(TARGET_CFLAGS) $(DEFINE) $(SILENT_DEFINE) COPTS += $(DEBUG) $(OPTIONS_CFLAGS) $(CFLAGS) $(ADDINC) ifneq ($(VERSION)$(SUBVERS)$(EXTRAVERSION),) @@ -1152,6 +1157,7 @@ opts: @echo -n 'ARCH_FLAGS="$(strip $(ARCH_FLAGS))" ' @echo -n 'CPU_CFLAGS="$(strip $(CPU_CFLAGS))" ' @echo -n 'DEBUG_CFLAGS="$(strip $(DEBUG_CFLAGS))" ' + @echo -n 'STD_CFLAGS="$(strip $(STD_CFLAGS))" ' @echo -n 'CFLAGS="$(strip $(CFLAGS))" ' @#echo "$(strip $(BUILD_OPTIONS))" @$(foreach opt,$(enabled_opts),\