htcp

Properties of water suspended in clouds
git clone git://git.meso-star.fr/htcp.git
Log | Files | Refs | README | LICENSE

commit 0a06be7452c204e8cc76f8c2e60e4e659399518b
parent 45e11bae6b983236fe35d9dd32f23a8474160404
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Mon, 25 Sep 2023 16:12:20 +0200

Make generated binaries safer and more robust

Define the CFLAGS_HARDENED and LDFLAGS_HARDENED macros, which list
compiler and linker options that activate various hardening features
aimed at increasing the security and robustness of generated binaries.

The link editor options have all been available since at least ld 2.25.
So you don't have to worry about compatibility issues.

The compiler options are in fact some of those that will be enabled by
the -fhardened option to be introduced in GCC 14. In the following, we
list them and indicate the version of GCC from which they are documented
in the manual, i.e. from which version of GCC they would appear to be
available:

  -D_FORTIFY_SOURCE [GCC 5.5]
  -fcf-protection options [GCC 8.5]
  -fstack-protector-strong [GCC 6.5]
  -fstack-clash-protection [GCC 8.5]
  -ftrivial-auto-var-init [GCC 12.3]

The latter, -ftrivial-auto-var-init, is too recent. To avoid any
compatibility problems, we haven't activated it yet.

Diffstat:
Mconfig.mk | 14+++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/config.mk b/config.mk @@ -45,11 +45,19 @@ WFLAGS =\ -Wmissing-prototypes\ -Wshadow +# Increase the security and robustness of generated binaries +CFLAGS_HARDENED =\ + -D_FORTIFY_SOURCES=2\ + -fcf-protection=full\ + -fstack-clash-protection\ + -fstack-protector-strong + CFLAGS_COMMON =\ -std=c89\ -pedantic\ -fvisibility=hidden\ -fstrict-aliasing\ + $(CFLAGS_HARDENED)\ $(WFLAGS) CFLAGS_RELEASE = -O2 -DNDEBUG $(CFLAGS_COMMON) @@ -60,9 +68,9 @@ CFLAGS_EXE = $(CFLAGS_$(BUILD_TYPE)) -fPIE ################################################################################ # Linker options ################################################################################ +LDFLAGS_COMMON = -Wl,-z,relro,-z,now +LDFLAGS_DEBUG = $(LDFLAGS_COMMON) +LDFLAGS_RELEASE = -s $(LDFLAGS_COMMON) -LDFLAGS_DEBUG = -LDFLAGS_RELEASE = -s -LDFLAGS = $(LDFLAGS_$(BUILD_TYPE)) LDFLAGS_SO = $(LDFLAGS_$(BUILD_TYPE)) -shared -Wl,--no-undefined LDFLAGS_EXE = $(LDFLAGS_$(BUILD_TYPE)) -pie