From 95cd6db590a5be0fa822cf8741454a0874cc259a Mon Sep 17 00:00:00 2001 From: Florian Mayer Date: Thu, 23 Mar 2023 17:48:07 -0700 Subject: [PATCH] Add handling for libc_hwasan to Soong libc_hwasan is a new library in the runtime apex that lives in bionic/hwasan/libc.so and is symlinked to /system/lib64/hwasan/libc.so. This is chosen by the linker if an app or binary requires HWASan support. Bug: 276930343 Change-Id: If331744ad84241ad99a41805ea3110d37cf9b0af --- apex/apex.go | 5 ++++- cc/cc.go | 2 +- cc/library.go | 11 ++++++++++- cc/sanitize.go | 7 +++++++ 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/apex/apex.go b/apex/apex.go index 5451a0400..4fda5058f 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -1659,7 +1659,6 @@ func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, h if ccMod.Target().NativeBridge == android.NativeBridgeEnabled { dirInApex = filepath.Join(dirInApex, ccMod.Target().NativeBridgeRelativePath) } - dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath()) if handleSpecialLibs && cc.InstallToBootstrap(ccMod.BaseModuleName(), ctx.Config()) { // Special case for Bionic libs and other libs installed with them. This is to // prevent those libs from being included in the search path @@ -1672,6 +1671,10 @@ func apexFileForNativeLibrary(ctx android.BaseModuleContext, ccMod *cc.Module, h // loading of them, which isn't supported. dirInApex = filepath.Join(dirInApex, "bionic") } + // This needs to go after the runtime APEX handling because otherwise we would get + // weird paths like lib64/rel_install_path/bionic rather than + // lib64/bionic/rel_install_path. + dirInApex = filepath.Join(dirInApex, ccMod.RelativeInstallPath()) fileToCopy := android.OutputFileForModule(ctx, ccMod, "") androidMkModuleName := ccMod.BaseModuleName() + ccMod.Properties.SubName diff --git a/cc/cc.go b/cc/cc.go index 9c555a11e..10f566875 100644 --- a/cc/cc.go +++ b/cc/cc.go @@ -1475,7 +1475,7 @@ func isBionic(name string) bool { func InstallToBootstrap(name string, config android.Config) bool { // NOTE: also update //build/bazel/rules/apex/cc.bzl#_installed_to_bootstrap // if this list is updated. - if name == "libclang_rt.hwasan" { + if name == "libclang_rt.hwasan" || name == "libc_hwasan" { return true } return isBionic(name) diff --git a/cc/library.go b/cc/library.go index 7504302fd..172ca6459 100644 --- a/cc/library.go +++ b/cc/library.go @@ -2193,7 +2193,16 @@ func (library *libraryDecorator) toc() android.OptionalPath { func (library *libraryDecorator) installSymlinkToRuntimeApex(ctx ModuleContext, file android.Path) { dir := library.baseInstaller.installDir(ctx) dirOnDevice := android.InstallPathToOnDevicePath(ctx, dir) - target := "/" + filepath.Join("apex", "com.android.runtime", dir.Base(), "bionic", file.Base()) + // libc_hwasan has relative_install_dir set, which would mess up the dir.Base() logic. + // hardcode here because it's the only target, if we have other targets that use this + // we can generalise this. + var target string + if ctx.baseModuleName() == "libc_hwasan" { + target = "/" + filepath.Join("apex", "com.android.runtime", "lib64", "bionic", "hwasan", file.Base()) + } else { + base := dir.Base() + target = "/" + filepath.Join("apex", "com.android.runtime", base, "bionic", file.Base()) + } ctx.InstallAbsoluteSymlink(dir, file.Base(), target) library.postInstallCmds = append(library.postInstallCmds, makeSymlinkCmd(dirOnDevice, file.Base(), target)) } diff --git a/cc/sanitize.go b/cc/sanitize.go index f19659cc7..f34c63181 100644 --- a/cc/sanitize.go +++ b/cc/sanitize.go @@ -785,6 +785,13 @@ func (s *sanitize) flags(ctx ModuleContext, flags Flags) Flags { if Bool(sanProps.Writeonly) { flags.Local.CFlags = append(flags.Local.CFlags, "-mllvm", "-hwasan-instrument-reads=0") } + if !ctx.staticBinary() && !ctx.Host() { + if ctx.bootstrap() { + flags.DynamicLinker = "/system/bin/bootstrap/linker_hwasan64" + } else { + flags.DynamicLinker = "/system/bin/linker_hwasan64" + } + } } if Bool(sanProps.Fuzzer) {