Do not enable AFDO for coverage builds

This works around an incompatibility between coverage and the
-fdebug-info-for-profiling flag.

also moved -fdebug-info-for-profiling flag so that it is only applied to
the libraries that enabled AFDO.

Test: gzip -cd out/verbose.log.gz | grep debug-info-for-profiling
Bug: 345593672
Change-Id: I68493511da1e61091209d0ed1b2c86c7ba0e21f4
diff --git a/cc/afdo.go b/cc/afdo.go
index 6921edf..14d105e 100644
--- a/cc/afdo.go
+++ b/cc/afdo.go
@@ -47,6 +47,10 @@
 	if ctx.Config().Eng() {
 		afdo.Properties.Afdo = false
 	}
+	// Disable for native coverage builds.
+	if ctx.DeviceConfig().NativeCoverageEnabled() {
+		afdo.Properties.Afdo = false
+	}
 }
 
 // afdoEnabled returns true for binaries and shared libraries
@@ -76,6 +80,8 @@
 	}
 
 	if afdo.Properties.Afdo || afdo.Properties.AfdoDep {
+		// Emit additional debug info for AutoFDO
+		flags.Local.CFlags = append([]string{"-fdebug-info-for-profiling"}, flags.Local.CFlags...)
 		// 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
 		// generated for a binary without unique names doesn't work well building a binary with