Add ubsan_standalone library name to the toolchain.
and export the library name to make. Refactor the code a bit to avoid repeating the library name multiple times. Bug: 22033465 Test: Ran external/clang/build.py for aosp-llvm Change-Id: I25eb3858eb92e1dd493b09524d559802551b2547
This commit is contained in:
@@ -184,8 +184,8 @@ func (t *toolchainArm64) ToolchainClangCflags() string {
|
|||||||
return t.toolchainClangCflags
|
return t.toolchainClangCflags
|
||||||
}
|
}
|
||||||
|
|
||||||
func (toolchainArm64) AddressSanitizerRuntimeLibrary() string {
|
func (toolchainArm64) SanitizerRuntimeLibraryArch() string {
|
||||||
return "libclang_rt.asan-aarch64-android.so"
|
return "aarch64"
|
||||||
}
|
}
|
||||||
|
|
||||||
func arm64ToolchainFactory(arch android.Arch) Toolchain {
|
func arm64ToolchainFactory(arch android.Arch) Toolchain {
|
||||||
|
@@ -336,8 +336,8 @@ func (t *toolchainArm) ClangInstructionSetFlags(isa string) (string, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (toolchainArm) AddressSanitizerRuntimeLibrary() string {
|
func (toolchainArm) SanitizerRuntimeLibraryArch() string {
|
||||||
return "libclang_rt.asan-arm-android.so"
|
return "arm"
|
||||||
}
|
}
|
||||||
|
|
||||||
func armToolchainFactory(arch android.Arch) Toolchain {
|
func armToolchainFactory(arch android.Arch) Toolchain {
|
||||||
|
@@ -177,8 +177,8 @@ func (t *toolchainMips64) ClangLdflags() string {
|
|||||||
return "${config.Mips64ClangLdflags}"
|
return "${config.Mips64ClangLdflags}"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (toolchainMips64) AddressSanitizerRuntimeLibrary() string {
|
func (toolchainMips64) SanitizerRuntimeLibraryArch() string {
|
||||||
return "libclang_rt.asan-mips64-android.so"
|
return "mips64"
|
||||||
}
|
}
|
||||||
|
|
||||||
func mips64ToolchainFactory(arch android.Arch) Toolchain {
|
func mips64ToolchainFactory(arch android.Arch) Toolchain {
|
||||||
|
@@ -226,8 +226,8 @@ func (t *toolchainMips) ClangLdflags() string {
|
|||||||
return "${config.MipsClangLdflags}"
|
return "${config.MipsClangLdflags}"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (toolchainMips) AddressSanitizerRuntimeLibrary() string {
|
func (toolchainMips) SanitizerRuntimeLibraryArch() string {
|
||||||
return "libclang_rt.asan-mips-android.so"
|
return "mips"
|
||||||
}
|
}
|
||||||
|
|
||||||
func mipsToolchainFactory(arch android.Arch) Toolchain {
|
func mipsToolchainFactory(arch android.Arch) Toolchain {
|
||||||
|
@@ -71,7 +71,7 @@ type Toolchain interface {
|
|||||||
ShlibSuffix() string
|
ShlibSuffix() string
|
||||||
ExecutableSuffix() string
|
ExecutableSuffix() string
|
||||||
|
|
||||||
AddressSanitizerRuntimeLibrary() string
|
SanitizerRuntimeLibraryArch() string
|
||||||
|
|
||||||
AvailableLibraries() []string
|
AvailableLibraries() []string
|
||||||
}
|
}
|
||||||
@@ -125,7 +125,7 @@ func (toolchainBase) ClangAsflags() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (toolchainBase) AddressSanitizerRuntimeLibrary() string {
|
func (toolchainBase) SanitizerRuntimeLibraryArch() string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,3 +188,19 @@ func indexList(s string, list []string) int {
|
|||||||
func inList(s string, list []string) bool {
|
func inList(s string, list []string) bool {
|
||||||
return indexList(s, list) != -1
|
return indexList(s, list) != -1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func AddressSanitizerRuntimeLibrary(t Toolchain) string {
|
||||||
|
arch := t.SanitizerRuntimeLibraryArch()
|
||||||
|
if arch == "" {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return "libclang_rt.asan-" + arch + "-android.so"
|
||||||
|
}
|
||||||
|
|
||||||
|
func UndefinedBehaviorSanitizerRuntimeLibrary(t Toolchain) string {
|
||||||
|
arch := t.SanitizerRuntimeLibraryArch()
|
||||||
|
if arch == "" {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return "libclang_rt.ubsan_standalone-" + arch + "-android.so"
|
||||||
|
}
|
||||||
|
@@ -232,6 +232,10 @@ func (t *toolchainX86_64) ClangLdflags() string {
|
|||||||
return "${config.X86_64Ldflags}"
|
return "${config.X86_64Ldflags}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (toolchainX86_64) SanitizerRuntimeLibraryArch() string {
|
||||||
|
return "x86_64"
|
||||||
|
}
|
||||||
|
|
||||||
func x86_64ToolchainFactory(arch android.Arch) Toolchain {
|
func x86_64ToolchainFactory(arch android.Arch) Toolchain {
|
||||||
toolchainCflags := []string{
|
toolchainCflags := []string{
|
||||||
"${config.X86_64ToolchainCflags}",
|
"${config.X86_64ToolchainCflags}",
|
||||||
|
@@ -251,8 +251,8 @@ func (t *toolchainX86) ClangLdflags() string {
|
|||||||
return "${config.X86Ldflags}"
|
return "${config.X86Ldflags}"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (toolchainX86) AddressSanitizerRuntimeLibrary() string {
|
func (toolchainX86) SanitizerRuntimeLibraryArch() string {
|
||||||
return "libclang_rt.asan-i686-android.so"
|
return "i686"
|
||||||
}
|
}
|
||||||
|
|
||||||
func x86ToolchainFactory(arch android.Arch) Toolchain {
|
func x86ToolchainFactory(arch android.Arch) Toolchain {
|
||||||
|
@@ -172,7 +172,8 @@ func makeVarsToolchain(ctx android.MakeVarsContext, secondPrefix string,
|
|||||||
}, " "))
|
}, " "))
|
||||||
|
|
||||||
if target.Os.Class == android.Device {
|
if target.Os.Class == android.Device {
|
||||||
ctx.Strict(secondPrefix+"ADDRESS_SANITIZER_RUNTIME_LIBRARY", strings.TrimSuffix(toolchain.AddressSanitizerRuntimeLibrary(), ".so"))
|
ctx.Strict(secondPrefix+"ADDRESS_SANITIZER_RUNTIME_LIBRARY", strings.TrimSuffix(config.AddressSanitizerRuntimeLibrary(toolchain), ".so"))
|
||||||
|
ctx.Strict(secondPrefix+"UBSAN_RUNTIME_LIBRARY", strings.TrimSuffix(config.UndefinedBehaviorSanitizerRuntimeLibrary(toolchain), ".so"))
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is used by external/gentoo/...
|
// This is used by external/gentoo/...
|
||||||
|
@@ -21,6 +21,7 @@ import (
|
|||||||
"github.com/google/blueprint"
|
"github.com/google/blueprint"
|
||||||
|
|
||||||
"android/soong/android"
|
"android/soong/android"
|
||||||
|
"android/soong/cc/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
type sanitizerType int
|
type sanitizerType int
|
||||||
@@ -239,7 +240,7 @@ func (sanitize *sanitize) flags(ctx ModuleContext, flags Flags) Flags {
|
|||||||
flags.LdFlags = append(flags.LdFlags, "-Wl,-u,__asan_preinit")
|
flags.LdFlags = append(flags.LdFlags, "-Wl,-u,__asan_preinit")
|
||||||
|
|
||||||
// ASan runtime library must be the first in the link order.
|
// ASan runtime library must be the first in the link order.
|
||||||
runtimeLibrary := ctx.toolchain().AddressSanitizerRuntimeLibrary()
|
runtimeLibrary := config.AddressSanitizerRuntimeLibrary(ctx.toolchain())
|
||||||
if runtimeLibrary != "" {
|
if runtimeLibrary != "" {
|
||||||
flags.libFlags = append([]string{"${config.ClangAsanLibDir}/" + runtimeLibrary}, flags.libFlags...)
|
flags.libFlags = append([]string{"${config.ClangAsanLibDir}/" + runtimeLibrary}, flags.libFlags...)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user