Merge "Allow Linux hosts to use ubsan runtime sanitizers." am: 0dbb324a83
am: 3121be5eae
Change-Id: I656e23c1d2e06ee78914c22a1965b9eaf00d83c4
This commit is contained in:
@@ -234,7 +234,7 @@ func (t *toolchainLinuxX8664) YasmFlags() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (toolchainLinuxX86) LibclangRuntimeLibraryArch() string {
|
func (toolchainLinuxX86) LibclangRuntimeLibraryArch() string {
|
||||||
return "i686"
|
return "i386"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (toolchainLinuxX8664) LibclangRuntimeLibraryArch() string {
|
func (toolchainLinuxX8664) LibclangRuntimeLibraryArch() string {
|
||||||
|
@@ -334,8 +334,8 @@ func (sanitize *sanitize) begin(ctx BaseModuleContext) {
|
|||||||
s.Diag.Cfi = nil
|
s.Diag.Cfi = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disable sanitizers that depend on the UBSan runtime for host builds.
|
// Disable sanitizers that depend on the UBSan runtime for windows/darwin builds.
|
||||||
if ctx.Host() {
|
if !ctx.Os().Linux() {
|
||||||
s.Cfi = nil
|
s.Cfi = nil
|
||||||
s.Diag.Cfi = nil
|
s.Diag.Cfi = nil
|
||||||
s.Misc_undefined = nil
|
s.Misc_undefined = nil
|
||||||
@@ -433,11 +433,18 @@ func toDisableImplicitIntegerChange(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
|
minimalRuntimePath := "${config.ClangAsanLibDir}/" + minimalRuntimeLib
|
||||||
|
builtinsRuntimeLib := config.BuiltinsRuntimeLibrary(ctx.toolchain()) + ".a"
|
||||||
|
builtinsRuntimePath := "${config.ClangAsanLibDir}/" + builtinsRuntimeLib
|
||||||
|
|
||||||
if ctx.Device() && sanitize.Properties.MinimalRuntimeDep {
|
if sanitize.Properties.MinimalRuntimeDep {
|
||||||
flags.Local.LdFlags = append(flags.Local.LdFlags,
|
flags.Local.LdFlags = append(flags.Local.LdFlags,
|
||||||
minimalRuntimePath,
|
minimalRuntimePath,
|
||||||
"-Wl,--exclude-libs,"+minimalRuntimeLib)
|
"-Wl,--exclude-libs,"+minimalRuntimeLib)
|
||||||
|
if ctx.Host() {
|
||||||
|
flags.Local.LdFlags = append(flags.Local.LdFlags,
|
||||||
|
builtinsRuntimePath,
|
||||||
|
"-Wl,--exclude-libs,"+builtinsRuntimeLib)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if !sanitize.Properties.SanitizerEnabled && !sanitize.Properties.UbsanRuntimeDep {
|
if !sanitize.Properties.SanitizerEnabled && !sanitize.Properties.UbsanRuntimeDep {
|
||||||
return flags
|
return flags
|
||||||
@@ -541,11 +548,15 @@ func (sanitize *sanitize) flags(ctx ModuleContext, flags Flags) Flags {
|
|||||||
// there will always be undefined symbols in intermediate libraries.
|
// there will always be undefined symbols in intermediate libraries.
|
||||||
_, flags.Global.LdFlags = removeFromList("-Wl,--no-undefined", flags.Global.LdFlags)
|
_, flags.Global.LdFlags = removeFromList("-Wl,--no-undefined", flags.Global.LdFlags)
|
||||||
flags.Local.LdFlags = append(flags.Local.LdFlags, sanitizeArg)
|
flags.Local.LdFlags = append(flags.Local.LdFlags, sanitizeArg)
|
||||||
} else {
|
}
|
||||||
|
|
||||||
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.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...)
|
||||||
|
flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,--exclude-libs,"+builtinsRuntimeLib)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -887,7 +898,9 @@ func sanitizerRuntimeMutator(mctx android.BottomUpMutatorContext) {
|
|||||||
runtimeLibrary = config.UndefinedBehaviorSanitizerRuntimeLibrary(toolchain)
|
runtimeLibrary = config.UndefinedBehaviorSanitizerRuntimeLibrary(toolchain)
|
||||||
}
|
}
|
||||||
|
|
||||||
if mctx.Device() && runtimeLibrary != "" {
|
if runtimeLibrary != "" {
|
||||||
|
// Devices and LinuxBionic use the same libraries.
|
||||||
|
if toolchain.Bionic() {
|
||||||
if isLlndkLibrary(runtimeLibrary, mctx.Config()) && !c.static() && c.UseVndk() {
|
if isLlndkLibrary(runtimeLibrary, mctx.Config()) && !c.static() && c.UseVndk() {
|
||||||
runtimeLibrary = runtimeLibrary + llndkLibrarySuffix
|
runtimeLibrary = runtimeLibrary + llndkLibrarySuffix
|
||||||
}
|
}
|
||||||
@@ -915,6 +928,16 @@ func sanitizerRuntimeMutator(mctx android.BottomUpMutatorContext) {
|
|||||||
// static lib does not have dependency to the runtime library. The
|
// static lib does not have dependency to the runtime library. The
|
||||||
// dependency will be added to the executables or shared libs using
|
// dependency will be added to the executables or shared libs using
|
||||||
// the static lib.
|
// the static lib.
|
||||||
|
} else {
|
||||||
|
if c.sanitize.Properties.UbsanRuntimeDep {
|
||||||
|
// Support UBSan runtime on host modules, which requires the builtins linked in as well.
|
||||||
|
mctx.AddFarVariationDependencies(append(mctx.Target().Variations(), []blueprint.Variation{
|
||||||
|
{Mutator: "link", Variation: "static"},
|
||||||
|
c.ImageVariation(),
|
||||||
|
}...), StaticDepTag, append([]string{runtimeLibrary, config.BuiltinsRuntimeLibrary(toolchain)},
|
||||||
|
extraStaticDeps...)...)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user