From 0b5223e1cda35addb1e3e1b8a6d0601b2ee9bab6 Mon Sep 17 00:00:00 2001 From: Andrew Clayton Date: Thu, 29 Feb 2024 15:32:00 +0000 Subject: Disable strict-aliasing in clang by default Aliasing is essentially when you access the same memory via different types. If the compiler knows this doesn't happen it can make some optimisations. There is however code in Unit, for example in the wasm language module and the websocket code that may fall foul of strict-aliasing rules. (For the wasm module I explicitly disable it there) In auto/cc/test for GCC we have NXT_CFLAGS="$NXT_CFLAGS -O" ... # -O2 enables -fstrict-aliasing and -fstrict-overflow. #NXT_CFLAGS="$NXT_CFLAGS -O2" #NXT_CFLAGS="$NXT_CFLAGS -Wno-strict-aliasing" So with GCC by default we effectively compile with -fno-strict-aliasing. For clang we have this NXT_CFLAGS="$NXT_CFLAGS -O" ... #NXT_CFLAGS="$NXT_CFLAGS -O2" ... NXT_CFLAGS="$NXT_CFLAGS -fstrict-aliasing" (In _clang_, -fstrict-aliasing is always enabled by default) So in clang we always build with -fstrict-aliasing. I don't think this is the best idea, building with something as fundamental as this disabled in one compiler and enabled in another. This patch adjusts the Clang side of things to match that of GCC. I.e compile with -fno-strict-aliasing. It also explicitly sets -fno-strict-aliasing for GCC, which is what we were getting anyway but lets be explicit about it. Cc: Dan Callahan Reviewed-by: Alejandro Colomar Signed-off-by: Andrew Clayton --- auto/cc/test | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'auto') diff --git a/auto/cc/test b/auto/cc/test index 8c9f2fc1..10588dac 100644 --- a/auto/cc/test +++ b/auto/cc/test @@ -79,7 +79,7 @@ case $NXT_CC_NAME in # -O2 enables -fstrict-aliasing and -fstrict-overflow. #NXT_CFLAGS="$NXT_CFLAGS -O2" - #NXT_CFLAGS="$NXT_CFLAGS -Wno-strict-aliasing" + NXT_CFLAGS="$NXT_CFLAGS -fno-strict-aliasing" #NXT_CFLAGS="$NXT_CFLAGS -fomit-frame-pointer" #NXT_CFLAGS="$NXT_CFLAGS -momit-leaf-frame-pointer" @@ -116,8 +116,10 @@ case $NXT_CC_NAME in #NXT_CFLAGS="$NXT_CFLAGS -Wshorten-64-to-32" NXT_CFLAGS="$NXT_CFLAGS -Wwrite-strings" #NXT_CFLAGS="$NXT_CFLAGS -O2" + # strict-aliasing is always enabled by default in clang + NXT_CFLAGS="$NXT_CFLAGS -fno-strict-aliasing" + #NXT_CFLAGS="$NXT_CFLAGS -fomit-frame-pointer" - NXT_CFLAGS="$NXT_CFLAGS -fstrict-aliasing" NXT_CFLAGS="$NXT_CFLAGS -Wstrict-overflow=5" NXT_CFLAGS="$NXT_CFLAGS -Wmissing-prototypes" -- cgit