Merge "apex: install hwasan lib if depended on libc"
This commit is contained in:
27
apex/apex.go
27
apex/apex.go
@@ -1451,20 +1451,8 @@ func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
|
|||||||
target,
|
target,
|
||||||
a.getImageVariation(config))
|
a.getImageVariation(config))
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
|
|
||||||
for _, sanitizer := range ctx.Config().SanitizeDevice() {
|
|
||||||
if sanitizer == "hwaddress" {
|
|
||||||
addDependenciesForNativeModules(ctx,
|
|
||||||
ApexNativeDependencies{[]string{"libclang_rt.hwasan-aarch64-android"}, nil, nil, nil},
|
|
||||||
target, a.getImageVariation(config))
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// For prebuilt_etc, use the first variant (64 on 64/32bit device,
|
// For prebuilt_etc, use the first variant (64 on 64/32bit device,
|
||||||
// 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
|
// 32 on 32bit device) regardless of the TARGET_PREFER_* setting.
|
||||||
@@ -1595,6 +1583,21 @@ func (a *apexBundle) IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizer
|
|||||||
return android.InList(sanitizerName, globalSanitizerNames)
|
return android.InList(sanitizerName, globalSanitizerNames)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *apexBundle) AddSanitizerDependencies(ctx android.BottomUpMutatorContext, sanitizerName string) {
|
||||||
|
if ctx.Device() && sanitizerName == "hwaddress" && strings.HasPrefix(a.Name(), "com.android.runtime") {
|
||||||
|
for _, target := range ctx.MultiTargets() {
|
||||||
|
if target.Arch.ArchType.Multilib == "lib64" {
|
||||||
|
ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
|
||||||
|
{Mutator: "image", Variation: a.getImageVariation(ctx.DeviceConfig())},
|
||||||
|
{Mutator: "link", Variation: "shared"},
|
||||||
|
{Mutator: "version", Variation: ""}, // "" is the non-stub variant
|
||||||
|
}...), sharedLibTag, "libclang_rt.hwasan-aarch64-android")
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var _ cc.Coverage = (*apexBundle)(nil)
|
var _ cc.Coverage = (*apexBundle)(nil)
|
||||||
|
|
||||||
func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
|
func (a *apexBundle) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool {
|
||||||
|
@@ -909,6 +909,130 @@ func TestApexWithRuntimeLibsDependency(t *testing.T) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRuntimeApexShouldInstallHwasanIfLibcDependsOnIt(t *testing.T) {
|
||||||
|
ctx, _ := testApex(t, "", func(fs map[string][]byte, config android.Config) {
|
||||||
|
bp := `
|
||||||
|
apex {
|
||||||
|
name: "com.android.runtime",
|
||||||
|
key: "com.android.runtime.key",
|
||||||
|
native_shared_libs: ["libc"],
|
||||||
|
}
|
||||||
|
|
||||||
|
apex_key {
|
||||||
|
name: "com.android.runtime.key",
|
||||||
|
public_key: "testkey.avbpubkey",
|
||||||
|
private_key: "testkey.pem",
|
||||||
|
}
|
||||||
|
|
||||||
|
cc_library {
|
||||||
|
name: "libc",
|
||||||
|
no_libcrt: true,
|
||||||
|
nocrt: true,
|
||||||
|
stl: "none",
|
||||||
|
system_shared_libs: [],
|
||||||
|
stubs: { versions: ["1"] },
|
||||||
|
apex_available: ["com.android.runtime"],
|
||||||
|
|
||||||
|
sanitize: {
|
||||||
|
hwaddress: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cc_prebuilt_library_shared {
|
||||||
|
name: "libclang_rt.hwasan-aarch64-android",
|
||||||
|
no_libcrt: true,
|
||||||
|
nocrt: true,
|
||||||
|
stl: "none",
|
||||||
|
system_shared_libs: [],
|
||||||
|
srcs: [""],
|
||||||
|
stubs: { versions: ["1"] },
|
||||||
|
|
||||||
|
sanitize: {
|
||||||
|
never: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
`
|
||||||
|
// override bp to use hard-coded names: com.android.runtime and libc
|
||||||
|
fs["Android.bp"] = []byte(bp)
|
||||||
|
fs["system/sepolicy/apex/com.android.runtime-file_contexts"] = nil
|
||||||
|
})
|
||||||
|
|
||||||
|
ensureExactContents(t, ctx, "com.android.runtime", "android_common_hwasan_com.android.runtime_image", []string{
|
||||||
|
"lib64/bionic/libc.so",
|
||||||
|
"lib64/bionic/libclang_rt.hwasan-aarch64-android.so",
|
||||||
|
})
|
||||||
|
|
||||||
|
hwasan := ctx.ModuleForTests("libclang_rt.hwasan-aarch64-android", "android_arm64_armv8-a_shared")
|
||||||
|
|
||||||
|
installed := hwasan.Description("install libclang_rt.hwasan")
|
||||||
|
ensureContains(t, installed.Output.String(), "/system/lib64/bootstrap/libclang_rt.hwasan-aarch64-android.so")
|
||||||
|
|
||||||
|
symlink := hwasan.Description("install symlink libclang_rt.hwasan")
|
||||||
|
ensureEquals(t, symlink.Args["fromPath"], "/apex/com.android.runtime/lib64/bionic/libclang_rt.hwasan-aarch64-android.so")
|
||||||
|
ensureContains(t, symlink.Output.String(), "/system/lib64/libclang_rt.hwasan-aarch64-android.so")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRuntimeApexShouldInstallHwasanIfHwaddressSanitized(t *testing.T) {
|
||||||
|
ctx, _ := testApex(t, "", func(fs map[string][]byte, config android.Config) {
|
||||||
|
bp := `
|
||||||
|
apex {
|
||||||
|
name: "com.android.runtime",
|
||||||
|
key: "com.android.runtime.key",
|
||||||
|
native_shared_libs: ["libc"],
|
||||||
|
}
|
||||||
|
|
||||||
|
apex_key {
|
||||||
|
name: "com.android.runtime.key",
|
||||||
|
public_key: "testkey.avbpubkey",
|
||||||
|
private_key: "testkey.pem",
|
||||||
|
}
|
||||||
|
|
||||||
|
cc_library {
|
||||||
|
name: "libc",
|
||||||
|
no_libcrt: true,
|
||||||
|
nocrt: true,
|
||||||
|
stl: "none",
|
||||||
|
system_shared_libs: [],
|
||||||
|
stubs: { versions: ["1"] },
|
||||||
|
apex_available: ["com.android.runtime"],
|
||||||
|
}
|
||||||
|
|
||||||
|
cc_prebuilt_library_shared {
|
||||||
|
name: "libclang_rt.hwasan-aarch64-android",
|
||||||
|
no_libcrt: true,
|
||||||
|
nocrt: true,
|
||||||
|
stl: "none",
|
||||||
|
system_shared_libs: [],
|
||||||
|
srcs: [""],
|
||||||
|
stubs: { versions: ["1"] },
|
||||||
|
|
||||||
|
sanitize: {
|
||||||
|
never: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
`
|
||||||
|
// override bp to use hard-coded names: com.android.runtime and libc
|
||||||
|
fs["Android.bp"] = []byte(bp)
|
||||||
|
fs["system/sepolicy/apex/com.android.runtime-file_contexts"] = nil
|
||||||
|
|
||||||
|
config.TestProductVariables.SanitizeDevice = []string{"hwaddress"}
|
||||||
|
})
|
||||||
|
|
||||||
|
ensureExactContents(t, ctx, "com.android.runtime", "android_common_hwasan_com.android.runtime_image", []string{
|
||||||
|
"lib64/bionic/libc.so",
|
||||||
|
"lib64/bionic/libclang_rt.hwasan-aarch64-android.so",
|
||||||
|
})
|
||||||
|
|
||||||
|
hwasan := ctx.ModuleForTests("libclang_rt.hwasan-aarch64-android", "android_arm64_armv8-a_shared")
|
||||||
|
|
||||||
|
installed := hwasan.Description("install libclang_rt.hwasan")
|
||||||
|
ensureContains(t, installed.Output.String(), "/system/lib64/bootstrap/libclang_rt.hwasan-aarch64-android.so")
|
||||||
|
|
||||||
|
symlink := hwasan.Description("install symlink libclang_rt.hwasan")
|
||||||
|
ensureEquals(t, symlink.Args["fromPath"], "/apex/com.android.runtime/lib64/bionic/libclang_rt.hwasan-aarch64-android.so")
|
||||||
|
ensureContains(t, symlink.Output.String(), "/system/lib64/libclang_rt.hwasan-aarch64-android.so")
|
||||||
|
}
|
||||||
|
|
||||||
func TestApexDependsOnLLNDKTransitively(t *testing.T) {
|
func TestApexDependsOnLLNDKTransitively(t *testing.T) {
|
||||||
testcases := []struct {
|
testcases := []struct {
|
||||||
name string
|
name string
|
||||||
|
2
cc/cc.go
2
cc/cc.go
@@ -1074,7 +1074,7 @@ func isBionic(name string) bool {
|
|||||||
|
|
||||||
func InstallToBootstrap(name string, config android.Config) bool {
|
func InstallToBootstrap(name string, config android.Config) bool {
|
||||||
if name == "libclang_rt.hwasan-aarch64-android" {
|
if name == "libclang_rt.hwasan-aarch64-android" {
|
||||||
return inList("hwaddress", config.SanitizeDevice())
|
return true
|
||||||
}
|
}
|
||||||
return isBionic(name)
|
return isBionic(name)
|
||||||
}
|
}
|
||||||
|
@@ -989,6 +989,7 @@ type Sanitizeable interface {
|
|||||||
android.Module
|
android.Module
|
||||||
IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool
|
IsSanitizerEnabled(ctx android.BaseModuleContext, sanitizerName string) bool
|
||||||
EnableSanitizer(sanitizerName string)
|
EnableSanitizer(sanitizerName string)
|
||||||
|
AddSanitizerDependencies(ctx android.BottomUpMutatorContext, sanitizerName string)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create sanitized variants for modules that need them
|
// Create sanitized variants for modules that need them
|
||||||
@@ -1075,6 +1076,7 @@ func sanitizerMutator(t sanitizerType) func(android.BottomUpMutatorContext) {
|
|||||||
c.sanitize.Properties.SanitizeDep = false
|
c.sanitize.Properties.SanitizeDep = false
|
||||||
} else if sanitizeable, ok := mctx.Module().(Sanitizeable); ok && sanitizeable.IsSanitizerEnabled(mctx, t.name()) {
|
} else if sanitizeable, ok := mctx.Module().(Sanitizeable); ok && sanitizeable.IsSanitizerEnabled(mctx, t.name()) {
|
||||||
// APEX modules fall here
|
// APEX modules fall here
|
||||||
|
sanitizeable.AddSanitizerDependencies(mctx, t.name())
|
||||||
mctx.CreateVariations(t.variationName())
|
mctx.CreateVariations(t.variationName())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user