Add Toolchain.Bionic()

Move some cc ctx.Host() / ctx.Device() checks over to using
ctx.toolchain().Bionic(). There will be more changes, these are just the
obvious ones dealing with host_ldlibs / crt / system libraries.

Bug: 31559095
Test: out/soong/build.ninja is identical
Change-Id: Ibba60483b4ab0e01f6996eb7d883120e4acc1830
diff --git a/cc/binary.go b/cc/binary.go
index c16dae6..2b77514 100644
--- a/cc/binary.go
+++ b/cc/binary.go
@@ -91,7 +91,7 @@
 
 func (binary *binaryDecorator) linkerDeps(ctx BaseModuleContext, deps Deps) Deps {
 	deps = binary.baseLinker.linkerDeps(ctx, deps)
-	if ctx.Device() {
+	if ctx.toolchain().Bionic() {
 		if !Bool(binary.baseLinker.Properties.Nocrt) {
 			if !ctx.sdk() {
 				if binary.static() {
@@ -163,7 +163,7 @@
 func (binary *binaryDecorator) linkerInit(ctx BaseModuleContext) {
 	binary.baseLinker.linkerInit(ctx)
 
-	if ctx.Host() {
+	if !ctx.toolchain().Bionic() {
 		if ctx.Os() == android.Linux {
 			if binary.Properties.Static_executable == nil && Bool(ctx.AConfig().ProductVariables.HostStaticBinaries) {
 				binary.Properties.Static_executable = proptools.BoolPtr(true)
@@ -210,7 +210,7 @@
 		flags.CFlags = append(flags.CFlags, "-fpie")
 	}
 
-	if ctx.Device() {
+	if ctx.toolchain().Bionic() {
 		if binary.static() {
 			// Clang driver needs -static to create static executable.
 			// However, bionic/linker uses -shared to overwrite.
diff --git a/cc/config/toolchain.go b/cc/config/toolchain.go
index 5a4e032..020a0dd 100644
--- a/cc/config/toolchain.go
+++ b/cc/config/toolchain.go
@@ -74,6 +74,8 @@
 	SanitizerRuntimeLibraryArch() string
 
 	AvailableLibraries() []string
+
+	Bionic() bool
 }
 
 type toolchainBase struct {
@@ -133,6 +135,10 @@
 	return []string{}
 }
 
+func (toolchainBase) Bionic() bool {
+	return true
+}
+
 type toolchain64Bit struct {
 	toolchainBase
 }
diff --git a/cc/config/x86_darwin_host.go b/cc/config/x86_darwin_host.go
index 2db3cbf..a6d4aaf 100644
--- a/cc/config/x86_darwin_host.go
+++ b/cc/config/x86_darwin_host.go
@@ -269,6 +269,10 @@
 	return darwinAvailableLibraries
 }
 
+func (t *toolchainDarwin) Bionic() bool {
+	return false
+}
+
 var toolchainDarwinX86Singleton Toolchain = &toolchainDarwinX86{}
 var toolchainDarwinX8664Singleton Toolchain = &toolchainDarwinX8664{}
 
diff --git a/cc/config/x86_linux_host.go b/cc/config/x86_linux_host.go
index 676ea5c..80e9289 100644
--- a/cc/config/x86_linux_host.go
+++ b/cc/config/x86_linux_host.go
@@ -256,6 +256,10 @@
 	return linuxAvailableLibraries
 }
 
+func (t *toolchainLinux) Bionic() bool {
+	return false
+}
+
 var toolchainLinuxX86Singleton Toolchain = &toolchainLinuxX86{}
 var toolchainLinuxX8664Singleton Toolchain = &toolchainLinuxX8664{}
 
diff --git a/cc/config/x86_windows_host.go b/cc/config/x86_windows_host.go
index 79c9e36..ab593e9 100644
--- a/cc/config/x86_windows_host.go
+++ b/cc/config/x86_windows_host.go
@@ -202,6 +202,10 @@
 	return windowsAvailableLibraries
 }
 
+func (t *toolchainWindows) Bionic() bool {
+	return false
+}
+
 var toolchainWindowsX86Singleton Toolchain = &toolchainWindowsX86{}
 var toolchainWindowsX8664Singleton Toolchain = &toolchainWindowsX8664{}
 
diff --git a/cc/library.go b/cc/library.go
index dff38c8..35d0089 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -330,7 +330,7 @@
 		deps.StaticLibs = append(deps.StaticLibs, library.Properties.Static.Static_libs...)
 		deps.SharedLibs = append(deps.SharedLibs, library.Properties.Static.Shared_libs...)
 	} else {
-		if ctx.Device() && !Bool(library.baseLinker.Properties.Nocrt) {
+		if ctx.toolchain().Bionic() && !Bool(library.baseLinker.Properties.Nocrt) {
 			if !ctx.sdk() {
 				deps.CrtBegin = "crtbegin_so"
 				deps.CrtEnd = "crtend_so"
diff --git a/cc/linker.go b/cc/linker.go
index 28572c6..6d4edbc 100644
--- a/cc/linker.go
+++ b/cc/linker.go
@@ -119,7 +119,7 @@
 		deps.LateStaticLibs = append(deps.LateStaticLibs, "libcompiler_rt-extras")
 	}
 
-	if ctx.Device() {
+	if ctx.toolchain().Bionic() {
 		// libgcc and libatomic have to be last on the command line
 		deps.LateStaticLibs = append(deps.LateStaticLibs, "libatomic")
 		if !Bool(linker.Properties.No_libgcc) {
@@ -165,7 +165,7 @@
 			flags.LdFlags = append(flags.LdFlags, toolchain.Ldflags())
 		}
 
-		if ctx.Host() {
+		if !ctx.toolchain().Bionic() {
 			CheckBadHostLdlibs(ctx, "host_ldlibs", linker.Properties.Host_ldlibs)
 
 			flags.LdFlags = append(flags.LdFlags, linker.Properties.Host_ldlibs...)
diff --git a/cc/stl.go b/cc/stl.go
index 874e7ae..0ffeb03 100644
--- a/cc/stl.go
+++ b/cc/stl.go
@@ -97,7 +97,7 @@
 		} else {
 			deps.StaticLibs = append(deps.StaticLibs, stl.Properties.SelectedStl)
 		}
-		if ctx.Device() {
+		if ctx.toolchain().Bionic() {
 			if ctx.Arch().ArchType == android.Arm {
 				deps.StaticLibs = append(deps.StaticLibs, "libunwind_llvm")
 			}
@@ -135,7 +135,7 @@
 	switch stl.Properties.SelectedStl {
 	case "libc++", "libc++_static":
 		flags.CFlags = append(flags.CFlags, "-D_USING_LIBCXX")
-		if ctx.Host() {
+		if !ctx.toolchain().Bionic() {
 			flags.CppFlags = append(flags.CppFlags, "-nostdinc++")
 			flags.LdFlags = append(flags.LdFlags, "-nodefaultlibs")
 			flags.LdFlags = append(flags.LdFlags, "-lpthread", "-lm")
@@ -161,7 +161,7 @@
 		// Nothing
 	case "":
 		// None or error.
-		if ctx.Host() {
+		if !ctx.toolchain().Bionic() {
 			flags.CppFlags = append(flags.CppFlags, "-nostdinc++")
 			flags.LdFlags = append(flags.LdFlags, "-nodefaultlibs")
 			if ctx.staticBinary() {