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
diff --git a/cc/compiler.go b/cc/compiler.go
index 198b792..0e65c17 100644
--- a/cc/compiler.go
+++ b/cc/compiler.go
@@ -278,13 +278,22 @@
}
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 9b77662..348c586 100644
--- a/cc/config/global.go
+++ b/cc/config/global.go
@@ -37,9 +37,7 @@
"-UDEBUG",
}
- commonGlobalConlyflags = []string{
- "-std=gnu99",
- }
+ commonGlobalConlyflags = []string{}
deviceGlobalCflags = []string{
"-fdiagnostics-color",
@@ -66,6 +64,10 @@
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 098ec02..770e1d0 100644
--- a/cc/makevars.go
+++ b/cc/makevars.go
@@ -48,6 +48,10 @@
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)