From d68920063eb7266dd70b1c341ce08af0f3eb94c9 Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kittywhiskers@users.noreply.github.com> Date: Mon, 24 Jul 2023 07:50:32 +0000 Subject: [PATCH 01/20] build: define arguments as `--enable-[term]` instead of `--disable-[term]` The arguments were called `disable-{tests,bench,hardening}` but the variable they set was `use_[term]`, which could lead to an inversion. It appears that it is expected that developers declare enablement flags and Autotools will generate their equivalent disablement flags but there's no text to indicate that the same will happen vice-versa. --- configure.ac | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/configure.ac b/configure.ac index 23b61ec45..aad0bada4 100644 --- a/configure.ac +++ b/configure.ac @@ -58,21 +58,21 @@ AC_PATH_TOOL(STRIP, strip) AM_PROG_AS -AC_ARG_ENABLE(tests, - [AS_HELP_STRING([--disable-tests], - [do not compile tests (default is to compile)])], +AC_ARG_ENABLE([tests], + [AS_HELP_STRING([--enable-tests], + [Compile with tests (default is yes)])], [use_tests=$enableval], [use_tests=yes]) -AC_ARG_ENABLE(bench, - [AS_HELP_STRING([--disable-bench], - [do not compile benchmarks (default is to compile)])], +AC_ARG_ENABLE([bench], + [AS_HELP_STRING([--enable-bench], + [Compile with benchmarks (default is yes)])], [use_bench=$enableval], [use_bench=yes]) AC_ARG_ENABLE([hardening], - [AS_HELP_STRING([--disable-hardening], - [do not attempt to harden the resulting executables (default is to harden when possible)])], + [AS_HELP_STRING([--enable-hardening], + [Enable hardening flags and arguments (default is yes)])], [use_hardening=$enableval], [use_hardening=auto]) From f82bfee5dd01b1d33ec096f789d9f92ae0e67a88 Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kittywhiskers@users.noreply.github.com> Date: Mon, 24 Jul 2023 07:52:11 +0000 Subject: [PATCH 02/20] build: ensure help string format matches Autotool defaults --- configure.ac | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/configure.ac b/configure.ac index aad0bada4..0a6c09967 100644 --- a/configure.ac +++ b/configure.ac @@ -60,19 +60,19 @@ AM_PROG_AS AC_ARG_ENABLE([tests], [AS_HELP_STRING([--enable-tests], - [Compile with tests (default is yes)])], + [Compile with tests [default=yes]])], [use_tests=$enableval], [use_tests=yes]) AC_ARG_ENABLE([bench], [AS_HELP_STRING([--enable-bench], - [Compile with benchmarks (default is yes)])], + [Compile with benchmarks [default=yes]])], [use_bench=$enableval], [use_bench=yes]) AC_ARG_ENABLE([hardening], [AS_HELP_STRING([--enable-hardening], - [Enable hardening flags and arguments (default is yes)])], + [Enable hardening flags and arguments [default=auto]])], [use_hardening=$enableval], [use_hardening=auto]) @@ -260,7 +260,7 @@ AC_DEFINE([LOWER], [8], [Use implementation provided by the lower layer.]) dnl Define relic switches AC_ARG_ENABLE([debug], [AS_HELP_STRING([--enable-debug], - [Build with debugging support (default is no)])], + [Build with debugging support [default=no]])], [use_debug=$enableval], [use_debug=no]) @@ -270,7 +270,7 @@ fi AC_ARG_ENABLE([profiling], [AS_HELP_STRING([--enable-profiling], - [Build with profiling support (default is no)])], + [Build with profiling support [default=no]])], [use_profiling=$enableval], [use_profiling=no]) @@ -280,7 +280,7 @@ fi AC_ARG_ENABLE([check], [AS_HELP_STRING([--enable-check], - [Build with error-checking support (default is no)])], + [Build with error-checking support [default=no]])], [use_check=$enableval], [use_check=no]) @@ -290,7 +290,7 @@ fi AC_ARG_ENABLE([verbs], [AS_HELP_STRING([--enable-verbs], - [Build with detailed error messages (default is no)])], + [Build with detailed error messages [default=no]])], [use_verbs=$enableval], [use_verbs=no]) @@ -300,7 +300,7 @@ fi AC_ARG_ENABLE([overhead], [AS_HELP_STRING([--enable-overhead], - [Build with overhead estimation (default is no)])], + [Build with overhead estimation [default=no]])], [use_overhead=$enableval], [use_overhead=no]) @@ -310,7 +310,7 @@ fi AC_ARG_ENABLE([quiet], [AS_HELP_STRING([--enable-quiet], - [Build with printing disabled (default is yes)])], + [Build with printing disabled [default=yes]])], [use_quiet=$enableval], [use_quiet=yes]) @@ -320,7 +320,7 @@ fi AC_ARG_ENABLE([color], [AS_HELP_STRING([--enable-color], - [Build with colored output support (default is yes)])], + [Build with colored output support [default=yes]])], [use_color=$enableval], [use_color=yes]) @@ -330,7 +330,7 @@ fi AC_ARG_ENABLE([big_endian], [AS_HELP_STRING([--enable-big-endian], - [Build with big-endian support (default is no)])], + [Build with big-endian support [default=no]])], [use_big_endian=$enableval], [use_big_endian=no]) From 3687cd59e04b3d715de9726a8ab5f5056c04a61d Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kittywhiskers@users.noreply.github.com> Date: Mon, 24 Jul 2023 07:52:31 +0000 Subject: [PATCH 03/20] build: define new flag `--enable-optimizations` --- configure.ac | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/configure.ac b/configure.ac index 0a6c09967..d581162fc 100644 --- a/configure.ac +++ b/configure.ac @@ -76,6 +76,12 @@ AC_ARG_ENABLE([hardening], [use_hardening=$enableval], [use_hardening=auto]) +AC_ARG_ENABLE([optimizations], + [AS_HELP_STRING([--enable-optimizations], + [Enable compiler and library optimizations [default=yes]])], + [use_optimizations=$enableval], + [use_optimizations=yes]) + dnl Define enum mappings for relic config AC_DEFINE([RLC_VERSION], ["0.5.0"], [Relic Version]) @@ -753,6 +759,7 @@ AM_CONDITIONAL(WITH_FBX, test 1 -eq 1) AM_CONDITIONAL([USE_TESTS], [test x$BUILD_TEST = xyes]) AM_CONDITIONAL([USE_BENCH], [test x$BUILD_BENCH = xyes]) AM_CONDITIONAL([HARDEN], [test "$use_hardening" = "yes"]) +AM_CONDITIONAL([OPTIMIZE], [test "$use_optimizations" = "yes"]) AM_CONDITIONAL([ARITH_EASY], [test "$want_backend" = "easy"]) AM_CONDITIONAL([ARITH_GMP], [test "$want_backend" = "gmp"]) From f9328320af4ff7cb7cb94953af68939dd41c8159 Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kwvg@users.noreply.github.com> Date: Sat, 20 Apr 2024 16:54:24 +0000 Subject: [PATCH 04/20] build: use `easy` backend if optimizations are disabled unless specified --- configure.ac | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/configure.ac b/configure.ac index d581162fc..1690232a3 100644 --- a/configure.ac +++ b/configure.ac @@ -120,6 +120,9 @@ AC_ARG_WITH([backend], ) if test x"$want_backend" = x"auto"; then + if test x"$use_optimizations" = x"no"; then + want_backend=easy + else GMP_CHECK if test x"$has_gmp" = x"yes"; then case $host in @@ -140,6 +143,7 @@ if test x"$want_backend" = x"auto"; then else want_backend=easy fi + fi else case $want_backend in gmp) From 720d49a44bd641f28f43cd85d0becab2f331e5d5 Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kwvg@users.noreply.github.com> Date: Sat, 20 Apr 2024 16:56:12 +0000 Subject: [PATCH 05/20] trivial: fix indentation for `want_backend` check Co-authored-by: UdjinM6 --- configure.ac | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/configure.ac b/configure.ac index 1690232a3..0e74e0ebe 100644 --- a/configure.ac +++ b/configure.ac @@ -123,26 +123,26 @@ if test x"$want_backend" = x"auto"; then if test x"$use_optimizations" = x"no"; then want_backend=easy else - GMP_CHECK - if test x"$has_gmp" = x"yes"; then - case $host in - *darwin*) - case $host_cpu in - aarch*) - want_backend=easy - ;; - *) - want_backend=gmp - ;; - esac - ;; - *) - want_backend=gmp - ;; - esac - else - want_backend=easy - fi + GMP_CHECK + if test x"$has_gmp" = x"yes"; then + case $host in + *darwin*) + case $host_cpu in + aarch*) + want_backend=easy + ;; + *) + want_backend=gmp + ;; + esac + ;; + *) + want_backend=gmp + ;; + esac + else + want_backend=easy + fi fi else case $want_backend in From deb326982072a33416cc88b4f77166459632e12c Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kittywhiskers@users.noreply.github.com> Date: Mon, 24 Jul 2023 14:12:44 +0000 Subject: [PATCH 06/20] build: don't specify exact `{CPU_}ARCH` if optimizations are disabled --- configure.ac | 76 +++++++++++++++++++++++----------------------------- 1 file changed, 34 insertions(+), 42 deletions(-) diff --git a/configure.ac b/configure.ac index 0e74e0ebe..026908a48 100644 --- a/configure.ac +++ b/configure.ac @@ -350,48 +350,40 @@ fi use_pkgconfig=yes -case $host_cpu in - x86_64) - dnl Support for AMD64 (also known as x86_64 on some platforms) processors - CPU_ARCH="x64" - AC_DEFINE([ARCH], [X64], [Architecture.]) - AC_DEFINE([WSIZE], [64], [Size of word in this architecture.]) - ;; - aarch*) - dnl Relic doesn't support aarch64 yet, set CPU_ARCH to none. - dnl Support for 64-bit ARM processors - CPU_ARCH="none" - AC_DEFINE([ARCH], [ARM], [Architecture.]) - AC_DEFINE([WSIZE], [64], [Size of word in this architecture.]) - ;; - i?86) - dnl Support for Intel x86 processors - CPU_ARCH="x86" - AC_DEFINE([ARCH], [X86], [Architecture.]) - AC_DEFINE([WSIZE], [32], [Size of word in this architecture.]) - ;; - arm*) - dnl Support for 32-bit native ARM processors - CPU_ARCH="arm" - AC_DEFINE([ARCH], [ARM], [Architecture.]) - AC_DEFINE([WSIZE], [32], [Size of word in this architecture.]) - ;; - *32*) - dnl Support for an undefined 32-bit architecture - CPU_ARCH="none" - AC_DEFINE([ARCH], [RELIC_NONE], [Architecture.]) - AC_DEFINE([WSIZE], [32], [Size of word in this architecture.]) - ;; - *64*) - dnl Support for an undefined 64-bit architecture - CPU_ARCH="none" - AC_DEFINE([ARCH], [RELIC_NONE], [Architecture.]) - AC_DEFINE([WSIZE], [64], [Size of word in this architecture.]) - ;; - *) - AC_MSG_ERROR([Unable to determine host architecture, may not be supported!]) - ;; -esac +if [[[ "$host_cpu" == x86_64 && "$use_optimizations" == "yes" ]]]; then + dnl Support for AMD64 (also known as x86_64 on some platforms) processors + CPU_ARCH="x64" + AC_DEFINE([ARCH], [X64], [Architecture.]) + AC_DEFINE([WSIZE], [64], [Size of word in this architecture.]) +elif [[[ "$host_cpu" == aarch* && "$use_optimizations" == "yes" ]]]; then + dnl Relic doesn't support aarch64 yet, set CPU_ARCH to none. + dnl Support for 64-bit ARM processors + CPU_ARCH="none" + AC_DEFINE([ARCH], [ARM], [Architecture.]) + AC_DEFINE([WSIZE], [64], [Size of word in this architecture.]) +elif [[[ "$host_cpu" == i?86 && "$use_optimizations" == "yes" ]]]; then + dnl Support for Intel x86 processors + CPU_ARCH="x86" + AC_DEFINE([ARCH], [X86], [Architecture.]) + AC_DEFINE([WSIZE], [32], [Size of word in this architecture.]) +elif [[[ "$host_cpu" == arm* && "$use_optimizations" == "yes" ]]]; then + dnl Support for 32-bit native ARM processors + CPU_ARCH="arm" + AC_DEFINE([ARCH], [ARM], [Architecture.]) + AC_DEFINE([WSIZE], [32], [Size of word in this architecture.]) +elif [[[ "$host_cpu" == *32* ]]]; then + dnl Support for an undefined 32-bit architecture + CPU_ARCH="none" + AC_DEFINE([ARCH], [RELIC_NONE], [Architecture.]) + AC_DEFINE([WSIZE], [32], [Size of word in this architecture.]) +elif [[[ "$host_cpu" == *64* ]]]; then + dnl Support for an undefined 64-bit architecture + CPU_ARCH="none" + AC_DEFINE([ARCH], [RELIC_NONE], [Architecture.]) + AC_DEFINE([WSIZE], [64], [Size of word in this architecture.]) +else + AC_MSG_ERROR([Unable to determine host architecture, may not be supported!]) +fi case $host in *darwin*) From 883a0988685b740b588b0b5aad56a165259a670b Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kittywhiskers@users.noreply.github.com> Date: Mon, 24 Jul 2023 14:19:53 +0000 Subject: [PATCH 07/20] build: autodetect i?86 and arm as 32-bit This is a problem introduced by skipping architecture specific flags when building with optimizations disabled. Neither i?86 nor arm contain the number 32 in it, making number based matching unusable. But arm64 is 64-bit (though usually the recommended term is aarch64) and so we must match targets with the number 64 first before we assume anything with arm is 32-bit. --- configure.ac | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/configure.ac b/configure.ac index 026908a48..c91e68acd 100644 --- a/configure.ac +++ b/configure.ac @@ -371,16 +371,16 @@ elif [[[ "$host_cpu" == arm* && "$use_optimizations" == "yes" ]]]; then CPU_ARCH="arm" AC_DEFINE([ARCH], [ARM], [Architecture.]) AC_DEFINE([WSIZE], [32], [Size of word in this architecture.]) -elif [[[ "$host_cpu" == *32* ]]]; then - dnl Support for an undefined 32-bit architecture - CPU_ARCH="none" - AC_DEFINE([ARCH], [RELIC_NONE], [Architecture.]) - AC_DEFINE([WSIZE], [32], [Size of word in this architecture.]) elif [[[ "$host_cpu" == *64* ]]]; then dnl Support for an undefined 64-bit architecture CPU_ARCH="none" AC_DEFINE([ARCH], [RELIC_NONE], [Architecture.]) AC_DEFINE([WSIZE], [64], [Size of word in this architecture.]) +elif [[[ "$host_cpu" == *32* || "$host_cpu" == arm* || "$host_cpu" == i?86 ]]]; then + dnl Support for an undefined 32-bit architecture + CPU_ARCH="none" + AC_DEFINE([ARCH], [RELIC_NONE], [Architecture.]) + AC_DEFINE([WSIZE], [32], [Size of word in this architecture.]) else AC_MSG_ERROR([Unable to determine host architecture, may not be supported!]) fi From 2d77f7ae4941a9b38b61c35e93c565c17627aec7 Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kittywhiskers@users.noreply.github.com> Date: Mon, 24 Jul 2023 11:10:11 +0000 Subject: [PATCH 08/20] build: remove vestigial `LIBTOOL_{CXX,CPP,LD}FLAGS`, `HARDENED_CPPFLAGS` These are defined nowhere and used nowhere --- Makefile.am | 6 +++--- configure.ac | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Makefile.am b/Makefile.am index 9ce6ff4f6..92ae4ffda 100644 --- a/Makefile.am +++ b/Makefile.am @@ -9,9 +9,9 @@ print-%: FORCE ACLOCAL_AMFLAGS = -I build-aux/m4 .PHONY: deploy FORCE -AM_LDFLAGS = $(LIBTOOL_LDFLAGS) $(HARDENED_LDFLAGS) $(CORE_LDFLAGS) $(GMP_LDFLAGS) -AM_CXXFLAGS = $(LIBTOOL_CXXFLAGS) $(HARDENED_CXXFLAGS) $(CORE_CXXFLAGS) $(PIC_FLAGS) $(PIE_FLAGS) -AM_CPPFLAGS = $(LIBTOOL_CPPFLAGS) $(HARDENED_CPPFLAGS) $(CORE_CPPFLAGS) $(PIC_FLAGS) $(GMP_CPPFLAGS) +AM_LDFLAGS = $(HARDENED_LDFLAGS) $(CORE_LDFLAGS) $(GMP_LDFLAGS) +AM_CXXFLAGS = $(HARDENED_CXXFLAGS) $(CORE_CXXFLAGS) $(PIC_FLAGS) $(PIE_FLAGS) +AM_CPPFLAGS = $(CORE_CPPFLAGS) $(PIC_FLAGS) $(GMP_CPPFLAGS) PTHREAD_FLAGS = $(PTHREAD_CFLAGS) $(PTHREAD_LIBS) EXTRA_LIBRARIES = diff --git a/configure.ac b/configure.ac index c91e68acd..3433bc98b 100644 --- a/configure.ac +++ b/configure.ac @@ -767,7 +767,6 @@ AC_SUBST(WARN_CFLAGS) AC_SUBST(NOWARN_CFLAGS) AC_SUBST(LIBTOOL_APP_LDFLAGS) AC_SUBST(HARDENED_CXXFLAGS) -AC_SUBST(HARDENED_CPPFLAGS) AC_SUBST(HARDENED_LDFLAGS) AC_SUBST(PIC_FLAGS) AC_SUBST(PIE_FLAGS) From c90d43d43b63472c9f272c57ee84922a19c356c2 Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kittywhiskers@users.noreply.github.com> Date: Mon, 24 Jul 2023 11:08:58 +0000 Subject: [PATCH 09/20] build: add check to see if `CFLAGS` has been overridden --- configure.ac | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/configure.ac b/configure.ac index 3433bc98b..b6b248d02 100644 --- a/configure.ac +++ b/configure.ac @@ -24,11 +24,17 @@ dnl make the compilation flags quiet unless V=1 is used m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) dnl Compiler checks (here before libtool). +if test "x${CFLAGS+set}" = "xset"; then + CFLAGS_overridden=yes +else + CFLAGS_overridden=no +fi if test "x${CXXFLAGS+set}" = "xset"; then CXXFLAGS_overridden=yes else CXXFLAGS_overridden=no fi + AC_PROG_CXX AM_PROG_CC_C_O From 3036b83181ff6dd0d3d34e8bc69b0e6cdbacdb70 Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kittywhiskers@users.noreply.github.com> Date: Mon, 24 Jul 2023 14:26:32 +0000 Subject: [PATCH 10/20] build: expand `--enable-debug` to include `-O0`, `-ftrapv` and dbg info --- Makefile.am | 7 ++++--- configure.ac | 38 ++++++++++++++++++++++++++++++-------- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/Makefile.am b/Makefile.am index 92ae4ffda..18f01e34a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -9,9 +9,10 @@ print-%: FORCE ACLOCAL_AMFLAGS = -I build-aux/m4 .PHONY: deploy FORCE -AM_LDFLAGS = $(HARDENED_LDFLAGS) $(CORE_LDFLAGS) $(GMP_LDFLAGS) -AM_CXXFLAGS = $(HARDENED_CXXFLAGS) $(CORE_CXXFLAGS) $(PIC_FLAGS) $(PIE_FLAGS) -AM_CPPFLAGS = $(CORE_CPPFLAGS) $(PIC_FLAGS) $(GMP_CPPFLAGS) +AM_LDFLAGS = $(HARDENED_LDFLAGS) $(CORE_LDFLAGS) $(GMP_LDFLAGS) +AM_CFLAGS = $(DEBUG_FLAGS) +AM_CPPFLAGS = $(CORE_CPPFLAGS) $(PIC_FLAGS) $(GMP_CPPFLAGS) +AM_CXXFLAGS = $(DEBUG_FLAGS) $(HARDENED_CXXFLAGS) $(CORE_CXXFLAGS) $(PIC_FLAGS) $(PIE_FLAGS) PTHREAD_FLAGS = $(PTHREAD_CFLAGS) $(PTHREAD_LIBS) EXTRA_LIBRARIES = diff --git a/configure.ac b/configure.ac index b6b248d02..512b09b0d 100644 --- a/configure.ac +++ b/configure.ac @@ -88,6 +88,33 @@ AC_ARG_ENABLE([optimizations], [use_optimizations=$enableval], [use_optimizations=yes]) +AC_ARG_ENABLE([debug], + [AS_HELP_STRING([--enable-debug], + [Build with debugging support [default=no]])], + [use_debug=$enableval], + [use_debug=no]) + +if [[[ "$use_debug" == "yes" ]]]; then + dnl Clear default -g -O2 flags + if test x"$CFLAGS_overridden" = x"no"; then + CFLAGS="" + fi + if test x"$CXXFLAGS_overridden" = x"no"; then + CXXFLAGS="" + fi + + dnl Disable optimizations + AX_CHECK_COMPILE_FLAG([-O0], [[DEBUG_FLAGS="$DEBUG_FLAGS -O0"]]) + + dnl Prefer -g3, fall back to -g if that is unavailable. + AX_CHECK_COMPILE_FLAG( + [-g3], + [[DEBUG_FLAGS="$DEBUG_FLAGS -g3"]], + [AX_CHECK_COMPILE_FLAG([-g],[[DEBUG_FLAGS="$DEBUG_FLAGS -g"]])]) + + AX_CHECK_COMPILE_FLAG([-ftrapv],[DEBUG_FLAGS="$DEBUG_FLAGS -ftrapv"]) +fi + dnl Define enum mappings for relic config AC_DEFINE([RLC_VERSION], ["0.5.0"], [Relic Version]) @@ -273,17 +300,11 @@ AC_DEFINE([BRUCH], [6], [Hardware-friendly inversion by Brunner-Curiger-Hofste AC_DEFINE([CTAIA], [7], [Constant-time version of almost inverse.]) AC_DEFINE([LOWER], [8], [Use implementation provided by the lower layer.]) -dnl Define relic switches -AC_ARG_ENABLE([debug], - [AS_HELP_STRING([--enable-debug], - [Build with debugging support [default=no]])], - [use_debug=$enableval], - [use_debug=no]) - -if test x$use_debug = xyes; then +if test x"$use_debug" = x"yes"; then AC_DEFINE([DEBUG], [1], [Define this symbol if debugging support is enabled]) fi +dnl Define relic switches AC_ARG_ENABLE([profiling], [AS_HELP_STRING([--enable-profiling], [Build with profiling support [default=no]])], @@ -767,6 +788,7 @@ AM_CONDITIONAL([ARITH_EASY], [test "$want_backend" = "easy"]) AM_CONDITIONAL([ARITH_GMP], [test "$want_backend" = "gmp"]) AC_SUBST(CPU_ARCH) +AC_SUBST(DEBUG_FLAGS) AC_SUBST(RAND_PATH, hashd) AC_SUBST(RELIC_CPPFLAGS) AC_SUBST(WARN_CFLAGS) From 9ff8618a1bc6f5c1c9bfc485b5a4f8ddcb2ef01a Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kittywhiskers@users.noreply.github.com> Date: Mon, 24 Jul 2023 10:56:58 +0000 Subject: [PATCH 11/20] build: expand `--disable-optimizations` to include `-O0` and `-fwrapv` --- configure.ac | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/configure.ac b/configure.ac index 512b09b0d..52075cdce 100644 --- a/configure.ac +++ b/configure.ac @@ -94,7 +94,7 @@ AC_ARG_ENABLE([debug], [use_debug=$enableval], [use_debug=no]) -if [[[ "$use_debug" == "yes" ]]]; then +if [[[ "$use_debug" == "yes" || "$use_optimizations" == "no" ]]]; then dnl Clear default -g -O2 flags if test x"$CFLAGS_overridden" = x"no"; then CFLAGS="" @@ -106,13 +106,21 @@ if [[[ "$use_debug" == "yes" ]]]; then dnl Disable optimizations AX_CHECK_COMPILE_FLAG([-O0], [[DEBUG_FLAGS="$DEBUG_FLAGS -O0"]]) - dnl Prefer -g3, fall back to -g if that is unavailable. - AX_CHECK_COMPILE_FLAG( - [-g3], - [[DEBUG_FLAGS="$DEBUG_FLAGS -g3"]], - [AX_CHECK_COMPILE_FLAG([-g],[[DEBUG_FLAGS="$DEBUG_FLAGS -g"]])]) - - AX_CHECK_COMPILE_FLAG([-ftrapv],[DEBUG_FLAGS="$DEBUG_FLAGS -ftrapv"]) + if [[[ "$use_debug" == "yes" ]]]; then + dnl Prefer -g3, fall back to -g if that is unavailable. + AX_CHECK_COMPILE_FLAG( + [-g3], + [[DEBUG_FLAGS="$DEBUG_FLAGS -g3"]], + [AX_CHECK_COMPILE_FLAG([-g],[[DEBUG_FLAGS="$DEBUG_FLAGS -g"]])]) + + AX_CHECK_COMPILE_FLAG([-ftrapv],[DEBUG_FLAGS="$DEBUG_FLAGS -ftrapv"]) + else + dnl Reintroduce -g flag deleted during C(XX)FLAGS reset + AX_CHECK_COMPILE_FLAG([-g],[[DEBUG_FLAGS="$DEBUG_FLAGS -g"]]) + + dnl -ftrapv and -fwrapv conflict, so we only set this if use_debug=no + AX_CHECK_COMPILE_FLAG([-fwrapv],[DEBUG_FLAGS="$DEBUG_FLAGS -fwrapv"]) + fi fi dnl Define enum mappings for relic config From af0e3daef5eeaa4c7efb8277a7b7064ea4745ed4 Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kittywhiskers@users.noreply.github.com> Date: Mon, 24 Jul 2023 11:30:14 +0000 Subject: [PATCH 12/20] build: subsume `PI{C,E}_FLAGS` into `HARDENED_CXXFLAGS` --- Makefile.am | 4 ++-- configure.ac | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/Makefile.am b/Makefile.am index 18f01e34a..60f03bad0 100644 --- a/Makefile.am +++ b/Makefile.am @@ -11,8 +11,8 @@ ACLOCAL_AMFLAGS = -I build-aux/m4 AM_LDFLAGS = $(HARDENED_LDFLAGS) $(CORE_LDFLAGS) $(GMP_LDFLAGS) AM_CFLAGS = $(DEBUG_FLAGS) -AM_CPPFLAGS = $(CORE_CPPFLAGS) $(PIC_FLAGS) $(GMP_CPPFLAGS) -AM_CXXFLAGS = $(DEBUG_FLAGS) $(HARDENED_CXXFLAGS) $(CORE_CXXFLAGS) $(PIC_FLAGS) $(PIE_FLAGS) +AM_CPPFLAGS = $(CORE_CPPFLAGS) $(GMP_CPPFLAGS) +AM_CXXFLAGS = $(DEBUG_FLAGS) $(HARDENED_CXXFLAGS) $(CORE_CXXFLAGS) PTHREAD_FLAGS = $(PTHREAD_CFLAGS) $(PTHREAD_LIBS) EXTRA_LIBRARIES = diff --git a/configure.ac b/configure.ac index 52075cdce..00e25771f 100644 --- a/configure.ac +++ b/configure.ac @@ -652,7 +652,7 @@ AC_SEARCH_LIBS([clock_gettime],[rt]) if test "$TARGET_OS" != "windows"; then dnl All windows code is PIC, forcing it on just adds useless compile warnings - AX_CHECK_COMPILE_FLAG([-fPIC], [PIC_FLAGS="-fPIC"]) + AX_CHECK_COMPILE_FLAG([-fPIC], [HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -fPIC"]) fi dnl All versions of gcc that we commonly use for building are subject to bug @@ -683,7 +683,7 @@ if test "$use_hardening" != "no"; then AX_CHECK_LINK_FLAG([-Wl,-z,relro], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,relro"], [], []) AX_CHECK_LINK_FLAG([-Wl,-z,now], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,now"], [], []) AX_CHECK_LINK_FLAG([-Wl,-z,separate-code], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,separate-code"], [], []) - AX_CHECK_LINK_FLAG([-fPIE -pie], [PIE_FLAGS="-fPIE"; HARDENED_LDFLAGS="$HARDENED_LDFLAGS -pie"], [], []) + AX_CHECK_LINK_FLAG([-fPIE -pie], [HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -fPIE"; HARDENED_LDFLAGS="$HARDENED_LDFLAGS -pie"], [], []) case $host in *mingw*) @@ -804,8 +804,6 @@ AC_SUBST(NOWARN_CFLAGS) AC_SUBST(LIBTOOL_APP_LDFLAGS) AC_SUBST(HARDENED_CXXFLAGS) AC_SUBST(HARDENED_LDFLAGS) -AC_SUBST(PIC_FLAGS) -AC_SUBST(PIE_FLAGS) AC_SUBST(CORE_LDFLAGS) AC_SUBST(CORE_CPPFLAGS) AC_SUBST(CORE_CXXFLAGS) From e6008148e47a12c8cf61cbb42137dfdd64b5800d Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kittywhiskers@users.noreply.github.com> Date: Mon, 24 Jul 2023 11:21:01 +0000 Subject: [PATCH 13/20] trivial: rename `HARDENED_CXXFLAGS` to `HARDENED_FLAGS` --- Makefile.am | 2 +- configure.ac | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Makefile.am b/Makefile.am index 60f03bad0..6d60a8302 100644 --- a/Makefile.am +++ b/Makefile.am @@ -12,7 +12,7 @@ ACLOCAL_AMFLAGS = -I build-aux/m4 AM_LDFLAGS = $(HARDENED_LDFLAGS) $(CORE_LDFLAGS) $(GMP_LDFLAGS) AM_CFLAGS = $(DEBUG_FLAGS) AM_CPPFLAGS = $(CORE_CPPFLAGS) $(GMP_CPPFLAGS) -AM_CXXFLAGS = $(DEBUG_FLAGS) $(HARDENED_CXXFLAGS) $(CORE_CXXFLAGS) +AM_CXXFLAGS = $(DEBUG_FLAGS) $(HARDENED_FLAGS) $(CORE_CXXFLAGS) PTHREAD_FLAGS = $(PTHREAD_CFLAGS) $(PTHREAD_LIBS) EXTRA_LIBRARIES = diff --git a/configure.ac b/configure.ac index 00e25771f..82a929de7 100644 --- a/configure.ac +++ b/configure.ac @@ -652,19 +652,19 @@ AC_SEARCH_LIBS([clock_gettime],[rt]) if test "$TARGET_OS" != "windows"; then dnl All windows code is PIC, forcing it on just adds useless compile warnings - AX_CHECK_COMPILE_FLAG([-fPIC], [HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -fPIC"]) + AX_CHECK_COMPILE_FLAG([-fPIC], [HARDENED_FLAGS="$HARDENED_FLAGS -fPIC"]) fi dnl All versions of gcc that we commonly use for building are subject to bug dnl https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90348. To work around that, set dnl -fstack-reuse=none for all gcc builds. (Only gcc understands this flag) -AX_CHECK_COMPILE_FLAG([-fstack-reuse=none], [HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -fstack-reuse=none"]) +AX_CHECK_COMPILE_FLAG([-fstack-reuse=none], [HARDENED_FLAGS="$HARDENED_FLAGS -fstack-reuse=none"]) if test "$use_hardening" != "no"; then use_hardening=yes - AX_CHECK_COMPILE_FLAG([-Wstack-protector], [HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -Wstack-protector"]) - AX_CHECK_COMPILE_FLAG([-fstack-protector-all], [HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -fstack-protector-all"]) + AX_CHECK_COMPILE_FLAG([-Wstack-protector], [HARDENED_FLAGS="$HARDENED_FLAGS -Wstack-protector"]) + AX_CHECK_COMPILE_FLAG([-fstack-protector-all], [HARDENED_FLAGS="$HARDENED_FLAGS -fstack-protector-all"]) - AX_CHECK_COMPILE_FLAG([-fcf-protection=full], [HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -fcf-protection=full"]) + AX_CHECK_COMPILE_FLAG([-fcf-protection=full], [HARDENED_FLAGS="$HARDENED_FLAGS -fcf-protection=full"]) case $host in *mingw*) @@ -672,7 +672,7 @@ if test "$use_hardening" != "no"; then dnl See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90458 for more details. ;; *) - AX_CHECK_COMPILE_FLAG([-fstack-clash-protection], [HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -fstack-clash-protection"], [], []) + AX_CHECK_COMPILE_FLAG([-fstack-clash-protection], [HARDENED_FLAGS="$HARDENED_FLAGS -fstack-clash-protection"], [], []) ;; esac @@ -683,7 +683,7 @@ if test "$use_hardening" != "no"; then AX_CHECK_LINK_FLAG([-Wl,-z,relro], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,relro"], [], []) AX_CHECK_LINK_FLAG([-Wl,-z,now], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,now"], [], []) AX_CHECK_LINK_FLAG([-Wl,-z,separate-code], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,separate-code"], [], []) - AX_CHECK_LINK_FLAG([-fPIE -pie], [HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -fPIE"; HARDENED_LDFLAGS="$HARDENED_LDFLAGS -pie"], [], []) + AX_CHECK_LINK_FLAG([-fPIE -pie], [HARDENED_FLAGS="$HARDENED_FLAGS -fPIE"; HARDENED_LDFLAGS="$HARDENED_LDFLAGS -pie"], [], []) case $host in *mingw*) @@ -802,7 +802,7 @@ AC_SUBST(RELIC_CPPFLAGS) AC_SUBST(WARN_CFLAGS) AC_SUBST(NOWARN_CFLAGS) AC_SUBST(LIBTOOL_APP_LDFLAGS) -AC_SUBST(HARDENED_CXXFLAGS) +AC_SUBST(HARDENED_FLAGS) AC_SUBST(HARDENED_LDFLAGS) AC_SUBST(CORE_LDFLAGS) AC_SUBST(CORE_CPPFLAGS) From b630c2c323ea97c8fe1558f35dd0572d0de4101b Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kwvg@users.noreply.github.com> Date: Sun, 21 Apr 2024 10:31:24 +0000 Subject: [PATCH 14/20] build: append `HARDENED_FLAGS` to `AM_CFLAGS` --- Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index 6d60a8302..4ba3d97cc 100644 --- a/Makefile.am +++ b/Makefile.am @@ -10,7 +10,7 @@ ACLOCAL_AMFLAGS = -I build-aux/m4 .PHONY: deploy FORCE AM_LDFLAGS = $(HARDENED_LDFLAGS) $(CORE_LDFLAGS) $(GMP_LDFLAGS) -AM_CFLAGS = $(DEBUG_FLAGS) +AM_CFLAGS = $(DEBUG_FLAGS) $(HARDENED_FLAGS) AM_CPPFLAGS = $(CORE_CPPFLAGS) $(GMP_CPPFLAGS) AM_CXXFLAGS = $(DEBUG_FLAGS) $(HARDENED_FLAGS) $(CORE_CXXFLAGS) PTHREAD_FLAGS = $(PTHREAD_CFLAGS) $(PTHREAD_LIBS) From 32c2f0f5f899834210e0ba81b6c57e294719cc27 Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kwvg@users.noreply.github.com> Date: Sun, 21 Apr 2024 10:39:38 +0000 Subject: [PATCH 15/20] trivial: rename `CORE_CXXFLAGS` to `CORE_FLAGS`, use with C{++} --- Makefile.am | 4 ++-- configure.ac | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile.am b/Makefile.am index 4ba3d97cc..5f367599d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -10,9 +10,9 @@ ACLOCAL_AMFLAGS = -I build-aux/m4 .PHONY: deploy FORCE AM_LDFLAGS = $(HARDENED_LDFLAGS) $(CORE_LDFLAGS) $(GMP_LDFLAGS) -AM_CFLAGS = $(DEBUG_FLAGS) $(HARDENED_FLAGS) +AM_CFLAGS = $(DEBUG_FLAGS) $(HARDENED_FLAGS) $(CORE_FLAGS) AM_CPPFLAGS = $(CORE_CPPFLAGS) $(GMP_CPPFLAGS) -AM_CXXFLAGS = $(DEBUG_FLAGS) $(HARDENED_FLAGS) $(CORE_CXXFLAGS) +AM_CXXFLAGS = $(DEBUG_FLAGS) $(HARDENED_FLAGS) $(CORE_FLAGS) PTHREAD_FLAGS = $(PTHREAD_CFLAGS) $(PTHREAD_LIBS) EXTRA_LIBRARIES = diff --git a/configure.ac b/configure.ac index 82a929de7..76f2e2e2f 100644 --- a/configure.ac +++ b/configure.ac @@ -745,7 +745,7 @@ if test "$TARGET_OS" = "darwin"; then fi dnl Don't allow extended (non-ASCII) symbols in identifiers. This is easier for code review. -AX_CHECK_COMPILE_FLAG([-fno-extended-identifiers], [CORE_CXXFLAGS="$CORE_CXXFLAGS -fno-extended-identifiers"], [], []) +AX_CHECK_COMPILE_FLAG([-fno-extended-identifiers], [CORE_FLAGS="$CORE_FLAGS -fno-extended-identifiers"], [], []) AC_MSG_CHECKING([whether to build runtest]) if test x$use_tests = xyes; then @@ -806,7 +806,7 @@ AC_SUBST(HARDENED_FLAGS) AC_SUBST(HARDENED_LDFLAGS) AC_SUBST(CORE_LDFLAGS) AC_SUBST(CORE_CPPFLAGS) -AC_SUBST(CORE_CXXFLAGS) +AC_SUBST(CORE_FLAGS) AC_SUBST(GMP_LDFLAGS) AC_SUBST(GMP_CPPFLAGS) From 28bea63838fc6e14ab3878108dab99a42296234e Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kwvg@users.noreply.github.com> Date: Sun, 21 Apr 2024 11:26:54 +0000 Subject: [PATCH 16/20] build: set {`NO`}`WARN_CFLAGS` flags if not overridden and uniformly --- Makefile.am | 2 +- Makefile.relic.include | 2 +- configure.ac | 29 ++++++++++++++++++----------- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/Makefile.am b/Makefile.am index 5f367599d..d43278998 100644 --- a/Makefile.am +++ b/Makefile.am @@ -10,7 +10,7 @@ ACLOCAL_AMFLAGS = -I build-aux/m4 .PHONY: deploy FORCE AM_LDFLAGS = $(HARDENED_LDFLAGS) $(CORE_LDFLAGS) $(GMP_LDFLAGS) -AM_CFLAGS = $(DEBUG_FLAGS) $(HARDENED_FLAGS) $(CORE_FLAGS) +AM_CFLAGS = $(DEBUG_FLAGS) $(HARDENED_FLAGS) $(CORE_FLAGS) $(WARN_CFLAGS) $(NOWARN_CFLAGS) AM_CPPFLAGS = $(CORE_CPPFLAGS) $(GMP_CPPFLAGS) AM_CXXFLAGS = $(DEBUG_FLAGS) $(HARDENED_FLAGS) $(CORE_FLAGS) PTHREAD_FLAGS = $(PTHREAD_CFLAGS) $(PTHREAD_LIBS) diff --git a/Makefile.relic.include b/Makefile.relic.include index 725e8ca4f..92bd7c7e8 100644 --- a/Makefile.relic.include +++ b/Makefile.relic.include @@ -464,7 +464,7 @@ librelic_la_SOURCES = \ librelic_la_CPPFLAGS = $(AM_CPPFLAGS) $(RELIC_CPPFLAGS) $(RELIC_INCLUDES) librelic_la_CXXFLAGS = $(AM_CXXFLAGS) -librelic_la_CFLAGS = $(AM_CFLAGS) $(WARN_CFLAGS) $(NOWARN_CFLAGS) +librelic_la_CFLAGS = $(AM_CFLAGS) librelic_la_LDFLAGS = $(AM_LDFLAGS) noinst_LTLIBRARIES += $(LIBRELIC) diff --git a/configure.ac b/configure.ac index 76f2e2e2f..108b51b02 100644 --- a/configure.ac +++ b/configure.ac @@ -94,6 +94,8 @@ AC_ARG_ENABLE([debug], [use_debug=$enableval], [use_debug=no]) +AC_LANG_PUSH([C]) + if [[[ "$use_debug" == "yes" || "$use_optimizations" == "no" ]]]; then dnl Clear default -g -O2 flags if test x"$CFLAGS_overridden" = x"no"; then @@ -517,17 +519,20 @@ AC_COMPILE_IFELSE([AC_LANG_SOURCE([[char foo;]])], CFLAGS="$saved_CFLAGS" ]) -AC_LANG_PUSH([C]) -AX_CHECK_COMPILE_FLAG([-Wall],[WARN_CFLAGS="$WARN_CFLAGS -Wall"],,) -AX_CHECK_COMPILE_FLAG([-Wextra],[WARN_CFLAGS="$WARN_CFLAGS -Wextra"],,) -AX_CHECK_COMPILE_FLAG([-Wcast-align],[WARN_CFLAGS="$WARN_CFLAGS -Wcast-align"],,) -AX_CHECK_COMPILE_FLAG([-Wunused-parameter],[NOWARN_CFLAGS="$NOWARN_CFLAGS -Wno-unused-parameter"],,) -AX_CHECK_COMPILE_FLAG([-Wshadow],[NOWARN_CFLAGS="$NOWARN_CFLAGS -Wno-shadow"],,) -AX_CHECK_COMPILE_FLAG([-Wsign-compare],[NOWARN_CFLAGS="$NOWARN_CFLAGS -Wno-sign-compare"],,) -AX_CHECK_COMPILE_FLAG([-Wstrict-prototypes],[NOWARN_CFLAGS="$NOWARN_CFLAGS -Wno-strict-prototypes"],,) -AX_CHECK_COMPILE_FLAG([-Wunused-function],[NOWARN_CFLAGS="$NOWARN_CFLAGS -Wno-unused-function"],,) -AX_CHECK_COMPILE_FLAG([-Wlong-long],[NOWARN_CFLAGS="$NOWARN_CFLAGS -Wno-long-long"],,) -AC_LANG_POP([C]) +if [[[ "$CFLAGS_overridden" == "no" ]]]; then + dnl Enable warnings + AX_CHECK_COMPILE_FLAG([-Wall],[WARN_CFLAGS="$WARN_CFLAGS -Wall"],,) + AX_CHECK_COMPILE_FLAG([-Wextra],[WARN_CFLAGS="$WARN_CFLAGS -Wextra"],,) + AX_CHECK_COMPILE_FLAG([-Wcast-align],[WARN_CFLAGS="$WARN_CFLAGS -Wcast-align"],,) + + dnl Exclude known warnings + AX_CHECK_COMPILE_FLAG([-Wunused-parameter],[NOWARN_CFLAGS="$NOWARN_CFLAGS -Wno-unused-parameter"],,) + AX_CHECK_COMPILE_FLAG([-Wshadow],[NOWARN_CFLAGS="$NOWARN_CFLAGS -Wno-shadow"],,) + AX_CHECK_COMPILE_FLAG([-Wsign-compare],[NOWARN_CFLAGS="$NOWARN_CFLAGS -Wno-sign-compare"],,) + AX_CHECK_COMPILE_FLAG([-Wstrict-prototypes],[NOWARN_CFLAGS="$NOWARN_CFLAGS -Wno-strict-prototypes"],,) + AX_CHECK_COMPILE_FLAG([-Wunused-function],[NOWARN_CFLAGS="$NOWARN_CFLAGS -Wno-unused-function"],,) + AX_CHECK_COMPILE_FLAG([-Wlong-long],[NOWARN_CFLAGS="$NOWARN_CFLAGS -Wno-long-long"],,) +fi dnl set default settings for relic AC_DEFINE([ALIGN], [1], [Byte boundary to align digit vectors.]) @@ -747,6 +752,8 @@ fi dnl Don't allow extended (non-ASCII) symbols in identifiers. This is easier for code review. AX_CHECK_COMPILE_FLAG([-fno-extended-identifiers], [CORE_FLAGS="$CORE_FLAGS -fno-extended-identifiers"], [], []) +AC_LANG_POP([C]) + AC_MSG_CHECKING([whether to build runtest]) if test x$use_tests = xyes; then AC_MSG_RESULT([yes]) From 7a1b227637d08965a9c1f3a98973828b171ef978 Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kwvg@users.noreply.github.com> Date: Sun, 21 Apr 2024 11:37:46 +0000 Subject: [PATCH 17/20] build: rename {`NO`}`WARN_CFLAGS` to {`NO`}`WARN_FLAGS`, use with C{++} --- Makefile.am | 4 ++-- configure.ac | 24 ++++++++++++------------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Makefile.am b/Makefile.am index d43278998..1c1e5d19d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -10,9 +10,9 @@ ACLOCAL_AMFLAGS = -I build-aux/m4 .PHONY: deploy FORCE AM_LDFLAGS = $(HARDENED_LDFLAGS) $(CORE_LDFLAGS) $(GMP_LDFLAGS) -AM_CFLAGS = $(DEBUG_FLAGS) $(HARDENED_FLAGS) $(CORE_FLAGS) $(WARN_CFLAGS) $(NOWARN_CFLAGS) +AM_CFLAGS = $(DEBUG_FLAGS) $(HARDENED_FLAGS) $(CORE_FLAGS) $(WARN_FLAGS) $(NOWARN_FLAGS) AM_CPPFLAGS = $(CORE_CPPFLAGS) $(GMP_CPPFLAGS) -AM_CXXFLAGS = $(DEBUG_FLAGS) $(HARDENED_FLAGS) $(CORE_FLAGS) +AM_CXXFLAGS = $(DEBUG_FLAGS) $(HARDENED_FLAGS) $(CORE_FLAGS) $(WARN_FLAGS) $(NOWARN_FLAGS) PTHREAD_FLAGS = $(PTHREAD_CFLAGS) $(PTHREAD_LIBS) EXTRA_LIBRARIES = diff --git a/configure.ac b/configure.ac index 108b51b02..62c61b2f2 100644 --- a/configure.ac +++ b/configure.ac @@ -519,19 +519,19 @@ AC_COMPILE_IFELSE([AC_LANG_SOURCE([[char foo;]])], CFLAGS="$saved_CFLAGS" ]) -if [[[ "$CFLAGS_overridden" == "no" ]]]; then +if [[[ "$CFLAGS_overridden" == "no" && "$CXXFLAGS_overridden" == "no" ]]]; then dnl Enable warnings - AX_CHECK_COMPILE_FLAG([-Wall],[WARN_CFLAGS="$WARN_CFLAGS -Wall"],,) - AX_CHECK_COMPILE_FLAG([-Wextra],[WARN_CFLAGS="$WARN_CFLAGS -Wextra"],,) - AX_CHECK_COMPILE_FLAG([-Wcast-align],[WARN_CFLAGS="$WARN_CFLAGS -Wcast-align"],,) + AX_CHECK_COMPILE_FLAG([-Wall],[WARN_FLAGS="$WARN_FLAGS -Wall"],,) + AX_CHECK_COMPILE_FLAG([-Wcast-align],[WARN_FLAGS="$WARN_FLAGS -Wcast-align"],,) + AX_CHECK_COMPILE_FLAG([-Wextra],[WARN_FLAGS="$WARN_FLAGS -Wextra"],,) dnl Exclude known warnings - AX_CHECK_COMPILE_FLAG([-Wunused-parameter],[NOWARN_CFLAGS="$NOWARN_CFLAGS -Wno-unused-parameter"],,) - AX_CHECK_COMPILE_FLAG([-Wshadow],[NOWARN_CFLAGS="$NOWARN_CFLAGS -Wno-shadow"],,) - AX_CHECK_COMPILE_FLAG([-Wsign-compare],[NOWARN_CFLAGS="$NOWARN_CFLAGS -Wno-sign-compare"],,) - AX_CHECK_COMPILE_FLAG([-Wstrict-prototypes],[NOWARN_CFLAGS="$NOWARN_CFLAGS -Wno-strict-prototypes"],,) - AX_CHECK_COMPILE_FLAG([-Wunused-function],[NOWARN_CFLAGS="$NOWARN_CFLAGS -Wno-unused-function"],,) - AX_CHECK_COMPILE_FLAG([-Wlong-long],[NOWARN_CFLAGS="$NOWARN_CFLAGS -Wno-long-long"],,) + AX_CHECK_COMPILE_FLAG([-Wlong-long],[NOWARN_FLAGS="$NOWARN_FLAGS -Wno-long-long"],,) + AX_CHECK_COMPILE_FLAG([-Wshadow],[NOWARN_FLAGS="$NOWARN_FLAGS -Wno-shadow"],,) + AX_CHECK_COMPILE_FLAG([-Wsign-compare],[NOWARN_FLAGS="$NOWARN_FLAGS -Wno-sign-compare"],,) + AX_CHECK_COMPILE_FLAG([-Wstrict-prototypes],[NOWARN_FLAGS="$NOWARN_FLAGS -Wno-strict-prototypes"],,) + AX_CHECK_COMPILE_FLAG([-Wunused-function],[NOWARN_FLAGS="$NOWARN_FLAGS -Wno-unused-function"],,) + AX_CHECK_COMPILE_FLAG([-Wunused-parameter],[NOWARN_FLAGS="$NOWARN_FLAGS -Wno-unused-parameter"],,) fi dnl set default settings for relic @@ -806,8 +806,8 @@ AC_SUBST(CPU_ARCH) AC_SUBST(DEBUG_FLAGS) AC_SUBST(RAND_PATH, hashd) AC_SUBST(RELIC_CPPFLAGS) -AC_SUBST(WARN_CFLAGS) -AC_SUBST(NOWARN_CFLAGS) +AC_SUBST(WARN_FLAGS) +AC_SUBST(NOWARN_FLAGS) AC_SUBST(LIBTOOL_APP_LDFLAGS) AC_SUBST(HARDENED_FLAGS) AC_SUBST(HARDENED_LDFLAGS) From 6a3c28f6cab03e78fdd889d48e32a102f5ba2038 Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kwvg@users.noreply.github.com> Date: Sun, 21 Apr 2024 10:20:06 +0000 Subject: [PATCH 18/20] build: use stricter `-Werror` when testing compile flags Helps us avoid a situation where a compiler will report a warning instead of erroring out when testing a flag, giving `autotools` the impression they are supported when they are not, polluting the build log with "argument unused during compilation" messages. --- configure.ac | 49 +++++++++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/configure.ac b/configure.ac index 62c61b2f2..09f296d58 100644 --- a/configure.ac +++ b/configure.ac @@ -96,6 +96,15 @@ AC_ARG_ENABLE([debug], AC_LANG_PUSH([C]) +dnl Check for a flag to turn compiler warnings into errors. This is helpful for checks which may +dnl appear to succeed because by default they merely emit warnings when they fail. +dnl +dnl Note that this is not necessarily a check to see if -Werror is supported, but rather to see if +dnl a compile with -Werror can succeed. This is important because the compiler may already be +dnl warning about something unrelated, for example about some path issue. If that is the case, +dnl -Werror cannot be used because all of those warnings would be turned into errors. +AX_CHECK_COMPILE_FLAG([-Werror], [FLAG_WERROR="-Werror"], [FLAG_WERROR=""]) + if [[[ "$use_debug" == "yes" || "$use_optimizations" == "no" ]]]; then dnl Clear default -g -O2 flags if test x"$CFLAGS_overridden" = x"no"; then @@ -106,22 +115,22 @@ if [[[ "$use_debug" == "yes" || "$use_optimizations" == "no" ]]]; then fi dnl Disable optimizations - AX_CHECK_COMPILE_FLAG([-O0], [[DEBUG_FLAGS="$DEBUG_FLAGS -O0"]]) + AX_CHECK_COMPILE_FLAG([-O0], [[DEBUG_FLAGS="$DEBUG_FLAGS -O0"]], [], [[$FLAG_WERROR]]) if [[[ "$use_debug" == "yes" ]]]; then dnl Prefer -g3, fall back to -g if that is unavailable. AX_CHECK_COMPILE_FLAG( [-g3], [[DEBUG_FLAGS="$DEBUG_FLAGS -g3"]], - [AX_CHECK_COMPILE_FLAG([-g],[[DEBUG_FLAGS="$DEBUG_FLAGS -g"]])]) + [AX_CHECK_COMPILE_FLAG([-g],[[DEBUG_FLAGS="$DEBUG_FLAGS -g"]])], [[$FLAG_WERROR]]) - AX_CHECK_COMPILE_FLAG([-ftrapv],[DEBUG_FLAGS="$DEBUG_FLAGS -ftrapv"]) + AX_CHECK_COMPILE_FLAG([-ftrapv],[DEBUG_FLAGS="$DEBUG_FLAGS -ftrapv"], [], [[$FLAG_WERROR]]) else dnl Reintroduce -g flag deleted during C(XX)FLAGS reset - AX_CHECK_COMPILE_FLAG([-g],[[DEBUG_FLAGS="$DEBUG_FLAGS -g"]]) + AX_CHECK_COMPILE_FLAG([-g],[[DEBUG_FLAGS="$DEBUG_FLAGS -g"]], [], [[$FLAG_WERROR]]) dnl -ftrapv and -fwrapv conflict, so we only set this if use_debug=no - AX_CHECK_COMPILE_FLAG([-fwrapv],[DEBUG_FLAGS="$DEBUG_FLAGS -fwrapv"]) + AX_CHECK_COMPILE_FLAG([-fwrapv],[DEBUG_FLAGS="$DEBUG_FLAGS -fwrapv"], [], [[$FLAG_WERROR]]) fi fi @@ -521,17 +530,17 @@ AC_COMPILE_IFELSE([AC_LANG_SOURCE([[char foo;]])], if [[[ "$CFLAGS_overridden" == "no" && "$CXXFLAGS_overridden" == "no" ]]]; then dnl Enable warnings - AX_CHECK_COMPILE_FLAG([-Wall],[WARN_FLAGS="$WARN_FLAGS -Wall"],,) - AX_CHECK_COMPILE_FLAG([-Wcast-align],[WARN_FLAGS="$WARN_FLAGS -Wcast-align"],,) - AX_CHECK_COMPILE_FLAG([-Wextra],[WARN_FLAGS="$WARN_FLAGS -Wextra"],,) + AX_CHECK_COMPILE_FLAG([-Wall],[WARN_FLAGS="$WARN_FLAGS -Wall"], [], [[$FLAG_WERROR]]) + AX_CHECK_COMPILE_FLAG([-Wcast-align],[WARN_FLAGS="$WARN_FLAGS -Wcast-align"], [], [[$FLAG_WERROR]]) + AX_CHECK_COMPILE_FLAG([-Wextra],[WARN_FLAGS="$WARN_FLAGS -Wextra"], [], [[$FLAG_WERROR]]) dnl Exclude known warnings - AX_CHECK_COMPILE_FLAG([-Wlong-long],[NOWARN_FLAGS="$NOWARN_FLAGS -Wno-long-long"],,) - AX_CHECK_COMPILE_FLAG([-Wshadow],[NOWARN_FLAGS="$NOWARN_FLAGS -Wno-shadow"],,) - AX_CHECK_COMPILE_FLAG([-Wsign-compare],[NOWARN_FLAGS="$NOWARN_FLAGS -Wno-sign-compare"],,) - AX_CHECK_COMPILE_FLAG([-Wstrict-prototypes],[NOWARN_FLAGS="$NOWARN_FLAGS -Wno-strict-prototypes"],,) - AX_CHECK_COMPILE_FLAG([-Wunused-function],[NOWARN_FLAGS="$NOWARN_FLAGS -Wno-unused-function"],,) - AX_CHECK_COMPILE_FLAG([-Wunused-parameter],[NOWARN_FLAGS="$NOWARN_FLAGS -Wno-unused-parameter"],,) + AX_CHECK_COMPILE_FLAG([-Wlong-long],[NOWARN_FLAGS="$NOWARN_FLAGS -Wno-long-long"], [], [[$FLAG_WERROR]]) + AX_CHECK_COMPILE_FLAG([-Wshadow],[NOWARN_FLAGS="$NOWARN_FLAGS -Wno-shadow"], [], [[$FLAG_WERROR]]) + AX_CHECK_COMPILE_FLAG([-Wsign-compare],[NOWARN_FLAGS="$NOWARN_FLAGS -Wno-sign-compare"], [], [[$FLAG_WERROR]]) + AX_CHECK_COMPILE_FLAG([-Wstrict-prototypes],[NOWARN_FLAGS="$NOWARN_FLAGS -Wno-strict-prototypes"], [], [[$FLAG_WERROR]]) + AX_CHECK_COMPILE_FLAG([-Wunused-function],[NOWARN_FLAGS="$NOWARN_FLAGS -Wno-unused-function"], [], [[$FLAG_WERROR]]) + AX_CHECK_COMPILE_FLAG([-Wunused-parameter],[NOWARN_FLAGS="$NOWARN_FLAGS -Wno-unused-parameter"], [], [[$FLAG_WERROR]]) fi dnl set default settings for relic @@ -657,19 +666,19 @@ AC_SEARCH_LIBS([clock_gettime],[rt]) if test "$TARGET_OS" != "windows"; then dnl All windows code is PIC, forcing it on just adds useless compile warnings - AX_CHECK_COMPILE_FLAG([-fPIC], [HARDENED_FLAGS="$HARDENED_FLAGS -fPIC"]) + AX_CHECK_COMPILE_FLAG([-fPIC], [HARDENED_FLAGS="$HARDENED_FLAGS -fPIC"], [], [[$FLAG_WERROR]]) fi dnl All versions of gcc that we commonly use for building are subject to bug dnl https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90348. To work around that, set dnl -fstack-reuse=none for all gcc builds. (Only gcc understands this flag) -AX_CHECK_COMPILE_FLAG([-fstack-reuse=none], [HARDENED_FLAGS="$HARDENED_FLAGS -fstack-reuse=none"]) +AX_CHECK_COMPILE_FLAG([-fstack-reuse=none], [HARDENED_FLAGS="$HARDENED_FLAGS -fstack-reuse=none"], [], [[$FLAG_WERROR]]) if test "$use_hardening" != "no"; then use_hardening=yes AX_CHECK_COMPILE_FLAG([-Wstack-protector], [HARDENED_FLAGS="$HARDENED_FLAGS -Wstack-protector"]) - AX_CHECK_COMPILE_FLAG([-fstack-protector-all], [HARDENED_FLAGS="$HARDENED_FLAGS -fstack-protector-all"]) + AX_CHECK_COMPILE_FLAG([-fstack-protector-all], [HARDENED_FLAGS="$HARDENED_FLAGS -fstack-protector-all"], [], [[$FLAG_WERROR]]) - AX_CHECK_COMPILE_FLAG([-fcf-protection=full], [HARDENED_FLAGS="$HARDENED_FLAGS -fcf-protection=full"]) + AX_CHECK_COMPILE_FLAG([-fcf-protection=full], [HARDENED_FLAGS="$HARDENED_FLAGS -fcf-protection=full"], [], [[$FLAG_WERROR]]) case $host in *mingw*) @@ -677,7 +686,7 @@ if test "$use_hardening" != "no"; then dnl See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90458 for more details. ;; *) - AX_CHECK_COMPILE_FLAG([-fstack-clash-protection], [HARDENED_FLAGS="$HARDENED_FLAGS -fstack-clash-protection"], [], []) + AX_CHECK_COMPILE_FLAG([-fstack-clash-protection], [HARDENED_FLAGS="$HARDENED_FLAGS -fstack-clash-protection"], [], [[$FLAG_WERROR]]) ;; esac @@ -750,7 +759,7 @@ if test "$TARGET_OS" = "darwin"; then fi dnl Don't allow extended (non-ASCII) symbols in identifiers. This is easier for code review. -AX_CHECK_COMPILE_FLAG([-fno-extended-identifiers], [CORE_FLAGS="$CORE_FLAGS -fno-extended-identifiers"], [], []) +AX_CHECK_COMPILE_FLAG([-fno-extended-identifiers], [CORE_FLAGS="$CORE_FLAGS -fno-extended-identifiers"], [], [[$FLAG_WERROR]]) AC_LANG_POP([C]) From 73106a0121644d412d26acc2ce86a6ac0d98d4dc Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kwvg@users.noreply.github.com> Date: Sun, 21 Apr 2024 10:10:06 +0000 Subject: [PATCH 19/20] build: use `-mbranch-protection=bti` on supporting `aarch64` compilers --- configure.ac | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/configure.ac b/configure.ac index 09f296d58..34c5363c7 100644 --- a/configure.ac +++ b/configure.ac @@ -690,6 +690,12 @@ if test "$use_hardening" != "no"; then ;; esac + case $host in + *aarch64*) + AX_CHECK_COMPILE_FLAG([-mbranch-protection=bti], [HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -mbranch-protection=bti"], [], [[$CXXFLAG_WERROR]]) + ;; + esac + AX_CHECK_LINK_FLAG([-Wl,--enable-reloc-section], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,--enable-reloc-section"], [], []) AX_CHECK_LINK_FLAG([-Wl,--dynamicbase], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,--dynamicbase"], [], []) AX_CHECK_LINK_FLAG([-Wl,--nxcompat], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,--nxcompat"], [], []) From 39791d4e312abcc1051a194b09894f599ea74513 Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kwvg@users.noreply.github.com> Date: Sun, 21 Apr 2024 10:56:10 +0000 Subject: [PATCH 20/20] build: print build options after configure Co-authored-by: UdjinM6 --- configure.ac | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/configure.ac b/configure.ac index 34c5363c7..5cfa66ac3 100644 --- a/configure.ac +++ b/configure.ac @@ -842,3 +842,20 @@ AC_OUTPUT dnl Peplace conflict-prone PACKAGE-prefixed macros with DASHBLS sed -i.old 's/PACKAGE/DASHBLS/g' depends/relic/include/relic_conf.h sed -i.old 's/PACKAGE/DASHBLS/g' config.status + +echo +echo "Options used to compile and link:" +echo " target os = $TARGET_OS" +echo " backend = $want_backend" +echo " build bench = $BUILD_BENCH" +echo " build test = $BUILD_TEST" +echo " use debug = $use_debug" +echo " use hardening = $use_hardening" +echo " use optimizations = $use_optimizations" +echo +echo " LDFLAGS = $HARDENED_LDFLAGS $CORE_LDFLAGS $GMP_LDFLAGS" +echo " CFLAGS = $DEBUG_FLAGS $HARDENED_FLAGS $CORE_FLAGS $WARN_FLAGS $NOWARN_FLAGS" +echo " CPPFLAGS = $CORE_CPPFLAGS $GMP_CPPFLAGS" +echo " CXXFLAGS = $DEBUG_FLAGS $HARDENED_FLAGS $CORE_FLAGS $WARN_FLAGS $NOWARN_FLAGS" +echo " PTHREAD_FLAGS = $PTHREAD_CFLAGS $PTHREAD_LIBS" +echo