diff --git a/cc/lto_test.go b/cc/lto_test.go index fbd91be46..ff2eddcf9 100644 --- a/cc/lto_test.go +++ b/cc/lto_test.go @@ -15,10 +15,11 @@ package cc import ( - "android/soong/android" "strings" "testing" + "android/soong/android" + "github.com/google/blueprint" ) @@ -177,3 +178,35 @@ func TestThinLtoOnlyOnStaticDep(t *testing.T) { t.Errorf("'baz' expected to have flags %q, but got %q", w, libFooCFlags) } } + +func TestLtoDisabledButEnabledForArch(t *testing.T) { + t.Parallel() + bp := ` + cc_library { + name: "libfoo", + srcs: ["foo.c"], + host_supported:true, + lto: { + never: true, + }, + target: { + android: { + lto: { + never: false, + thin: true, + }, + }, + }, + }` + result := android.GroupFixturePreparers( + prepareForCcTest, + ).RunTestWithBp(t, bp) + + libFooWithLto := result.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Rule("ld") + libFooWithoutLto := result.ModuleForTests("libfoo", "linux_glibc_x86_64_shared").Rule("ld") + + android.AssertStringDoesContain(t, "missing flag for LTO in variant that expects it", + libFooWithLto.Args["ldFlags"], "-flto=thin") + android.AssertStringDoesNotContain(t, "got flag for LTO in variant that doesn't expect it", + libFooWithoutLto.Args["ldFlags"], "-flto=thin") +}