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)