From 933e38093d12452587a7bf0d2c9a87ab128757ce Mon Sep 17 00:00:00 2001 From: zijunzhao Date: Thu, 12 Jan 2023 07:26:20 +0000 Subject: [PATCH] Add noOverride64GlobalCflags support to Soong Bug: b/261642850 Test: Build and check warnings. Add two xfail tests in bionic and see the results locally. Change-Id: I68fca0084787c329b6c49ce4dff6fd132f820735 --- cc/builder.go | 7 +++++++ cc/cc_test.go | 33 +++++++++++++++++++++++++++++++++ cc/config/global.go | 18 +++++++++++++++++- cc/makevars.go | 1 + 4 files changed, 58 insertions(+), 1 deletion(-) diff --git a/cc/builder.go b/cc/builder.go index 0629406c2..fef00d4d5 100644 --- a/cc/builder.go +++ b/cc/builder.go @@ -519,6 +519,13 @@ func transformSourceToObj(ctx ModuleContext, subdir string, srcFiles, noTidySrcs cppflags += " ${config.NoOverrideGlobalCflags}" toolingCppflags += " ${config.NoOverrideGlobalCflags}" + if flags.toolchain.Is64Bit() { + cflags += " ${config.NoOverride64GlobalCflags}" + toolingCflags += " ${config.NoOverride64GlobalCflags}" + cppflags += " ${config.NoOverride64GlobalCflags}" + toolingCppflags += " ${config.NoOverride64GlobalCflags}" + } + modulePath := android.PathForModuleSrc(ctx).String() if android.IsThirdPartyPath(modulePath) { cflags += " ${config.NoOverrideExternalGlobalCflags}" diff --git a/cc/cc_test.go b/cc/cc_test.go index 6dfd395cb..8293f2db7 100644 --- a/cc/cc_test.go +++ b/cc/cc_test.go @@ -4483,6 +4483,39 @@ func TestIncludeDirectoryOrdering(t *testing.T) { } +func TestAddnoOverride64GlobalCflags(t *testing.T) { + t.Parallel() + ctx := testCc(t, ` + cc_library_shared { + name: "libclient", + srcs: ["foo.c"], + shared_libs: ["libfoo#1"], + } + + cc_library_shared { + name: "libfoo", + srcs: ["foo.c"], + shared_libs: ["libbar"], + export_shared_lib_headers: ["libbar"], + stubs: { + symbol_file: "foo.map.txt", + versions: ["1", "2", "3"], + }, + } + + cc_library_shared { + name: "libbar", + export_include_dirs: ["include/libbar"], + srcs: ["foo.c"], + }`) + + cFlags := ctx.ModuleForTests("libclient", "android_arm64_armv8-a_shared").Rule("cc").Args["cFlags"] + + if !strings.Contains(cFlags, "${config.NoOverride64GlobalCflags}") { + t.Errorf("expected %q in cflags, got %q", "${config.NoOverride64GlobalCflags}", cFlags) + } +} + func TestCcBuildBrokenClangProperty(t *testing.T) { t.Parallel() tests := []struct { diff --git a/cc/config/global.go b/cc/config/global.go index 811e86ec5..2205c9e48 100644 --- a/cc/config/global.go +++ b/cc/config/global.go @@ -247,6 +247,8 @@ var ( "-Wno-error=enum-constexpr-conversion", // http://b/243964282 } + noOverride64GlobalCflags = []string{} + noOverrideExternalGlobalCflags = []string{ // http://b/148815709 "-Wno-sizeof-array-div", @@ -384,12 +386,26 @@ func init() { return strings.Join(deviceGlobalCflags, " ") }) - // Export the static default NoOverrideGlobalCflags to Bazel. + // Export the static default NoOverrideGlobalCflags and NoOverride64GlobalCflags to Bazel. exportedVars.ExportStringList("NoOverrideGlobalCflags", noOverrideGlobalCflags) + exportedVars.ExportStringList("NoOverride64GlobalCflags", noOverride64GlobalCflags) pctx.VariableFunc("NoOverrideGlobalCflags", func(ctx android.PackageVarContext) string { flags := noOverrideGlobalCflags if ctx.Config().IsEnvTrue("LLVM_NEXT") { flags = append(noOverrideGlobalCflags, llvmNextExtraCommonGlobalCflags...) + if ctx.Config().Android64() { + flags = append(noOverride64GlobalCflags) + } + } + return strings.Join(flags, " ") + }) + + // Export the static default NoOverride64GlobalCflags to Bazel. + exportedVars.ExportStringList("NoOverride64GlobalCflags", noOverride64GlobalCflags) + pctx.VariableFunc("NoOverride64GlobalCflags", func(ctx android.PackageVarContext) string { + flags := noOverride64GlobalCflags + if ctx.Config().IsEnvTrue("LLVM_NEXT") && ctx.Config().Android64() { + flags = append(noOverride64GlobalCflags, llvmNextExtraCommonGlobalCflags...) } return strings.Join(flags, " ") }) diff --git a/cc/makevars.go b/cc/makevars.go index c70d4a6ff..6c3f551d7 100644 --- a/cc/makevars.go +++ b/cc/makevars.go @@ -93,6 +93,7 @@ func makeVarsProvider(ctx android.MakeVarsContext) { ctx.Strict("CLANG_EXTERNAL_CFLAGS", "${config.ExternalCflags}") ctx.Strict("GLOBAL_CLANG_CFLAGS_NO_OVERRIDE", "${config.NoOverrideGlobalCflags}") + ctx.Strict("GLOBAL_CLANG_CFLAGS_64_NO_OVERRIDE", "${config.NoOverride64GlobalCflags}") ctx.Strict("GLOBAL_CLANG_CPPFLAGS_NO_OVERRIDE", "") ctx.Strict("GLOBAL_CLANG_EXTERNAL_CFLAGS_NO_OVERRIDE", "${config.NoOverrideExternalGlobalCflags}")