From f1db4356e6dff4cfa8c39eca515866d5690c8ed9 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sun, 27 Nov 2022 11:52:14 +0000 Subject: [PATCH] macros: Update CFLAGS (again) This commit tidies up how we build the CFLAGS variable (as there is no point in putting together an auxiliary variable first). Signed-off-by: Michael Tremer --- macros/cflags.macro | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/macros/cflags.macro b/macros/cflags.macro index b9405cb00..7ab68f43e 100644 --- a/macros/cflags.macro +++ b/macros/cflags.macro @@ -1,27 +1,35 @@ +# Export CFLAGS +export CFLAGS = # empty -# Export CFLAGS + CXXFLAGS -GLOBAL_CFLAGS = -O2 -g +# Export CXXFLAGS +export CXXFLAGS = %{CFLAGS} + +# Export LDFLAGS +export LDFLAGS = -Wl,-z,relro -Wl,-z,now + +# Enable optimisation and compile in debugging information +CFLAGS = -O2 -g # Enable all compiler warnings -GLOBAL_CFLAGS += -Wall +CFLAGS += -Wall -Werror=format-security # Fortify Source -GLOBAL_CFLAGS += -Wp,-U_FORTIFY_SOURCE-Wp,-D_FORTIFY_SOURCE=3 +CFLAGS += -Wp,-U_FORTIFY_SOURCE-Wp,-D_FORTIFY_SOURCE=3 # Build Position Independent Code -GLOBAL_CFLAGS += -fPIC +CFLAGS += -fPIC # Enable Stack Smashing Protection -GLOBAL_CFLAGS += -fstack-protector-strong +CFLAGS += -fstack-protector-strong # Enable unwind tables -GLOBAL_CFLAGS += -funwind-tables -fasynchronous-unwind-tables +CFLAGS += -funwind-tables -fasynchronous-unwind-tables # Enable Stack Clash Protection -GLOBAL_CFLAGS += -fstack-clash-protection +CFLAGS += -fstack-clash-protection # Tell the compiler where the source will be put -GLOBAL_CFLAGS += -fdebug-prefix-map=%{DIR_SRC}=%{debugsourcedir} +CFLAGS += -fdebug-prefix-map=%{DIR_SRC}=%{debugsourcedir} # Arch: x86_64 CFLAGS_x86_64 = -m64 -march=x86-64-v2 -mtune=generic @@ -29,7 +37,9 @@ CFLAGS_x86_64 = -m64 -march=x86-64-v2 -mtune=generic # Arch: aarch64 CFLAGS_aarch64 = -mbranch-protection=standard -export CFLAGS = %{GLOBAL_CFLAGS} %{CFLAGS_%{DISTRO_ARCH}} -export CXXFLAGS = %{CFLAGS} +# Append architecture optimisations +CFLAGS += %{CFLAGS_%{DISTRO_ARCH}} -export LDFLAGS = -Wl,-z,relro -Wl,-z,now +# Enable LTO +LTO_CFLAGS = -flto=auto -ffat-lto-objects +CFLAGS += %{LTO_CFLAGS} -- 2.39.5