Merge changes from topic "libc-bionic"

* changes:
  Give a knob to have apex ignore system-lib special cases
  Add limited target-specific configuration to apex.
diff --git a/Android.bp b/Android.bp
index 3215fa2..a70f73c 100644
--- a/Android.bp
+++ b/Android.bp
@@ -61,6 +61,7 @@
         "android/prebuilt_etc.go",
         "android/proto.go",
         "android/register.go",
+        "android/sh_binary.go",
         "android/singleton.go",
         "android/testing.go",
         "android/util.go",
diff --git a/OWNERS b/OWNERS
index 7983c19..85c70df 100644
--- a/OWNERS
+++ b/OWNERS
@@ -3,4 +3,3 @@
 per-file clang.go,global.go = srhines@google.com, chh@google.com, pirama@google.com, yikong@google.com
 per-file tidy.go = srhines@google.com, chh@google.com
 per-file lto.go,pgo.go = srhines@google.com, pirama@google.com, yikong@google.com
-per-file apex.go = jiyong@google.com
diff --git a/android/prebuilt_etc.go b/android/prebuilt_etc.go
index 46d128e..42c7c2c 100644
--- a/android/prebuilt_etc.go
+++ b/android/prebuilt_etc.go
@@ -125,7 +125,8 @@
 	p.outputFilePath = PathForModuleOut(ctx, filename).OutputPath
 	p.installDirPath = PathForModuleInstall(ctx, "etc", String(p.properties.Sub_dir))
 
-	// This ensures that outputFilePath has the same name as this module.
+	// This ensures that outputFilePath has the correct name for others to
+	// use, as the source file may have a different name.
 	ctx.Build(pctx, BuildParams{
 		Rule:   Cp,
 		Output: p.outputFilePath,
diff --git a/android/sh_binary.go b/android/sh_binary.go
new file mode 100644
index 0000000..3915193
--- /dev/null
+++ b/android/sh_binary.go
@@ -0,0 +1,141 @@
+// Copyright 2019 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package android
+
+import (
+	"fmt"
+	"io"
+)
+
+// sh_binary is for shell scripts (and batch files) that are installed as
+// executable files into .../bin/
+//
+// Do not use them for prebuilt C/C++/etc files.  Use cc_prebuilt_binary
+// instead.
+
+func init() {
+	RegisterModuleType("sh_binary", ShBinaryFactory)
+	RegisterModuleType("sh_binary_host", ShBinaryHostFactory)
+}
+
+type shBinaryProperties struct {
+	// Source file of this prebuilt.
+	Src *string `android:"arch_variant"`
+
+	// optional subdirectory under which this file is installed into
+	Sub_dir *string `android:"arch_variant"`
+
+	// optional name for the installed file. If unspecified, name of the module is used as the file name
+	Filename *string `android:"arch_variant"`
+
+	// when set to true, and filename property is not set, the name for the installed file
+	// is the same as the file name of the source file.
+	Filename_from_src *bool `android:"arch_variant"`
+
+	// Whether this module is directly installable to one of the partitions. Default: true.
+	Installable *bool
+}
+
+type ShBinary struct {
+	ModuleBase
+
+	properties shBinaryProperties
+
+	sourceFilePath Path
+	outputFilePath OutputPath
+}
+
+func (s *ShBinary) DepsMutator(ctx BottomUpMutatorContext) {
+	if s.properties.Src == nil {
+		ctx.PropertyErrorf("src", "missing prebuilt source file")
+	}
+
+	// To support ":modulename" in src
+	ExtractSourceDeps(ctx, s.properties.Src)
+}
+
+func (s *ShBinary) SourceFilePath(ctx ModuleContext) Path {
+	return ctx.ExpandSource(String(s.properties.Src), "src")
+}
+
+func (s *ShBinary) OutputFile() OutputPath {
+	return s.outputFilePath
+}
+
+func (s *ShBinary) SubDir() string {
+	return String(s.properties.Sub_dir)
+}
+
+func (s *ShBinary) Installable() bool {
+	return s.properties.Installable == nil || Bool(s.properties.Installable)
+}
+
+func (s *ShBinary) GenerateAndroidBuildActions(ctx ModuleContext) {
+	s.sourceFilePath = ctx.ExpandSource(String(s.properties.Src), "src")
+	filename := String(s.properties.Filename)
+	filename_from_src := Bool(s.properties.Filename_from_src)
+	if filename == "" {
+		if filename_from_src {
+			filename = s.sourceFilePath.Base()
+		} else {
+			filename = ctx.ModuleName()
+		}
+	} else if filename_from_src {
+		ctx.PropertyErrorf("filename_from_src", "filename is set. filename_from_src can't be true")
+		return
+	}
+	s.outputFilePath = PathForModuleOut(ctx, filename).OutputPath
+
+	// This ensures that outputFilePath has the correct name for others to
+	// use, as the source file may have a different name.
+	ctx.Build(pctx, BuildParams{
+		Rule:   CpExecutable,
+		Output: s.outputFilePath,
+		Input:  s.sourceFilePath,
+	})
+}
+
+func (s *ShBinary) AndroidMk() AndroidMkData {
+	return AndroidMkData{
+		Class:      "EXECUTABLES",
+		OutputFile: OptionalPathForPath(s.outputFilePath),
+		Include:    "$(BUILD_SYSTEM)/soong_cc_prebuilt.mk",
+		Extra: []AndroidMkExtraFunc{
+			func(w io.Writer, outputFile Path) {
+				fmt.Fprintln(w, "LOCAL_MODULE_RELATIVE_PATH :=", String(s.properties.Sub_dir))
+				fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX :=")
+				fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", s.outputFilePath.Rel())
+			},
+		},
+	}
+}
+
+func InitShBinaryModule(s *ShBinary) {
+	s.AddProperties(&s.properties)
+}
+
+func ShBinaryFactory() Module {
+	module := &ShBinary{}
+	InitShBinaryModule(module)
+	InitAndroidArchModule(module, HostAndDeviceSupported, MultilibFirst)
+	return module
+}
+
+func ShBinaryHostFactory() Module {
+	module := &ShBinary{}
+	InitShBinaryModule(module)
+	InitAndroidArchModule(module, HostSupported, MultilibFirst)
+	return module
+}
diff --git a/apex/OWNERS b/apex/OWNERS
new file mode 100644
index 0000000..a382ae8
--- /dev/null
+++ b/apex/OWNERS
@@ -0,0 +1 @@
+per-file * = jiyong@google.com
\ No newline at end of file
diff --git a/cc/binary.go b/cc/binary.go
index 4c86371..d4edc1a 100644
--- a/cc/binary.go
+++ b/cc/binary.go
@@ -249,7 +249,11 @@
 				} else {
 					switch ctx.Os() {
 					case android.Android:
-						flags.DynamicLinker = "/system/bin/linker"
+						if ctx.bootstrap() {
+							flags.DynamicLinker = "/system/bin/bootstrap/linker"
+						} else {
+							flags.DynamicLinker = "/system/bin/linker"
+						}
 						if flags.Toolchain.Is64Bit() {
 							flags.DynamicLinker += "64"
 						}
diff --git a/cc/builder.go b/cc/builder.go
index b012d6f..645b3c2 100644
--- a/cc/builder.go
+++ b/cc/builder.go
@@ -663,18 +663,33 @@
 // Generate a rule to combine .dump sAbi dump files from multiple source files
 // into a single .ldump sAbi dump file
 func TransformDumpToLinkedDump(ctx android.ModuleContext, sAbiDumps android.Paths, soFile android.Path,
-	baseName, exportedHeaderFlags string) android.OptionalPath {
+	baseName, exportedHeaderFlags string, symbolFile android.OptionalPath,
+	excludedSymbolVersions, excludedSymbolTags []string) android.OptionalPath {
+
 	outputFile := android.PathForModuleOut(ctx, baseName+".lsdump")
 	sabiLock.Lock()
 	lsdumpPaths = append(lsdumpPaths, outputFile.String())
 	sabiLock.Unlock()
+
+	implicits := android.Paths{soFile}
 	symbolFilterStr := "-so " + soFile.String()
+
+	if symbolFile.Valid() {
+		implicits = append(implicits, symbolFile.Path())
+		symbolFilterStr += " -v " + symbolFile.String()
+	}
+	for _, ver := range excludedSymbolVersions {
+		symbolFilterStr += " --exclude-symbol-version " + ver
+	}
+	for _, tag := range excludedSymbolTags {
+		symbolFilterStr += " --exclude-symbol-tag " + tag
+	}
 	ctx.Build(pctx, android.BuildParams{
 		Rule:        sAbiLink,
 		Description: "header-abi-linker " + outputFile.Base(),
 		Output:      outputFile,
 		Inputs:      sAbiDumps,
-		Implicit:    soFile,
+		Implicits:   implicits,
 		Args: map[string]string{
 			"symbolFilter":        symbolFilterStr,
 			"arch":                ctx.Arch().ArchType.Name,
diff --git a/cc/cc.go b/cc/cc.go
index 062e6d9..58ea5e1 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -261,6 +261,7 @@
 	apexName() string
 	hasStubsVariants() bool
 	isStubs() bool
+	bootstrap() bool
 }
 
 type ModuleContext interface {
@@ -571,6 +572,10 @@
 	return false
 }
 
+func (c *Module) bootstrap() bool {
+	return Bool(c.Properties.Bootstrap)
+}
+
 type baseModuleContext struct {
 	android.BaseContext
 	moduleContextImpl
@@ -741,6 +746,10 @@
 	return ctx.mod.IsStubs()
 }
 
+func (ctx *moduleContextImpl) bootstrap() bool {
+	return ctx.mod.bootstrap()
+}
+
 func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
 	return &Module{
 		hod:      hod,
@@ -1553,7 +1562,7 @@
 					// If not building for APEX, use stubs only when it is from
 					// an APEX (and not from platform)
 					useThisDep = (depInPlatform != depIsStubs)
-					if c.inRecovery() || Bool(c.Properties.Bootstrap) {
+					if c.inRecovery() || c.bootstrap() {
 						// However, for recovery or bootstrap modules,
 						// always link to non-stub variant
 						useThisDep = !depIsStubs
diff --git a/cc/library.go b/cc/library.go
index ad07db4..c01b3e7 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -87,6 +87,19 @@
 	// binaries would be installed by default (in PRODUCT_PACKAGES) the other library will be removed
 	// from PRODUCT_PACKAGES.
 	Overrides []string
+
+	// Properties for ABI compatibility checker
+	Header_abi_checker struct {
+		// Path to a symbol file that specifies the symbols to be included in the generated
+		// ABI dump file
+		Symbol_file *string
+
+		// Symbol versions that should be ignored from the symbol file
+		Exclude_symbol_versions []string
+
+		// Symbol tags that should be ignored from the symbol file
+		Exclude_symbol_tags []string
+	}
 }
 
 type LibraryMutatedProperties struct {
@@ -567,11 +580,15 @@
 		deps.WholeStaticLibs = removeListFromList(deps.WholeStaticLibs, library.baseLinker.Properties.Target.Vendor.Exclude_static_libs)
 		deps.SharedLibs = removeListFromList(deps.SharedLibs, library.baseLinker.Properties.Target.Vendor.Exclude_shared_libs)
 		deps.StaticLibs = removeListFromList(deps.StaticLibs, library.baseLinker.Properties.Target.Vendor.Exclude_static_libs)
+		deps.ReexportSharedLibHeaders = removeListFromList(deps.ReexportSharedLibHeaders, library.baseLinker.Properties.Target.Vendor.Exclude_shared_libs)
+		deps.ReexportStaticLibHeaders = removeListFromList(deps.ReexportStaticLibHeaders, library.baseLinker.Properties.Target.Vendor.Exclude_static_libs)
 	}
 	if ctx.inRecovery() {
 		deps.WholeStaticLibs = removeListFromList(deps.WholeStaticLibs, library.baseLinker.Properties.Target.Recovery.Exclude_static_libs)
 		deps.SharedLibs = removeListFromList(deps.SharedLibs, library.baseLinker.Properties.Target.Recovery.Exclude_shared_libs)
 		deps.StaticLibs = removeListFromList(deps.StaticLibs, library.baseLinker.Properties.Target.Recovery.Exclude_static_libs)
+		deps.ReexportSharedLibHeaders = removeListFromList(deps.ReexportSharedLibHeaders, library.baseLinker.Properties.Target.Recovery.Exclude_shared_libs)
+		deps.ReexportStaticLibHeaders = removeListFromList(deps.ReexportStaticLibHeaders, library.baseLinker.Properties.Target.Recovery.Exclude_static_libs)
 	}
 
 	android.ExtractSourceDeps(ctx, library.Properties.Unexported_symbols_list)
@@ -760,7 +777,10 @@
 			SourceAbiFlags = append(SourceAbiFlags, reexportedInclude)
 		}
 		exportedHeaderFlags := strings.Join(SourceAbiFlags, " ")
-		library.sAbiOutputFile = TransformDumpToLinkedDump(ctx, objs.sAbiDumpFiles, soFile, fileName, exportedHeaderFlags)
+		library.sAbiOutputFile = TransformDumpToLinkedDump(ctx, objs.sAbiDumpFiles, soFile, fileName, exportedHeaderFlags,
+			android.OptionalPathForModuleSrc(ctx, library.Properties.Header_abi_checker.Symbol_file),
+			library.Properties.Header_abi_checker.Exclude_symbol_versions,
+			library.Properties.Header_abi_checker.Exclude_symbol_tags)
 
 		refAbiDumpFile := getRefAbiDumpFile(ctx, vndkVersion, fileName)
 		if refAbiDumpFile != nil {
@@ -867,6 +887,18 @@
 					library.baseInstaller.subDir += "-" + vndkVersion
 				}
 			}
+		} else if len(library.Properties.Stubs.Versions) > 0 && android.DirectlyInAnyApex(ctx, ctx.ModuleName()) {
+			// If a library in an APEX has stable versioned APIs, we basically don't need
+			// to have the platform variant of the library in /system partition because
+			// platform components can just use the lib from the APEX without fearing about
+			// compatibility. However, if the library is required for some early processes
+			// before the APEX is activated, the platform variant may also be required.
+			// In that case, it is installed to the subdirectory 'bootstrap' in order to
+			// be distinguished/isolated from other non-bootstrap libraries in /system/lib
+			// so that the bootstrap libraries are used only when the APEX isn't ready.
+			if !library.buildStubs() && ctx.Arch().Native {
+				library.baseInstaller.subDir = "bootstrap"
+			}
 		}
 		library.baseInstaller.install(ctx, file)
 	}
diff --git a/cc/xom.go b/cc/xom.go
index 182069f..9337990 100644
--- a/cc/xom.go
+++ b/cc/xom.go
@@ -50,7 +50,7 @@
 	// If any static dependencies have XOM disabled, we should disable XOM in this module,
 	// the assumption being if it's been explicitly disabled then there's probably incompatible
 	// code in the library which may get pulled in.
-	if !ctx.static() && !disableXom {
+	if !disableXom {
 		ctx.VisitDirectDeps(func(m android.Module) {
 			cc, ok := m.(*Module)
 			if !ok || cc.xom == nil || !cc.static() {
diff --git a/java/android_resources.go b/java/android_resources.go
index 47535d2..efd3e3d 100644
--- a/java/android_resources.go
+++ b/java/android_resources.go
@@ -44,10 +44,6 @@
 type overlayGlobResult struct {
 	dir   string
 	paths android.DirectorySortedPaths
-
-	// Set to true of the product has selected that values in this overlay should not be moved to
-	// Runtime Resource Overlay (RRO) packages.
-	excludeFromRRO bool
 }
 
 const overlayDataKey = "overlayDataKey"
@@ -69,10 +65,11 @@
 		files := data.paths.PathsInDirectory(filepath.Join(data.dir, dir.String()))
 		if len(files) > 0 {
 			overlayModuleDir := android.PathForSource(ctx, data.dir, dir.String())
+
 			// If enforce RRO is enabled for this module and this overlay is not in the
 			// exclusion list, ignore the overlay.  The list of ignored overlays will be
 			// passed to Make to be turned into an RRO package.
-			if rroEnabled && !data.excludeFromRRO {
+			if rroEnabled && !ctx.Config().EnforceRROExcludedOverlay(overlayModuleDir.String()) {
 				rroDirs = append(rroDirs, overlayModuleDir)
 			} else {
 				res = append(res, globbedResourceDir{
@@ -102,10 +99,6 @@
 		var result overlayGlobResult
 		result.dir = overlay
 
-		// Mark overlays that will not have Runtime Resource Overlays enforced on them
-		// based on the product config
-		result.excludeFromRRO = ctx.Config().EnforceRROExcludedOverlay(overlay)
-
 		files, err := ctx.GlobWithDeps(filepath.Join(overlay, "**/*"), androidResourceIgnoreFilenames)
 		if err != nil {
 			ctx.Errorf("failed to glob resource dir %q: %s", overlay, err.Error())
diff --git a/java/androidmk.go b/java/androidmk.go
index 62d754a..089ed4f 100644
--- a/java/androidmk.go
+++ b/java/androidmk.go
@@ -382,7 +382,7 @@
 					fmt.Fprintln(w, ddoc.Name()+"-check-last-released-api:",
 						ddoc.checkLastReleasedApiTimestamp.String())
 
-					if ddoc.Name() == "api-stubs-docs" {
+					if ddoc.Name() == "api-stubs-docs" || ddoc.Name() == "system-api-stubs-docs" {
 						fmt.Fprintln(w, ".PHONY: checkapi")
 						fmt.Fprintln(w, "checkapi:",
 							ddoc.checkLastReleasedApiTimestamp.String())
@@ -469,7 +469,7 @@
 					fmt.Fprintln(w, dstubs.Name()+"-check-last-released-api:",
 						dstubs.checkLastReleasedApiTimestamp.String())
 
-					if dstubs.Name() == "api-stubs-docs" {
+					if dstubs.Name() == "api-stubs-docs" || dstubs.Name() == "system-api-stubs-docs" {
 						fmt.Fprintln(w, ".PHONY: checkapi")
 						fmt.Fprintln(w, "checkapi:",
 							dstubs.checkLastReleasedApiTimestamp.String())
diff --git a/java/app_test.go b/java/app_test.go
index 7e06dba..21bda3c 100644
--- a/java/app_test.go
+++ b/java/app_test.go
@@ -149,9 +149,13 @@
 		},
 	},
 	{
-		name:                       "enforce RRO on all",
-		enforceRROTargets:          []string{"*"},
-		enforceRROExcludedOverlays: []string{"device/vendor/blah/static_overlay"},
+		name:              "enforce RRO on all",
+		enforceRROTargets: []string{"*"},
+		enforceRROExcludedOverlays: []string{
+			// Excluding specific apps/res directories also allowed.
+			"device/vendor/blah/static_overlay/foo",
+			"device/vendor/blah/static_overlay/bar/res",
+		},
 		overlayFiles: map[string][]string{
 			"foo": []string{"device/vendor/blah/static_overlay/foo/res/values/strings.xml"},
 			"bar": []string{"device/vendor/blah/static_overlay/bar/res/values/strings.xml"},
@@ -208,11 +212,12 @@
 
 			getOverlays := func(moduleName string) ([]string, []string) {
 				module := ctx.ModuleForTests(moduleName, "android_common")
-				overlayCompiledPaths := module.Output("aapt2/overlay.list").Inputs.Strings()
-
+				overlayFile := module.MaybeOutput("aapt2/overlay.list")
 				var overlayFiles []string
-				for _, o := range overlayCompiledPaths {
-					overlayFiles = append(overlayFiles, module.Output(o).Inputs.Strings()...)
+				if overlayFile.Rule != nil {
+					for _, o := range overlayFile.Inputs.Strings() {
+						overlayFiles = append(overlayFiles, module.Output(o).Inputs.Strings()...)
+					}
 				}
 
 				rroDirs := module.Module().(*AndroidApp).rroDirs.Strings()
diff --git a/ui/status/kati.go b/ui/status/kati.go
index 7c26d42..1485c8d 100644
--- a/ui/status/kati.go
+++ b/ui/status/kati.go
@@ -121,6 +121,7 @@
 	}
 
 	scanner := bufio.NewScanner(pipe)
+	scanner.Buffer(nil, 2*1024*1024)
 	for scanner.Scan() {
 		parser.parseLine(scanner.Text())
 	}