Merge "Add Nan to OWNERS"
diff --git a/android/config.go b/android/config.go
index 43d743b..5d38d71 100644
--- a/android/config.go
+++ b/android/config.go
@@ -712,6 +712,13 @@
 	return PrefixInList(path, *c.ProductVariables.CFIExcludePaths)
 }
 
+func (c *config) IntegerOverflowEnabledForPath(path string) bool {
+	if c.ProductVariables.IntegerOverflowIncludePaths == nil {
+		return false
+	}
+	return PrefixInList(path, *c.ProductVariables.IntegerOverflowIncludePaths)
+}
+
 func (c *config) CFIEnabledForPath(path string) bool {
 	if c.ProductVariables.CFIIncludePaths == nil {
 		return false
diff --git a/android/variable.go b/android/variable.go
index d58ed6a..aa751a0 100644
--- a/android/variable.go
+++ b/android/variable.go
@@ -167,6 +167,7 @@
 	MinimizeJavaDebugInfo      *bool `json:",omitempty"`
 
 	IntegerOverflowExcludePaths *[]string `json:",omitempty"`
+	IntegerOverflowIncludePaths *[]string `json:",omitempty"`
 
 	EnableCFI       *bool     `json:",omitempty"`
 	CFIExcludePaths *[]string `json:",omitempty"`
diff --git a/cc/builder.go b/cc/builder.go
index fcc4318..1e1c4f2 100644
--- a/cc/builder.go
+++ b/cc/builder.go
@@ -711,8 +711,12 @@
 }
 
 func SourceAbiDiff(ctx android.ModuleContext, inputDump android.Path, referenceDump android.Path,
-	baseName string) android.OptionalPath {
+	baseName, exportedHeaderFlags string) android.OptionalPath {
 	outputFile := android.PathForModuleOut(ctx, baseName+".abidiff")
+	localAbiCheckAllowFlags := append([]string(nil), abiCheckAllowFlags...)
+	if exportedHeaderFlags == "" {
+		localAbiCheckAllowFlags = append(localAbiCheckAllowFlags, "-advice-only")
+	}
 	ctx.Build(pctx, android.BuildParams{
 		Rule:        sAbiDiff,
 		Description: "header-abi-diff " + outputFile.Base(),
@@ -723,7 +727,7 @@
 			"referenceDump": referenceDump.String(),
 			"libName":       baseName,
 			"arch":          ctx.Arch().ArchType.Name,
-			"allowFlags":    strings.Join(abiCheckAllowFlags, " "),
+			"allowFlags":    strings.Join(localAbiCheckAllowFlags, " "),
 		},
 	})
 	return android.OptionalPathForPath(outputFile)
diff --git a/cc/cc.go b/cc/cc.go
index e5a483d..a3af304 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -1442,12 +1442,17 @@
 		mod := mctx.CreateVariations(vendorMode)
 		vendor := mod[0].(*Module)
 		vendor.Properties.UseVndk = true
-	} else if _, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
+	} else if prebuilt, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
 		// Make vendor variants only for the versions in BOARD_VNDK_VERSION and
 		// PRODUCT_EXTRA_VNDK_VERSIONS.
 		mod := mctx.CreateVariations(vendorMode)
 		vendor := mod[0].(*Module)
 		vendor.Properties.UseVndk = true
+		arches := mctx.DeviceConfig().Arches()
+		if len(arches) == 0 || arches[0].ArchType.String() != prebuilt.arch() {
+			vendor.Properties.PreventInstall = true
+			vendor.Properties.HideFromMake = true
+		}
 	} else if m.hasVendorVariant() {
 		// This will be available in both /system and /vendor
 		// or a /system directory that is available to vendor.
diff --git a/cc/config/global.go b/cc/config/global.go
index ef710c8..5e99cde 100644
--- a/cc/config/global.go
+++ b/cc/config/global.go
@@ -112,7 +112,7 @@
 	ExperimentalCStdVersion   = "gnu11"
 	ExperimentalCppStdVersion = "gnu++1z"
 
-	NdkMaxPrebuiltVersionInt = 24
+	NdkMaxPrebuiltVersionInt = 27
 
 	// prebuilts/clang default settings.
 	ClangDefaultBase         = "prebuilts/clang/host"
diff --git a/cc/library.go b/cc/library.go
index adbd6b5..0ed1848 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -632,7 +632,7 @@
 		library.sAbiOutputFile = TransformDumpToLinkedDump(ctx, objs.sAbiDumpFiles, soFile, fileName, exportedHeaderFlags)
 		if refSourceDumpFile.Valid() {
 			unzippedRefDump := UnzipRefDump(ctx, refSourceDumpFile.Path(), fileName)
-			library.sAbiDiff = SourceAbiDiff(ctx, library.sAbiOutputFile.Path(), unzippedRefDump, fileName)
+			library.sAbiDiff = SourceAbiDiff(ctx, library.sAbiOutputFile.Path(), unzippedRefDump, fileName, exportedHeaderFlags)
 		}
 	}
 }
diff --git a/cc/sanitize.go b/cc/sanitize.go
index 1afec26..859478b 100644
--- a/cc/sanitize.go
+++ b/cc/sanitize.go
@@ -232,6 +232,14 @@
 		}
 	}
 
+	// Enable Integer Overflow for all components in the include paths
+	if !ctx.Host() && ctx.Config().IntegerOverflowEnabledForPath(ctx.ModuleDir()) && s.Integer_overflow == nil {
+		s.Integer_overflow = boolPtr(true)
+		if inList("integer_overflow", ctx.Config().SanitizeDeviceDiag()) {
+			s.Diag.Integer_overflow = boolPtr(true)
+		}
+	}
+
 	// CFI needs gold linker, and mips toolchain does not have one.
 	if !ctx.Config().EnableCFI() || ctx.Arch().ArchType == android.Mips || ctx.Arch().ArchType == android.Mips64 {
 		s.Cfi = nil
@@ -417,6 +425,7 @@
 			sanitizers = append(sanitizers, "unsigned-integer-overflow")
 			sanitizers = append(sanitizers, "signed-integer-overflow")
 			flags.CFlags = append(flags.CFlags, intOverflowCflags...)
+
 			if Bool(sanitize.Properties.Sanitize.Diag.Integer_overflow) {
 				diagSanitizers = append(diagSanitizers, "unsigned-integer-overflow")
 				diagSanitizers = append(diagSanitizers, "signed-integer-overflow")
@@ -424,6 +433,8 @@
 		}
 	}
 
+	diagSanitizeArgs := "-fno-sanitize-trap=" + strings.Join(diagSanitizers, ",")
+
 	if len(sanitizers) > 0 {
 		sanitizeArg := "-fsanitize=" + strings.Join(sanitizers, ",")
 		flags.CFlags = append(flags.CFlags, sanitizeArg)
@@ -436,10 +447,19 @@
 		} else {
 			flags.CFlags = append(flags.CFlags, "-fsanitize-trap=all", "-ftrap-function=abort")
 		}
+
+		// Specific settings for userdebug and eng builds
+		if Bool(ctx.Config().ProductVariables.Debuggable) {
+			// TODO(ivanlozano): uncomment after switch to clang-4536805.
+			// Run integer overflow sanitizers with the minimal runtime diagnostics.
+			if strings.Contains(sanitizeArg, "integer") && !strings.Contains(diagSanitizeArgs, "integer") && !Bool(sanitize.Properties.Sanitize.Address) {
+				//flags.CFlags = append(flags.CFlags, "-fsanitize-minimal-runtime")
+			}
+		}
 	}
 
 	if len(diagSanitizers) > 0 {
-		flags.CFlags = append(flags.CFlags, "-fno-sanitize-trap="+strings.Join(diagSanitizers, ","))
+		flags.CFlags = append(flags.CFlags, diagSanitizeArgs)
 	}
 	// FIXME: enable RTTI if diag + (cfi or vptr)
 
diff --git a/cc/vndk_prebuilt.go b/cc/vndk_prebuilt.go
index b4fcb57..99e35f3 100644
--- a/cc/vndk_prebuilt.go
+++ b/cc/vndk_prebuilt.go
@@ -111,12 +111,10 @@
 
 func (p *vndkPrebuiltLibraryDecorator) install(ctx ModuleContext, file android.Path) {
 	if p.shared() {
-		if ctx.Device() && ctx.useVndk() {
-			if ctx.isVndkSp() {
-				p.baseInstaller.subDir = "vndk-sp-" + p.version()
-			} else if ctx.isVndk() {
-				p.baseInstaller.subDir = "vndk-" + p.version()
-			}
+		if ctx.isVndkSp() {
+			p.baseInstaller.subDir = "vndk-sp-" + p.version()
+		} else if ctx.isVndk() {
+			p.baseInstaller.subDir = "vndk-" + p.version()
 		}
 		p.baseInstaller.install(ctx, file)
 	}