# DP: Add empty distro and hardening specs --- a/src/gcc/gcc.cc +++ b/src/gcc/gcc.cc @@ -27,6 +27,11 @@ CC recognizes how to compile each input Once it knows which kind of compilation to perform, the procedure for compilation is specified by a string called a "spec". */ +/* Inject some default compilation flags which are used as the default. + Done by the packaging build system. Should that be done in the headers + gcc/config//*.h instead? */ +#include "distro-defaults.h" + #define INCLUDE_STRING #include "config.h" #include "system.h" @@ -988,6 +993,127 @@ proper position among the other output f #define LINK_GCC_C_SEQUENCE_SPEC "%G %{!nolibc:%L %G}" #endif +/* Generate full unwind information covering all program points. + Only needed for some architectures. */ +#ifndef ASYNC_UNWIND_SPEC +# ifdef DIST_DEFAULT_ASYNC_UNWIND +# define ASYNC_UNWIND_SPEC "%{!fno-asynchronous-unwind-tables:-fasynchronous-unwind-tables}" +# else +# define ASYNC_UNWIND_SPEC "" +# endif +#endif + +/* Turn on stack protector. + */ +#ifndef SSP_DEFAULT_SPEC +# ifdef DIST_DEFAULT_SSP +# ifdef DIST_DEFAULT_SSP_STRONG +# define SSP_DEFAULT_SPEC " %{!fno-stack-protector:%{!fstack-protector-explicit:%{!fstack-protector-all:%{!ffreestanding:%{!nostdlib:%{!fstack-protector:-fstack-protector-strong}}}}}}" +# else +# define SSP_DEFAULT_SPEC " %{!fno-stack-protector:%{!fstack-protector-explicit:%{!fstack-protector-all:%{!ffreestanding:%{!nostdlib:-fstack-protector}}}}}" +# endif +# else +# define SSP_DEFAULT_SPEC "" +# endif +#endif + +/* Turn on -Wformat -Wformat-security by default for C, C++, + ObjC, ObjC++. */ +#ifndef FORMAT_SECURITY_SPEC +# ifdef DIST_DEFAULT_FORMAT_SECURITY +# define FORMAT_SECURITY_SPEC " %{!Wformat:%{!Wformat=2:%{!Wformat=0:%{!Wall:-Wformat} %{!Wno-format-security:-Wformat-security}}}}" +# else +# define FORMAT_SECURITY_SPEC "" +# endif +#endif + +/* Enable -fstack-clash-protection by default. Only available + on some targets. */ +#ifndef STACK_CLASH_SPEC +# ifdef DIST_DEFAULT_STACK_CLASH +# define STACK_CLASH_SPEC " %{!fno-stack-clash-protection:-fstack-clash-protection}" +# else +# define STACK_CLASH_SPEC "" +# endif +#endif + +/* Enable code instrumentation of control-flow transfers. + Available on x86 and x86_64. */ +#ifndef CF_PROTECTION_SPEC +# ifdef DIST_DEFAULT_CF_PROTECTION +# define CF_PROTECTION_SPEC " %{!m16:%{!m32:%{!fcf-protection*:%{!fno-cf-protection:-fcf-protection}}}}" +# else +# define CF_PROTECTION_SPEC "" +# endif +#endif + +/* Enable -D_TIME_BITS=64, only available on some 32bit targets. */ +#ifndef TIMET64_SPEC +# ifdef DIST_DEFAULT_TIMET64 +# define TIMET64_SPEC " %{!m16:%{!m64:%{!D_DISTRO_EVADE_TIME_BITS:%{!D_TIME_BITS=*:%{!U_TIME_BITS:-D_TIME_BITS=64%{!D_FILE_OFFSET_BITS=*:%{!U_FILE_OFFSET_BITS: -D_FILE_OFFSET_BITS=64}}}}}}}" +# else +# define TIMET64_SPEC "" +# endif +#endif + +/* Enable -D_FORTIFY_SOURCE= */ +#ifndef FORTIFY_SOURCE_SPEC +# ifdef DIST_DEFAULT_FORTIFY_SOURCE +# define FORTIFY_SOURCE_SPEC " %{!O0:%{O*:%{!D_FORTIFY_SOURCE=*:%{!U_FORTIFY_SOURCE:-D_FORTIFY_SOURCE=" DIST_DEFAULT_FORTIFY_SOURCE_S "}}}}" +# else +# define FORTIFY_SOURCE_SPEC "" +# endif +#endif + +#ifndef BIND_NOW_SPEC +# if defined(DIST_DEFAULT_BIND_NOW) && !defined(ACCEL_COMPILER) +# define BIND_NOW_SPEC " -z now" +# else +# define BIND_NOW_SPEC "" +# endif +#endif + +#ifndef RELRO_SPEC +# ifdef DIST_DEFAULT_RELRO +# define RELRO_SPEC " -z relro " +# else +# define RELRO_SPEC "" +# endif +#endif + +/* Enable sframe support by default. */ +#ifndef SFRAME_SPEC +# ifdef DIST_DEFAULT_SFRAME +# define SFRAME_SPEC " %{!m16:%{!m32:%{!mx32:%{!ffreestanding:--gsframe}}}}" +# else +# define SFRAME_SPEC "" +# endif +#endif + +/* Don't enable any of those for the offload compilers, + unsupported. */ +#if !defined(DISTRO_DEFAULT_ASM_SPEC) && !defined(ACCEL_COMPILER) +# define DISTRO_DEFAULT_ASM_SPEC SFRAME_SPEC +#else +# define DISTRO_DEFAULT_ASM_SPEC "" +#endif +#if !defined(DISTRO_DEFAULT_CPP_SPEC) && !defined(ACCEL_COMPILER) +# define DISTRO_DEFAULT_CPP_SPEC TIMET64_SPEC FORTIFY_SOURCE_SPEC +#else +# define DISTRO_DEFAULT_CPP_SPEC "" +#endif +#if !defined(DISTRO_DEFAULT_SPEC) && !defined(ACCEL_COMPILER) +# define DISTRO_DEFAULT_SPEC ASYNC_UNWIND_SPEC SSP_DEFAULT_SPEC \ + FORMAT_SECURITY_SPEC STACK_CLASH_SPEC CF_PROTECTION_SPEC +#else +# define DISTRO_DEFAULT_SPEC "" +#endif +#if !defined(DISTRO_DEFAULT_LINK_SPEC) && !defined(ACCEL_COMPILER) +# define DISTRO_DEFAULT_LINK_SPEC RELRO_SPEC +#else +# define DISTRO_DEFAULT_LINK_SPEC "" +#endif + #ifndef LINK_SSP_SPEC #ifdef TARGET_LIBC_PROVIDES_SSP #define LINK_SSP_SPEC "%{fstack-protector|fstack-protector-all" \ @@ -1044,7 +1170,7 @@ proper position among the other output f #ifndef LINK_PIE_SPEC #ifdef HAVE_LD_PIE #ifndef LD_PIE_SPEC -#define LD_PIE_SPEC "-pie" +#define LD_PIE_SPEC "-pie" BIND_NOW_SPEC #endif #else #define LD_PIE_SPEC "" @@ -1161,6 +1287,7 @@ proper position among the other output f "%{flto|flto=*:%