From 5007c4a06d7452c7b8dbed2910665d6719d0d390 Mon Sep 17 00:00:00 2001 From: Mitch Phillips Date: Wed, 2 Mar 2022 01:25:22 +0000 Subject: [PATCH] Revert "[cc_fuzz] Revert 'disable LTO' patches." Revert submission 1976512-revert-nolto-fuzzing Reason for revert: b/222160662 Reverted Changes: Iacee4fa29:[cc_fuzz] Revert 'disable LTO' patches. Ic509b00a1:[cc_fuzz] Revert 'disable LTO' patches. If85931f09:[cc_fuzz] Revert 'disable LTO' patches. Change-Id: I84e01a4f84145e3331c2955836c8cc9bfa05c36b --- cc/lto.go | 6 ++++++ cc/sanitize.go | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/cc/lto.go b/cc/lto.go index a48a12ce4..6d555790c 100644 --- a/cc/lto.go +++ b/cc/lto.go @@ -82,6 +82,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.Local.CFlags) { + return flags + } + if lto.LTO(ctx) { var ltoCFlag string var ltoLdFlag string diff --git a/cc/sanitize.go b/cc/sanitize.go index 9e047d5d1..6c6882217 100644 --- a/cc/sanitize.go +++ b/cc/sanitize.go @@ -540,6 +540,12 @@ func (sanitize *sanitize) begin(ctx BaseModuleContext) { s.Address = nil s.Thread = nil } + + // TODO(b/131771163): CFI transiently depends on LTO, and thus Fuzzer is + // mutually incompatible. + if Bool(s.Fuzzer) { + s.Cfi = nil + } } func toDisableImplicitIntegerChange(flags []string) bool { @@ -642,6 +648,12 @@ func (sanitize *sanitize) flags(ctx ModuleContext, flags Flags) Flags { if Bool(sanitize.Properties.Sanitize.Fuzzer) { flags.Local.CFlags = append(flags.Local.CFlags, "-fsanitize=fuzzer-no-link") + // TODO(b/131771163): LTO and Fuzzer support is mutually incompatible. + _, flags.Local.LdFlags = removeFromList("-flto", flags.Local.LdFlags) + _, flags.Local.CFlags = removeFromList("-flto", flags.Local.CFlags) + flags.Local.LdFlags = append(flags.Local.LdFlags, "-fno-lto") + flags.Local.CFlags = append(flags.Local.CFlags, "-fno-lto") + // TODO(b/142430592): Upstream linker scripts for sanitizer runtime libraries // discard the sancov_lowest_stack symbol, because it's emulated TLS (and thus // doesn't match the linker script due to the "__emutls_v." prefix).