From 5511593dacb771490f6d12d78e7485c5ff8a0b38 Mon Sep 17 00:00:00 2001 From: Andrew Clayton Date: Wed, 6 Mar 2024 21:00:38 +0000 Subject: Remove support for Microsoft's Visual C++ compiler We don't run on Windows and only really support compiling Unit with GCC and Clang. Cc: Dan Callahan Co-developed-by: Alejandro Colomar Signed-off-by: Alejandro Colomar Signed-off-by: Andrew Clayton --- auto/cc/test | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'auto/cc') diff --git a/auto/cc/test b/auto/cc/test index 9c9602db..c7adcfc0 100644 --- a/auto/cc/test +++ b/auto/cc/test @@ -69,19 +69,10 @@ then $echo " + using Intel C++ compiler" NXT_CC_VERSION=ICC -else -if `/bin/sh -c "($CC -v)" 2>&1 \ - | grep "Microsoft (R) 32-bit C/C" >> $NXT_AUTOCONF_ERR 2>&1` -then - NXT_CC_NAME=MSVC - $echo " + using MS Visual C++ compiler" - NXT_CC_VERSION=MSVC - else NXT_CC_NAME=cc NXT_CC_VERSION=cc -fi # MSVC fi # ICC fi # xlC fi # SunC @@ -197,9 +188,6 @@ case $NXT_CC_NAME in ICC) ;; - MSVC) - ;; - *) ;; -- cgit From 0c2d7786b1b79c952712179d271efd9c6057ffc7 Mon Sep 17 00:00:00 2001 From: Andrew Clayton Date: Wed, 6 Mar 2024 21:04:05 +0000 Subject: Remove support for Intel's icc compiler We only really support building Unit with GCC and Clang. Cc: Dan Callahan Reviewed-by: Alejandro Colomar Signed-off-by: Andrew Clayton --- auto/cc/test | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'auto/cc') diff --git a/auto/cc/test b/auto/cc/test index c7adcfc0..b1745505 100644 --- a/auto/cc/test +++ b/auto/cc/test @@ -62,18 +62,10 @@ then NXT_CC_VERSION=`/bin/sh -c "($CC -qversion)" 2>&1 | grep "IBM XL" 2>&1` $echo " + $NXT_CC_VERSION" -else -if `/bin/sh -c "($CC -V)" 2>&1 | grep "Intel(R) C" >> $NXT_AUTOCONF_ERR 2>&1` -then - NXT_CC_NAME=ICC - $echo " + using Intel C++ compiler" - NXT_CC_VERSION=ICC - else NXT_CC_NAME=cc NXT_CC_VERSION=cc -fi # ICC fi # xlC fi # SunC fi # Apple LLVM clang @@ -185,9 +177,6 @@ case $NXT_CC_NAME in NXT_CFLAGS="$NXT_CFLAGS -qsuppress=1506-159" ;; - ICC) - ;; - *) ;; -- cgit From e79e463556d6a08432a7008d185c958907fa4f40 Mon Sep 17 00:00:00 2001 From: Andrew Clayton Date: Wed, 6 Mar 2024 21:06:34 +0000 Subject: Remove support for IBM's XL C compiler We really only support building Unit with GCC and Clang. Cc: Dan Callahan Reviewed-by: Alejandro Colomar Signed-off-by: Andrew Clayton --- auto/cc/test | 24 ------------------------ 1 file changed, 24 deletions(-) (limited to 'auto/cc') diff --git a/auto/cc/test b/auto/cc/test index b1745505..499a2fb1 100644 --- a/auto/cc/test +++ b/auto/cc/test @@ -53,20 +53,10 @@ then NXT_CC_VERSION=`/bin/sh -c "($CC -V)" 2>&1 | grep "Sun C" 2>&1` $echo " + $NXT_CC_VERSION" -else -if `/bin/sh -c "($CC -qversion)" 2>&1 \ - | grep "^IBM XL" >> $NXT_AUTOCONF_ERR 2>&1` -then - NXT_CC_NAME=xlC - $echo " + using AIX xlC compiler" - NXT_CC_VERSION=`/bin/sh -c "($CC -qversion)" 2>&1 | grep "IBM XL" 2>&1` - $echo " + $NXT_CC_VERSION" - else NXT_CC_NAME=cc NXT_CC_VERSION=cc -fi # xlC fi # SunC fi # Apple LLVM clang fi # clang @@ -163,20 +153,6 @@ case $NXT_CC_NAME in NXT_CFLAGS="$NXT_CFLAGS -g" ;; - xlC) - nxt_have=NXT_XLC . auto/have - - #NXT_CFLAGS="$NXT_CFLAGS -qalloca" - # alloca support. - NXT_CFLAGS="$NXT_CFLAGS -qlanglvl=extc99" - # __thread support. - NXT_CFLAGS="$NXT_CFLAGS -qtls" - # Suppress warning - # 1506-159 (E) Bit field type specified for XXX is not valid. - # Type unsigned assumed. - NXT_CFLAGS="$NXT_CFLAGS -qsuppress=1506-159" - ;; - *) ;; -- cgit From 9cd11133f9eaf4f31f7d1c477613d12c22774b09 Mon Sep 17 00:00:00 2001 From: Andrew Clayton Date: Wed, 6 Mar 2024 21:08:43 +0000 Subject: Remove support for Sun's Sun Studio/SunPro C compiler We really only support building Unit with GCC and Clang. Cc: Dan Callahan Reviewed-by: Alejandro Colomar Signed-off-by: Andrew Clayton --- auto/cc/deps | 12 ------------ auto/cc/test | 21 --------------------- 2 files changed, 33 deletions(-) (limited to 'auto/cc') diff --git a/auto/cc/deps b/auto/cc/deps index 11429788..8b4deca7 100644 --- a/auto/cc/deps +++ b/auto/cc/deps @@ -1,18 +1,6 @@ case "$NXT_CC_NAME" in - SunC): - nxt_gen_dep_flags() { - $echo "-xMMD -xMF $NXT_BUILD_DIR/$nxt_dep.tmp" - } - - nxt_gen_dep_post() { - $echo -n "@sed -e 's#^.*:#$NXT_BUILD_DIR/$nxt_obj:#' " - $echo -n "$NXT_BUILD_DIR/$nxt_dep.tmp > $NXT_BUILD_DIR/$nxt_dep" - $echo " && rm -f $NXT_BUILD_DIR/$nxt_dep.tmp" - } - ;; - *) nxt_gen_dep_flags() { $echo "-MMD -MF $NXT_BUILD_DIR/$nxt_dep -MT $NXT_BUILD_DIR/$nxt_obj" diff --git a/auto/cc/test b/auto/cc/test index 499a2fb1..dbaa7124 100644 --- a/auto/cc/test +++ b/auto/cc/test @@ -45,19 +45,10 @@ then NXT_CC_VERSION=`/bin/sh -c "($CC -v)" 2>&1 | grep "Apple LLVM version" 2>&1` $echo " + $NXT_CC_VERSION" -else -if `/bin/sh -c "($CC -V)" 2>&1 | grep "Sun C" >> $NXT_AUTOCONF_ERR 2>&1` -then - NXT_CC_NAME=SunC - $echo " + using Sun C compiler" - NXT_CC_VERSION=`/bin/sh -c "($CC -V)" 2>&1 | grep "Sun C" 2>&1` - $echo " + $NXT_CC_VERSION" - else NXT_CC_NAME=cc NXT_CC_VERSION=cc -fi # SunC fi # Apple LLVM clang fi # clang fi # gcc @@ -141,18 +132,6 @@ case $NXT_CC_NAME in fi ;; - SunC) - nxt_have=NXT_SUNC . auto/have - - NXT_CFLAGS="$NXT_CFLAGS -fPIC" - # Optimization. - NXT_CFLAGS="$NXT_CFLAGS -O -fast" - # Stop on warning. - NXT_CFLAGS="$NXT_CFLAGS -errwarn=%all" - # Debug. - NXT_CFLAGS="$NXT_CFLAGS -g" - ;; - *) ;; -- cgit From 806e209df541114f79033651271ef62d80bb69f5 Mon Sep 17 00:00:00 2001 From: Andrew Clayton Date: Wed, 28 Feb 2024 19:08:41 +0000 Subject: Remove -W from compiler flags This is what -Wextra used to be called, but any version of GCC or Clang in at least the last decade has -Wextra. Cc: Dan Callahan Reviewed-by: Alejandro Colomar Signed-off-by: Andrew Clayton --- auto/cc/test | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'auto/cc') diff --git a/auto/cc/test b/auto/cc/test index dbaa7124..fdb84760 100644 --- a/auto/cc/test +++ b/auto/cc/test @@ -70,7 +70,7 @@ case $NXT_CC_NAME in NXT_CFLAGS="$NXT_CFLAGS -O" #NXT_CFLAGS="$NXT_CFLAGS -O0" - NXT_CFLAGS="$NXT_CFLAGS -W -Wall -Wextra" + NXT_CFLAGS="$NXT_CFLAGS -Wall -Wextra" #NXT_CFLAGS="$NXT_CFLAGS -Wunused-result" NXT_CFLAGS="$NXT_CFLAGS -Wno-unused-parameter" @@ -107,7 +107,7 @@ case $NXT_CC_NAME in NXT_CFLAGS="$NXT_CFLAGS -O" #NXT_CFLAGS="$NXT_CFLAGS -O0" - NXT_CFLAGS="$NXT_CFLAGS -W -Wall -Wextra" + NXT_CFLAGS="$NXT_CFLAGS -Wall -Wextra" #NXT_CFLAGS="$NXT_CFLAGS -Wunused-result" NXT_CFLAGS="$NXT_CFLAGS -Wno-unused-parameter" -- cgit From 1dcb5383319a2e41969234d838a20f6a4316334e Mon Sep 17 00:00:00 2001 From: Andrew Clayton Date: Thu, 29 Feb 2024 02:41:59 +0000 Subject: Expand the comment about -Wstrict-overflow on GCC Expand on the comment on why we don't enable -Wstrict-overflow=5 on GCC. Link: Reviewed-by: Alejandro Colomar Signed-off-by: Andrew Clayton --- auto/cc/test | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'auto/cc') diff --git a/auto/cc/test b/auto/cc/test index fdb84760..8c9f2fc1 100644 --- a/auto/cc/test +++ b/auto/cc/test @@ -84,7 +84,9 @@ case $NXT_CC_NAME in #NXT_CFLAGS="$NXT_CFLAGS -fomit-frame-pointer" #NXT_CFLAGS="$NXT_CFLAGS -momit-leaf-frame-pointer" - # -Wstrict-overflow is supported by GCC 4.2+. + # While -Wstrict-overflow is supported by GCC 4.2+, + # at level 3 and above it is prone to give false + # positives. #NXT_CFLAGS="$NXT_CFLAGS -Wstrict-overflow=5" NXT_CFLAGS="$NXT_CFLAGS -Wmissing-prototypes" -- cgit 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/cc') 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 From c1e3f02f99a3cab181c36d1f55c552e2bcfba370 Mon Sep 17 00:00:00 2001 From: Andrew Clayton Date: Thu, 7 Mar 2024 00:43:37 +0000 Subject: Compile with -fno-strict-overflow This causes signed integer & pointer overflow to have a defined behaviour of wrapping according to two's compliment. I.e INT_MAX will wrap to INT_MIN and vice versa. This is mainly to cover existing cases, not an invitation to add more. Cc: Dan Callahan Suggested-by: Alejandro Colomar Reviewed-by: Alejandro Colomar Signed-off-by: Andrew Clayton --- auto/cc/test | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'auto/cc') diff --git a/auto/cc/test b/auto/cc/test index 10588dac..5bd94d2f 100644 --- a/auto/cc/test +++ b/auto/cc/test @@ -65,6 +65,8 @@ case $NXT_CC_NAME in # Do not export symbols except explicitly marked with NXT_EXPORT. NXT_CFLAGS="$NXT_CFLAGS -fvisibility=hidden" + NXT_CFLAGS="$NXT_CFLAGS -fno-strict-overflow" + # c99/gnu99 conflict with Solaris XOPEN. #NXT_CFLAGS="$NXT_CFLAGS -std=gnu99" @@ -107,6 +109,8 @@ case $NXT_CC_NAME in # Do not export symbols except explicitly marked with NXT_EXPORT. NXT_CFLAGS="$NXT_CFLAGS -fvisibility=hidden" + NXT_CFLAGS="$NXT_CFLAGS -fno-strict-overflow" + NXT_CFLAGS="$NXT_CFLAGS -O" #NXT_CFLAGS="$NXT_CFLAGS -O0" NXT_CFLAGS="$NXT_CFLAGS -Wall -Wextra" -- cgit From 15072fbde9b7d451aa4fde815d59a7454604036c Mon Sep 17 00:00:00 2001 From: Andrew Clayton Date: Sat, 2 Mar 2024 03:45:00 +0000 Subject: Enable optional 'debuggable' builds One issue you have when trying to debug Unit under say GDB is that at the default optimisation level we use of -O (-O1) the compiler will often optimise things out which means they are not available for inspection in the debugger. This patch allows you to pass 'D=1' to make, e.g $ make D=1 ... Which will set -O0 overriding the previously set -O, basically disabling optimisations, we could use -Og, but the clang(1) man page says this is best and it seems to not cause any issues when debugging GCC generated code. Co-developed-by: Alejandro Colomar Signed-off-by: Alejandro Colomar Signed-off-by: Andrew Clayton --- auto/cc/test | 2 -- 1 file changed, 2 deletions(-) (limited to 'auto/cc') diff --git a/auto/cc/test b/auto/cc/test index 5bd94d2f..4d6d5a43 100644 --- a/auto/cc/test +++ b/auto/cc/test @@ -71,7 +71,6 @@ case $NXT_CC_NAME in #NXT_CFLAGS="$NXT_CFLAGS -std=gnu99" NXT_CFLAGS="$NXT_CFLAGS -O" - #NXT_CFLAGS="$NXT_CFLAGS -O0" NXT_CFLAGS="$NXT_CFLAGS -Wall -Wextra" #NXT_CFLAGS="$NXT_CFLAGS -Wunused-result" @@ -112,7 +111,6 @@ case $NXT_CC_NAME in NXT_CFLAGS="$NXT_CFLAGS -fno-strict-overflow" NXT_CFLAGS="$NXT_CFLAGS -O" - #NXT_CFLAGS="$NXT_CFLAGS -O0" NXT_CFLAGS="$NXT_CFLAGS -Wall -Wextra" #NXT_CFLAGS="$NXT_CFLAGS -Wunused-result" -- cgit From b65e49c5d6b4c9395d84257b71d380f10bb5823f Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Fri, 28 Oct 2022 01:49:55 +0200 Subject: Build with -std=gnu11 (C11 with GNU extensions) Currently Unit doesn't specify any specific C standard for compiling and will thus be compiled under whatever the compiler happens to default to. Current releases of GCC and Clang (13.x & 17.x respectively at the time of writing) default to gnu17 (C17 + GNU extensions). Our oldest still-supported system is RHEL/CentOS 7, that comes with GCC 4.8.5 which defaults to gnu90. Up until now this hasn't really been an issue and we have been able to use some C99 features that are implemented as GNU extensions in older compilers, e.g - designated initializers - flexible array members - trailing comma in enum declaration (compiles with -std=c89, warns with -std=c89 -pedantic) - snprintf(3) - long long (well we test for it but don't actually use it) - bool / stdbool.h - variadic macros However there are a couple of C99 features that aren't GNU extensions that would be handy to be able to use, i.e - The ability to declare variables inside for () loops, e.g for (int i = 0; ...; ...) - C99 inline functions (not to be confused with what's available with -std=gnu89). However, if we are going to switch up to C99, then perhaps we should just leap frog to C11 instead (the Linux Kernel did in fact make the switch from gnu89 to gnu11 in March '22). C17 is perhaps still a little new and is really just C11 + errata. GCC 4.8 as in RHEL 7 has *some* support for C11, so while we can make full use of C99, we couldn't yet make full use of C11, However RHEL 7 is EOL on June 30th 2024, after which we will no longer have that restriction and in the meantime we can restrict ourselves to the supported set of features (or implement fallbacks where appropriate). It can only be a benefit that we would be compiling Unit consistently under the same language standard. This will also help give the impression that Unit is a modern C code base. It is also worth noting the following regarding GCC "A version with corrections integrated was prepared in 2017 and published in 2018 as ISO/IEC 9899:2018; it is known as C17 and is supported with -std=c17 or -std=iso9899:2017; the corrections are also applied with - std=c11, and the only difference between the options is the value of STDC_VERSION." Suggested-by: Andrew Clayton Acked-by: Andrew Clayton [ Andrew wrote the commit message ] Signed-off-by: Alejandro Colomar Link: Link: Link: Cc: Dan Callahan Signed-off-by: Andrew Clayton --- auto/cc/test | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'auto/cc') diff --git a/auto/cc/test b/auto/cc/test index 4d6d5a43..34e4379e 100644 --- a/auto/cc/test +++ b/auto/cc/test @@ -67,8 +67,7 @@ case $NXT_CC_NAME in NXT_CFLAGS="$NXT_CFLAGS -fno-strict-overflow" - # c99/gnu99 conflict with Solaris XOPEN. - #NXT_CFLAGS="$NXT_CFLAGS -std=gnu99" + NXT_CFLAGS="$NXT_CFLAGS -std=gnu11" NXT_CFLAGS="$NXT_CFLAGS -O" NXT_CFLAGS="$NXT_CFLAGS -Wall -Wextra" @@ -110,6 +109,8 @@ case $NXT_CC_NAME in NXT_CFLAGS="$NXT_CFLAGS -fno-strict-overflow" + NXT_CFLAGS="$NXT_CFLAGS -std=gnu11" + NXT_CFLAGS="$NXT_CFLAGS -O" NXT_CFLAGS="$NXT_CFLAGS -Wall -Wextra" -- cgit