Merge "Fail gracefully when apek_key is not found"
diff --git a/cc/builder.go b/cc/builder.go
index 3d12538..6d5b595 100644
--- a/cc/builder.go
+++ b/cc/builder.go
@@ -247,7 +247,6 @@
 	systemIncludeFlags string
 
 	groupStaticLibs bool
-	arGoldPlugin    bool
 
 	stripKeepSymbols       bool
 	stripKeepMiniDebugInfo bool
@@ -485,9 +484,6 @@
 	if !ctx.Darwin() {
 		arFlags += " -format=gnu"
 	}
-	if flags.arGoldPlugin {
-		arFlags += " --plugin ${config.LLVMGoldPlugin}"
-	}
 	if flags.arFlags != "" {
 		arFlags += " " + flags.arFlags
 	}
diff --git a/cc/cc.go b/cc/cc.go
index 0569563..fcd8a45 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -157,7 +157,6 @@
 	LdFlagsDeps android.Paths // Files depended on by linker flags
 
 	GroupStaticLibs bool
-	ArGoldPlugin    bool // Whether LLVM gold plugin option is passed to llvm-ar
 }
 
 type ObjectLinkerProperties struct {
diff --git a/cc/cc_test.go b/cc/cc_test.go
index e4904f2..d6ffe51 100644
--- a/cc/cc_test.go
+++ b/cc/cc_test.go
@@ -894,9 +894,7 @@
 		}
 	`)
 
-	// The pattern should be "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\""
-	// but target.vendor.shared_libs has not been supported yet.
-	testCcError(t, "unrecognized property \"target.vendor.shared_libs\"", `
+	testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
 		cc_library {
 			name: "libvndk",
 			vendor_available: true,
@@ -965,9 +963,7 @@
 		}
 	`)
 
-	// The pattern should be "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\""
-	// but target.vendor.shared_libs has not been supported yet.
-	testCcError(t, "unrecognized property \"target.vendor.shared_libs\"", `
+	testCcError(t, "module \".*\" variant \".*\": \\(.*\\) should not link to \".*\"", `
 		cc_library {
 			name: "libvndk_sp",
 			vendor_available: true,
diff --git a/cc/compdb.go b/cc/compdb.go
index acfc924..4dfc55b 100644
--- a/cc/compdb.go
+++ b/cc/compdb.go
@@ -126,28 +126,32 @@
 	return out
 }
 
-func getArguments(src android.Path, ctx android.SingletonContext, ccModule *Module) []string {
+func getArguments(src android.Path, ctx android.SingletonContext, ccModule *Module, ccPath string, cxxPath string) []string {
 	var args []string
 	isCpp := false
 	isAsm := false
 	// TODO It would be better to ask soong for the types here.
+	var clangPath string
 	switch src.Ext() {
 	case ".S", ".s", ".asm":
 		isAsm = true
 		isCpp = false
+		clangPath = ccPath
 	case ".c":
 		isAsm = false
 		isCpp = false
+		clangPath = ccPath
 	case ".cpp", ".cc", ".mm":
 		isAsm = false
 		isCpp = true
+		clangPath = cxxPath
 	default:
 		log.Print("Unknown file extension " + src.Ext() + " on file " + src.String())
 		isAsm = true
 		isCpp = false
+		clangPath = ccPath
 	}
-	// The executable for the compilation doesn't matter but we need something there.
-	args = append(args, "/bin/false")
+	args = append(args, clangPath)
 	args = append(args, expandAllVars(ctx, ccModule.flags.GlobalFlags)...)
 	args = append(args, expandAllVars(ctx, ccModule.flags.CFlags)...)
 	if isCpp {
@@ -166,12 +170,19 @@
 		return
 	}
 
+	pathToCC, err := ctx.Eval(pctx, "${config.ClangBin}/")
+	ccPath := "/bin/false"
+	cxxPath := "/bin/false"
+	if err == nil {
+		ccPath = pathToCC + "clang"
+		cxxPath = pathToCC + "clang++"
+	}
 	rootDir := getCompdbAndroidSrcRootDirectory(ctx)
 	for _, src := range srcs {
 		if _, ok := builds[src.String()]; !ok {
 			builds[src.String()] = compDbEntry{
 				Directory: rootDir,
-				Arguments: getArguments(src, ctx, ccModule),
+				Arguments: getArguments(src, ctx, ccModule, ccPath, cxxPath),
 				File:      src.String(),
 			}
 		}
diff --git a/cc/config/arm64_device.go b/cc/config/arm64_device.go
index bcff775..6a63828 100644
--- a/cc/config/arm64_device.go
+++ b/cc/config/arm64_device.go
@@ -25,11 +25,6 @@
 	arm64Cflags = []string{
 		// Help catch common 32/64-bit errors.
 		"-Werror=implicit-function-declaration",
-
-		// Prevent use of x18 register.
-		// TODO(pcc): Remove this flag once we upgrade past LLVM r340889
-		// which does this by default on Android.
-		"-ffixed-x18",
 	}
 
 	arm64ArchVariantCflags = map[string][]string{
diff --git a/cc/config/global.go b/cc/config/global.go
index 057e08a..d4f86b8 100644
--- a/cc/config/global.go
+++ b/cc/config/global.go
@@ -15,7 +15,6 @@
 package config
 
 import (
-	"runtime"
 	"strings"
 
 	"android/soong/android"
@@ -211,11 +210,6 @@
 		return ClangDefaultShortVersion
 	})
 	pctx.StaticVariable("ClangAsanLibDir", "${ClangBase}/linux-x86/${ClangVersion}/lib64/clang/${ClangShortVersion}/lib/linux")
-	if runtime.GOOS == "darwin" {
-		pctx.StaticVariable("LLVMGoldPlugin", "${ClangPath}/lib64/LLVMgold.dylib")
-	} else {
-		pctx.StaticVariable("LLVMGoldPlugin", "${ClangPath}/lib64/LLVMgold.so")
-	}
 
 	// These are tied to the version of LLVM directly in external/llvm, so they might trail the host prebuilts
 	// being used for the rest of the build process.
diff --git a/cc/linker.go b/cc/linker.go
index e96bfcb..a1593ee 100644
--- a/cc/linker.go
+++ b/cc/linker.go
@@ -99,6 +99,10 @@
 
 	Target struct {
 		Vendor struct {
+			// list of shared libs that only should be used to build the vendor
+			// variant of the C/C++ module.
+			Shared_libs []string
+
 			// list of shared libs that should not be used to build the vendor variant
 			// of the C/C++ module.
 			Exclude_shared_libs []string
@@ -116,6 +120,10 @@
 			Exclude_runtime_libs []string
 		}
 		Recovery struct {
+			// list of shared libs that only should be used to build the recovery
+			// variant of the C/C++ module.
+			Shared_libs []string
+
 			// list of shared libs that should not be used to build
 			// the recovery variant of the C/C++ module.
 			Exclude_shared_libs []string
@@ -200,6 +208,7 @@
 	}
 
 	if ctx.useVndk() {
+		deps.SharedLibs = append(deps.SharedLibs, linker.Properties.Target.Vendor.Shared_libs...)
 		deps.SharedLibs = removeListFromList(deps.SharedLibs, linker.Properties.Target.Vendor.Exclude_shared_libs)
 		deps.ReexportSharedLibHeaders = removeListFromList(deps.ReexportSharedLibHeaders, linker.Properties.Target.Vendor.Exclude_shared_libs)
 		deps.StaticLibs = removeListFromList(deps.StaticLibs, linker.Properties.Target.Vendor.Exclude_static_libs)
@@ -210,6 +219,7 @@
 	}
 
 	if ctx.inRecovery() {
+		deps.SharedLibs = append(deps.SharedLibs, linker.Properties.Target.Recovery.Shared_libs...)
 		deps.SharedLibs = removeListFromList(deps.SharedLibs, linker.Properties.Target.Recovery.Exclude_shared_libs)
 		deps.ReexportSharedLibHeaders = removeListFromList(deps.ReexportSharedLibHeaders, linker.Properties.Target.Recovery.Exclude_shared_libs)
 		deps.StaticLibs = removeListFromList(deps.StaticLibs, linker.Properties.Target.Recovery.Exclude_static_libs)
diff --git a/cc/lto.go b/cc/lto.go
index d9d2662..6302748 100644
--- a/cc/lto.go
+++ b/cc/lto.go
@@ -105,21 +105,12 @@
 			flags.LdFlags = append(flags.LdFlags, cachePolicyFormat+policy)
 		}
 
-		flags.ArGoldPlugin = true
-
 		// If the module does not have a profile, be conservative and do not inline
 		// or unroll loops during LTO, in order to prevent significant size bloat.
 		if !ctx.isPgoCompile() && !lto.useClangLld(ctx) {
 			flags.LdFlags = append(flags.LdFlags, "-Wl,-plugin-opt,-inline-threshold=0")
 			flags.LdFlags = append(flags.LdFlags, "-Wl,-plugin-opt,-unroll-threshold=0")
 		}
-
-		if ctx.Arch().ArchType == android.Arm64 {
-			// Prevent use of x18 register on arm64.
-			// TODO(pcc): Remove this flag once we upgrade past LLVM r340889
-			// which does this by default on Android.
-			flags.LdFlags = append(flags.LdFlags, "-Wl,-plugin-opt,-mattr=+reserve-x18")
-		}
 	}
 	return flags
 }
diff --git a/cc/sanitize.go b/cc/sanitize.go
index 527ae33..cd3b3e9 100644
--- a/cc/sanitize.go
+++ b/cc/sanitize.go
@@ -466,18 +466,10 @@
 			flags.CFlags = append(flags.CFlags, "-fvisibility=default")
 		}
 		flags.LdFlags = append(flags.LdFlags, cfiLdflags...)
-		flags.ArGoldPlugin = true
 		if Bool(sanitize.Properties.Sanitize.Diag.Cfi) {
 			diagSanitizers = append(diagSanitizers, "cfi")
 		}
 
-		if ctx.Arch().ArchType == android.Arm64 {
-			// Prevent use of x18 register on arm64.
-			// TODO(pcc): Remove this flag once we upgrade past LLVM r340889
-			// which does this by default on Android.
-			flags.LdFlags = append(flags.LdFlags, "-Wl,-plugin-opt,-mattr=+reserve-x18")
-		}
-
 		if ctx.staticBinary() {
 			_, flags.CFlags = removeFromList("-fsanitize-cfi-cross-dso", flags.CFlags)
 			_, flags.LdFlags = removeFromList("-fsanitize-cfi-cross-dso", flags.LdFlags)
diff --git a/cc/util.go b/cc/util.go
index 1412d54..c900423 100644
--- a/cc/util.go
+++ b/cc/util.go
@@ -86,7 +86,6 @@
 		systemIncludeFlags: strings.Join(in.SystemIncludeFlags, " "),
 
 		groupStaticLibs: in.GroupStaticLibs,
-		arGoldPlugin:    in.ArGoldPlugin,
 	}
 }