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 464148024..0addb60b4 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 a7f3a0575..80797a391 100644 --- a/cc/library.go +++ b/cc/library.go @@ -2207,7 +2207,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 4601ee612..45d7fab4f 100644 --- a/cc/sanitize.go +++ b/cc/sanitize.go @@ -792,6 +792,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) {