summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrew Clayton <a.clayton@nginx.com>2024-02-29 15:32:00 +0000
committerAndrew Clayton <a.clayton@nginx.com>2024-03-09 00:42:27 +0000
commit0b5223e1cda35addb1e3e1b8a6d0601b2ee9bab6 (patch)
tree928ada6dbe97b91a03a4759de03d9dd095963e42
parent1dcb5383319a2e41969234d838a20f6a4316334e (diff)
downloadunit-0b5223e1cda35addb1e3e1b8a6d0601b2ee9bab6.tar.gz
unit-0b5223e1cda35addb1e3e1b8a6d0601b2ee9bab6.tar.bz2
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 <d.callahan@f5.com> Reviewed-by: Alejandro Colomar <alx@kernel.org> Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
-rw-r--r--auto/cc/test6
1 files changed, 4 insertions, 2 deletions
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"