aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Collingbourne2019-04-24 16:41:12 -0500
committerPeter Collingbourne2019-05-17 12:00:39 -0500
commit3478bb2a7fbcaaea1326a1df4a564d7ca24056ce (patch)
tree79335e512ae8ce190a8a13b114a42d2d729a6879
parent4c83b8950af48bd503c89988f4de7c6c41023c71 (diff)
downloadplatform-build-soong-3478bb2a7fbcaaea1326a1df4a564d7ca24056ce.tar.gz
platform-build-soong-3478bb2a7fbcaaea1326a1df4a564d7ca24056ce.tar.xz
platform-build-soong-3478bb2a7fbcaaea1326a1df4a564d7ca24056ce.zip
Teach soong not to duplicate the HWASAN runtime into each APEX.
When HWASAN is enabled, the runtime is conceptually part of Bionic (and mutually depends on it), so it needs to be treated in the same way as the Bionic libs. Now there are only two copies of the runtime: the one in /system/lib64/bootstrap (which won't be used by ordinary processes) and the one in the runtime APEX. This reduces the size of the HWASAN system image and fixes an issue where multiple copies of the HWASAN runtime were being loaded into 64-bit binaries in APEXes because the linker namespace for the binary is different from the one for its dependent libraries outside of APEXes. HWASAN only supports loading one copy of the runtime per process, so this was causing such binaries to crash on startup. Change-Id: I228896e193a035e6dfba9f6e28d0b2e12fc163ea
-rw-r--r--apex/apex.go11
-rw-r--r--cc/binary.go4
-rw-r--r--cc/cc.go10
-rw-r--r--cc/library.go6
-rw-r--r--cc/makevars.go15
5 files changed, 40 insertions, 6 deletions
diff --git a/apex/apex.go b/apex/apex.go
index 68d0bc14..51d0718a 100644
--- a/apex/apex.go
+++ b/apex/apex.go
@@ -521,6 +521,17 @@ func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
521 a.properties.Multilib.Prefer32.Binaries, target.String(), 521 a.properties.Multilib.Prefer32.Binaries, target.String(),
522 a.getImageVariation(config)) 522 a.getImageVariation(config))
523 } 523 }
524
525 if strings.HasPrefix(ctx.ModuleName(), "com.android.runtime") && target.Os.Class == android.Device {
526 for _, sanitizer := range ctx.Config().SanitizeDevice() {
527 if sanitizer == "hwaddress" {
528 addDependenciesForNativeModules(ctx,
529 []string{"libclang_rt.hwasan-aarch64-android"},
530 nil, target.String(), a.getImageVariation(config))
531 break
532 }
533 }
534 }
524 } 535 }
525 536
526 } 537 }
diff --git a/cc/binary.go b/cc/binary.go
index 51e68fcd..93d1de2d 100644
--- a/cc/binary.go
+++ b/cc/binary.go
@@ -440,8 +440,8 @@ func (binary *binaryDecorator) install(ctx ModuleContext, file android.Path) {
440 // Bionic binaries (e.g. linker) is installed to the bootstrap subdirectory. 440 // Bionic binaries (e.g. linker) is installed to the bootstrap subdirectory.
441 // The original path becomes a symlink to the corresponding file in the 441 // The original path becomes a symlink to the corresponding file in the
442 // runtime APEX. 442 // runtime APEX.
443 if isBionic(ctx.baseModuleName()) && ctx.Arch().Native && ctx.apexName() == "" && !ctx.inRecovery() { 443 if installToBootstrap(ctx.baseModuleName(), ctx.Config()) && ctx.Arch().Native && ctx.apexName() == "" && !ctx.inRecovery() {
444 if ctx.Device() { 444 if ctx.Device() && isBionic(ctx.baseModuleName()) {
445 binary.installSymlinkToRuntimeApex(ctx, file) 445 binary.installSymlinkToRuntimeApex(ctx, file)
446 } 446 }
447 binary.baseInstaller.subDir = "bootstrap" 447 binary.baseInstaller.subDir = "bootstrap"
diff --git a/cc/cc.go b/cc/cc.go
index a3b9a92d..786e4fd2 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -600,6 +600,9 @@ func (c *Module) HasStubsVariants() bool {
600 if library, ok := c.linker.(*libraryDecorator); ok { 600 if library, ok := c.linker.(*libraryDecorator); ok {
601 return len(library.Properties.Stubs.Versions) > 0 601 return len(library.Properties.Stubs.Versions) > 0
602 } 602 }
603 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
604 return len(library.Properties.Stubs.Versions) > 0
605 }
603 return false 606 return false
604} 607}
605 608
@@ -619,6 +622,13 @@ func isBionic(name string) bool {
619 return false 622 return false
620} 623}
621 624
625func installToBootstrap(name string, config android.Config) bool {
626 if name == "libclang_rt.hwasan-aarch64-android" {
627 return inList("hwaddress", config.SanitizeDevice())
628 }
629 return isBionic(name)
630}
631
622type baseModuleContext struct { 632type baseModuleContext struct {
623 android.BaseContext 633 android.BaseContext
624 moduleContextImpl 634 moduleContextImpl
diff --git a/cc/library.go b/cc/library.go
index c2ab098f..97b3cecb 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -958,12 +958,12 @@ func (library *libraryDecorator) install(ctx ModuleContext, file android.Path) {
958 library.baseInstaller.subDir += "-" + vndkVersion 958 library.baseInstaller.subDir += "-" + vndkVersion
959 } 959 }
960 } 960 }
961 } else if len(library.Properties.Stubs.Versions) > 0 && android.DirectlyInAnyApex(ctx, ctx.ModuleName()) { 961 } else if len(library.Properties.Stubs.Versions) > 0 {
962 // Bionic libraries (e.g. libc.so) is installed to the bootstrap subdirectory. 962 // Bionic libraries (e.g. libc.so) is installed to the bootstrap subdirectory.
963 // The original path becomes a symlink to the corresponding file in the 963 // The original path becomes a symlink to the corresponding file in the
964 // runtime APEX. 964 // runtime APEX.
965 if isBionic(ctx.baseModuleName()) && !library.buildStubs() && ctx.Arch().Native && !ctx.inRecovery() { 965 if installToBootstrap(ctx.baseModuleName(), ctx.Config()) && !library.buildStubs() && ctx.Arch().Native && !ctx.inRecovery() {
966 if ctx.Device() { 966 if ctx.Device() && isBionic(ctx.baseModuleName()) {
967 library.installSymlinkToRuntimeApex(ctx, file) 967 library.installSymlinkToRuntimeApex(ctx, file)
968 } 968 }
969 library.baseInstaller.subDir = "bootstrap" 969 library.baseInstaller.subDir = "bootstrap"
diff --git a/cc/makevars.go b/cc/makevars.go
index 3c24f347..a71f479a 100644
--- a/cc/makevars.go
+++ b/cc/makevars.go
@@ -96,7 +96,20 @@ func makeVarsProvider(ctx android.MakeVarsContext) {
96 96
97 ctx.Strict("VNDK_CORE_LIBRARIES", strings.Join(*vndkCoreLibraries(ctx.Config()), " ")) 97 ctx.Strict("VNDK_CORE_LIBRARIES", strings.Join(*vndkCoreLibraries(ctx.Config()), " "))
98 ctx.Strict("VNDK_SAMEPROCESS_LIBRARIES", strings.Join(*vndkSpLibraries(ctx.Config()), " ")) 98 ctx.Strict("VNDK_SAMEPROCESS_LIBRARIES", strings.Join(*vndkSpLibraries(ctx.Config()), " "))
99 ctx.Strict("LLNDK_LIBRARIES", strings.Join(*llndkLibraries(ctx.Config()), " ")) 99
100 // Make uses LLNDK_LIBRARIES to determine which libraries to install.
101 // HWASAN is only part of the LL-NDK in builds in which libc depends on HWASAN.
102 // Therefore, by removing the library here, we cause it to only be installed if libc
103 // depends on it.
104 installedLlndkLibraries := []string{}
105 for _, lib := range *llndkLibraries(ctx.Config()) {
106 if strings.HasPrefix(lib, "libclang_rt.hwasan-") {
107 continue
108 }
109 installedLlndkLibraries = append(installedLlndkLibraries, lib)
110 }
111 ctx.Strict("LLNDK_LIBRARIES", strings.Join(installedLlndkLibraries, " "))
112
100 ctx.Strict("VNDK_PRIVATE_LIBRARIES", strings.Join(*vndkPrivateLibraries(ctx.Config()), " ")) 113 ctx.Strict("VNDK_PRIVATE_LIBRARIES", strings.Join(*vndkPrivateLibraries(ctx.Config()), " "))
101 ctx.Strict("VNDK_USING_CORE_VARIANT_LIBRARIES", strings.Join(*vndkUsingCoreVariantLibraries(ctx.Config()), " ")) 114 ctx.Strict("VNDK_USING_CORE_VARIANT_LIBRARIES", strings.Join(*vndkUsingCoreVariantLibraries(ctx.Config()), " "))
102 115