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
This commit is contained in:
Dan Willemsen 2016-11-17 01:02:25 -08:00
parent 967c6a9b87
commit 2e47b34435
9 changed files with 30 additions and 9 deletions

View File

@ -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",

View File

@ -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.

View File

@ -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
}

View File

@ -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{}

View File

@ -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{}

View File

@ -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{}

View File

@ -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"

View File

@ -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...)

View File

@ -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() {