diff options
Diffstat (limited to 'cc')
| -rw-r--r-- | cc/afdo.go | 5 | ||||
| -rw-r--r-- | cc/config/global.go | 2 | ||||
| -rw-r--r-- | cc/lto.go | 35 |
3 files changed, 22 insertions, 20 deletions
diff --git a/cc/afdo.go b/cc/afdo.go index 137ea97fe..bc7cd5212 100644 --- a/cc/afdo.go +++ b/cc/afdo.go @@ -34,7 +34,8 @@ var ( var afdoProfileProjectsConfigKey = android.NewOnceKey("AfdoProfileProjects") -const afdoCFlagsFormat = "-fprofile-sample-use=%s" +// This flag needs to be in both CFlags and LdFlags to ensure correct symbol ordering +const afdoFlagsFormat = "-fprofile-sample-use=%s" func recordMissingAfdoProfileFile(ctx android.BaseModuleContext, missing string) { getNamedMapForConfig(ctx.Config(), modulesMissingProfileFileKey).Store(missing, true) @@ -86,7 +87,7 @@ func (afdo *afdo) flags(ctx ModuleContext, flags Flags) Flags { } if path := afdo.Properties.FdoProfilePath; path != nil { // The flags are prepended to allow overriding. - profileUseFlag := fmt.Sprintf(afdoCFlagsFormat, *path) + profileUseFlag := fmt.Sprintf(afdoFlagsFormat, *path) flags.Local.CFlags = append([]string{profileUseFlag}, flags.Local.CFlags...) flags.Local.LdFlags = append([]string{profileUseFlag, "-Wl,-mllvm,-no-warn-sample-unused=true"}, flags.Local.LdFlags...) diff --git a/cc/config/global.go b/cc/config/global.go index e450ba7ba..013b6592b 100644 --- a/cc/config/global.go +++ b/cc/config/global.go @@ -305,7 +305,7 @@ var ( // prebuilts/clang default settings. ClangDefaultBase = "prebuilts/clang/host" - ClangDefaultVersion = "clang-r487747c" + ClangDefaultVersion = "clang-r498229" ClangDefaultShortVersion = "17" // Directories with warnings from Android.bp files. @@ -76,43 +76,44 @@ func (lto *lto) flags(ctx BaseModuleContext, flags Flags) Flags { return flags } if lto.Properties.LtoEnabled { - var ltoCFlag string - var ltoLdFlag string - if lto.ThinLTO() { - ltoCFlag = "-flto=thin -fsplit-lto-unit" - } else { - ltoCFlag = "-flto=thin -fsplit-lto-unit" - ltoLdFlag = "-Wl,--lto-O0" + ltoCFlags := []string{"-flto=thin", "-fsplit-lto-unit"} + var ltoLdFlags []string + + // The module did not explicitly turn on LTO. Only leverage LTO's + // better dead code elinmination and CFG simplification, but do + // not perform costly optimizations for a balance between compile + // time, binary size and performance. + if !lto.ThinLTO() { + ltoLdFlags = append(ltoLdFlags, "-Wl,--lto-O0") } - flags.Local.CFlags = append(flags.Local.CFlags, ltoCFlag) - flags.Local.AsFlags = append(flags.Local.AsFlags, ltoCFlag) - flags.Local.LdFlags = append(flags.Local.LdFlags, ltoCFlag) - flags.Local.LdFlags = append(flags.Local.LdFlags, ltoLdFlag) - if Bool(lto.Properties.Whole_program_vtables) { - flags.Local.CFlags = append(flags.Local.CFlags, "-fwhole-program-vtables") + ltoCFlags = append(ltoCFlags, "-fwhole-program-vtables") } if ctx.Config().IsEnvTrue("USE_THINLTO_CACHE") { // Set appropriate ThinLTO cache policy cacheDirFormat := "-Wl,--thinlto-cache-dir=" cacheDir := android.PathForOutput(ctx, "thinlto-cache").String() - flags.Local.LdFlags = append(flags.Local.LdFlags, cacheDirFormat+cacheDir) + ltoLdFlags = append(ltoLdFlags, cacheDirFormat+cacheDir) // Limit the size of the ThinLTO cache to the lesser of 10% of available // disk space and 10GB. cachePolicyFormat := "-Wl,--thinlto-cache-policy=" policy := "cache_size=10%:cache_size_bytes=10g" - flags.Local.LdFlags = append(flags.Local.LdFlags, cachePolicyFormat+policy) + ltoLdFlags = append(ltoLdFlags, cachePolicyFormat+policy) } // If the module does not have a profile, be conservative and limit cross TU inline // limit to 5 LLVM IR instructions, to balance binary size increase and performance. if !ctx.Darwin() && !ctx.isPgoCompile() && !ctx.isAfdoCompile() { - flags.Local.LdFlags = append(flags.Local.LdFlags, - "-Wl,-plugin-opt,-import-instr-limit=5") + ltoLdFlags = append(ltoLdFlags, "-Wl,-plugin-opt,-import-instr-limit=5") } + + flags.Local.CFlags = append(flags.Local.CFlags, ltoCFlags...) + flags.Local.AsFlags = append(flags.Local.AsFlags, ltoCFlags...) + flags.Local.LdFlags = append(flags.Local.LdFlags, ltoCFlags...) + flags.Local.LdFlags = append(flags.Local.LdFlags, ltoLdFlags...) } return flags } |