From 6f6a428760905469d1f118e3bc3a23ae81a3228b Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Mon, 17 Oct 2016 14:19:06 -0700 Subject: [PATCH 1/2] Consolidate -std flags Define the default -std values in global.go, export them in makevars.go, and use them in compiler.go. Test: builds Change-Id: Ia2ae01f63e182d0ad7f371e6d32184bff35a8897 --- cc/compiler.go | 17 +++++++++++++---- cc/config/global.go | 8 +++++--- cc/makevars.go | 4 ++++ 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/cc/compiler.go b/cc/compiler.go index 198b79241..0e65c174c 100644 --- a/cc/compiler.go +++ b/cc/compiler.go @@ -278,13 +278,22 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags) Flag } if !ctx.sdk() { - if ctx.Host() && !flags.Clang { + cStd := config.CStdVersion + cppStd := config.CppStdVersion + + if !flags.Clang { + // GCC uses an invalid C++14 ABI (emits calls to + // __cxa_throw_bad_array_length, which is not a valid C++ RT ABI). + // http://b/25022512 + cppStd = config.GccCppStdVersion + } else if ctx.Host() && !flags.Clang { // The host GCC doesn't support C++14 (and is deprecated, so likely // never will). Build these modules with C++11. - flags.CppFlags = append(flags.CppFlags, "-std=gnu++11") - } else { - flags.CppFlags = append(flags.CppFlags, "-std=gnu++14") + cppStd = config.GccCppStdVersion } + + flags.ConlyFlags = append([]string{"-std=" + cStd}, flags.ConlyFlags...) + flags.CppFlags = append([]string{"-std=" + cppStd}, flags.CppFlags...) } // We can enforce some rules more strictly in the code we own. strict diff --git a/cc/config/global.go b/cc/config/global.go index 9b776629d..348c586cb 100644 --- a/cc/config/global.go +++ b/cc/config/global.go @@ -37,9 +37,7 @@ var ( "-UDEBUG", } - commonGlobalConlyflags = []string{ - "-std=gnu99", - } + commonGlobalConlyflags = []string{} deviceGlobalCflags = []string{ "-fdiagnostics-color", @@ -66,6 +64,10 @@ var ( IllegalFlags = []string{ "-w", } + + CStdVersion = "gnu99" + CppStdVersion = "gnu++14" + GccCppStdVersion = "gnu++11" ) var pctx = android.NewPackageContext("android/soong/cc/config") diff --git a/cc/makevars.go b/cc/makevars.go index 098ec02c8..770e1d0d9 100644 --- a/cc/makevars.go +++ b/cc/makevars.go @@ -48,6 +48,10 @@ func makeVarsProvider(ctx android.MakeVarsContext) { ctx.Strict("ADDRESS_SANITIZER_CONFIG_EXTRA_LDFLAGS", asanLdflags) ctx.Strict("ADDRESS_SANITIZER_CONFIG_EXTRA_STATIC_LIBRARIES", asanLibs) + ctx.Strict("DEFAULT_C_STD_VERSION", config.CStdVersion) + ctx.Strict("DEFAULT_CPP_STD_VERSION", config.CppStdVersion) + ctx.Strict("DEFAULT_GCC_CPP_STD_VERSION", config.GccCppStdVersion) + includeFlags, err := ctx.Eval("${config.CommonGlobalIncludes} ${config.CommonGlobalSystemIncludes}") if err != nil { panic(err) From 948f0cb9eab847a806877d783e5235faf423ad1f Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Mon, 17 Oct 2016 14:24:56 -0700 Subject: [PATCH 2/2] Allow disabling gnu extensions Pass -std=c++14 instead of -std=gnu++14 (or whatever the current default is) when "gnu_extensions: false" is specified in the blueprints files. Bug: 32159540 Test: builds Change-Id: If206228a972129d9574bcf50ddff283b7e7d3fd7 --- cc/compiler.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cc/compiler.go b/cc/compiler.go index 0e65c174c..a0068ada3 100644 --- a/cc/compiler.go +++ b/cc/compiler.go @@ -84,6 +84,9 @@ type BaseCompilerProperties struct { // pass -frtti instead of -fno-rtti Rtti *bool + // if set to false, use -std=c++* instead of -std=gnu++* + Gnu_extensions *bool + Debug, Release struct { // list of module-specific flags that will be used for C and C++ compiles in debug or // release builds @@ -292,6 +295,11 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags) Flag cppStd = config.GccCppStdVersion } + if compiler.Properties.Gnu_extensions != nil && *compiler.Properties.Gnu_extensions == false { + cStd = gnuToCReplacer.Replace(cStd) + cppStd = gnuToCReplacer.Replace(cppStd) + } + flags.ConlyFlags = append([]string{"-std=" + cStd}, flags.ConlyFlags...) flags.CppFlags = append([]string{"-std=" + cppStd}, flags.CppFlags...) } @@ -315,6 +323,8 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags) Flag return flags } +var gnuToCReplacer = strings.NewReplacer("gnu", "c") + func ndkPathDeps(ctx ModuleContext) android.Paths { if ctx.sdk() { // The NDK sysroot timestamp file depends on all the NDK sysroot files