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:
@@ -582,20 +582,12 @@ func toDisableUnsignedShiftBaseChange(flags []string) bool {
|
|||||||
|
|
||||||
func (sanitize *sanitize) flags(ctx ModuleContext, flags Flags) Flags {
|
func (sanitize *sanitize) flags(ctx ModuleContext, flags Flags) Flags {
|
||||||
minimalRuntimeLib := config.UndefinedBehaviorSanitizerMinimalRuntimeLibrary(ctx.toolchain()) + ".a"
|
minimalRuntimeLib := config.UndefinedBehaviorSanitizerMinimalRuntimeLibrary(ctx.toolchain()) + ".a"
|
||||||
minimalRuntimePath := "${config.ClangAsanLibDir}/" + minimalRuntimeLib
|
|
||||||
builtinsRuntimeLib := config.BuiltinsRuntimeLibrary(ctx.toolchain()) + ".a"
|
|
||||||
builtinsRuntimePath := "${config.ClangAsanLibDir}/" + builtinsRuntimeLib
|
|
||||||
|
|
||||||
if sanitize.Properties.MinimalRuntimeDep {
|
if sanitize.Properties.MinimalRuntimeDep {
|
||||||
flags.Local.LdFlags = append(flags.Local.LdFlags,
|
flags.Local.LdFlags = append(flags.Local.LdFlags,
|
||||||
minimalRuntimePath,
|
|
||||||
"-Wl,--exclude-libs,"+minimalRuntimeLib)
|
"-Wl,--exclude-libs,"+minimalRuntimeLib)
|
||||||
}
|
}
|
||||||
|
|
||||||
if sanitize.Properties.BuiltinsDep {
|
|
||||||
flags.libFlags = append([]string{builtinsRuntimePath}, flags.libFlags...)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !sanitize.Properties.SanitizerEnabled && !sanitize.Properties.UbsanRuntimeDep {
|
if !sanitize.Properties.SanitizerEnabled && !sanitize.Properties.UbsanRuntimeDep {
|
||||||
return flags
|
return flags
|
||||||
}
|
}
|
||||||
@@ -725,11 +717,7 @@ func (sanitize *sanitize) flags(ctx ModuleContext, flags Flags) Flags {
|
|||||||
|
|
||||||
if enableMinimalRuntime(sanitize) {
|
if enableMinimalRuntime(sanitize) {
|
||||||
flags.Local.CFlags = append(flags.Local.CFlags, strings.Join(minimalRuntimeFlags, " "))
|
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)
|
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) {
|
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) {
|
if runtimeLibrary != "" && (toolchain.Bionic() || c.sanitize.Properties.UbsanRuntimeDep) {
|
||||||
// UBSan is supported on non-bionic linux host builds as well
|
// 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
|
// Note that by adding dependency with {static|shared}DepTag, the lib is
|
||||||
// added to libFlags and LOCAL_SHARED_LIBRARIES by cc.Module
|
// added to libFlags and LOCAL_SHARED_LIBRARIES by cc.Module
|
||||||
if c.staticBinary() {
|
if c.staticBinary() {
|
||||||
deps := append(extraStaticDeps, runtimeLibrary)
|
addStaticDeps(runtimeLibrary)
|
||||||
// If we're using snapshots, redirect to snapshot whenever possible
|
addStaticDeps(extraStaticDeps...)
|
||||||
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...)
|
|
||||||
} else if !c.static() && !c.Header() {
|
} else if !c.static() && !c.Header() {
|
||||||
// If we're using snapshots, redirect to snapshot whenever possible
|
// If we're using snapshots, redirect to snapshot whenever possible
|
||||||
snapshot := mctx.Provider(SnapshotInfoProvider).(SnapshotInfo)
|
snapshot := mctx.Provider(SnapshotInfoProvider).(SnapshotInfo)
|
||||||
@@ -1250,6 +1253,10 @@ func sanitizerRuntimeMutator(mctx android.BottomUpMutatorContext) {
|
|||||||
if c.Device() {
|
if c.Device() {
|
||||||
variations = append(variations, c.ImageVariation())
|
variations = append(variations, c.ImageVariation())
|
||||||
}
|
}
|
||||||
|
if c.UseSdk() {
|
||||||
|
variations = append(variations,
|
||||||
|
blueprint.Variation{Mutator: "sdk", Variation: "sdk"})
|
||||||
|
}
|
||||||
AddSharedLibDependenciesWithVersions(mctx, c, variations, depTag, runtimeLibrary, "", true)
|
AddSharedLibDependenciesWithVersions(mctx, c, variations, depTag, runtimeLibrary, "", true)
|
||||||
}
|
}
|
||||||
// static lib does not have dependency to the runtime library. The
|
// static lib does not have dependency to the runtime library. The
|
||||||
|
@@ -99,6 +99,18 @@ func commonDefaultModules() string {
|
|||||||
vendor_ramdisk_available: true,
|
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 {
|
cc_prebuilt_library_shared {
|
||||||
name: "libclang_rt.hwasan-aarch64-android",
|
name: "libclang_rt.hwasan-aarch64-android",
|
||||||
defaults: ["toolchain_libs_defaults"],
|
defaults: ["toolchain_libs_defaults"],
|
||||||
@@ -168,6 +180,16 @@ func commonDefaultModules() string {
|
|||||||
defaults: ["toolchain_libs_defaults"],
|
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 {
|
cc_library {
|
||||||
name: "libc",
|
name: "libc",
|
||||||
defaults: ["linux_bionic_supported"],
|
defaults: ["linux_bionic_supported"],
|
||||||
|
@@ -37,6 +37,8 @@ var prepareForShTest = android.GroupFixturePreparers(
|
|||||||
//
|
//
|
||||||
// deprecated
|
// deprecated
|
||||||
func testShBinary(t *testing.T, bp string) (*android.TestContext, android.Config) {
|
func testShBinary(t *testing.T, bp string) (*android.TestContext, android.Config) {
|
||||||
|
bp = bp + cc.GatherRequiredDepsForTest(android.Android)
|
||||||
|
|
||||||
result := prepareForShTest.RunTestWithBp(t, bp)
|
result := prepareForShTest.RunTestWithBp(t, bp)
|
||||||
|
|
||||||
return result.TestContext, result.Config
|
return result.TestContext, result.Config
|
||||||
|
Reference in New Issue
Block a user