diff --git a/cc/sanitize.go b/cc/sanitize.go index b8e1468e4..1db221915 100644 --- a/cc/sanitize.go +++ b/cc/sanitize.go @@ -582,20 +582,12 @@ func toDisableUnsignedShiftBaseChange(flags []string) bool { func (sanitize *sanitize) flags(ctx ModuleContext, flags Flags) Flags { minimalRuntimeLib := config.UndefinedBehaviorSanitizerMinimalRuntimeLibrary(ctx.toolchain()) + ".a" - minimalRuntimePath := "${config.ClangAsanLibDir}/" + minimalRuntimeLib - builtinsRuntimeLib := config.BuiltinsRuntimeLibrary(ctx.toolchain()) + ".a" - builtinsRuntimePath := "${config.ClangAsanLibDir}/" + builtinsRuntimeLib if sanitize.Properties.MinimalRuntimeDep { flags.Local.LdFlags = append(flags.Local.LdFlags, - minimalRuntimePath, "-Wl,--exclude-libs,"+minimalRuntimeLib) } - if sanitize.Properties.BuiltinsDep { - flags.libFlags = append([]string{builtinsRuntimePath}, flags.libFlags...) - } - if !sanitize.Properties.SanitizerEnabled && !sanitize.Properties.UbsanRuntimeDep { return flags } @@ -725,11 +717,7 @@ func (sanitize *sanitize) flags(ctx ModuleContext, flags Flags) Flags { if enableMinimalRuntime(sanitize) { flags.Local.CFlags = append(flags.Local.CFlags, strings.Join(minimalRuntimeFlags, " ")) - flags.libFlags = append([]string{minimalRuntimePath}, flags.libFlags...) flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,--exclude-libs,"+minimalRuntimeLib) - if !ctx.toolchain().Bionic() { - flags.libFlags = append([]string{builtinsRuntimePath}, flags.libFlags...) - } } if Bool(sanitize.Properties.Sanitize.Fuzzer) { @@ -1198,6 +1186,36 @@ func sanitizerRuntimeMutator(mctx android.BottomUpMutatorContext) { } } + addStaticDeps := func(deps ...string) { + // If we're using snapshots, redirect to snapshot whenever possible + snapshot := mctx.Provider(SnapshotInfoProvider).(SnapshotInfo) + for idx, dep := range deps { + if lib, ok := snapshot.StaticLibs[dep]; ok { + deps[idx] = lib + } + } + + // static executable gets static runtime libs + depTag := libraryDependencyTag{Kind: staticLibraryDependency} + variations := append(mctx.Target().Variations(), + blueprint.Variation{Mutator: "link", Variation: "static"}) + if c.Device() { + variations = append(variations, c.ImageVariation()) + } + if c.UseSdk() { + variations = append(variations, + blueprint.Variation{Mutator: "sdk", Variation: "sdk"}) + } + mctx.AddFarVariationDependencies(variations, depTag, deps...) + + } + if enableMinimalRuntime(c.sanitize) || c.sanitize.Properties.MinimalRuntimeDep { + addStaticDeps(config.UndefinedBehaviorSanitizerMinimalRuntimeLibrary(toolchain)) + } + if c.sanitize.Properties.BuiltinsDep { + addStaticDeps(config.BuiltinsRuntimeLibrary(toolchain)) + } + if runtimeLibrary != "" && (toolchain.Bionic() || c.sanitize.Properties.UbsanRuntimeDep) { // UBSan is supported on non-bionic linux host builds as well @@ -1209,23 +1227,8 @@ func sanitizerRuntimeMutator(mctx android.BottomUpMutatorContext) { // Note that by adding dependency with {static|shared}DepTag, the lib is // added to libFlags and LOCAL_SHARED_LIBRARIES by cc.Module if c.staticBinary() { - deps := append(extraStaticDeps, runtimeLibrary) - // If we're using snapshots, redirect to snapshot whenever possible - snapshot := mctx.Provider(SnapshotInfoProvider).(SnapshotInfo) - for idx, dep := range deps { - if lib, ok := snapshot.StaticLibs[dep]; ok { - deps[idx] = lib - } - } - - // static executable gets static runtime libs - depTag := libraryDependencyTag{Kind: staticLibraryDependency} - variations := append(mctx.Target().Variations(), - blueprint.Variation{Mutator: "link", Variation: "static"}) - if c.Device() { - variations = append(variations, c.ImageVariation()) - } - mctx.AddFarVariationDependencies(variations, depTag, deps...) + addStaticDeps(runtimeLibrary) + addStaticDeps(extraStaticDeps...) } else if !c.static() && !c.Header() { // If we're using snapshots, redirect to snapshot whenever possible snapshot := mctx.Provider(SnapshotInfoProvider).(SnapshotInfo) @@ -1250,6 +1253,10 @@ func sanitizerRuntimeMutator(mctx android.BottomUpMutatorContext) { if c.Device() { variations = append(variations, c.ImageVariation()) } + if c.UseSdk() { + variations = append(variations, + blueprint.Variation{Mutator: "sdk", Variation: "sdk"}) + } AddSharedLibDependenciesWithVersions(mctx, c, variations, depTag, runtimeLibrary, "", true) } // static lib does not have dependency to the runtime library. The diff --git a/cc/testing.go b/cc/testing.go index 3d0c10a88..a03d147a0 100644 --- a/cc/testing.go +++ b/cc/testing.go @@ -99,6 +99,18 @@ func commonDefaultModules() string { vendor_ramdisk_available: true, } + cc_prebuilt_library_static { + name: "libclang_rt.builtins-x86_64", + defaults: ["toolchain_libs_defaults"], + host_supported: true, + } + + cc_prebuilt_library_static { + name: "libclang_rt.builtins-i386", + defaults: ["toolchain_libs_defaults"], + host_supported: true, + } + cc_prebuilt_library_shared { name: "libclang_rt.hwasan-aarch64-android", defaults: ["toolchain_libs_defaults"], @@ -168,6 +180,16 @@ func commonDefaultModules() string { defaults: ["toolchain_libs_defaults"], } + cc_prebuilt_library_static { + name: "libclang_rt.ubsan_minimal-aarch64-android", + defaults: ["toolchain_libs_defaults"], + } + + cc_prebuilt_library_static { + name: "libclang_rt.ubsan_minimal-arm-android", + defaults: ["toolchain_libs_defaults"], + } + cc_library { name: "libc", defaults: ["linux_bionic_supported"], diff --git a/sh/sh_binary_test.go b/sh/sh_binary_test.go index 7fe1d8538..89b8126f1 100644 --- a/sh/sh_binary_test.go +++ b/sh/sh_binary_test.go @@ -37,6 +37,8 @@ var prepareForShTest = android.GroupFixturePreparers( // // deprecated func testShBinary(t *testing.T, bp string) (*android.TestContext, android.Config) { + bp = bp + cc.GatherRequiredDepsForTest(android.Android) + result := prepareForShTest.RunTestWithBp(t, bp) return result.TestContext, result.Config