From 577a73a22dde3ba0c653677c93f93617fbb4ca11 Mon Sep 17 00:00:00 2001 From: Yi Kong Date: Thu, 5 Oct 2023 05:03:42 +0000 Subject: [PATCH] Change lto_test to use GlobalThinLTO configuration This is now the default, and we will be removing non-GlobalThinLTO configuration. Also changed handling for lto: never, it doesn't need to create an lto-none variant. Change-Id: I971baa920df867fb762923d925eed22215a89c27 Test: presubmit --- cc/lto.go | 8 +++-- cc/lto_test.go | 91 +++++++++++++++++++++----------------------------- 2 files changed, 43 insertions(+), 56 deletions(-) diff --git a/cc/lto.go b/cc/lto.go index df9ca0ab8..281b52700 100644 --- a/cc/lto.go +++ b/cc/lto.go @@ -35,11 +35,11 @@ import ( // optimized at link time and may not be compatible with features that require // LTO, such as CFI. // -// This file adds support to soong to automatically propogate LTO options to a +// This file adds support to soong to automatically propagate LTO options to a // new variant of all static dependencies for each module with LTO enabled. type LTOProperties struct { - // Lto must violate capitialization style for acronyms so that it can be + // Lto must violate capitalization style for acronyms so that it can be // referred to in blueprint files as "lto" Lto struct { Never *bool `android:"arch_variant"` @@ -67,10 +67,12 @@ func (lto *lto) props() []interface{} { } func (lto *lto) begin(ctx BaseModuleContext) { - // First, determine the module indepedent default LTO mode. + // First, determine the module independent default LTO mode. ltoDefault := GlobalThinLTO(ctx) if ctx.Config().IsEnvTrue("DISABLE_LTO") { ltoDefault = false + } else if lto.Never() { + ltoDefault = false } else if ctx.Host() { // Performance and binary size are less important for host binaries. ltoDefault = false diff --git a/cc/lto_test.go b/cc/lto_test.go index e0afd4a73..7b7fe8c8a 100644 --- a/cc/lto_test.go +++ b/cc/lto_test.go @@ -23,11 +23,19 @@ import ( "github.com/google/blueprint" ) -var NoGlobalThinLTOPreparer = android.GroupFixturePreparers( +var LTOPreparer = android.GroupFixturePreparers( prepareForCcTest, - android.FixtureModifyEnv(func(env map[string]string) { - env["GLOBAL_THINLTO"] = "false" - })) +) + +func hasDep(result *android.TestResult, m android.Module, wantDep android.Module) bool { + var found bool + result.VisitDirectDeps(m, func(dep blueprint.Module) { + if dep == wantDep { + found = true + } + }) + return found +} func TestThinLtoDeps(t *testing.T) { t.Parallel() @@ -37,9 +45,6 @@ func TestThinLtoDeps(t *testing.T) { srcs: ["src.c"], static_libs: ["foo", "lib_never_lto"], shared_libs: ["bar"], - lto: { - thin: true, - } } cc_library_static { name: "foo", @@ -63,50 +68,40 @@ func TestThinLtoDeps(t *testing.T) { } ` - result := NoGlobalThinLTOPreparer.RunTestWithBp(t, bp) + result := LTOPreparer.RunTestWithBp(t, bp) libLto := result.ModuleForTests("lto_enabled", "android_arm64_armv8-a_shared").Module() - hasDep := func(m android.Module, wantDep android.Module) bool { - var found bool - result.VisitDirectDeps(m, func(dep blueprint.Module) { - if dep == wantDep { - found = true - } - }) - return found + libFoo := result.ModuleForTests("foo", "android_arm64_armv8-a_static").Module() + if !hasDep(result, libLto, libFoo) { + t.Errorf("'lto_enabled' missing dependency on the default variant of 'foo'") } - libFoo := result.ModuleForTests("foo", "android_arm64_armv8-a_static_lto-thin").Module() - if !hasDep(libLto, libFoo) { - t.Errorf("'lto_enabled' missing dependency on thin lto variant of 'foo'") + libBaz := result.ModuleForTests("baz", "android_arm64_armv8-a_static").Module() + if !hasDep(result, libFoo, libBaz) { + t.Errorf("'foo' missing dependency on the default variant of transitive dep 'baz'") } - libBaz := result.ModuleForTests("baz", "android_arm64_armv8-a_static_lto-thin").Module() - if !hasDep(libFoo, libBaz) { - t.Errorf("'foo' missing dependency on thin lto variant of transitive dep 'baz'") - } - - libNeverLto := result.ModuleForTests("lib_never_lto", "android_arm64_armv8-a_static_lto-thin").Module() - if !hasDep(libLto, libNeverLto) { - t.Errorf("'lto_enabled' missing dependency on NO-thin lto variant of 'lib_never_lto'") + libNeverLto := result.ModuleForTests("lib_never_lto", "android_arm64_armv8-a_static").Module() + if !hasDep(result, libLto, libNeverLto) { + t.Errorf("'lto_enabled' missing dependency on the default variant of 'lib_never_lto'") } libBar := result.ModuleForTests("bar", "android_arm64_armv8-a_shared").Module() - if !hasDep(libLto, libBar) { - t.Errorf("'lto_enabled' missing dependency on non-thin lto variant of 'bar'") + if !hasDep(result, libLto, libBar) { + t.Errorf("'lto_enabled' missing dependency on the default variant of 'bar'") } barVariants := result.ModuleVariantsForTests("bar") for _, v := range barVariants { - if strings.Contains(v, "lto-thin") { - t.Errorf("Expected variants for 'bar' to not contain 'lto-thin', but found %q", v) + if strings.Contains(v, "lto-none") { + t.Errorf("Expected variants for 'bar' to not contain 'lto-none', but found %q", v) } } quxVariants := result.ModuleVariantsForTests("qux") for _, v := range quxVariants { - if strings.Contains(v, "lto-thin") { - t.Errorf("Expected variants for 'qux' to not contain 'lto-thin', but found %q", v) + if strings.Contains(v, "lto-none") { + t.Errorf("Expected variants for 'qux' to not contain 'lto-none', but found %q", v) } } } @@ -141,28 +136,18 @@ func TestThinLtoOnlyOnStaticDep(t *testing.T) { } ` - result := NoGlobalThinLTOPreparer.RunTestWithBp(t, bp) + result := LTOPreparer.RunTestWithBp(t, bp) libRoot := result.ModuleForTests("root", "android_arm64_armv8-a_shared").Module() libRootLtoNever := result.ModuleForTests("root_no_lto", "android_arm64_armv8-a_shared").Module() - hasDep := func(m android.Module, wantDep android.Module) bool { - var found bool - result.VisitDirectDeps(m, func(dep blueprint.Module) { - if dep == wantDep { - found = true - } - }) - return found - } - libFoo := result.ModuleForTests("foo", "android_arm64_armv8-a_static") - if !hasDep(libRoot, libFoo.Module()) { - t.Errorf("'root' missing dependency on thin lto variant of 'foo'") + if !hasDep(result, libRoot, libFoo.Module()) { + t.Errorf("'root' missing dependency on the default variant of 'foo'") } - if !hasDep(libRootLtoNever, libFoo.Module()) { - t.Errorf("'root_no_lto' missing dependency on thin lto variant of 'foo'") + if !hasDep(result, libRootLtoNever, libFoo.Module()) { + t.Errorf("'root_no_lto' missing dependency on the default variant of 'foo'") } libFooCFlags := libFoo.Rule("cc").Args["cFlags"] @@ -170,9 +155,9 @@ func TestThinLtoOnlyOnStaticDep(t *testing.T) { t.Errorf("'foo' expected to have flags %q, but got %q", w, libFooCFlags) } - libBaz := result.ModuleForTests("baz", "android_arm64_armv8-a_static_lto-thin") - if !hasDep(libFoo.Module(), libBaz.Module()) { - t.Errorf("'foo' missing dependency on thin lto variant of transitive dep 'baz'") + libBaz := result.ModuleForTests("baz", "android_arm64_armv8-a_static") + if !hasDep(result, libFoo.Module(), libBaz.Module()) { + t.Errorf("'foo' missing dependency on the default variant of transitive dep 'baz'") } libBazCFlags := libFoo.Rule("cc").Args["cFlags"] @@ -199,7 +184,7 @@ func TestLtoDisabledButEnabledForArch(t *testing.T) { }, }, }` - result := NoGlobalThinLTOPreparer.RunTestWithBp(t, bp) + result := LTOPreparer.RunTestWithBp(t, bp) libFooWithLto := result.ModuleForTests("libfoo", "android_arm_armv7-a-neon_shared").Rule("ld") libFooWithoutLto := result.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Rule("ld") @@ -227,7 +212,7 @@ func TestLtoDoesNotPropagateToRuntimeLibs(t *testing.T) { }, }` - result := NoGlobalThinLTOPreparer.RunTestWithBp(t, bp) + result := LTOPreparer.RunTestWithBp(t, bp) libFoo := result.ModuleForTests("libfoo", "android_arm_armv7-a-neon_shared").Rule("ld") libBar := result.ModuleForTests("runtime_libbar", "android_arm_armv7-a-neon_shared").Rule("ld")