Merge changes from topic "soong_sanitize_fix" am: 8c69770ff0
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1385288 Change-Id: Ib9bacd5827c479fc9bc2e01d081ab6c4ddab4634
This commit is contained in:
27
cc/image.go
27
cc/image.go
@@ -24,6 +24,33 @@ import (
|
|||||||
|
|
||||||
var _ android.ImageInterface = (*Module)(nil)
|
var _ android.ImageInterface = (*Module)(nil)
|
||||||
|
|
||||||
|
type imageVariantType string
|
||||||
|
|
||||||
|
const (
|
||||||
|
coreImageVariant imageVariantType = "core"
|
||||||
|
vendorImageVariant imageVariantType = "vendor"
|
||||||
|
productImageVariant imageVariantType = "product"
|
||||||
|
ramdiskImageVariant imageVariantType = "ramdisk"
|
||||||
|
recoveryImageVariant imageVariantType = "recovery"
|
||||||
|
hostImageVariant imageVariantType = "host"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (c *Module) getImageVariantType() imageVariantType {
|
||||||
|
if c.Host() {
|
||||||
|
return hostImageVariant
|
||||||
|
} else if c.inVendor() {
|
||||||
|
return vendorImageVariant
|
||||||
|
} else if c.inProduct() {
|
||||||
|
return productImageVariant
|
||||||
|
} else if c.InRamdisk() {
|
||||||
|
return ramdiskImageVariant
|
||||||
|
} else if c.InRecovery() {
|
||||||
|
return recoveryImageVariant
|
||||||
|
} else {
|
||||||
|
return coreImageVariant
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// VendorVariationPrefix is the variant prefix used for /vendor code that compiles
|
// VendorVariationPrefix is the variant prefix used for /vendor code that compiles
|
||||||
// against the VNDK.
|
// against the VNDK.
|
||||||
|
106
cc/sanitize.go
106
cc/sanitize.go
@@ -57,9 +57,7 @@ var (
|
|||||||
cfiAsflags = []string{"-flto", "-fvisibility=default"}
|
cfiAsflags = []string{"-flto", "-fvisibility=default"}
|
||||||
cfiLdflags = []string{"-flto", "-fsanitize-cfi-cross-dso", "-fsanitize=cfi",
|
cfiLdflags = []string{"-flto", "-fsanitize-cfi-cross-dso", "-fsanitize=cfi",
|
||||||
"-Wl,-plugin-opt,O1"}
|
"-Wl,-plugin-opt,O1"}
|
||||||
cfiExportsMapPath = "build/soong/cc/config/cfi_exports.map"
|
cfiExportsMapPath = "build/soong/cc/config/cfi_exports.map"
|
||||||
cfiStaticLibsMutex sync.Mutex
|
|
||||||
hwasanStaticLibsMutex sync.Mutex
|
|
||||||
|
|
||||||
intOverflowCflags = []string{"-fsanitize-blacklist=build/soong/cc/config/integer_overflow_blocklist.txt"}
|
intOverflowCflags = []string{"-fsanitize-blacklist=build/soong/cc/config/integer_overflow_blocklist.txt"}
|
||||||
|
|
||||||
@@ -1050,15 +1048,9 @@ func sanitizerMutator(t sanitizerType) func(android.BottomUpMutatorContext) {
|
|||||||
// Export the static lib name to make
|
// Export the static lib name to make
|
||||||
if c.static() && c.ExportedToMake() {
|
if c.static() && c.ExportedToMake() {
|
||||||
if t == cfi {
|
if t == cfi {
|
||||||
appendStringSync(c.Name(), cfiStaticLibs(mctx.Config()), &cfiStaticLibsMutex)
|
cfiStaticLibs(mctx.Config()).add(c, c.Name())
|
||||||
} else if t == hwasan {
|
} else if t == hwasan {
|
||||||
if c.UseVndk() {
|
hwasanStaticLibs(mctx.Config()).add(c, c.Name())
|
||||||
appendStringSync(c.Name(), hwasanVendorStaticLibs(mctx.Config()),
|
|
||||||
&hwasanStaticLibsMutex)
|
|
||||||
} else {
|
|
||||||
appendStringSync(c.Name(), hwasanStaticLibs(mctx.Config()),
|
|
||||||
&hwasanStaticLibsMutex)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -1088,34 +1080,74 @@ func sanitizerMutator(t sanitizerType) func(android.BottomUpMutatorContext) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type sanitizerStaticLibsMap struct {
|
||||||
|
// libsMap contains one list of modules per each image and each arch.
|
||||||
|
// e.g. libs[vendor]["arm"] contains arm modules installed to vendor
|
||||||
|
libsMap map[imageVariantType]map[string][]string
|
||||||
|
libsMapLock sync.Mutex
|
||||||
|
sanitizerType sanitizerType
|
||||||
|
}
|
||||||
|
|
||||||
|
func newSanitizerStaticLibsMap(t sanitizerType) *sanitizerStaticLibsMap {
|
||||||
|
return &sanitizerStaticLibsMap{
|
||||||
|
sanitizerType: t,
|
||||||
|
libsMap: make(map[imageVariantType]map[string][]string),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add the current module to sanitizer static libs maps
|
||||||
|
// Each module should pass its exported name as names of Make and Soong can differ.
|
||||||
|
func (s *sanitizerStaticLibsMap) add(c *Module, name string) {
|
||||||
|
image := c.getImageVariantType()
|
||||||
|
arch := c.Arch().ArchType.String()
|
||||||
|
|
||||||
|
s.libsMapLock.Lock()
|
||||||
|
defer s.libsMapLock.Unlock()
|
||||||
|
|
||||||
|
if _, ok := s.libsMap[image]; !ok {
|
||||||
|
s.libsMap[image] = make(map[string][]string)
|
||||||
|
}
|
||||||
|
|
||||||
|
s.libsMap[image][arch] = append(s.libsMap[image][arch], name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exports makefile variables in the following format:
|
||||||
|
// SOONG_{sanitizer}_{image}_{arch}_STATIC_LIBRARIES
|
||||||
|
// e.g. SOONG_cfi_core_x86_STATIC_LIBRARIES
|
||||||
|
// These are to be used by use_soong_sanitized_static_libraries.
|
||||||
|
// See build/make/core/binary.mk for more details.
|
||||||
|
func (s *sanitizerStaticLibsMap) exportToMake(ctx android.MakeVarsContext) {
|
||||||
|
for _, image := range android.SortedStringKeys(s.libsMap) {
|
||||||
|
archMap := s.libsMap[imageVariantType(image)]
|
||||||
|
for _, arch := range android.SortedStringKeys(archMap) {
|
||||||
|
libs := archMap[arch]
|
||||||
|
sort.Strings(libs)
|
||||||
|
|
||||||
|
key := fmt.Sprintf(
|
||||||
|
"SOONG_%s_%s_%s_STATIC_LIBRARIES",
|
||||||
|
s.sanitizerType.variationName(),
|
||||||
|
image, // already upper
|
||||||
|
arch)
|
||||||
|
|
||||||
|
ctx.Strict(key, strings.Join(libs, " "))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var cfiStaticLibsKey = android.NewOnceKey("cfiStaticLibs")
|
var cfiStaticLibsKey = android.NewOnceKey("cfiStaticLibs")
|
||||||
|
|
||||||
func cfiStaticLibs(config android.Config) *[]string {
|
func cfiStaticLibs(config android.Config) *sanitizerStaticLibsMap {
|
||||||
return config.Once(cfiStaticLibsKey, func() interface{} {
|
return config.Once(cfiStaticLibsKey, func() interface{} {
|
||||||
return &[]string{}
|
return newSanitizerStaticLibsMap(cfi)
|
||||||
}).(*[]string)
|
}).(*sanitizerStaticLibsMap)
|
||||||
}
|
}
|
||||||
|
|
||||||
var hwasanStaticLibsKey = android.NewOnceKey("hwasanStaticLibs")
|
var hwasanStaticLibsKey = android.NewOnceKey("hwasanStaticLibs")
|
||||||
|
|
||||||
func hwasanStaticLibs(config android.Config) *[]string {
|
func hwasanStaticLibs(config android.Config) *sanitizerStaticLibsMap {
|
||||||
return config.Once(hwasanStaticLibsKey, func() interface{} {
|
return config.Once(hwasanStaticLibsKey, func() interface{} {
|
||||||
return &[]string{}
|
return newSanitizerStaticLibsMap(hwasan)
|
||||||
}).(*[]string)
|
}).(*sanitizerStaticLibsMap)
|
||||||
}
|
|
||||||
|
|
||||||
var hwasanVendorStaticLibsKey = android.NewOnceKey("hwasanVendorStaticLibs")
|
|
||||||
|
|
||||||
func hwasanVendorStaticLibs(config android.Config) *[]string {
|
|
||||||
return config.Once(hwasanVendorStaticLibsKey, func() interface{} {
|
|
||||||
return &[]string{}
|
|
||||||
}).(*[]string)
|
|
||||||
}
|
|
||||||
|
|
||||||
func appendStringSync(item string, list *[]string, mutex *sync.Mutex) {
|
|
||||||
mutex.Lock()
|
|
||||||
*list = append(*list, item)
|
|
||||||
mutex.Unlock()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func enableMinimalRuntime(sanitize *sanitize) bool {
|
func enableMinimalRuntime(sanitize *sanitize) bool {
|
||||||
@@ -1145,17 +1177,9 @@ func enableUbsanRuntime(sanitize *sanitize) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func cfiMakeVarsProvider(ctx android.MakeVarsContext) {
|
func cfiMakeVarsProvider(ctx android.MakeVarsContext) {
|
||||||
cfiStaticLibs := cfiStaticLibs(ctx.Config())
|
cfiStaticLibs(ctx.Config()).exportToMake(ctx)
|
||||||
sort.Strings(*cfiStaticLibs)
|
|
||||||
ctx.Strict("SOONG_CFI_STATIC_LIBRARIES", strings.Join(*cfiStaticLibs, " "))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func hwasanMakeVarsProvider(ctx android.MakeVarsContext) {
|
func hwasanMakeVarsProvider(ctx android.MakeVarsContext) {
|
||||||
hwasanStaticLibs := hwasanStaticLibs(ctx.Config())
|
hwasanStaticLibs(ctx.Config()).exportToMake(ctx)
|
||||||
sort.Strings(*hwasanStaticLibs)
|
|
||||||
ctx.Strict("SOONG_HWASAN_STATIC_LIBRARIES", strings.Join(*hwasanStaticLibs, " "))
|
|
||||||
|
|
||||||
hwasanVendorStaticLibs := hwasanVendorStaticLibs(ctx.Config())
|
|
||||||
sort.Strings(*hwasanVendorStaticLibs)
|
|
||||||
ctx.Strict("SOONG_HWASAN_VENDOR_STATIC_LIBRARIES", strings.Join(*hwasanVendorStaticLibs, " "))
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user