Move sanitizer.libraries.txt logic into Soong
Currently sanitizer.libraries.txt module is defined from Makefile, while all logics to create the list of modules is implmented within the Soong. This change moves sanitizer.libraries.txt module definition into Soong, so it can be generated without sharing list of modules over Make variable. Bug: 339131599 Test: AOSP CF build succeeded, with same list of modules in /system/etc/sanitizer.libraries.txt Change-Id: I987684877aa8dae221a03227d784f2a8ca4f5cc4
This commit is contained in:
152
cc/sanitize.go
152
cc/sanitize.go
@@ -25,6 +25,7 @@ import (
|
||||
|
||||
"android/soong/android"
|
||||
"android/soong/cc/config"
|
||||
"android/soong/etc"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -408,6 +409,8 @@ func init() {
|
||||
android.RegisterMakeVarsProvider(pctx, cfiMakeVarsProvider)
|
||||
android.RegisterMakeVarsProvider(pctx, hwasanMakeVarsProvider)
|
||||
android.RegisterMakeVarsProvider(pctx, memtagStackMakeVarsProvider)
|
||||
|
||||
RegisterSanitizerLibrariesTxtType(android.InitRegistrationContext)
|
||||
}
|
||||
|
||||
func (sanitize *sanitize) props() []interface{} {
|
||||
@@ -1316,7 +1319,7 @@ func (s *sanitizerSplitMutator) Mutate(mctx android.BottomUpMutatorContext, vari
|
||||
} else if s.sanitizer == cfi {
|
||||
cfiStaticLibs(mctx.Config()).add(c, c.Module().Name())
|
||||
} else if s.sanitizer == Memtag_stack {
|
||||
memtagStackStaticLibs(mctx.Config()).add(c, c.Module().Name());
|
||||
memtagStackStaticLibs(mctx.Config()).add(c, c.Module().Name())
|
||||
}
|
||||
}
|
||||
} else if c.IsSanitizerEnabled(s.sanitizer) {
|
||||
@@ -1522,25 +1525,25 @@ func sanitizerRuntimeMutator(mctx android.BottomUpMutatorContext) {
|
||||
if Bool(sanProps.Address) {
|
||||
if toolchain.Musl() || (c.staticBinary() && toolchain.Bionic()) {
|
||||
// Use a static runtime for musl to match what clang does for glibc.
|
||||
addStaticDeps(config.AddressSanitizerStaticRuntimeLibrary(toolchain), false)
|
||||
addStaticDeps(config.AddressSanitizerCXXStaticRuntimeLibrary(toolchain), false)
|
||||
addStaticDeps(config.AddressSanitizerStaticRuntimeLibrary(), false)
|
||||
addStaticDeps(config.AddressSanitizerCXXStaticRuntimeLibrary(), false)
|
||||
} else {
|
||||
runtimeSharedLibrary = config.AddressSanitizerRuntimeLibrary(toolchain)
|
||||
runtimeSharedLibrary = config.AddressSanitizerRuntimeLibrary()
|
||||
}
|
||||
} else if Bool(sanProps.Hwaddress) {
|
||||
if c.staticBinary() {
|
||||
addStaticDeps(config.HWAddressSanitizerStaticLibrary(toolchain), true)
|
||||
addStaticDeps(config.HWAddressSanitizerStaticLibrary(), true)
|
||||
addStaticDeps("libdl", false)
|
||||
} else {
|
||||
runtimeSharedLibrary = config.HWAddressSanitizerRuntimeLibrary(toolchain)
|
||||
runtimeSharedLibrary = config.HWAddressSanitizerRuntimeLibrary()
|
||||
}
|
||||
} else if Bool(sanProps.Thread) {
|
||||
runtimeSharedLibrary = config.ThreadSanitizerRuntimeLibrary(toolchain)
|
||||
runtimeSharedLibrary = config.ThreadSanitizerRuntimeLibrary()
|
||||
} else if Bool(sanProps.Scudo) {
|
||||
if len(diagSanitizers) == 0 && !c.sanitize.Properties.UbsanRuntimeDep {
|
||||
runtimeSharedLibrary = config.ScudoMinimalRuntimeLibrary(toolchain)
|
||||
runtimeSharedLibrary = config.ScudoMinimalRuntimeLibrary()
|
||||
} else {
|
||||
runtimeSharedLibrary = config.ScudoRuntimeLibrary(toolchain)
|
||||
runtimeSharedLibrary = config.ScudoRuntimeLibrary()
|
||||
}
|
||||
} else if len(diagSanitizers) > 0 || c.sanitize.Properties.UbsanRuntimeDep ||
|
||||
Bool(sanProps.Fuzzer) ||
|
||||
@@ -1553,17 +1556,17 @@ func sanitizerRuntimeMutator(mctx android.BottomUpMutatorContext) {
|
||||
// Also manually add a static runtime for musl to match what clang does for glibc.
|
||||
// Otherwise dlopening libraries that depend on libclang_rt.ubsan_standalone.so fails with:
|
||||
// Error relocating ...: initial-exec TLS resolves to dynamic definition
|
||||
addStaticDeps(config.UndefinedBehaviorSanitizerRuntimeLibrary(toolchain)+".static", true)
|
||||
addStaticDeps(config.UndefinedBehaviorSanitizerRuntimeLibrary()+".static", true)
|
||||
} else {
|
||||
runtimeSharedLibrary = config.UndefinedBehaviorSanitizerRuntimeLibrary(toolchain)
|
||||
runtimeSharedLibrary = config.UndefinedBehaviorSanitizerRuntimeLibrary()
|
||||
}
|
||||
}
|
||||
|
||||
if enableMinimalRuntime(c.sanitize) || c.sanitize.Properties.MinimalRuntimeDep {
|
||||
addStaticDeps(config.UndefinedBehaviorSanitizerMinimalRuntimeLibrary(toolchain), true)
|
||||
addStaticDeps(config.UndefinedBehaviorSanitizerMinimalRuntimeLibrary(), true)
|
||||
}
|
||||
if c.sanitize.Properties.BuiltinsDep {
|
||||
addStaticDeps(config.BuiltinsRuntimeLibrary(toolchain), true)
|
||||
addStaticDeps(config.BuiltinsRuntimeLibrary(), true)
|
||||
}
|
||||
|
||||
if runtimeSharedLibrary != "" && (toolchain.Bionic() || toolchain.Musl()) {
|
||||
@@ -1787,3 +1790,126 @@ func hwasanMakeVarsProvider(ctx android.MakeVarsContext) {
|
||||
func memtagStackMakeVarsProvider(ctx android.MakeVarsContext) {
|
||||
memtagStackStaticLibs(ctx.Config()).exportToMake(ctx)
|
||||
}
|
||||
|
||||
type sanitizerLibrariesTxtModule struct {
|
||||
android.ModuleBase
|
||||
|
||||
outputFile android.OutputPath
|
||||
}
|
||||
|
||||
var _ etc.PrebuiltEtcModule = (*sanitizerLibrariesTxtModule)(nil)
|
||||
var _ android.OutputFileProducer = (*sanitizerLibrariesTxtModule)(nil)
|
||||
|
||||
func RegisterSanitizerLibrariesTxtType(ctx android.RegistrationContext) {
|
||||
ctx.RegisterModuleType("sanitizer_libraries_txt", sanitizerLibrariesTxtFactory)
|
||||
}
|
||||
|
||||
func sanitizerLibrariesTxtFactory() android.Module {
|
||||
m := &sanitizerLibrariesTxtModule{}
|
||||
android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
|
||||
return m
|
||||
}
|
||||
|
||||
type sanitizerLibraryDependencyTag struct {
|
||||
blueprint.BaseDependencyTag
|
||||
}
|
||||
|
||||
func (t sanitizerLibraryDependencyTag) AllowDisabledModuleDependency(target android.Module) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
var _ android.AllowDisabledModuleDependency = (*sanitizerLibraryDependencyTag)(nil)
|
||||
|
||||
func (txt *sanitizerLibrariesTxtModule) DepsMutator(actx android.BottomUpMutatorContext) {
|
||||
targets := actx.Config().Targets[android.Android]
|
||||
depTag := sanitizerLibraryDependencyTag{}
|
||||
|
||||
for _, target := range targets {
|
||||
variation := append(target.Variations(),
|
||||
blueprint.Variation{Mutator: "image", Variation: ""},
|
||||
blueprint.Variation{Mutator: "sdk", Variation: ""},
|
||||
blueprint.Variation{Mutator: "link", Variation: "shared"},
|
||||
)
|
||||
for _, lib := range android.SortedStringValues(sanitizerVariables) {
|
||||
if actx.OtherModuleFarDependencyVariantExists(variation, lib) {
|
||||
actx.AddFarVariationDependencies(variation, depTag, lib)
|
||||
}
|
||||
|
||||
prebuiltLibName := "prebuilt_" + lib
|
||||
if actx.OtherModuleFarDependencyVariantExists(variation, prebuiltLibName) {
|
||||
actx.AddFarVariationDependencies(variation, depTag, prebuiltLibName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (txt *sanitizerLibrariesTxtModule) getSanitizerLibs(ctx android.ModuleContext) string {
|
||||
var sanitizerLibStems []string
|
||||
|
||||
ctx.VisitDirectDepsIf(func(m android.Module) bool {
|
||||
if !m.Enabled(ctx) {
|
||||
return false
|
||||
}
|
||||
|
||||
ccModule, _ := m.(*Module)
|
||||
if ccModule == nil || ccModule.library == nil || !ccModule.library.shared() {
|
||||
return false
|
||||
}
|
||||
|
||||
targets := ctx.Config().Targets[android.Android]
|
||||
|
||||
for _, target := range targets {
|
||||
if m.Target().Os == target.Os && m.Target().Arch.ArchType == target.Arch.ArchType {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}, func(m android.Module) {
|
||||
ccModule, _ := m.(*Module)
|
||||
outputFile := ccModule.outputFile
|
||||
if outputFile.Valid() {
|
||||
sanitizerLibStems = append(sanitizerLibStems, outputFile.Path().Base())
|
||||
}
|
||||
})
|
||||
|
||||
sanitizerLibStems = android.SortedUniqueStrings(sanitizerLibStems)
|
||||
return strings.Join(sanitizerLibStems, "\n")
|
||||
}
|
||||
|
||||
func (txt *sanitizerLibrariesTxtModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||
filename := txt.Name()
|
||||
|
||||
txt.outputFile = android.PathForModuleOut(ctx, filename).OutputPath
|
||||
android.WriteFileRule(ctx, txt.outputFile, txt.getSanitizerLibs(ctx))
|
||||
|
||||
installPath := android.PathForModuleInstall(ctx, "etc")
|
||||
ctx.InstallFile(installPath, filename, txt.outputFile)
|
||||
}
|
||||
|
||||
func (txt *sanitizerLibrariesTxtModule) AndroidMkEntries() []android.AndroidMkEntries {
|
||||
return []android.AndroidMkEntries{{
|
||||
Class: "ETC",
|
||||
OutputFile: android.OptionalPathForPath(txt.outputFile),
|
||||
}}
|
||||
}
|
||||
|
||||
// PrebuiltEtcModule interface
|
||||
func (txt *sanitizerLibrariesTxtModule) OutputFile() android.OutputPath {
|
||||
return txt.outputFile
|
||||
}
|
||||
|
||||
// PrebuiltEtcModule interface
|
||||
func (txt *sanitizerLibrariesTxtModule) BaseDir() string {
|
||||
return "etc"
|
||||
}
|
||||
|
||||
// PrebuiltEtcModule interface
|
||||
func (txt *sanitizerLibrariesTxtModule) SubDir() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (txt *sanitizerLibrariesTxtModule) OutputFiles(tag string) (android.Paths, error) {
|
||||
return android.Paths{txt.outputFile}, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user