Disable LTO when building with fuzzer support.
Bug: 131771163 LTO is currently broken when building with SANITIZE_TARGET=fuzzer. The compiler bug is currently being addressed upstream (see linked bug), but we have applied a local workaround in the build system to disable LTO when building using the fuzzer config. There is a bug here however. In the sanitizer mutator we explicitly remove -flto and add -fno-lto. The sanitizer mutator runs after the LTO mutator, so (in general) this works just fine. The problem exists when a target specifies an explicit 'lto: { ... }' flag in their Android.bp. In this case, the sanitizer mutator disables LTO, then the flags are parsed from the Android.bp, re-enabling LTO. This patch fixes this issue. If the sanitizer mutator has added the -fsanitize=fuzzer-no-link flags, then the LTO mutator won't add the LTO flags after this fact. Test: Build a target with SANITIZE_TARGET=fuzzer (or a cc_fuzz target), where there is an explitiy 'lto: { ... }' and watch it now succeed in building. Change-Id: I6643909417f666539c23469816926b806e204b06
This commit is contained in:
@@ -80,6 +80,12 @@ func (lto *lto) useClangLld(ctx BaseModuleContext) bool {
|
||||
}
|
||||
|
||||
func (lto *lto) flags(ctx BaseModuleContext, flags Flags) Flags {
|
||||
// TODO(b/131771163): Disable LTO when using explicit fuzzing configurations.
|
||||
// LTO breaks fuzzer builds.
|
||||
if inList("-fsanitize=fuzzer-no-link", flags.CFlags) {
|
||||
return flags
|
||||
}
|
||||
|
||||
if lto.LTO() {
|
||||
var ltoFlag string
|
||||
if Bool(lto.Properties.Lto.Thin) {
|
||||
|
@@ -464,7 +464,9 @@ func (sanitize *sanitize) flags(ctx ModuleContext, flags Flags) Flags {
|
||||
|
||||
// TODO(b/131771163): LTO and Fuzzer support is mutually incompatible.
|
||||
_, flags.LdFlags = removeFromList("-flto", flags.LdFlags)
|
||||
_, flags.CFlags = removeFromList("-flto", flags.CFlags)
|
||||
flags.LdFlags = append(flags.LdFlags, "-fno-lto")
|
||||
flags.CFlags = append(flags.CFlags, "-fno-lto")
|
||||
|
||||
// TODO(b/133876586): Experimental PM breaks sanitizer coverage.
|
||||
_, flags.CFlags = removeFromList("-fexperimental-new-pass-manager", flags.CFlags)
|
||||
|
Reference in New Issue
Block a user