diff options
Diffstat (limited to 'cc')
| -rw-r--r-- | cc/binary.go | 4 | ||||
| -rw-r--r-- | cc/cc.go | 26 | ||||
| -rw-r--r-- | cc/config/global.go | 2 | ||||
| -rw-r--r-- | cc/library.go | 6 | ||||
| -rw-r--r-- | cc/llndk_library.go | 2 | ||||
| -rw-r--r-- | cc/makevars.go | 15 | ||||
| -rw-r--r-- | cc/sanitize.go | 163 |
7 files changed, 121 insertions, 97 deletions
diff --git a/cc/binary.go b/cc/binary.go index 99fb79531..2a6ceb821 100644 --- a/cc/binary.go +++ b/cc/binary.go @@ -444,8 +444,8 @@ func (binary *binaryDecorator) install(ctx ModuleContext, file android.Path) { // Bionic binaries (e.g. linker) is installed to the bootstrap subdirectory. // The original path becomes a symlink to the corresponding file in the // runtime APEX. - if isBionic(ctx.baseModuleName()) && ctx.Arch().Native && ctx.apexName() == "" && !ctx.inRecovery() { - if ctx.Device() { + if installToBootstrap(ctx.baseModuleName(), ctx.Config()) && ctx.Arch().Native && ctx.apexName() == "" && !ctx.inRecovery() { + if ctx.Device() && isBionic(ctx.baseModuleName()) { binary.installSymlinkToRuntimeApex(ctx, file) } binary.baseInstaller.subDir = "bootstrap" @@ -51,6 +51,8 @@ func init() { ctx.TopDown("hwasan_deps", sanitizerDepsMutator(hwasan)) ctx.BottomUp("hwasan", sanitizerMutator(hwasan)).Parallel() + // cfi mutator shouldn't run before sanitizers that return true for + // incompatibleWithCfi() ctx.TopDown("cfi_deps", sanitizerDepsMutator(cfi)) ctx.BottomUp("cfi", sanitizerMutator(cfi)).Parallel() @@ -239,6 +241,7 @@ type VendorProperties struct { type ModuleContextIntf interface { static() bool staticBinary() bool + header() bool toolchain() config.Toolchain useSdk() bool sdkVersion() string @@ -605,6 +608,9 @@ func (c *Module) HasStubsVariants() bool { if library, ok := c.linker.(*libraryDecorator); ok { return len(library.Properties.Stubs.Versions) > 0 } + if library, ok := c.linker.(*prebuiltLibraryLinker); ok { + return len(library.Properties.Stubs.Versions) > 0 + } return false } @@ -624,6 +630,13 @@ func isBionic(name string) bool { return false } +func installToBootstrap(name string, config android.Config) bool { + if name == "libclang_rt.hwasan-aarch64-android" { + return inList("hwaddress", config.SanitizeDevice()) + } + return isBionic(name) +} + type baseModuleContext struct { android.BaseContext moduleContextImpl @@ -661,6 +674,10 @@ func (ctx *moduleContextImpl) staticBinary() bool { return ctx.mod.staticBinary() } +func (ctx *moduleContextImpl) header() bool { + return ctx.mod.header() +} + func (ctx *moduleContextImpl) useSdk() bool { if ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRecovery() && !ctx.ctx.Fuchsia() { return String(ctx.mod.Properties.Sdk_version) != "" @@ -1924,6 +1941,15 @@ func (c *Module) staticBinary() bool { return false } +func (c *Module) header() bool { + if h, ok := c.linker.(interface { + header() bool + }); ok { + return h.header() + } + return false +} + func (c *Module) getMakeLinkType() string { if c.useVndk() { if inList(c.Name(), vndkCoreLibraries) || inList(c.Name(), vndkSpLibraries) || inList(c.Name(), llndkLibraries) { diff --git a/cc/config/global.go b/cc/config/global.go index ca4092d51..4af622115 100644 --- a/cc/config/global.go +++ b/cc/config/global.go @@ -123,7 +123,7 @@ var ( // prebuilts/clang default settings. ClangDefaultBase = "prebuilts/clang/host" - ClangDefaultVersion = "clang-r353983c" + ClangDefaultVersion = "clang-r353983c1" ClangDefaultShortVersion = "9.0.3" // Directories with warnings from Android.bp files. diff --git a/cc/library.go b/cc/library.go index f93f5aff1..39f7a724b 100644 --- a/cc/library.go +++ b/cc/library.go @@ -938,12 +938,12 @@ func (library *libraryDecorator) install(ctx ModuleContext, file android.Path) { library.baseInstaller.subDir += "-" + vndkVersion } } - } else if len(library.Properties.Stubs.Versions) > 0 && android.DirectlyInAnyApex(ctx, ctx.ModuleName()) { + } else if len(library.Properties.Stubs.Versions) > 0 { // Bionic libraries (e.g. libc.so) is installed to the bootstrap subdirectory. // The original path becomes a symlink to the corresponding file in the // runtime APEX. - if isBionic(ctx.baseModuleName()) && !library.buildStubs() && ctx.Arch().Native && !ctx.inRecovery() { - if ctx.Device() { + if installToBootstrap(ctx.baseModuleName(), ctx.Config()) && !library.buildStubs() && ctx.Arch().Native && !ctx.inRecovery() { + if ctx.Device() && isBionic(ctx.baseModuleName()) { library.installSymlinkToRuntimeApex(ctx, file) } library.baseInstaller.subDir = "bootstrap" diff --git a/cc/llndk_library.go b/cc/llndk_library.go index 56ef2b67b..52c58eb78 100644 --- a/cc/llndk_library.go +++ b/cc/llndk_library.go @@ -221,7 +221,7 @@ func llndkHeadersFactory() android.Module { &library.MutatedProperties, &library.flagExporter.Properties) - android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibBoth) + module.Init() return module } diff --git a/cc/makevars.go b/cc/makevars.go index aa6fdea56..b03e170f3 100644 --- a/cc/makevars.go +++ b/cc/makevars.go @@ -95,7 +95,20 @@ func makeVarsProvider(ctx android.MakeVarsContext) { ctx.Strict("VNDK_CORE_LIBRARIES", strings.Join(vndkCoreLibraries, " ")) ctx.Strict("VNDK_SAMEPROCESS_LIBRARIES", strings.Join(vndkSpLibraries, " ")) - ctx.Strict("LLNDK_LIBRARIES", strings.Join(llndkLibraries, " ")) + + // Make uses LLNDK_LIBRARIES to determine which libraries to install. + // HWASAN is only part of the LL-NDK in builds in which libc depends on HWASAN. + // Therefore, by removing the library here, we cause it to only be installed if libc + // depends on it. + installedLlndkLibraries := []string{} + for _, lib := range llndkLibraries { + if strings.HasPrefix(lib, "libclang_rt.hwasan-") { + continue + } + installedLlndkLibraries = append(installedLlndkLibraries, lib) + } + ctx.Strict("LLNDK_LIBRARIES", strings.Join(installedLlndkLibraries, " ")) + ctx.Strict("VNDK_PRIVATE_LIBRARIES", strings.Join(vndkPrivateLibraries, " ")) ctx.Strict("VNDK_USING_CORE_VARIANT_LIBRARIES", strings.Join(vndkUsingCoreVariantLibraries, " ")) diff --git a/cc/sanitize.go b/cc/sanitize.go index b7a36a60c..c1b055afe 100644 --- a/cc/sanitize.go +++ b/cc/sanitize.go @@ -120,6 +120,10 @@ func (t sanitizerType) name() string { } } +func (t sanitizerType) incompatibleWithCfi() bool { + return t == asan || t == hwasan +} + type SanitizeProperties struct { // enable AddressSanitizer, ThreadSanitizer, or UndefinedBehaviorSanitizer Sanitize struct { @@ -543,16 +547,18 @@ func (sanitize *sanitize) flags(ctx ModuleContext, flags Flags) Flags { } func (sanitize *sanitize) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) { - // Add a suffix for CFI-enabled static libraries to allow surfacing both to make without a - // name conflict. - if ret.Class == "STATIC_LIBRARIES" && Bool(sanitize.Properties.Sanitize.Cfi) { - ret.SubName += ".cfi" - } - if ret.Class == "STATIC_LIBRARIES" && Bool(sanitize.Properties.Sanitize.Hwaddress) { - ret.SubName += ".hwasan" - } - if ret.Class == "STATIC_LIBRARIES" && Bool(sanitize.Properties.Sanitize.Scs) { - ret.SubName += ".scs" + // Add a suffix for cfi/hwasan/scs-enabled static/header libraries to allow surfacing + // both the sanitized and non-sanitized variants to make without a name conflict. + if ret.Class == "STATIC_LIBRARIES" || ret.Class == "HEADER_LIBRARIES" { + if Bool(sanitize.Properties.Sanitize.Cfi) { + ret.SubName += ".cfi" + } + if Bool(sanitize.Properties.Sanitize.Hwaddress) { + ret.SubName += ".hwasan" + } + if Bool(sanitize.Properties.Sanitize.Scs) { + ret.SubName += ".scs" + } } } @@ -841,7 +847,7 @@ func sanitizerRuntimeMutator(mctx android.BottomUpMutatorContext) { {Mutator: "image", Variation: c.imageVariation()}, {Mutator: "arch", Variation: mctx.Target().String()}, }, staticDepTag, runtimeLibrary) - } else if !c.static() { + } else if !c.static() && !c.header() { // dynamic executable and shared libs get shared runtime libs mctx.AddFarVariationDependencies([]blueprint.Variation{ {Mutator: "link", Variation: "shared"}, @@ -870,60 +876,37 @@ func sanitizerMutator(t sanitizerType) func(android.BottomUpMutatorContext) { modules := mctx.CreateVariations(t.variationName()) modules[0].(*Module).sanitize.SetSanitizer(t, true) } else if c.sanitize.isSanitizerEnabled(t) || c.sanitize.Properties.SanitizeDep { - // Save original sanitizer status before we assign values to variant - // 0 as that overwrites the original. isSanitizerEnabled := c.sanitize.isSanitizerEnabled(t) - - modules := mctx.CreateVariations("", t.variationName()) - modules[0].(*Module).sanitize.SetSanitizer(t, false) - modules[1].(*Module).sanitize.SetSanitizer(t, true) - - modules[0].(*Module).sanitize.Properties.SanitizeDep = false - modules[1].(*Module).sanitize.Properties.SanitizeDep = false - - // We don't need both variants active for anything but CFI-enabled - // target static libraries, so suppress the appropriate variant in - // all other cases. - if t == cfi { - if c.static() { - if !mctx.Device() { - if isSanitizerEnabled { - modules[0].(*Module).Properties.PreventInstall = true - modules[0].(*Module).Properties.HideFromMake = true - } else { - modules[1].(*Module).Properties.PreventInstall = true - modules[1].(*Module).Properties.HideFromMake = true - } - } else { - cfiStaticLibs := cfiStaticLibs(mctx.Config()) - - cfiStaticLibsMutex.Lock() - *cfiStaticLibs = append(*cfiStaticLibs, c.Name()) - cfiStaticLibsMutex.Unlock() - } - } else { - modules[0].(*Module).Properties.PreventInstall = true - modules[0].(*Module).Properties.HideFromMake = true - } - } else if t == asan { - if mctx.Device() { - // CFI and ASAN are currently mutually exclusive so disable - // CFI if this is an ASAN variant. - modules[1].(*Module).sanitize.Properties.InSanitizerDir = true - modules[1].(*Module).sanitize.SetSanitizer(cfi, false) - } - if isSanitizerEnabled { - modules[0].(*Module).Properties.PreventInstall = true - modules[0].(*Module).Properties.HideFromMake = true - } else { - modules[1].(*Module).Properties.PreventInstall = true - modules[1].(*Module).Properties.HideFromMake = true - } - } else if t == scs { - // We don't currently link any static libraries built with make into - // libraries built with SCS, so we don't need logic for propagating - // SCSness of dependencies into make. - if !c.static() { + if mctx.Device() && t.incompatibleWithCfi() { + // TODO: Make sure that cfi mutator runs "after" any of the sanitizers that + // are incompatible with cfi + c.sanitize.SetSanitizer(cfi, false) + } + if c.static() || c.header() || t == asan { + // Static and header libs are split into non-sanitized and sanitized variants. + // Shared libs are not split. However, for asan, we split even for shared + // libs because a library sanitized for asan can't be linked from a library + // that isn't sanitized for asan. + // + // Note for defaultVariation: since we don't split for shared libs but for static/header + // libs, it is possible for the sanitized variant of a static/header lib to depend + // on non-sanitized variant of a shared lib. Such unfulfilled variation causes an + // error when the module is split. defaultVariation is the name of the variation that + // will be used when such a dangling dependency occurs during the split of the current + // module. By setting it to the name of the sanitized variation, the dangling dependency + // is redirected to the sanitized variant of the dependent module. + defaultVariation := t.variationName() + mctx.SetDefaultDependencyVariation(&defaultVariation) + modules := mctx.CreateVariations("", t.variationName()) + modules[0].(*Module).sanitize.SetSanitizer(t, false) + modules[1].(*Module).sanitize.SetSanitizer(t, true) + modules[0].(*Module).sanitize.Properties.SanitizeDep = false + modules[1].(*Module).sanitize.Properties.SanitizeDep = false + + // For cfi/scs/hwasan, we can export both sanitized and un-sanitized variants + // to Make, because the sanitized version has a different suffix in name. + // For other types of sanitizers, suppress the variation that is disabled. + if t != cfi && t != scs && t != hwasan { if isSanitizerEnabled { modules[0].(*Module).Properties.PreventInstall = true modules[0].(*Module).Properties.HideFromMake = true @@ -932,34 +915,30 @@ func sanitizerMutator(t sanitizerType) func(android.BottomUpMutatorContext) { modules[1].(*Module).Properties.HideFromMake = true } } - } else if t == hwasan { - if mctx.Device() { - // CFI and HWASAN are currently mutually exclusive so disable - // CFI if this is an HWASAN variant. - modules[1].(*Module).sanitize.SetSanitizer(cfi, false) - } - + // Export the static lib name to make if c.static() { - if c.useVndk() { - hwasanVendorStaticLibs := hwasanVendorStaticLibs(mctx.Config()) - hwasanStaticLibsMutex.Lock() - *hwasanVendorStaticLibs = append(*hwasanVendorStaticLibs, c.Name()) - hwasanStaticLibsMutex.Unlock() - } else { - hwasanStaticLibs := hwasanStaticLibs(mctx.Config()) - hwasanStaticLibsMutex.Lock() - *hwasanStaticLibs = append(*hwasanStaticLibs, c.Name()) - hwasanStaticLibsMutex.Unlock() - } - } else { - if isSanitizerEnabled { - modules[0].(*Module).Properties.PreventInstall = true - modules[0].(*Module).Properties.HideFromMake = true - } else { - modules[1].(*Module).Properties.PreventInstall = true - modules[1].(*Module).Properties.HideFromMake = true + if t == cfi { + appendStringSync(c.Name(), cfiStaticLibs(mctx.Config()), &cfiStaticLibsMutex) + } else if t == hwasan { + if c.useVndk() { + appendStringSync(c.Name(), hwasanVendorStaticLibs(mctx.Config()), + &hwasanStaticLibsMutex) + } else { + appendStringSync(c.Name(), hwasanStaticLibs(mctx.Config()), + &hwasanStaticLibsMutex) + } } } + } else { + // Shared libs are not split. Only the sanitized variant is created. + modules := mctx.CreateVariations(t.variationName()) + modules[0].(*Module).sanitize.SetSanitizer(t, true) + modules[0].(*Module).sanitize.Properties.SanitizeDep = false + + // locate the asan libraries under /data/asan + if mctx.Device() && t == asan && isSanitizerEnabled { + modules[0].(*Module).sanitize.Properties.InSanitizerDir = true + } } } c.sanitize.Properties.SanitizeDep = false @@ -994,6 +973,12 @@ func hwasanVendorStaticLibs(config android.Config) *[]string { }).(*[]string) } +func appendStringSync(item string, list *[]string, mutex *sync.Mutex) { + mutex.Lock() + *list = append(*list, item) + mutex.Unlock() +} + func enableMinimalRuntime(sanitize *sanitize) bool { if !Bool(sanitize.Properties.Sanitize.Address) && !Bool(sanitize.Properties.Sanitize.Hwaddress) && |