From 1de2e358caf9a22359e38ab8573cc3e5dcc1602f Mon Sep 17 00:00:00 2001 From: George Burgess IV Date: Tue, 15 Aug 2017 11:03:07 -0700 Subject: [PATCH] Enable FORTIFY in unoptimized builds GCC's FORTIFY required optimizations to be enabled in order to function properly. Clang's FORTIFY doesn't have this limitation, so it seems pointless to keep it disabled due to a GCC-specific limitation. Bug: 12231437 Test: Checkbuild on bullhead internal master + CtsBionicTestCases. No new failures. Change-Id: I74aa35f9d3f3d2a6b11a7adfe72a787e3d7f7f36 --- libc/include/sys/cdefs.h | 6 +++--- tools/versioner/src/Driver.cpp | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/libc/include/sys/cdefs.h b/libc/include/sys/cdefs.h index 954152076..71d84260f 100644 --- a/libc/include/sys/cdefs.h +++ b/libc/include/sys/cdefs.h @@ -239,7 +239,8 @@ #define __BIONIC_FORTIFY_UNKNOWN_SIZE ((size_t) -1) -#if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0 +#if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && \ + (defined(__clang__) || (defined(__OPTIMIZE__) && __OPTIMIZE__ > 0)) # define __BIONIC_FORTIFY 1 # if _FORTIFY_SOURCE == 2 # define __bos_level 1 @@ -281,8 +282,7 @@ #define __pass_object_size __pass_object_size_n(__bos_level) #define __pass_object_size0 __pass_object_size_n(0) -/* FIXME: This should be __BIONIC_FORTIFY, but we don't enable FORTIFY in -O0. */ -#if (defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0) || defined(__BIONIC_DECLARE_FORTIFY_HELPERS) +#if defined(__BIONIC_FORTIFY) || defined(__BIONIC_DECLARE_FORTIFY_HELPERS) # define __BIONIC_INCLUDE_FORTIFY_HEADERS 1 #endif diff --git a/tools/versioner/src/Driver.cpp b/tools/versioner/src/Driver.cpp index a09481838..8a8e00a8f 100644 --- a/tools/versioner/src/Driver.cpp +++ b/tools/versioner/src/Driver.cpp @@ -119,7 +119,14 @@ static void generateTargetCC1Flags(llvm::IntrusiveRefCntPtr