Merge changes Ib4fe4def,I6fdecefa
* changes: Disable sanitizer for vendor_snapshot_object modules VSDK: capture hwasan static libs for vsdk snapshot build
This commit is contained in:
@@ -630,15 +630,8 @@ func (sanitize *sanitize) begin(ctx BaseModuleContext) {
|
||||
|
||||
// Also disable CFI for VNDK variants of components
|
||||
if ctx.isVndk() && ctx.useVndk() {
|
||||
if ctx.static() {
|
||||
// Cfi variant for static vndk should be captured as vendor snapshot,
|
||||
// so don't strictly disable Cfi.
|
||||
s.Cfi = nil
|
||||
s.Diag.Cfi = nil
|
||||
} else {
|
||||
s.Cfi = nil
|
||||
s.Diag.Cfi = nil
|
||||
}
|
||||
s.Cfi = nil
|
||||
s.Diag.Cfi = nil
|
||||
}
|
||||
|
||||
// HWASan ramdisk (which is built from recovery) goes over some bootloader limit.
|
||||
@@ -1067,6 +1060,11 @@ func (m *Module) SanitizableDepTagChecker() SantizableDependencyTagChecker {
|
||||
// as vendor snapshot. Such modules must create both cfi and non-cfi variants,
|
||||
// except for ones which explicitly disable cfi.
|
||||
func needsCfiForVendorSnapshot(mctx android.BaseModuleContext) bool {
|
||||
if inList("hwaddress", mctx.Config().SanitizeDevice()) {
|
||||
// cfi will not be built if SANITIZE_TARGET=hwaddress is set
|
||||
return false
|
||||
}
|
||||
|
||||
if snapshot.IsVendorProprietaryModule(mctx) {
|
||||
return false
|
||||
}
|
||||
@@ -1163,10 +1161,12 @@ func (s *sanitizerSplitMutator) Split(ctx android.BaseModuleContext) []string {
|
||||
//TODO: When Rust modules have vendor support, enable this path for PlatformSanitizeable
|
||||
|
||||
// Check if it's a snapshot module supporting sanitizer
|
||||
if ss, ok := c.linker.(snapshotSanitizer); ok && ss.isSanitizerAvailable(s.sanitizer) {
|
||||
return []string{"", s.sanitizer.variationName()}
|
||||
} else {
|
||||
return []string{""}
|
||||
if ss, ok := c.linker.(snapshotSanitizer); ok {
|
||||
if ss.isSanitizerAvailable(s.sanitizer) {
|
||||
return []string{"", s.sanitizer.variationName()}
|
||||
} else {
|
||||
return []string{""}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -801,6 +801,10 @@ func VendorSnapshotObjectFactory() android.Module {
|
||||
|
||||
prebuilt.Init(module, VendorSnapshotImageSingleton, snapshotObjectSuffix)
|
||||
module.AddProperties(&prebuilt.properties)
|
||||
|
||||
// vendor_snapshot_object module does not provide sanitizer variants
|
||||
module.sanitize.Properties.Sanitize.Never = BoolPtr(true)
|
||||
|
||||
return module.Init()
|
||||
}
|
||||
|
||||
|
@@ -93,17 +93,18 @@ func isSnapshotAware(cfg android.DeviceConfig, m LinkableInterface, inProprietar
|
||||
// Libraries
|
||||
if sanitizable, ok := m.(PlatformSanitizeable); ok && sanitizable.IsSnapshotLibrary() {
|
||||
if sanitizable.SanitizePropDefined() {
|
||||
// scs and hwasan export both sanitized and unsanitized variants for static and header
|
||||
// Always use unsanitized variants of them.
|
||||
for _, t := range []SanitizerType{scs, Hwasan} {
|
||||
if !sanitizable.Shared() && sanitizable.IsSanitizerEnabled(t) {
|
||||
return false
|
||||
}
|
||||
// scs exports both sanitized and unsanitized variants for static and header
|
||||
// Always use unsanitized variant of it.
|
||||
if !sanitizable.Shared() && sanitizable.IsSanitizerEnabled(scs) {
|
||||
return false
|
||||
}
|
||||
// cfi also exports both variants. But for static, we capture both.
|
||||
// cfi and hwasan also export both variants. But for static, we capture both.
|
||||
// This is because cfi static libraries can't be linked from non-cfi modules,
|
||||
// and vice versa. This isn't the case for scs and hwasan sanitizers.
|
||||
if !sanitizable.Static() && !sanitizable.Shared() && sanitizable.IsSanitizerEnabled(cfi) {
|
||||
// and vice versa.
|
||||
// hwasan is captured as well to support hwasan build.
|
||||
if !sanitizable.Static() &&
|
||||
!sanitizable.Shared() &&
|
||||
(sanitizable.IsSanitizerEnabled(cfi) || sanitizable.IsSanitizerEnabled(Hwasan)) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -303,14 +304,22 @@ var ccSnapshotAction snapshot.GenerateSnapshotAction = func(s snapshot.SnapshotS
|
||||
libPath := m.OutputFile().Path()
|
||||
stem = libPath.Base()
|
||||
if sanitizable, ok := m.(PlatformSanitizeable); ok {
|
||||
if (sanitizable.Static() || sanitizable.Rlib()) && sanitizable.SanitizePropDefined() && sanitizable.IsSanitizerEnabled(cfi) {
|
||||
// both cfi and non-cfi variant for static libraries can exist.
|
||||
// attach .cfi to distinguish between cfi and non-cfi.
|
||||
// e.g. libbase.a -> libbase.cfi.a
|
||||
ext := filepath.Ext(stem)
|
||||
stem = strings.TrimSuffix(stem, ext) + ".cfi" + ext
|
||||
prop.Sanitize = "cfi"
|
||||
prop.ModuleName += ".cfi"
|
||||
if (sanitizable.Static() || sanitizable.Rlib()) && sanitizable.SanitizePropDefined() {
|
||||
if sanitizable.IsSanitizerEnabled(cfi) {
|
||||
// both cfi and non-cfi variant for static libraries can exist.
|
||||
// attach .cfi to distinguish between cfi and non-cfi.
|
||||
// e.g. libbase.a -> libbase.cfi.a
|
||||
ext := filepath.Ext(stem)
|
||||
stem = strings.TrimSuffix(stem, ext) + ".cfi" + ext
|
||||
prop.Sanitize = "cfi"
|
||||
prop.ModuleName += ".cfi"
|
||||
} else if sanitizable.IsSanitizerEnabled(Hwasan) {
|
||||
// Same for the hwasan
|
||||
ext := filepath.Ext(stem)
|
||||
stem = strings.TrimSuffix(stem, ext) + ".hwasan" + ext
|
||||
prop.Sanitize = "hwasan"
|
||||
prop.ModuleName += ".hwasan"
|
||||
}
|
||||
}
|
||||
}
|
||||
snapshotLibOut := filepath.Join(snapshotArchDir, targetArch, libType, stem)
|
||||
|
@@ -1050,6 +1050,12 @@ func TestVendorSnapshotSanitizer(t *testing.T) {
|
||||
"libsnapshot",
|
||||
"note_memtag_heap_sync",
|
||||
],
|
||||
objects: [
|
||||
"snapshot_object",
|
||||
],
|
||||
vndk_libs: [
|
||||
"libclang_rt.hwasan",
|
||||
],
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -1084,6 +1090,35 @@ func TestVendorSnapshotSanitizer(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
vndk_prebuilt_shared {
|
||||
name: "libclang_rt.hwasan",
|
||||
version: "28",
|
||||
target_arch: "arm64",
|
||||
vendor_available: true,
|
||||
product_available: true,
|
||||
vndk: {
|
||||
enabled: true,
|
||||
},
|
||||
arch: {
|
||||
arm64: {
|
||||
srcs: ["libclang_rt.hwasan.so"],
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
vendor_snapshot_object {
|
||||
name: "snapshot_object",
|
||||
vendor: true,
|
||||
target_arch: "arm64",
|
||||
version: "28",
|
||||
arch: {
|
||||
arm64: {
|
||||
src: "snapshot_object.o",
|
||||
},
|
||||
},
|
||||
stl: "none",
|
||||
}
|
||||
|
||||
cc_test {
|
||||
name: "vstest",
|
||||
gtest: false,
|
||||
@@ -1100,15 +1135,18 @@ func TestVendorSnapshotSanitizer(t *testing.T) {
|
||||
mockFS := map[string][]byte{
|
||||
"vendor/Android.bp": []byte(bp),
|
||||
"vendor/libc++demangle.a": nil,
|
||||
"vendor/libclang_rt.hwasan.so": nil,
|
||||
"vendor/libsnapshot.a": nil,
|
||||
"vendor/libsnapshot.cfi.a": nil,
|
||||
"vendor/libsnapshot.hwasan.a": nil,
|
||||
"vendor/note_memtag_heap_sync.a": nil,
|
||||
"vendor/snapshot_object.o": nil,
|
||||
}
|
||||
|
||||
config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
|
||||
config.TestProductVariables.DeviceVndkVersion = StringPtr("28")
|
||||
config.TestProductVariables.Platform_vndk_version = StringPtr("29")
|
||||
config.TestProductVariables.SanitizeDevice = []string{"hwaddress"}
|
||||
ctx := testCcWithConfig(t, config)
|
||||
|
||||
// Check non-cfi, cfi and hwasan variant.
|
||||
@@ -1130,6 +1168,11 @@ func TestVendorSnapshotSanitizer(t *testing.T) {
|
||||
if !staticHwasanCfiModule.HiddenFromMake() || !staticHwasanCfiModule.PreventInstall() {
|
||||
t.Errorf("Hwasan and Cfi cannot enabled at the same time.")
|
||||
}
|
||||
|
||||
snapshotObjModule := ctx.ModuleForTests("snapshot_object.vendor_object.28.arm64", "android_vendor.28_arm64_armv8-a").Module()
|
||||
snapshotObjMkEntries := android.AndroidMkEntriesForTest(t, ctx, snapshotObjModule)
|
||||
// snapshot object must not add ".hwasan" suffix
|
||||
assertString(t, snapshotObjMkEntries[0].EntryMap["LOCAL_MODULE"][0], "snapshot_object")
|
||||
}
|
||||
|
||||
func TestVendorSnapshotExclude(t *testing.T) {
|
||||
|
Reference in New Issue
Block a user