From 7278afc5a83894aa7883fc10a9e71c22a7c3f3fc Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Thu, 2 Nov 2017 22:38:32 -0700 Subject: [PATCH 1/6] Consolidate global cflags Move all the flags that are used everywhere (or should be used everywhere) into cc/config/global.go: -no-canonical-prefixes -fno-exceptions -Wno-multichar -O2 -g -fno-strict-aliasing Also remove flags that are already in noOverrideGlobalCflags: -Werror=pointer-to-int-cast -Werror=int-to-pointer-cast x86 and x86_64 were specifying -fstrict-aliasing, but that was being overriden later by -fno-strict-aliasing, so remove it. ARM devices still override -fno-strict-aliasing to -fstrict-aliasing when using ARM (vs. Thumb) instruction set. Bug: 68855788 Test: m checkbuild Change-Id: Ia2b5891bdefb60f974ad92b4b84a8548c2dcc7dc --- cc/config/arm64_device.go | 8 -------- cc/config/arm_device.go | 7 ------- cc/config/global.go | 12 +++++++++++- cc/config/mips64_device.go | 9 --------- cc/config/mips_device.go | 7 ------- cc/config/x86_64_device.go | 12 ------------ cc/config/x86_darwin_host.go | 7 ------- cc/config/x86_device.go | 10 ---------- cc/config/x86_linux_bionic_host.go | 10 ---------- cc/config/x86_linux_host.go | 9 --------- cc/config/x86_windows_host.go | 8 -------- 11 files changed, 11 insertions(+), 88 deletions(-) diff --git a/cc/config/arm64_device.go b/cc/config/arm64_device.go index 390936a40..e8b479751 100644 --- a/cc/config/arm64_device.go +++ b/cc/config/arm64_device.go @@ -23,9 +23,6 @@ import ( var ( arm64Cflags = []string{ - "-fno-exceptions", // from build/core/combo/select.mk - "-Wno-multichar", // from build/core/combo/select.mk - "-fno-strict-aliasing", "-fstack-protector-strong", "-ffunction-sections", "-fdata-sections", @@ -34,19 +31,14 @@ var ( "-Werror=format-security", "-D_FORTIFY_SOURCE=2", "-fno-short-enums", - "-no-canonical-prefixes", "-fno-canonical-system-headers", // Help catch common 32/64-bit errors. - "-Werror=pointer-to-int-cast", - "-Werror=int-to-pointer-cast", "-Werror=implicit-function-declaration", "-fno-strict-volatile-bitfields", // TARGET_RELEASE_CFLAGS - "-DNDEBUG", - "-O2 -g", "-Wstrict-aliasing=2", "-fgcse-after-reload", "-frerun-cse-after-loop", diff --git a/cc/config/arm_device.go b/cc/config/arm_device.go index 7110ccb52..8e890ff4f 100644 --- a/cc/config/arm_device.go +++ b/cc/config/arm_device.go @@ -28,8 +28,6 @@ var ( } armCflags = []string{ - "-fno-exceptions", // from build/core/combo/select.mk - "-Wno-multichar", // from build/core/combo/select.mk "-ffunction-sections", "-fdata-sections", "-funwind-tables", @@ -38,15 +36,12 @@ var ( "-Werror=format-security", "-D_FORTIFY_SOURCE=2", "-fno-short-enums", - "-no-canonical-prefixes", "-fno-canonical-system-headers", "-fno-builtin-sin", "-fno-strict-volatile-bitfields", // TARGET_RELEASE_CFLAGS - "-DNDEBUG", - "-g", "-Wstrict-aliasing=2", "-fgcse-after-reload", "-frerun-cse-after-loop", @@ -71,7 +66,6 @@ var ( } armArmCflags = []string{ - "-O2", "-fomit-frame-pointer", "-fstrict-aliasing", "-funswitch-loops", @@ -81,7 +75,6 @@ var ( "-mthumb", "-Os", "-fomit-frame-pointer", - "-fno-strict-aliasing", } armArchVariantCflags = map[string][]string{ diff --git a/cc/config/global.go b/cc/config/global.go index dae218c16..5587eae86 100644 --- a/cc/config/global.go +++ b/cc/config/global.go @@ -34,9 +34,19 @@ var ( "-Winit-self", "-Wpointer-arith", - // COMMON_RELEASE_CFLAGS + // Make paths in deps files relative + "-no-canonical-prefixes", + "-DNDEBUG", "-UDEBUG", + + "-fno-exceptions", + "-Wno-multichar", + + "-O2", + "-g", + + "-fno-strict-aliasing", } commonGlobalConlyflags = []string{} diff --git a/cc/config/mips64_device.go b/cc/config/mips64_device.go index e05dbf182..7da693f3d 100644 --- a/cc/config/mips64_device.go +++ b/cc/config/mips64_device.go @@ -22,11 +22,7 @@ import ( var ( mips64Cflags = []string{ - "-fno-exceptions", // from build/core/combo/select.mk - "-Wno-multichar", // from build/core/combo/select.mk - "-O2", "-fomit-frame-pointer", - "-fno-strict-aliasing", "-funswitch-loops", "-Umips", "-ffunction-sections", @@ -36,17 +32,12 @@ var ( "-Wa,--noexecstack", "-Werror=format-security", "-D_FORTIFY_SOURCE=2", - "-no-canonical-prefixes", "-fno-canonical-system-headers", // Help catch common 32/64-bit errors. - "-Werror=pointer-to-int-cast", - "-Werror=int-to-pointer-cast", "-Werror=implicit-function-declaration", // TARGET_RELEASE_CFLAGS - "-DNDEBUG", - "-g", "-Wstrict-aliasing=2", "-fgcse-after-reload", "-frerun-cse-after-loop", diff --git a/cc/config/mips_device.go b/cc/config/mips_device.go index 78e95b6f2..f8470bf64 100644 --- a/cc/config/mips_device.go +++ b/cc/config/mips_device.go @@ -22,11 +22,7 @@ import ( var ( mipsCflags = []string{ - "-fno-exceptions", // from build/core/combo/select.mk - "-Wno-multichar", // from build/core/combo/select.mk - "-O2", "-fomit-frame-pointer", - "-fno-strict-aliasing", "-funswitch-loops", "-Umips", "-ffunction-sections", @@ -36,12 +32,9 @@ var ( "-Wa,--noexecstack", "-Werror=format-security", "-D_FORTIFY_SOURCE=2", - "-no-canonical-prefixes", "-fno-canonical-system-headers", // TARGET_RELEASE_CFLAGS - "-DNDEBUG", - "-g", "-Wstrict-aliasing=2", "-fgcse-after-reload", "-frerun-cse-after-loop", diff --git a/cc/config/x86_64_device.go b/cc/config/x86_64_device.go index a98001e3d..8d7a404f9 100644 --- a/cc/config/x86_64_device.go +++ b/cc/config/x86_64_device.go @@ -22,9 +22,6 @@ import ( var ( x86_64Cflags = []string{ - "-fno-exceptions", // from build/core/combo/select.mk - "-Wno-multichar", // from build/core/combo/select.mk - "-O2", "-Wa,--noexecstack", "-Werror=format-security", "-D_FORTIFY_SOURCE=2", @@ -33,22 +30,13 @@ var ( "-finline-functions", "-finline-limit=300", "-fno-short-enums", - "-fstrict-aliasing", "-funswitch-loops", "-funwind-tables", "-fstack-protector-strong", - "-no-canonical-prefixes", "-fno-canonical-system-headers", // Help catch common 32/64-bit errors. - "-Werror=pointer-to-int-cast", - "-Werror=int-to-pointer-cast", "-Werror=implicit-function-declaration", - - // TARGET_RELEASE_CFLAGS from build/core/combo/select.mk - "-O2", - "-g", - "-fno-strict-aliasing", } x86_64Cppflags = []string{} diff --git a/cc/config/x86_darwin_host.go b/cc/config/x86_darwin_host.go index 6d361b561..8d805c993 100644 --- a/cc/config/x86_darwin_host.go +++ b/cc/config/x86_darwin_host.go @@ -25,9 +25,6 @@ import ( var ( darwinCflags = []string{ - "-fno-exceptions", // from build/core/combo/select.mk - "-Wno-multichar", // from build/core/combo/select.mk - "-fdiagnostics-color", "-fPIC", @@ -38,10 +35,6 @@ var ( "-D__STDC_FORMAT_MACROS", "-D__STDC_CONSTANT_MACROS", - // HOST_RELEASE_CFLAGS - "-O2", // from build/core/combo/select.mk - "-g", // from build/core/combo/select.mk - "-fno-strict-aliasing", // from build/core/combo/select.mk "-isysroot ${macSdkRoot}", "-mmacosx-version-min=${macMinVersion}", "-DMACOSX_DEPLOYMENT_TARGET=${macMinVersion}", diff --git a/cc/config/x86_device.go b/cc/config/x86_device.go index 53d2265ca..59f8de738 100644 --- a/cc/config/x86_device.go +++ b/cc/config/x86_device.go @@ -22,9 +22,6 @@ import ( var ( x86Cflags = []string{ - "-fno-exceptions", // from build/core/combo/select.mk - "-Wno-multichar", // from build/core/combo/select.mk - "-O2", "-Wa,--noexecstack", "-Werror=format-security", "-D_FORTIFY_SOURCE=2", @@ -33,17 +30,10 @@ var ( "-finline-functions", "-finline-limit=300", "-fno-short-enums", - "-fstrict-aliasing", "-funswitch-loops", "-funwind-tables", "-fstack-protector-strong", - "-no-canonical-prefixes", "-fno-canonical-system-headers", - - // TARGET_RELEASE_CFLAGS from build/core/combo/select.mk - "-O2", - "-g", - "-fno-strict-aliasing", } x86ClangCflags = append(x86Cflags, []string{ diff --git a/cc/config/x86_linux_bionic_host.go b/cc/config/x86_linux_bionic_host.go index 277361b96..645ac2651 100644 --- a/cc/config/x86_linux_bionic_host.go +++ b/cc/config/x86_linux_bionic_host.go @@ -22,15 +22,11 @@ import ( var ( linuxBionicCflags = ClangFilterUnknownCflags([]string{ - "-fno-exceptions", // from build/core/combo/select.mk - "-Wno-multichar", // from build/core/combo/select.mk - "-fdiagnostics-color", "-Wa,--noexecstack", "-fPIC", - "-no-canonical-prefixes", "-U_FORTIFY_SOURCE", "-D_FORTIFY_SOURCE=2", @@ -43,14 +39,8 @@ var ( "-fno-short-enums", "-funswitch-loops", "-funwind-tables", - "-no-canonical-prefixes", "-fno-canonical-system-headers", - // HOST_RELEASE_CFLAGS - "-O2", // from build/core/combo/select.mk - "-g", // from build/core/combo/select.mk - "-fno-strict-aliasing", // from build/core/combo/select.mk - // Tell clang where the gcc toolchain is "--gcc-toolchain=${LinuxBionicGccRoot}", diff --git a/cc/config/x86_linux_host.go b/cc/config/x86_linux_host.go index 88bd5140e..4f0506804 100644 --- a/cc/config/x86_linux_host.go +++ b/cc/config/x86_linux_host.go @@ -22,15 +22,11 @@ import ( var ( linuxCflags = []string{ - "-fno-exceptions", // from build/core/combo/select.mk - "-Wno-multichar", // from build/core/combo/select.mk - "-fdiagnostics-color", "-Wa,--noexecstack", "-fPIC", - "-no-canonical-prefixes", "-U_FORTIFY_SOURCE", "-D_FORTIFY_SOURCE=2", @@ -40,11 +36,6 @@ var ( //See bug 12708004. "-D__STDC_FORMAT_MACROS", "-D__STDC_CONSTANT_MACROS", - - // HOST_RELEASE_CFLAGS - "-O2", // from build/core/combo/select.mk - "-g", // from build/core/combo/select.mk - "-fno-strict-aliasing", // from build/core/combo/select.mk } linuxLdflags = []string{ diff --git a/cc/config/x86_windows_host.go b/cc/config/x86_windows_host.go index 270084e48..c9bafe61a 100644 --- a/cc/config/x86_windows_host.go +++ b/cc/config/x86_windows_host.go @@ -22,9 +22,6 @@ import ( var ( windowsCflags = []string{ - "-fno-exceptions", // from build/core/combo/select.mk - "-Wno-multichar", // from build/core/combo/select.mk - "-DUSE_MINGW", "-DWIN32_LEAN_AND_MEAN", "-Wno-unused-parameter", @@ -43,11 +40,6 @@ var ( "-D_FILE_OFFSET_BITS=64", "--sysroot ${WindowsGccRoot}/${WindowsGccTriple}", - - // HOST_RELEASE_CFLAGS - "-O2", // from build/core/combo/select.mk - "-g", // from build/core/combo/select.mk - "-fno-strict-aliasing", // from build/core/combo/select.mk } windowsIncludeFlags = []string{ From 133dbe7bb0879a01af45895fb42e8bf58cf8e0f8 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Thu, 2 Nov 2017 22:55:19 -0700 Subject: [PATCH 2/6] Consolidate cflags that are set on all devices Move cflags that are set on all devices to deviceGlobalCflags: -fno-canonical-system-headers -ffunction-sections -funwind-tables -fstack-protector-strong -Wa,--noexecstack -D_FORTIFY_SOURCE=2 -Wstrict-aliasing=2 -Werror=format-security Bug: 68855788 Test: m checkbuild Change-Id: Iefec689fdd2749013d0cc003b3abec674a85fb74 --- cc/config/arm64_device.go | 8 -------- cc/config/arm_device.go | 8 -------- cc/config/global.go | 11 ++++++++++- cc/config/mips64_device.go | 8 -------- cc/config/mips_device.go | 8 -------- cc/config/x86_64_device.go | 8 -------- cc/config/x86_device.go | 8 -------- 7 files changed, 10 insertions(+), 49 deletions(-) diff --git a/cc/config/arm64_device.go b/cc/config/arm64_device.go index e8b479751..bdcbd05e0 100644 --- a/cc/config/arm64_device.go +++ b/cc/config/arm64_device.go @@ -23,15 +23,8 @@ import ( var ( arm64Cflags = []string{ - "-fstack-protector-strong", - "-ffunction-sections", "-fdata-sections", - "-funwind-tables", - "-Wa,--noexecstack", - "-Werror=format-security", - "-D_FORTIFY_SOURCE=2", "-fno-short-enums", - "-fno-canonical-system-headers", // Help catch common 32/64-bit errors. "-Werror=implicit-function-declaration", @@ -39,7 +32,6 @@ var ( "-fno-strict-volatile-bitfields", // TARGET_RELEASE_CFLAGS - "-Wstrict-aliasing=2", "-fgcse-after-reload", "-frerun-cse-after-loop", "-frename-registers", diff --git a/cc/config/arm_device.go b/cc/config/arm_device.go index 8e890ff4f..3411e074f 100644 --- a/cc/config/arm_device.go +++ b/cc/config/arm_device.go @@ -28,21 +28,13 @@ var ( } armCflags = []string{ - "-ffunction-sections", "-fdata-sections", - "-funwind-tables", - "-fstack-protector-strong", - "-Wa,--noexecstack", - "-Werror=format-security", - "-D_FORTIFY_SOURCE=2", "-fno-short-enums", - "-fno-canonical-system-headers", "-fno-builtin-sin", "-fno-strict-volatile-bitfields", // TARGET_RELEASE_CFLAGS - "-Wstrict-aliasing=2", "-fgcse-after-reload", "-frerun-cse-after-loop", "-frename-registers", diff --git a/cc/config/global.go b/cc/config/global.go index 5587eae86..4a2f6065a 100644 --- a/cc/config/global.go +++ b/cc/config/global.go @@ -54,12 +54,21 @@ var ( deviceGlobalCflags = []string{ "-fdiagnostics-color", - // TARGET_ERROR_FLAGS + "-fno-canonical-system-headers", + "-ffunction-sections", + "-funwind-tables", + "-fstack-protector-strong", + "-Wa,--noexecstack", + "-D_FORTIFY_SOURCE=2", + + "-Wstrict-aliasing=2", + "-Werror=return-type", "-Werror=non-virtual-dtor", "-Werror=address", "-Werror=sequence-point", "-Werror=date-time", + "-Werror=format-security", } hostGlobalCflags = []string{} diff --git a/cc/config/mips64_device.go b/cc/config/mips64_device.go index 7da693f3d..9dd116520 100644 --- a/cc/config/mips64_device.go +++ b/cc/config/mips64_device.go @@ -25,20 +25,12 @@ var ( "-fomit-frame-pointer", "-funswitch-loops", "-Umips", - "-ffunction-sections", "-fdata-sections", - "-funwind-tables", - "-fstack-protector-strong", - "-Wa,--noexecstack", - "-Werror=format-security", - "-D_FORTIFY_SOURCE=2", - "-fno-canonical-system-headers", // Help catch common 32/64-bit errors. "-Werror=implicit-function-declaration", // TARGET_RELEASE_CFLAGS - "-Wstrict-aliasing=2", "-fgcse-after-reload", "-frerun-cse-after-loop", "-frename-registers", diff --git a/cc/config/mips_device.go b/cc/config/mips_device.go index f8470bf64..840702acd 100644 --- a/cc/config/mips_device.go +++ b/cc/config/mips_device.go @@ -25,17 +25,9 @@ var ( "-fomit-frame-pointer", "-funswitch-loops", "-Umips", - "-ffunction-sections", "-fdata-sections", - "-funwind-tables", - "-fstack-protector-strong", - "-Wa,--noexecstack", - "-Werror=format-security", - "-D_FORTIFY_SOURCE=2", - "-fno-canonical-system-headers", // TARGET_RELEASE_CFLAGS - "-Wstrict-aliasing=2", "-fgcse-after-reload", "-frerun-cse-after-loop", "-frename-registers", diff --git a/cc/config/x86_64_device.go b/cc/config/x86_64_device.go index 8d7a404f9..eeb4d2f07 100644 --- a/cc/config/x86_64_device.go +++ b/cc/config/x86_64_device.go @@ -22,18 +22,10 @@ import ( var ( x86_64Cflags = []string{ - "-Wa,--noexecstack", - "-Werror=format-security", - "-D_FORTIFY_SOURCE=2", - "-Wstrict-aliasing=2", - "-ffunction-sections", "-finline-functions", "-finline-limit=300", "-fno-short-enums", "-funswitch-loops", - "-funwind-tables", - "-fstack-protector-strong", - "-fno-canonical-system-headers", // Help catch common 32/64-bit errors. "-Werror=implicit-function-declaration", diff --git a/cc/config/x86_device.go b/cc/config/x86_device.go index 59f8de738..be36de973 100644 --- a/cc/config/x86_device.go +++ b/cc/config/x86_device.go @@ -22,18 +22,10 @@ import ( var ( x86Cflags = []string{ - "-Wa,--noexecstack", - "-Werror=format-security", - "-D_FORTIFY_SOURCE=2", - "-Wstrict-aliasing=2", - "-ffunction-sections", "-finline-functions", "-finline-limit=300", "-fno-short-enums", "-funswitch-loops", - "-funwind-tables", - "-fstack-protector-strong", - "-fno-canonical-system-headers", } x86ClangCflags = append(x86Cflags, []string{ From 0e37bc78d4d08cbf0843b043208867229802b827 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Thu, 2 Nov 2017 23:07:20 -0700 Subject: [PATCH 3/6] Remove -Wl,--gc-sections from target flags -Wl,--gc-sections is already added by library.go and binary.go for anything that uses bionic. Bug: 68855788 Test: m checkbuild Change-Id: I229199045ef8595d69c07fcf1aa6bbdc0b753fe3 --- cc/config/x86_64_device.go | 1 - cc/config/x86_device.go | 1 - cc/config/x86_linux_bionic_host.go | 1 - 3 files changed, 3 deletions(-) diff --git a/cc/config/x86_64_device.go b/cc/config/x86_64_device.go index eeb4d2f07..1941eb8d5 100644 --- a/cc/config/x86_64_device.go +++ b/cc/config/x86_64_device.go @@ -40,7 +40,6 @@ var ( "-Wl,--build-id=md5", "-Wl,--warn-shared-textrel", "-Wl,--fatal-warnings", - "-Wl,--gc-sections", "-Wl,--hash-style=gnu", "-Wl,--no-undefined-version", } diff --git a/cc/config/x86_device.go b/cc/config/x86_device.go index be36de973..a95305bc0 100644 --- a/cc/config/x86_device.go +++ b/cc/config/x86_device.go @@ -46,7 +46,6 @@ var ( "-Wl,--build-id=md5", "-Wl,--warn-shared-textrel", "-Wl,--fatal-warnings", - "-Wl,--gc-sections", "-Wl,--hash-style=gnu", "-Wl,--no-undefined-version", } diff --git a/cc/config/x86_linux_bionic_host.go b/cc/config/x86_linux_bionic_host.go index 645ac2651..9f0bbbdf1 100644 --- a/cc/config/x86_linux_bionic_host.go +++ b/cc/config/x86_linux_bionic_host.go @@ -55,7 +55,6 @@ var ( "-Wl,--build-id=md5", "-Wl,--warn-shared-textrel", "-Wl,--fatal-warnings", - "-Wl,--gc-sections", "-Wl,--hash-style=gnu", "-Wl,--no-undefined-version", From 324a457440feee29a5e9c08bb1f311112809185c Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Thu, 2 Nov 2017 23:09:41 -0700 Subject: [PATCH 4/6] Consolidate ldflags that are used on all devices Move ldflags that are specified for all devices into deviceGlobalLdflags, and add them to linker.go: -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--build-id=md5 -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined-version Bug: 68855788 Test: m checkbuild Change-Id: I82561b4189287d7638006f9e298c5151f9930c5e --- cc/config/arm64_device.go | 7 ------- cc/config/arm_device.go | 7 ------- cc/config/global.go | 14 ++++++++++++++ cc/config/mips64_device.go | 7 ------- cc/config/mips_device.go | 7 ------- cc/config/x86_64_device.go | 7 ------- cc/config/x86_device.go | 7 ------- cc/linker.go | 6 ++++++ cc/makevars.go | 2 ++ 9 files changed, 22 insertions(+), 42 deletions(-) diff --git a/cc/config/arm64_device.go b/cc/config/arm64_device.go index bdcbd05e0..13e9a08ba 100644 --- a/cc/config/arm64_device.go +++ b/cc/config/arm64_device.go @@ -38,18 +38,11 @@ var ( } arm64Ldflags = []string{ - "-Wl,-z,noexecstack", - "-Wl,-z,relro", - "-Wl,-z,now", - "-Wl,--build-id=md5", - "-Wl,--warn-shared-textrel", - "-Wl,--fatal-warnings", "-Wl,-m,aarch64_elf64_le_vec", "-Wl,--hash-style=gnu", "-Wl,--fix-cortex-a53-843419", "-fuse-ld=gold", "-Wl,--icf=safe", - "-Wl,--no-undefined-version", } arm64Cppflags = []string{ diff --git a/cc/config/arm_device.go b/cc/config/arm_device.go index 3411e074f..80ec3240f 100644 --- a/cc/config/arm_device.go +++ b/cc/config/arm_device.go @@ -45,15 +45,8 @@ var ( } armLdflags = []string{ - "-Wl,-z,noexecstack", - "-Wl,-z,relro", - "-Wl,-z,now", - "-Wl,--build-id=md5", - "-Wl,--warn-shared-textrel", - "-Wl,--fatal-warnings", "-Wl,--icf=safe", "-Wl,--hash-style=gnu", - "-Wl,--no-undefined-version", "-Wl,-m,armelf", } diff --git a/cc/config/global.go b/cc/config/global.go index 4a2f6065a..7362f2e51 100644 --- a/cc/config/global.go +++ b/cc/config/global.go @@ -71,8 +71,20 @@ var ( "-Werror=format-security", } + deviceGlobalLdflags = []string{ + "-Wl,-z,noexecstack", + "-Wl,-z,relro", + "-Wl,-z,now", + "-Wl,--build-id=md5", + "-Wl,--warn-shared-textrel", + "-Wl,--fatal-warnings", + "-Wl,--no-undefined-version", + } + hostGlobalCflags = []string{} + hostGlobalLdflags = []string{} + commonGlobalCppflags = []string{ "-Wsign-promo", } @@ -110,7 +122,9 @@ func init() { pctx.StaticVariable("CommonGlobalCflags", strings.Join(commonGlobalCflags, " ")) pctx.StaticVariable("CommonGlobalConlyflags", strings.Join(commonGlobalConlyflags, " ")) pctx.StaticVariable("DeviceGlobalCflags", strings.Join(deviceGlobalCflags, " ")) + pctx.StaticVariable("DeviceGlobalLdflags", strings.Join(deviceGlobalLdflags, " ")) pctx.StaticVariable("HostGlobalCflags", strings.Join(hostGlobalCflags, " ")) + pctx.StaticVariable("HostGlobalLdflags", strings.Join(hostGlobalLdflags, " ")) pctx.StaticVariable("NoOverrideGlobalCflags", strings.Join(noOverrideGlobalCflags, " ")) pctx.StaticVariable("CommonGlobalCppflags", strings.Join(commonGlobalCppflags, " ")) diff --git a/cc/config/mips64_device.go b/cc/config/mips64_device.go index 9dd116520..487b11a1a 100644 --- a/cc/config/mips64_device.go +++ b/cc/config/mips64_device.go @@ -45,14 +45,7 @@ var ( } mips64Ldflags = []string{ - "-Wl,-z,noexecstack", - "-Wl,-z,relro", - "-Wl,-z,now", - "-Wl,--build-id=md5", - "-Wl,--warn-shared-textrel", - "-Wl,--fatal-warnings", "-Wl,--allow-shlib-undefined", - "-Wl,--no-undefined-version", } mips64ArchVariantCflags = map[string][]string{ diff --git a/cc/config/mips_device.go b/cc/config/mips_device.go index 840702acd..f178b978c 100644 --- a/cc/config/mips_device.go +++ b/cc/config/mips_device.go @@ -43,14 +43,7 @@ var ( } mipsLdflags = []string{ - "-Wl,-z,noexecstack", - "-Wl,-z,relro", - "-Wl,-z,now", - "-Wl,--build-id=md5", - "-Wl,--warn-shared-textrel", - "-Wl,--fatal-warnings", "-Wl,--allow-shlib-undefined", - "-Wl,--no-undefined-version", } mipsToolchainLdflags = []string{ diff --git a/cc/config/x86_64_device.go b/cc/config/x86_64_device.go index 1941eb8d5..1eab9dd65 100644 --- a/cc/config/x86_64_device.go +++ b/cc/config/x86_64_device.go @@ -34,14 +34,7 @@ var ( x86_64Cppflags = []string{} x86_64Ldflags = []string{ - "-Wl,-z,noexecstack", - "-Wl,-z,relro", - "-Wl,-z,now", - "-Wl,--build-id=md5", - "-Wl,--warn-shared-textrel", - "-Wl,--fatal-warnings", "-Wl,--hash-style=gnu", - "-Wl,--no-undefined-version", } x86_64ArchVariantCflags = map[string][]string{ diff --git a/cc/config/x86_device.go b/cc/config/x86_device.go index a95305bc0..8aea64d9c 100644 --- a/cc/config/x86_device.go +++ b/cc/config/x86_device.go @@ -40,14 +40,7 @@ var ( x86Cppflags = []string{} x86Ldflags = []string{ - "-Wl,-z,noexecstack", - "-Wl,-z,relro", - "-Wl,-z,now", - "-Wl,--build-id=md5", - "-Wl,--warn-shared-textrel", - "-Wl,--fatal-warnings", "-Wl,--hash-style=gnu", - "-Wl,--no-undefined-version", } x86ArchVariantCflags = map[string][]string{ diff --git a/cc/linker.go b/cc/linker.go index 1cf3f6137..d5727aa07 100644 --- a/cc/linker.go +++ b/cc/linker.go @@ -196,7 +196,13 @@ func (linker *baseLinker) linkerDeps(ctx BaseModuleContext, deps Deps) Deps { func (linker *baseLinker) linkerFlags(ctx ModuleContext, flags Flags) Flags { toolchain := ctx.toolchain() + hod := "Host" + if ctx.Os().Class == android.Device { + hod = "Device" + } + if !ctx.noDefaultCompilerFlags() { + flags.LdFlags = append(flags.LdFlags, fmt.Sprintf("${config.%sGlobalLdflags}", hod)) if Bool(linker.Properties.Allow_undefined_symbols) { if ctx.Darwin() { // darwin defaults to treating undefined symbols as errors diff --git a/cc/makevars.go b/cc/makevars.go index 295b4ac00..f84ae24e2 100644 --- a/cc/makevars.go +++ b/cc/makevars.go @@ -174,6 +174,7 @@ func makeVarsToolchain(ctx android.MakeVarsContext, secondPrefix string, toolchain.Cppflags(), }, " ")) ctx.Strict(makePrefix+"GLOBAL_LDFLAGS", strings.Join([]string{ + fmt.Sprintf("${config.%sGlobalLdflags}", hod), toolchain.Ldflags(), toolchain.ToolchainLdflags(), productExtraLdflags, @@ -219,6 +220,7 @@ func makeVarsToolchain(ctx android.MakeVarsContext, secondPrefix string, toolchain.ClangCppflags(), }, " ")) ctx.Strict(clangPrefix+"GLOBAL_LDFLAGS", strings.Join([]string{ + fmt.Sprintf("${config.%sGlobalLdflags}", hod), toolchain.ClangLdflags(), toolchain.ToolchainClangLdflags(), productExtraLdflags, From 0f1f679f5e5586703ed2255180a27ed6a44dd7e6 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Thu, 2 Nov 2017 23:10:13 -0700 Subject: [PATCH 5/6] Move -fomit-frame-pointer to armCflags -fomit-frame-pointer was specified twice, once for arm and once for thumb. Move it to the shared cflags. Bug: 68855788 Test: m checkbuild Change-Id: Iab1299c247808f1a2542b468084600b7c32996e8 --- cc/config/arm_device.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cc/config/arm_device.go b/cc/config/arm_device.go index 80ec3240f..2c439f061 100644 --- a/cc/config/arm_device.go +++ b/cc/config/arm_device.go @@ -38,6 +38,8 @@ var ( "-fgcse-after-reload", "-frerun-cse-after-loop", "-frename-registers", + + "-fomit-frame-pointer", } armCppflags = []string{ @@ -51,7 +53,6 @@ var ( } armArmCflags = []string{ - "-fomit-frame-pointer", "-fstrict-aliasing", "-funswitch-loops", } @@ -59,7 +60,6 @@ var ( armThumbCflags = []string{ "-mthumb", "-Os", - "-fomit-frame-pointer", } armArchVariantCflags = map[string][]string{ From 87dd963ace9285bb37dc04e39e3e7893e84c50ea Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Fri, 3 Nov 2017 13:31:05 -0700 Subject: [PATCH 6/6] Remove no_default_compiler_flags property no_default_compiler_flags is only used by the crt* modules, is unnecessary, and causes problems when necessary flags like -no-canonical-prefixes are not passed. Remove the property. Use useVndk() instead of noDefaultCompilerFlags() to determine if adding libc as a dependency is necessary and won't cause a circular dependency. Bug: 68719465 Test: m checkbuild Change-Id: Iea1a082dc701dfeab211049a22f7066257347b80 --- cc/cc.go | 9 ----- cc/compiler.go | 92 ++++++++++++++++++++++++-------------------------- cc/linker.go | 54 ++++++++++++++--------------- cc/object.go | 2 +- 4 files changed, 71 insertions(+), 86 deletions(-) diff --git a/cc/cc.go b/cc/cc.go index 02aaf1991..60c8f4190 100644 --- a/cc/cc.go +++ b/cc/cc.go @@ -159,10 +159,6 @@ type BaseProperties struct { // Minimum sdk version supported when compiling against the ndk Sdk_version string - // don't insert default compiler flags into asflags, cflags, - // cppflags, conlyflags, ldflags, or include_dirs - No_default_compiler_flags *bool - AndroidMkSharedLibs []string `blueprint:"mutated"` HideFromMake bool `blueprint:"mutated"` PreventInstall bool `blueprint:"mutated"` @@ -199,7 +195,6 @@ type ModuleContextIntf interface { staticBinary() bool clang() bool toolchain() config.Toolchain - noDefaultCompilerFlags() bool useSdk() bool sdkVersion() string useVndk() bool @@ -452,10 +447,6 @@ func (ctx *moduleContextImpl) staticBinary() bool { return false } -func (ctx *moduleContextImpl) noDefaultCompilerFlags() bool { - return Bool(ctx.mod.Properties.No_default_compiler_flags) -} - func (ctx *moduleContextImpl) useSdk() bool { if ctx.ctx.Device() && !ctx.useVndk() { return ctx.mod.Properties.Sdk_version != "" diff --git a/cc/compiler.go b/cc/compiler.go index 0a2d7bd7d..c40e1795a 100644 --- a/cc/compiler.go +++ b/cc/compiler.go @@ -232,16 +232,14 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags) Flag flags.YasmFlags = append(flags.YasmFlags, f) } - if !ctx.noDefaultCompilerFlags() { - flags.GlobalFlags = append(flags.GlobalFlags, "-I"+android.PathForModuleSrc(ctx).String()) - flags.YasmFlags = append(flags.YasmFlags, "-I"+android.PathForModuleSrc(ctx).String()) + flags.GlobalFlags = append(flags.GlobalFlags, "-I"+android.PathForModuleSrc(ctx).String()) + flags.YasmFlags = append(flags.YasmFlags, "-I"+android.PathForModuleSrc(ctx).String()) - if !(ctx.useSdk() || ctx.useVndk()) || ctx.Host() { - flags.SystemIncludeFlags = append(flags.SystemIncludeFlags, - "${config.CommonGlobalIncludes}", - tc.IncludeFlags(), - "${config.CommonNativehelperInclude}") - } + if !(ctx.useSdk() || ctx.useVndk()) || ctx.Host() { + flags.SystemIncludeFlags = append(flags.SystemIncludeFlags, + "${config.CommonGlobalIncludes}", + tc.IncludeFlags(), + "${config.CommonNativehelperInclude}") } if ctx.useSdk() { @@ -318,48 +316,46 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags) Flag hod = "Device" } - if !ctx.noDefaultCompilerFlags() { - flags.GlobalFlags = append(flags.GlobalFlags, instructionSetFlags) - flags.ConlyFlags = append([]string{"${config.CommonGlobalConlyflags}"}, flags.ConlyFlags...) + flags.GlobalFlags = append(flags.GlobalFlags, instructionSetFlags) + flags.ConlyFlags = append([]string{"${config.CommonGlobalConlyflags}"}, flags.ConlyFlags...) - if flags.Clang { - flags.AsFlags = append(flags.AsFlags, tc.ClangAsflags()) - flags.CppFlags = append([]string{"${config.CommonClangGlobalCppflags}"}, flags.CppFlags...) - flags.GlobalFlags = append(flags.GlobalFlags, - tc.ClangCflags(), - "${config.CommonClangGlobalCflags}", - fmt.Sprintf("${config.%sClangGlobalCflags}", hod)) - } else { - flags.CppFlags = append([]string{"${config.CommonGlobalCppflags}"}, flags.CppFlags...) - flags.GlobalFlags = append(flags.GlobalFlags, - tc.Cflags(), - "${config.CommonGlobalCflags}", - fmt.Sprintf("${config.%sGlobalCflags}", hod)) - } - - if Bool(ctx.AConfig().ProductVariables.Brillo) { - flags.GlobalFlags = append(flags.GlobalFlags, "-D__BRILLO__") - } - - if ctx.Device() { - if Bool(compiler.Properties.Rtti) { - flags.CppFlags = append(flags.CppFlags, "-frtti") - } else { - flags.CppFlags = append(flags.CppFlags, "-fno-rtti") - } - } - - flags.AsFlags = append(flags.AsFlags, "-D__ASSEMBLY__") - - if flags.Clang { - flags.CppFlags = append(flags.CppFlags, tc.ClangCppflags()) - } else { - flags.CppFlags = append(flags.CppFlags, tc.Cppflags()) - } - - flags.YasmFlags = append(flags.YasmFlags, tc.YasmFlags()) + if flags.Clang { + flags.AsFlags = append(flags.AsFlags, tc.ClangAsflags()) + flags.CppFlags = append([]string{"${config.CommonClangGlobalCppflags}"}, flags.CppFlags...) + flags.GlobalFlags = append(flags.GlobalFlags, + tc.ClangCflags(), + "${config.CommonClangGlobalCflags}", + fmt.Sprintf("${config.%sClangGlobalCflags}", hod)) + } else { + flags.CppFlags = append([]string{"${config.CommonGlobalCppflags}"}, flags.CppFlags...) + flags.GlobalFlags = append(flags.GlobalFlags, + tc.Cflags(), + "${config.CommonGlobalCflags}", + fmt.Sprintf("${config.%sGlobalCflags}", hod)) } + if Bool(ctx.AConfig().ProductVariables.Brillo) { + flags.GlobalFlags = append(flags.GlobalFlags, "-D__BRILLO__") + } + + if ctx.Device() { + if Bool(compiler.Properties.Rtti) { + flags.CppFlags = append(flags.CppFlags, "-frtti") + } else { + flags.CppFlags = append(flags.CppFlags, "-fno-rtti") + } + } + + flags.AsFlags = append(flags.AsFlags, "-D__ASSEMBLY__") + + if flags.Clang { + flags.CppFlags = append(flags.CppFlags, tc.ClangCppflags()) + } else { + flags.CppFlags = append(flags.CppFlags, tc.Cppflags()) + } + + flags.YasmFlags = append(flags.YasmFlags, tc.YasmFlags()) + if flags.Clang { flags.GlobalFlags = append(flags.GlobalFlags, tc.ToolchainClangCflags()) } else { diff --git a/cc/linker.go b/cc/linker.go index d5727aa07..fae55425b 100644 --- a/cc/linker.go +++ b/cc/linker.go @@ -201,39 +201,37 @@ func (linker *baseLinker) linkerFlags(ctx ModuleContext, flags Flags) Flags { hod = "Device" } - if !ctx.noDefaultCompilerFlags() { - flags.LdFlags = append(flags.LdFlags, fmt.Sprintf("${config.%sGlobalLdflags}", hod)) - if Bool(linker.Properties.Allow_undefined_symbols) { - if ctx.Darwin() { - // darwin defaults to treating undefined symbols as errors - flags.LdFlags = append(flags.LdFlags, "-Wl,-undefined,dynamic_lookup") - } - } else if !ctx.Darwin() { - flags.LdFlags = append(flags.LdFlags, "-Wl,--no-undefined") + flags.LdFlags = append(flags.LdFlags, fmt.Sprintf("${config.%sGlobalLdflags}", hod)) + if Bool(linker.Properties.Allow_undefined_symbols) { + if ctx.Darwin() { + // darwin defaults to treating undefined symbols as errors + flags.LdFlags = append(flags.LdFlags, "-Wl,-undefined,dynamic_lookup") } + } else if !ctx.Darwin() { + flags.LdFlags = append(flags.LdFlags, "-Wl,--no-undefined") + } - if flags.Clang { - flags.LdFlags = append(flags.LdFlags, toolchain.ClangLdflags()) - } else { - flags.LdFlags = append(flags.LdFlags, toolchain.Ldflags()) - } + if flags.Clang { + flags.LdFlags = append(flags.LdFlags, toolchain.ClangLdflags()) + } else { + flags.LdFlags = append(flags.LdFlags, toolchain.Ldflags()) + } - if !ctx.toolchain().Bionic() { - CheckBadHostLdlibs(ctx, "host_ldlibs", linker.Properties.Host_ldlibs) + if !ctx.toolchain().Bionic() { + CheckBadHostLdlibs(ctx, "host_ldlibs", linker.Properties.Host_ldlibs) - flags.LdFlags = append(flags.LdFlags, linker.Properties.Host_ldlibs...) + flags.LdFlags = append(flags.LdFlags, linker.Properties.Host_ldlibs...) - if !ctx.Windows() { - // Add -ldl, -lpthread, -lm and -lrt to host builds to match the default behavior of device - // builds - flags.LdFlags = append(flags.LdFlags, - "-ldl", - "-lpthread", - "-lm", - ) - if !ctx.Darwin() { - flags.LdFlags = append(flags.LdFlags, "-lrt") - } + if !ctx.Windows() { + // Add -ldl, -lpthread, -lm and -lrt to host builds to match the default behavior of device + // builds + flags.LdFlags = append(flags.LdFlags, + "-ldl", + "-lpthread", + "-lm", + ) + if !ctx.Darwin() { + flags.LdFlags = append(flags.LdFlags, "-lrt") } } } diff --git a/cc/object.go b/cc/object.go index 402b1050b..2246dd303 100644 --- a/cc/object.go +++ b/cc/object.go @@ -53,7 +53,7 @@ func (object *objectLinker) linkerProps() []interface{} { func (*objectLinker) linkerInit(ctx BaseModuleContext) {} func (object *objectLinker) linkerDeps(ctx DepsContext, deps Deps) Deps { - if !ctx.noDefaultCompilerFlags() && ctx.toolchain().Bionic() { + if ctx.useVndk() && ctx.toolchain().Bionic() { // Needed for VNDK builds where bionic headers aren't automatically added. deps.LateSharedLibs = append(deps.LateSharedLibs, "libc") }