# 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" @@ -971,6 +976,90 @@ 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-all:%{!ffreestanding:%{!nostdlib:%{!fstack-protector:-fstack-protector-strong}}}}}" +# else +# define SSP_DEFAULT_SPEC " %{!fno-stack-protector:%{!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 + +#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 + +/* Don't enable any of those for the offload compilers, + unsupported. */ +#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" \ @@ -1027,7 +1116,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 "" @@ -1144,6 +1233,7 @@ proper position among the other output f "%{flto|flto=*:%/ instead? */ +#include "distro-defaults.h" + #ifndef TARGET_OS_CPP_BUILTINS # define TARGET_OS_CPP_BUILTINS() #endif @@ -1546,6 +1551,12 @@ c_cpp_builtins (cpp_reader *pfile) builtin_define_with_value ("__REGISTER_PREFIX__", REGISTER_PREFIX, 0); builtin_define_with_value ("__USER_LABEL_PREFIX__", user_label_prefix, 0); +#ifdef DIST_DEFAULT_FORTIFY_SOURCE + /* Fortify Source enabled by default for optimization levels > 0 */ + if (optimize) + builtin_define_with_int_value ("_FORTIFY_SOURCE", DIST_DEFAULT_FORTIFY_SOURCE); +#endif + /* Misc. */ if (flag_gnu89_inline) cpp_define (pfile, "__GNUC_GNU_INLINE__");