From 2e47b34435de8cfe3f1533c553fe546217c98b3c Mon Sep 17 00:00:00 2001 From: Dan Willemsen Date: Thu, 17 Nov 2016 01:02:25 -0800 Subject: [PATCH] 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 --- Android.bp | 3 +++ cc/binary.go | 6 +++--- cc/config/toolchain.go | 6 ++++++ cc/config/x86_darwin_host.go | 4 ++++ cc/config/x86_linux_host.go | 4 ++++ cc/config/x86_windows_host.go | 4 ++++ cc/library.go | 2 +- cc/linker.go | 4 ++-- cc/stl.go | 6 +++--- 9 files changed, 30 insertions(+), 9 deletions(-) diff --git a/Android.bp b/Android.bp index 66702b1e8..a941ca491 100644 --- a/Android.bp +++ b/Android.bp @@ -209,6 +209,7 @@ cc_defaults { toolchain_library { name: "libatomic", + defaults: ["linux_bionic_supported"], arch: { arm: { instruction_set: "arm", @@ -218,6 +219,7 @@ toolchain_library { toolchain_library { name: "libgcc", + defaults: ["linux_bionic_supported"], arch: { arm: { instruction_set: "arm", @@ -227,6 +229,7 @@ toolchain_library { toolchain_library { name: "libgcov", + defaults: ["linux_bionic_supported"], arch: { arm: { instruction_set: "arm", diff --git a/cc/binary.go b/cc/binary.go index c16dae601..2b7751499 100644 --- a/cc/binary.go +++ b/cc/binary.go @@ -91,7 +91,7 @@ func (binary *binaryDecorator) getStem(ctx BaseModuleContext) string { 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 NewBinary(hod android.HostOrDeviceSupported) (*Module, *binaryDecorator) { 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 @@ func (binary *binaryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags 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 5a4e0325c..020a0dd46 100644 --- a/cc/config/toolchain.go +++ b/cc/config/toolchain.go @@ -74,6 +74,8 @@ type Toolchain interface { SanitizerRuntimeLibraryArch() string AvailableLibraries() []string + + Bionic() bool } type toolchainBase struct { @@ -133,6 +135,10 @@ func (toolchainBase) AvailableLibraries() []string { 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 2db3cbf12..a6d4aaf86 100644 --- a/cc/config/x86_darwin_host.go +++ b/cc/config/x86_darwin_host.go @@ -269,6 +269,10 @@ func (t *toolchainDarwin) AvailableLibraries() []string { 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 676ea5c69..80e928956 100644 --- a/cc/config/x86_linux_host.go +++ b/cc/config/x86_linux_host.go @@ -256,6 +256,10 @@ func (t *toolchainLinux) AvailableLibraries() []string { 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 79c9e36e0..ab593e94b 100644 --- a/cc/config/x86_windows_host.go +++ b/cc/config/x86_windows_host.go @@ -202,6 +202,10 @@ func (t *toolchainWindows) AvailableLibraries() []string { 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 dff38c84c..35d0089ed 100644 --- a/cc/library.go +++ b/cc/library.go @@ -330,7 +330,7 @@ func (library *libraryDecorator) linkerDeps(ctx BaseModuleContext, deps Deps) De 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 28572c69a..6d4edbcfe 100644 --- a/cc/linker.go +++ b/cc/linker.go @@ -119,7 +119,7 @@ func (linker *baseLinker) linkerDeps(ctx BaseModuleContext, deps Deps) Deps { 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 @@ func (linker *baseLinker) linkerFlags(ctx ModuleContext, flags Flags) Flags { 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 874e7ae74..0ffeb0311 100644 --- a/cc/stl.go +++ b/cc/stl.go @@ -97,7 +97,7 @@ func (stl *stl) deps(ctx BaseModuleContext, deps Deps) Deps { } 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 @@ func (stl *stl) flags(ctx ModuleContext, flags Flags) Flags { 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 @@ func (stl *stl) flags(ctx ModuleContext, flags Flags) Flags { // 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() {