rsimd

Make SIMD instruction sets easier to use
git clone git://git.meso-star.fr/rsimd.git
Log | Files | Refs | README | LICENSE

commit 4cd56733fa851d0611edc0647f8b7a3fc7426c15
parent b6b91dc1de905ffff78ac43f7f28bc65a6a822db
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Wed, 18 Oct 2023 15:18:59 +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:
MMakefile | 15++++++++-------
Mconfig.mk | 22++++++++++++++++++----
2 files changed, 26 insertions(+), 11 deletions(-)

diff --git a/Makefile b/Makefile @@ -44,7 +44,7 @@ build_library__: .config $(DEP) $(DEP) $(OBJ): config.mk $(LIBNAME_SHARED): $(OBJ) - $(CC) -std=c99 $(CFLAGS) $(DPDC_CFLAGS) -o $@ $(OBJ) $(LDFLAGS) $(SOFLAGS) $(DPDC_LIBS) + $(CC) -std=c99 $(CFLAGS_SO) $(DPDC_CFLAGS) -o $@ $(OBJ) $(LDFLAGS_SO) $(DPDC_LIBS) $(LIBNAME_STATIC): librsimd.o $(AR) -rc $@ $? @@ -66,10 +66,10 @@ librsimd.o: $(OBJ) .SUFFIXES: .c .d .o .c.d: - @$(CC) -std=c99 $(CFLAGS) $(DPDC_CFLAGS) -MM -MT "$(@:.d=.o) $@" $< -MF $@ + @$(CC) -std=c99 $(CFLAGS_SO) $(DPDC_CFLAGS) -MM -MT "$(@:.d=.o) $@" $< -MF $@ .c.o: - $(CC) -std=c99 $(CFLAGS) $(DPDC_CFLAGS) -DRSIMD_SHARED_BUILD -c $< -o $@ + $(CC) -std=c99 $(CFLAGS_SO) $(DPDC_CFLAGS) -DRSIMD_SHARED_BUILD -c $< -o $@ ################################################################################ # Miscellaneous targets @@ -206,10 +206,11 @@ clean_test: @$(SHELL) make.sh clean_test $(TEST_SRC) $(TEST_DEP): config.mk rsimd-local.pc - @$(CC) -std=c89 $(CFLAGS) $(RSIMD_CFLAGS) $(RSYS_CFLAGS) -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@ + @$(CC) -std=c89 $(CFLAGS_EXE) $(RSIMD_CFLAGS) $(RSYS_CFLAGS) \ + -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@ $(TEST_OBJ): config.mk rsimd-local.pc - $(CC) -std=c89 $(CFLAGS) $(RSIMD_CFLAGS) $(RSYS_CFLAGS) -c $(@:.o=.c) -o $@ + $(CC) -std=c89 $(CFLAGS_EXE) $(RSIMD_CFLAGS) $(RSYS_CFLAGS) -c $(@:.o=.c) -o $@ test_aosf33 \ test_aosf44 \ @@ -223,9 +224,9 @@ test_soa8f4 \ test_v4f \ test_v4i \ : config.mk rsimd-local.pc - $(CC) -o $@ src/$@.o $(LDFLAGS) $(RSIMD_LIBS) $(RSYS_LIBS) + $(CC) $(CFLAGS_EXE) -o $@ src/$@.o $(LDFLAGS_EXE) $(RSIMD_LIBS) $(RSYS_LIBS) test_math4 \ test_math8 \ : config.mk rsimd-local.pc - $(CC) -o $@ src/$@.o $(LDFLAGS) $(RSIMD_LIBS) $(RSYS_LIBS) -lm + $(CC) $(CFLAGS_EXE) -o $@ src/$@.o $(LDFLAGS_EXE) $(RSIMD_LIBS) $(RSYS_LIBS) -lm diff --git a/config.mk b/config.mk @@ -50,28 +50,42 @@ WFLAGS =\ -Wmissing-declarations\ -Wmissing-prototypes\ -Wshadow + +CFLAGS_HARDENED =\ + -D_FORTIFY_SOURCES=2\ + -fcf-protection=full\ + -fstack-clash-protection\ + -fstack-protector-strong + CFLAGS_SIMD = -march=native + CFLAGS_COMMON =\ -pedantic\ -fPIC\ -fvisibility=hidden\ -fstrict-aliasing\ $(WFLAGS)\ + $(CFLAGS_HARDENED)\ $(CFLAGS_SIMD) CFLAGS_DEBUG = -g $(CFLAGS_COMMON) CFLAGS_RELEASE = -O2 -DNDEBUG $(CFLAGS_COMMON) CFLAGS = $(CFLAGS_$(BUILD_TYPE)) +CFLAGS_SO = $(CFLAGS) -fPIC +CFLAGS_EXE = $(CFLAGS) -fPIE + ################################################################################ # Linker options ################################################################################ -SOFLAGS = -shared -Wl,--no-undefined - -LDFLAGS_DEBUG = -LDFLAGS_RELEASE = -s +LDFLAGS_HARDENED = -Wl,-z,relro,-z,now +LDFLAGS_DEBUG = $(LDFLAGS_HARDENED) +LDFLAGS_RELEASE = -s $(LDFLAGS_HARDENED) LDFLAGS = $(LDFLAGS_$(BUILD_TYPE)) +LDFLAGS_SO = $(LDFLAGS) -shared -Wl,--no-undefined +LDFLAGS_EXE = $(LDFLAGS) -pie + OCPFLAGS_DEBUG = --localize-hidden OCPFLAGS_RELEASE = --localize-hidden --strip-unneeded OCPFLAGS = $(OCPFLAGS_$(BUILD_TYPE))