diff options
author | 2020-09-15 02:32:35 +0100 | |
---|---|---|
committer | 2020-09-25 00:33:04 +0100 | |
commit | b024957791e7337167b8209c8b3d2a5ca9cb636e (patch) | |
tree | bed9c26ab07eff4fb0ce16b4a7c15b9478cae34d /cc | |
parent | 191c25f589c8018fddb5c3c4e12888c25ae61365 (diff) |
Propagate all sanitizer flags in SDK snapshots.
liblog snapshot needs to sanitizer.address=false to avoid cycle in asan
builds. Adding that separately in library_sdk_member.go would start to
feel like whack-a-mole, so the snapshot generation is instead extended
to handle nested property structs.
This uses the BpPropertySet.AddProperty extension in
https://r.android.com/1423510, and common value optimisation now
recurses into non-anonymous structs, instead of comparing them as a
whole.
Test: m nothing
Test: `m SANITIZE_TARGET=address nothing` with prebuilts/runtime
present in the manifest and a fresh snapshot made with this
Bug: 151303681
Change-Id: I472554117a488e6c800045cb2ed59377778571a4
Diffstat (limited to 'cc')
-rw-r--r-- | cc/library_sdk_member.go | 15 | ||||
-rw-r--r-- | cc/sanitize.go | 95 |
2 files changed, 56 insertions, 54 deletions
diff --git a/cc/library_sdk_member.go b/cc/library_sdk_member.go index 2f1554427..a1de84bc5 100644 --- a/cc/library_sdk_member.go +++ b/cc/library_sdk_member.go @@ -221,10 +221,7 @@ var includeDirProperties = []includeDirsProperty{ // Add properties that may, or may not, be arch specific. func addPossiblyArchSpecificProperties(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, libInfo *nativeLibInfoProperties, outputProperties android.BpPropertySet) { - if libInfo.SanitizeNever { - sanitizeSet := outputProperties.AddPropertySet("sanitize") - sanitizeSet.AddProperty("never", true) - } + outputProperties.AddProperty("sanitize", &libInfo.Sanitize) // Copy the generated library to the snapshot and add a reference to it in the .bp module. if libInfo.outputFile != nil { @@ -373,8 +370,10 @@ type nativeLibInfoProperties struct { // not vary by arch so cannot be android specific. StubsVersion string `sdk:"ignored-on-host"` - // Value of SanitizeProperties.Sanitize.Never. Needs to be propagated for CRT objects. - SanitizeNever bool `android:"arch_variant"` + // Value of SanitizeProperties.Sanitize. Several - but not all - of these + // affect the expanded variants. All are propagated to avoid entangling the + // sanitizer logic with the snapshot generation. + Sanitize SanitizeUserProps `android:"arch_variant"` // outputFile is not exported as it is always arch specific. outputFile android.Path @@ -423,8 +422,8 @@ func (p *nativeLibInfoProperties) PopulateFromVariant(ctx android.SdkMemberConte p.StubsVersion = ccModule.StubsVersion() } - if ccModule.sanitize != nil && proptools.Bool(ccModule.sanitize.Properties.Sanitize.Never) { - p.SanitizeNever = true + if ccModule.sanitize != nil { + p.Sanitize = ccModule.sanitize.Properties.Sanitize } } diff --git a/cc/sanitize.go b/cc/sanitize.go index 174dcfea5..8c3e97af3 100644 --- a/cc/sanitize.go +++ b/cc/sanitize.go @@ -139,56 +139,59 @@ func (t sanitizerType) incompatibleWithCfi() bool { return t == asan || t == fuzzer || t == hwasan } -type SanitizeProperties struct { - // enable AddressSanitizer, ThreadSanitizer, or UndefinedBehaviorSanitizer - Sanitize struct { - Never *bool `android:"arch_variant"` - - // main sanitizers - Address *bool `android:"arch_variant"` - Thread *bool `android:"arch_variant"` - Hwaddress *bool `android:"arch_variant"` - - // local sanitizers +type SanitizeUserProps struct { + Never *bool `android:"arch_variant"` + + // main sanitizers + Address *bool `android:"arch_variant"` + Thread *bool `android:"arch_variant"` + Hwaddress *bool `android:"arch_variant"` + + // local sanitizers + Undefined *bool `android:"arch_variant"` + All_undefined *bool `android:"arch_variant"` + Misc_undefined []string `android:"arch_variant"` + Fuzzer *bool `android:"arch_variant"` + Safestack *bool `android:"arch_variant"` + Cfi *bool `android:"arch_variant"` + Integer_overflow *bool `android:"arch_variant"` + Scudo *bool `android:"arch_variant"` + Scs *bool `android:"arch_variant"` + + // A modifier for ASAN and HWASAN for write only instrumentation + Writeonly *bool `android:"arch_variant"` + + // Sanitizers to run in the diagnostic mode (as opposed to the release mode). + // Replaces abort() on error with a human-readable error message. + // Address and Thread sanitizers always run in diagnostic mode. + Diag struct { Undefined *bool `android:"arch_variant"` - All_undefined *bool `android:"arch_variant"` - Misc_undefined []string `android:"arch_variant"` - Fuzzer *bool `android:"arch_variant"` - Safestack *bool `android:"arch_variant"` Cfi *bool `android:"arch_variant"` Integer_overflow *bool `android:"arch_variant"` - Scudo *bool `android:"arch_variant"` - Scs *bool `android:"arch_variant"` - - // A modifier for ASAN and HWASAN for write only instrumentation - Writeonly *bool `android:"arch_variant"` - - // Sanitizers to run in the diagnostic mode (as opposed to the release mode). - // Replaces abort() on error with a human-readable error message. - // Address and Thread sanitizers always run in diagnostic mode. - Diag struct { - Undefined *bool `android:"arch_variant"` - Cfi *bool `android:"arch_variant"` - Integer_overflow *bool `android:"arch_variant"` - Misc_undefined []string `android:"arch_variant"` - No_recover []string - } + Misc_undefined []string `android:"arch_variant"` + No_recover []string + } + + // value to pass to -fsanitize-recover= + Recover []string - // value to pass to -fsanitize-recover= - Recover []string - - // value to pass to -fsanitize-blacklist - Blocklist *string - } `android:"arch_variant"` - - SanitizerEnabled bool `blueprint:"mutated"` - SanitizeDep bool `blueprint:"mutated"` - MinimalRuntimeDep bool `blueprint:"mutated"` - BuiltinsDep bool `blueprint:"mutated"` - UbsanRuntimeDep bool `blueprint:"mutated"` - InSanitizerDir bool `blueprint:"mutated"` - Sanitizers []string `blueprint:"mutated"` - DiagSanitizers []string `blueprint:"mutated"` + // value to pass to -fsanitize-blacklist + Blocklist *string +} + +type SanitizeProperties struct { + // Enable AddressSanitizer, ThreadSanitizer, UndefinedBehaviorSanitizer, and + // others. Please see SanitizerUserProps in build/soong/cc/sanitize.go for + // details. + Sanitize SanitizeUserProps `android:"arch_variant"` + SanitizerEnabled bool `blueprint:"mutated"` + SanitizeDep bool `blueprint:"mutated"` + MinimalRuntimeDep bool `blueprint:"mutated"` + BuiltinsDep bool `blueprint:"mutated"` + UbsanRuntimeDep bool `blueprint:"mutated"` + InSanitizerDir bool `blueprint:"mutated"` + Sanitizers []string `blueprint:"mutated"` + DiagSanitizers []string `blueprint:"mutated"` } type sanitize struct { |