Add builtins and minimal runtime as dependencies instead of flags

Use dependencies instead of libflags to link libclang_rt.builtins
and libclang_rt.ubsan_minimal.

Test: m checkbuild
Change-Id: I403cee0fb8cc21c347b42d8f8a3c20d6f43337a4
This commit is contained in:
Colin Cross 2022-02-10 10:34:19 -08:00
parent 72ee67659d
commit 06c80eb851
3 changed files with 60 additions and 29 deletions

View file

@ -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

View file

@ -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"],

View file

@ -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