Merge "Revert "Refactor rate_limit.go for more clarify""
am: 1115ddc838

Change-Id: Ic17c986c5058b463b529542588f67eb5e3ac83d5
diff --git a/android/variable.go b/android/variable.go
index 74fa868..9cb8c63 100644
--- a/android/variable.go
+++ b/android/variable.go
@@ -81,6 +81,7 @@
 		Debuggable struct {
 			Cflags   []string
 			Cppflags []string
+			Init_rc  []string
 		}
 
 		// eng is true for -eng builds, and can be used to turn on additionaly heavyweight debugging
diff --git a/cc/cc.go b/cc/cc.go
index ba06be2..bda9c9d 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -35,7 +35,6 @@
 
 	android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
 		ctx.BottomUp("link", linkageMutator).Parallel()
-		ctx.BottomUp("vndk", vndkMutator).Parallel()
 		ctx.BottomUp("image", vendorMutator).Parallel()
 		ctx.BottomUp("ndk_api", ndkApiMutator).Parallel()
 		ctx.BottomUp("test_per_src", testPerSrcMutator).Parallel()
@@ -465,7 +464,7 @@
 
 // Create source abi dumps if the module belongs to the list of VndkLibraries.
 func (ctx *moduleContextImpl) createVndkSourceAbiDump() bool {
-	return ctx.ctx.Device() && (ctx.mod.isVndk() || inList(ctx.baseModuleName(), llndkLibraries))
+	return ctx.ctx.Device() && (ctx.mod.isVndk() || inList(ctx.baseModuleName(), config.LLndkLibraries()))
 }
 
 func (ctx *moduleContextImpl) selectedStl() string {
@@ -763,7 +762,7 @@
 					} else {
 						variantLibs = append(variantLibs, entry+ndkLibrarySuffix)
 					}
-				} else if ctx.vndk() && inList(entry, llndkLibraries) {
+				} else if ctx.vndk() && inList(entry, config.LLndkLibraries()) {
 					nonvariantLibs = append(nonvariantLibs, entry+llndkLibrarySuffix)
 				} else {
 					nonvariantLibs = append(nonvariantLibs, entry)
@@ -1127,7 +1126,7 @@
 		case sharedDepTag, sharedExportDepTag, lateSharedDepTag:
 			libName := strings.TrimSuffix(name, llndkLibrarySuffix)
 			libName = strings.TrimPrefix(libName, "prebuilt_")
-			isLLndk := inList(libName, llndkLibraries)
+			isLLndk := inList(libName, config.LLndkLibraries())
 			if c.vndk() && (Bool(cc.Properties.Vendor_available) || isLLndk) {
 				libName += vendorSuffix
 			}
diff --git a/cc/config/global.go b/cc/config/global.go
index 82a44e6..64fbd32 100644
--- a/cc/config/global.go
+++ b/cc/config/global.go
@@ -191,6 +191,17 @@
 	}, " ")
 }
 
+func VndkLibraries() []string {
+	return []string{}
+}
+
+// This needs to be kept up to date with the list in system/core/rootdir/etc/ld.config.txt:
+// [vendor]
+// namespace.default.link.system.shared_libs
+func LLndkLibraries() []string {
+	return []string{"libc", "libm", "libdl", "liblog", "libandroid_net", "ld-android"}
+}
+
 func replaceFirst(slice []string, from, to string) {
 	if slice[0] != from {
 		panic(fmt.Errorf("Expected %q, found %q", from, to))
diff --git a/cc/library.go b/cc/library.go
index 4a173a5..4e3e2b3 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -21,6 +21,7 @@
 	"github.com/google/blueprint/pathtools"
 
 	"android/soong/android"
+	"android/soong/cc/config"
 )
 
 type LibraryProperties struct {
@@ -620,7 +621,7 @@
 }
 
 func vndkVsNdk(ctx ModuleContext) bool {
-	if inList(ctx.baseModuleName(), llndkLibraries) {
+	if inList(ctx.baseModuleName(), config.LLndkLibraries()) {
 		return false
 	}
 	return true
diff --git a/cc/makevars.go b/cc/makevars.go
index 8bdcf9f..294f3e6 100644
--- a/cc/makevars.go
+++ b/cc/makevars.go
@@ -59,10 +59,6 @@
 		ctx.Strict("BOARD_VNDK_VERSION", "")
 	}
 
-	ctx.Strict("VNDK_CORE_LIBRARIES", strings.Join(vndkCoreLibraries, " "))
-	ctx.Strict("VNDK_SAMEPROCESS_LIBRARIES", strings.Join(vndkSpLibraries, " "))
-	ctx.Strict("LLNDK_LIBRARIES", strings.Join(llndkLibraries, " "))
-
 	ctx.Strict("ADDRESS_SANITIZER_CONFIG_EXTRA_CFLAGS", strings.Join(asanCflags, " "))
 	ctx.Strict("ADDRESS_SANITIZER_CONFIG_EXTRA_LDFLAGS", strings.Join(asanLdflags, " "))
 	ctx.Strict("ADDRESS_SANITIZER_CONFIG_EXTRA_STATIC_LIBRARIES", strings.Join(asanLibs, " "))
diff --git a/cc/sabi.go b/cc/sabi.go
index 15d980c..1a5361d 100644
--- a/cc/sabi.go
+++ b/cc/sabi.go
@@ -79,7 +79,7 @@
 
 func sabiDepsMutator(mctx android.TopDownMutatorContext) {
 	if c, ok := mctx.Module().(*Module); ok &&
-		(c.isVndk() || inList(c.Name(), llndkLibraries) ||
+		(c.isVndk() || inList(c.Name(), config.LLndkLibraries()) ||
 			(c.sabi != nil && c.sabi.Properties.CreateSAbiDumps)) {
 		mctx.VisitDirectDeps(func(m blueprint.Module) {
 			tag := mctx.OtherModuleDependencyTag(m)
diff --git a/cc/util.go b/cc/util.go
index cc89af6..eeb64eb 100644
--- a/cc/util.go
+++ b/cc/util.go
@@ -131,10 +131,3 @@
 	}
 	return list
 }
-
-func addSuffix(list []string, suffix string) []string {
-	for i := range list {
-		list[i] = list[i] + suffix
-	}
-	return list
-}
diff --git a/cc/vndk.go b/cc/vndk.go
index 2e6ac13..fd1bdcb 100644
--- a/cc/vndk.go
+++ b/cc/vndk.go
@@ -15,9 +15,6 @@
 package cc
 
 import (
-	"strings"
-	"sync"
-
 	"android/soong/android"
 )
 
@@ -99,38 +96,3 @@
 		return
 	}
 }
-
-var (
-	vndkCoreLibraries []string
-	vndkSpLibraries   []string
-	llndkLibraries    []string
-	vndkLibrariesLock sync.Mutex
-)
-
-// gather list of vndk-core, vndk-sp, and ll-ndk libs
-func vndkMutator(mctx android.BottomUpMutatorContext) {
-	if m, ok := mctx.Module().(*Module); ok {
-		if _, ok := m.linker.(*llndkStubDecorator); ok {
-			vndkLibrariesLock.Lock()
-			defer vndkLibrariesLock.Unlock()
-			name := strings.TrimSuffix(m.Name(), llndkLibrarySuffix)
-			if !inList(name, llndkLibraries) {
-				llndkLibraries = append(llndkLibraries, name)
-			}
-		} else if lib, ok := m.linker.(*libraryDecorator); ok && lib.shared() {
-			if m.vndkdep.isVndk() {
-				vndkLibrariesLock.Lock()
-				defer vndkLibrariesLock.Unlock()
-				if m.vndkdep.isVndkSp() {
-					if !inList(m.Name(), vndkSpLibraries) {
-						vndkSpLibraries = append(vndkSpLibraries, m.Name())
-					}
-				} else {
-					if !inList(m.Name(), vndkCoreLibraries) {
-						vndkCoreLibraries = append(vndkCoreLibraries, m.Name())
-					}
-				}
-			}
-		}
-	}
-}