Merge "Fix adding manual ubsan runtime to static glibc binaries" into main
This commit is contained in:
@@ -1650,12 +1650,12 @@ func sanitizerRuntimeMutator(mctx android.BottomUpMutatorContext) {
|
|||||||
Bool(sanProps.Fuzzer) ||
|
Bool(sanProps.Fuzzer) ||
|
||||||
Bool(sanProps.Undefined) ||
|
Bool(sanProps.Undefined) ||
|
||||||
Bool(sanProps.All_undefined) {
|
Bool(sanProps.All_undefined) {
|
||||||
if toolchain.Musl() || (c.staticBinary() && toolchain.Bionic()) {
|
if toolchain.Musl() || c.staticBinary() {
|
||||||
// Use a static runtime for static binaries.
|
// Use a static runtime for static binaries. For sanitized glibc binaries the runtime is
|
||||||
// Also use a static runtime for musl to match
|
// added automatically by clang, but for static glibc binaries that are not sanitized but
|
||||||
// what clang does for glibc. Otherwise dlopening
|
// have a sanitized dependency the runtime needs to be added manually.
|
||||||
// libraries that depend on libclang_rt.ubsan_standalone.so
|
// Also manually add a static runtime for musl to match what clang does for glibc.
|
||||||
// fails with:
|
// Otherwise dlopening libraries that depend on libclang_rt.ubsan_standalone.so fails with:
|
||||||
// Error relocating ...: initial-exec TLS resolves to dynamic definition
|
// Error relocating ...: initial-exec TLS resolves to dynamic definition
|
||||||
addStaticDeps(config.UndefinedBehaviorSanitizerRuntimeLibrary(toolchain)+".static", true)
|
addStaticDeps(config.UndefinedBehaviorSanitizerRuntimeLibrary(toolchain)+".static", true)
|
||||||
} else {
|
} else {
|
||||||
|
@@ -714,6 +714,15 @@ func TestUbsan(t *testing.T) {
|
|||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cc_binary {
|
||||||
|
name: "static_bin_with_ubsan_dep",
|
||||||
|
static_executable: true,
|
||||||
|
host_supported: true,
|
||||||
|
static_libs: [
|
||||||
|
"libubsan_diag",
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
cc_library_shared {
|
cc_library_shared {
|
||||||
name: "libshared",
|
name: "libshared",
|
||||||
host_supported: true,
|
host_supported: true,
|
||||||
@@ -741,6 +750,17 @@ func TestUbsan(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cc_library_static {
|
||||||
|
name: "libubsan_diag",
|
||||||
|
host_supported: true,
|
||||||
|
sanitize: {
|
||||||
|
undefined: true,
|
||||||
|
diag: {
|
||||||
|
undefined: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
cc_library_static {
|
cc_library_static {
|
||||||
name: "libstatic",
|
name: "libstatic",
|
||||||
host_supported: true,
|
host_supported: true,
|
||||||
@@ -763,6 +783,7 @@ func TestUbsan(t *testing.T) {
|
|||||||
sharedVariant := variant + "_shared"
|
sharedVariant := variant + "_shared"
|
||||||
|
|
||||||
minimalRuntime := result.ModuleForTests("libclang_rt.ubsan_minimal", staticVariant)
|
minimalRuntime := result.ModuleForTests("libclang_rt.ubsan_minimal", staticVariant)
|
||||||
|
standaloneRuntime := result.ModuleForTests("libclang_rt.ubsan_standalone.static", staticVariant)
|
||||||
|
|
||||||
// The binaries, one with ubsan and one without
|
// The binaries, one with ubsan and one without
|
||||||
binWithUbsan := result.ModuleForTests("bin_with_ubsan", variant)
|
binWithUbsan := result.ModuleForTests("bin_with_ubsan", variant)
|
||||||
@@ -770,6 +791,7 @@ func TestUbsan(t *testing.T) {
|
|||||||
libSharedUbsan := result.ModuleForTests("libsharedubsan", sharedVariant)
|
libSharedUbsan := result.ModuleForTests("libsharedubsan", sharedVariant)
|
||||||
binDependsUbsanShared := result.ModuleForTests("bin_depends_ubsan_shared", variant)
|
binDependsUbsanShared := result.ModuleForTests("bin_depends_ubsan_shared", variant)
|
||||||
binNoUbsan := result.ModuleForTests("bin_no_ubsan", variant)
|
binNoUbsan := result.ModuleForTests("bin_no_ubsan", variant)
|
||||||
|
staticBin := result.ModuleForTests("static_bin_with_ubsan_dep", variant)
|
||||||
|
|
||||||
android.AssertStringListContains(t, "missing libclang_rt.ubsan_minimal in bin_with_ubsan static libs",
|
android.AssertStringListContains(t, "missing libclang_rt.ubsan_minimal in bin_with_ubsan static libs",
|
||||||
strings.Split(binWithUbsan.Rule("ld").Args["libFlags"], " "),
|
strings.Split(binWithUbsan.Rule("ld").Args["libFlags"], " "),
|
||||||
@@ -810,6 +832,11 @@ func TestUbsan(t *testing.T) {
|
|||||||
android.AssertStringListDoesNotContain(t, "unexpected -Wl,--exclude-libs for minimal runtime in bin_no_ubsan static libs",
|
android.AssertStringListDoesNotContain(t, "unexpected -Wl,--exclude-libs for minimal runtime in bin_no_ubsan static libs",
|
||||||
strings.Split(binNoUbsan.Rule("ld").Args["ldFlags"], " "),
|
strings.Split(binNoUbsan.Rule("ld").Args["ldFlags"], " "),
|
||||||
"-Wl,--exclude-libs="+minimalRuntime.OutputFiles(t, "")[0].Base())
|
"-Wl,--exclude-libs="+minimalRuntime.OutputFiles(t, "")[0].Base())
|
||||||
|
|
||||||
|
android.AssertStringListContains(t, "missing libclang_rt.ubsan_standalone.static in static_bin_with_ubsan_dep static libs",
|
||||||
|
strings.Split(staticBin.Rule("ld").Args["libFlags"], " "),
|
||||||
|
standaloneRuntime.OutputFiles(t, "")[0].String())
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Run("host", func(t *testing.T) { check(t, buildOS, preparer) })
|
t.Run("host", func(t *testing.T) { check(t, buildOS, preparer) })
|
||||||
|
Reference in New Issue
Block a user