Disable more of AFDO for host modules
afdo.addDep would never add a depencency on a profile for a host module, but afdoDepsMutator would still propagate AfdoRDeps to dependencies, afdoMutator would still create afdo variants, and afdo.flags would still add the -funique-internal-linkage-names flag. Exit early from all of these functions, since the afdo variations will never be useful. Test: afdo_test.go Change-Id: I255fcbb86c99871916e571fbc74075d918b24745
This commit is contained in:
12
cc/afdo.go
12
cc/afdo.go
@@ -68,6 +68,10 @@ func (afdo *afdo) afdoEnabled() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (afdo *afdo) flags(ctx ModuleContext, flags Flags) Flags {
|
func (afdo *afdo) flags(ctx ModuleContext, flags Flags) Flags {
|
||||||
|
if ctx.Host() {
|
||||||
|
return flags
|
||||||
|
}
|
||||||
|
|
||||||
if afdo.Properties.Afdo {
|
if afdo.Properties.Afdo {
|
||||||
// We use `-funique-internal-linkage-names` to associate profiles to the right internal
|
// We use `-funique-internal-linkage-names` to associate profiles to the right internal
|
||||||
// functions. This option should be used before generating a profile. Because a profile
|
// functions. This option should be used before generating a profile. Because a profile
|
||||||
@@ -147,6 +151,10 @@ var _ FdoProfileMutatorInterface = (*Module)(nil)
|
|||||||
|
|
||||||
// Propagate afdo requirements down from binaries and shared libraries
|
// Propagate afdo requirements down from binaries and shared libraries
|
||||||
func afdoDepsMutator(mctx android.TopDownMutatorContext) {
|
func afdoDepsMutator(mctx android.TopDownMutatorContext) {
|
||||||
|
if mctx.Host() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if m, ok := mctx.Module().(*Module); ok && m.afdo.afdoEnabled() {
|
if m, ok := mctx.Module().(*Module); ok && m.afdo.afdoEnabled() {
|
||||||
path := m.afdo.Properties.FdoProfilePath
|
path := m.afdo.Properties.FdoProfilePath
|
||||||
mctx.WalkDeps(func(dep android.Module, parent android.Module) bool {
|
mctx.WalkDeps(func(dep android.Module, parent android.Module) bool {
|
||||||
@@ -181,6 +189,10 @@ func afdoDepsMutator(mctx android.TopDownMutatorContext) {
|
|||||||
|
|
||||||
// Create afdo variants for modules that need them
|
// Create afdo variants for modules that need them
|
||||||
func afdoMutator(mctx android.BottomUpMutatorContext) {
|
func afdoMutator(mctx android.BottomUpMutatorContext) {
|
||||||
|
if mctx.Host() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if m, ok := mctx.Module().(*Module); ok && m.afdo != nil {
|
if m, ok := mctx.Module().(*Module); ok && m.afdo != nil {
|
||||||
if !m.static() && m.afdo.Properties.Afdo {
|
if !m.static() && m.afdo.Properties.Afdo {
|
||||||
mctx.SetDependencyVariation(encodeTarget(m.Name()))
|
mctx.SetDependencyVariation(encodeTarget(m.Name()))
|
||||||
|
@@ -42,6 +42,7 @@ func TestAfdoDeps(t *testing.T) {
|
|||||||
bp := `
|
bp := `
|
||||||
cc_library_shared {
|
cc_library_shared {
|
||||||
name: "libTest",
|
name: "libTest",
|
||||||
|
host_supported: true,
|
||||||
srcs: ["test.c"],
|
srcs: ["test.c"],
|
||||||
static_libs: ["libFoo"],
|
static_libs: ["libFoo"],
|
||||||
afdo: true,
|
afdo: true,
|
||||||
@@ -52,12 +53,14 @@ func TestAfdoDeps(t *testing.T) {
|
|||||||
|
|
||||||
cc_library_static {
|
cc_library_static {
|
||||||
name: "libFoo",
|
name: "libFoo",
|
||||||
|
host_supported: true,
|
||||||
srcs: ["foo.c"],
|
srcs: ["foo.c"],
|
||||||
static_libs: ["libBar"],
|
static_libs: ["libBar"],
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_library_static {
|
cc_library_static {
|
||||||
name: "libBar",
|
name: "libBar",
|
||||||
|
host_supported: true,
|
||||||
srcs: ["bar.c"],
|
srcs: ["bar.c"],
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
@@ -210,6 +213,52 @@ func TestAfdoDeps(t *testing.T) {
|
|||||||
t.Errorf("Expected arm32 'libBar' to enable afdo, but did not find %q in cflags %q", uniqueInternalLinkageNamesCFlag, cFlags)
|
t.Errorf("Expected arm32 'libBar' to enable afdo, but did not find %q in cflags %q", uniqueInternalLinkageNamesCFlag, cFlags)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Verify that the host variants don't enable afdo
|
||||||
|
libTestHost := result.ModuleForTests("libTest", result.Config.BuildOSTarget.String()+"_shared")
|
||||||
|
libFooHost := result.ModuleForTests("libFoo", result.Config.BuildOSTarget.String()+"_static_lto-thin")
|
||||||
|
libBarHost := result.ModuleForTests("libBar", result.Config.BuildOSTarget.String()+"_static_lto-thin")
|
||||||
|
|
||||||
|
cFlags = libTestHost.Rule("cc").Args["cFlags"]
|
||||||
|
if strings.Contains(cFlags, profileSampleCFlag) {
|
||||||
|
t.Errorf("Expected host 'libTest' to not enable afdo profile, but found %q in cflags %q", profileSampleCFlag, cFlags)
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.Contains(cFlags, uniqueInternalLinkageNamesCFlag) {
|
||||||
|
t.Errorf("Expected host 'libTest' to not enable afdo but found %q in cflags %q",
|
||||||
|
uniqueInternalLinkageNamesCFlag, cFlags)
|
||||||
|
}
|
||||||
|
|
||||||
|
ldFlags = libTestHost.Rule("ld").Args["ldFlags"]
|
||||||
|
if !strings.Contains(ldFlags, noAfdoLtoLdFlag) {
|
||||||
|
t.Errorf("Expected host 'libTest' to not enable afdo, but did not find %q in ldflags %q", noAfdoLtoLdFlag, ldFlags)
|
||||||
|
}
|
||||||
|
if strings.Contains(ldFlags, afdoLtoLdFlag) {
|
||||||
|
t.Errorf("Expected host 'libTest' to not enable afdo, but found %q in ldflags %q", afdoLtoLdFlag, ldFlags)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check dependency edge from afdo-enabled module to static deps
|
||||||
|
if !hasDirectDep(result, libTestHost.Module(), libFooHost.Module()) {
|
||||||
|
t.Errorf("host libTest missing dependency on non-afdo variant of libFoo")
|
||||||
|
}
|
||||||
|
|
||||||
|
if !hasDirectDep(result, libFooHost.Module(), libBarHost.Module()) {
|
||||||
|
t.Errorf("host libTest missing dependency on non-afdo variant of libBar")
|
||||||
|
}
|
||||||
|
|
||||||
|
cFlags = libFooHost.Rule("cc").Args["cFlags"]
|
||||||
|
if strings.Contains(cFlags, profileSampleCFlag) {
|
||||||
|
t.Errorf("Expected host 'libFoo' to not enable afdo profile, but found %q in cflags %q", uniqueInternalLinkageNamesCFlag, cFlags)
|
||||||
|
}
|
||||||
|
if strings.Contains(cFlags, uniqueInternalLinkageNamesCFlag) {
|
||||||
|
t.Errorf("Expected host 'libFoo' to not enable afdo, but found %q in cflags %q", uniqueInternalLinkageNamesCFlag, cFlags)
|
||||||
|
}
|
||||||
|
cFlags = libBarHost.Rule("cc").Args["cFlags"]
|
||||||
|
if strings.Contains(cFlags, profileSampleCFlag) {
|
||||||
|
t.Errorf("Expected host 'libBar' to not enable afdo profile, but found %q in cflags %q", uniqueInternalLinkageNamesCFlag, cFlags)
|
||||||
|
}
|
||||||
|
if strings.Contains(cFlags, uniqueInternalLinkageNamesCFlag) {
|
||||||
|
t.Errorf("Expected host 'libBar' to not enable afdo, but found %q in cflags %q", uniqueInternalLinkageNamesCFlag, cFlags)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAfdoEnabledOnStaticDepNoAfdo(t *testing.T) {
|
func TestAfdoEnabledOnStaticDepNoAfdo(t *testing.T) {
|
||||||
|
Reference in New Issue
Block a user