Refactor sanitized library on-disk layout - Soong.

This CL moves the location of ASAN-ified libraries on disk in the
following manner:
/data/lib* --> /data/asan/system/lib*
/data/vendor/* --> /data/asan/vendor/*

There are a couple of advantages to this, including better isolation
from other components, and more transparent linker renaming and
SELinux policies.

Bug: 36574794
Bug: 36674745
Test: m -j40 && SANITIZE_TARGET="address" m -j40 and the device
boots. All sanitized libraries are correctly located in /data/asan/*.

Change-Id: I06bf459260ec451d4495a02562f640ad622f34c2
diff --git a/android/module.go b/android/module.go
index 8228a9c..4fba1cf 100644
--- a/android/module.go
+++ b/android/module.go
@@ -89,6 +89,7 @@
 	AddMissingDependencies(deps []string)
 
 	InstallInData() bool
+	InstallInSanitizerDir() bool
 
 	RequiredModuleNames() []string
 }
@@ -103,6 +104,7 @@
 	Enabled() bool
 	Target() Target
 	InstallInData() bool
+	InstallInSanitizerDir() bool
 	SkipInstall()
 }
 
@@ -399,6 +401,10 @@
 	return false
 }
 
+func (p *ModuleBase) InstallInSanitizerDir() bool {
+	return false
+}
+
 func (a *ModuleBase) generateModuleTarget(ctx blueprint.ModuleContext) {
 	allInstalledFiles := Paths{}
 	allCheckbuildFiles := Paths{}
@@ -629,6 +635,10 @@
 	return a.module.InstallInData()
 }
 
+func (a *androidModuleContext) InstallInSanitizerDir() bool {
+	return a.module.InstallInSanitizerDir()
+}
+
 func (a *androidModuleContext) InstallFileName(installPath OutputPath, name string, srcPath Path,
 	deps ...Path) OutputPath {
 
diff --git a/android/paths.go b/android/paths.go
index 037c98d..fe639e6 100644
--- a/android/paths.go
+++ b/android/paths.go
@@ -652,7 +652,10 @@
 		if ctx.Proprietary() {
 			partition = ctx.DeviceConfig().VendorPath()
 		}
-		if ctx.InstallInData() {
+
+		if ctx.InstallInSanitizerDir() {
+			partition = "data/asan/" + partition
+		} else if ctx.InstallInData() {
 			partition = "data"
 		}
 		outPaths = []string{"target", "product", ctx.AConfig().DeviceName(), partition}
diff --git a/cc/cc.go b/cc/cc.go
index b107d01..6f5539f 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -212,6 +212,7 @@
 	installerProps() []interface{}
 	install(ctx ModuleContext, path android.Path)
 	inData() bool
+	inSanitizerDir() bool
 	hostToolPath() android.OptionalPath
 }
 
@@ -993,10 +994,17 @@
 	if c.installer == nil {
 		return false
 	}
-	if c.sanitize != nil && c.sanitize.inData() {
+	return c.installer.inData()
+}
+
+func (c *Module) InstallInSanitizerDir() bool {
+	if c.installer == nil {
+		return false
+	}
+	if c.sanitize != nil && c.sanitize.inSanitizerDir() {
 		return true
 	}
-	return c.installer.inData()
+	return c.installer.inSanitizerDir()
 }
 
 func (c *Module) HostToolPath() android.OptionalPath {
diff --git a/cc/installer.go b/cc/installer.go
index 64f87d9..c4de589 100644
--- a/cc/installer.go
+++ b/cc/installer.go
@@ -30,8 +30,9 @@
 type installLocation int
 
 const (
-	InstallInSystem installLocation = 0
-	InstallInData                   = iota
+	InstallInSystem       installLocation = 0
+	InstallInData                         = iota
+	InstallInSanitizerDir                 = iota
 )
 
 func NewBaseInstaller(dir, dir64 string, location installLocation) *baseInstaller {
@@ -78,6 +79,10 @@
 	return installer.location == InstallInData
 }
 
+func (installer *baseInstaller) inSanitizerDir() bool {
+	return installer.location == InstallInSanitizerDir
+}
+
 func (installer *baseInstaller) hostToolPath() android.OptionalPath {
 	return android.OptionalPath{}
 }
diff --git a/cc/library.go b/cc/library.go
index 0658fef..953c37a 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -349,8 +349,8 @@
 
 func (library *libraryDecorator) linkerInit(ctx BaseModuleContext) {
 	location := InstallInSystem
-	if library.sanitize.inData() {
-		location = InstallInData
+	if library.sanitize.inSanitizerDir() {
+		location = InstallInSanitizerDir
 	}
 	library.baseInstaller.location = location
 
diff --git a/cc/sanitize.go b/cc/sanitize.go
index bccd28d..18d6c16 100644
--- a/cc/sanitize.go
+++ b/cc/sanitize.go
@@ -97,7 +97,7 @@
 
 	SanitizerEnabled bool `blueprint:"mutated"`
 	SanitizeDep      bool `blueprint:"mutated"`
-	InData           bool `blueprint:"mutated"`
+	InSanitizerDir   bool `blueprint:"mutated"`
 }
 
 type sanitize struct {
@@ -383,8 +383,8 @@
 	return flags
 }
 
-func (sanitize *sanitize) inData() bool {
-	return sanitize.Properties.InData
+func (sanitize *sanitize) inSanitizerDir() bool {
+	return sanitize.Properties.InSanitizerDir
 }
 
 func (sanitize *sanitize) Sanitizer(t sanitizerType) bool {
@@ -447,7 +447,7 @@
 				modules[0].(*Module).sanitize.Properties.SanitizeDep = false
 				modules[1].(*Module).sanitize.Properties.SanitizeDep = false
 				if mctx.Device() {
-					modules[1].(*Module).sanitize.Properties.InData = true
+					modules[1].(*Module).sanitize.Properties.InSanitizerDir = true
 				} else {
 					modules[0].(*Module).Properties.PreventInstall = true
 				}