diff --git a/Android.bp b/Android.bp index b56d492a9..4d0671020 100644 --- a/Android.bp +++ b/Android.bp @@ -95,6 +95,7 @@ bootstrap_go_package { "cc/config/x86_darwin_host.go", "cc/config/x86_linux_host.go", + "cc/config/x86_linux_bionic_host.go", "cc/config/x86_windows_host.go", ], testSrcs: [ diff --git a/android/androidmk.go b/android/androidmk.go index 793947e0e..ec3abe119 100644 --- a/android/androidmk.go +++ b/android/androidmk.go @@ -164,6 +164,11 @@ func translateAndroidMkModule(ctx blueprint.SingletonContext, w io.Writer, mod b return err } + // Make does not understand LinuxBionic + if amod.Os() == LinuxBionic { + return nil + } + if data.SubName != "" { name += data.SubName } diff --git a/android/arch.go b/android/arch.go index 5a88f23da..3d56b372e 100644 --- a/android/arch.go +++ b/android/arch.go @@ -781,6 +781,10 @@ func decodeTargetProductVariables(config *config) (map[OsClass][]Target, error) addTarget(BuildOs, *variables.HostSecondaryArch, nil, nil, nil) } + if config.Host_bionic != nil && *config.Host_bionic { + addTarget(LinuxBionic, "x86_64", nil, nil, nil) + } + if variables.CrossHost != nil && *variables.CrossHost != "" { crossHostOs := osByName(*variables.CrossHost) if crossHostOs == NoOsType { diff --git a/android/config.go b/android/config.go index bae935293..2413f5265 100644 --- a/android/config.go +++ b/android/config.go @@ -40,6 +40,7 @@ const productVariablesFileName = "soong.variables" type FileConfigurableOptions struct { Mega_device *bool `json:",omitempty"` Ndk_abis *bool `json:",omitempty"` + Host_bionic *bool `json:",omitempty"` } func (f *FileConfigurableOptions) SetDefaultConfig() { diff --git a/cc/binary.go b/cc/binary.go index 521ccb703..637f6c7a3 100644 --- a/cc/binary.go +++ b/cc/binary.go @@ -15,6 +15,8 @@ package cc import ( + "path/filepath" + "github.com/google/blueprint" "github.com/google/blueprint/proptools" @@ -236,7 +238,22 @@ func (binary *binaryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags if binary.Properties.DynamicLinker != "" { flags.DynamicLinker = binary.Properties.DynamicLinker } else { - flags.DynamicLinker = "/system/bin/linker" + switch ctx.Os() { + case android.Android: + flags.DynamicLinker = "/system/bin/linker" + case android.LinuxBionic: + // The linux kernel expects the linker to be an + // absolute path + path := android.PathForOutput(ctx, + "host", "linux_bionic-x86", "bin", "linker") + if p, err := filepath.Abs(path.String()); err == nil { + flags.DynamicLinker = p + } else { + ctx.ModuleErrorf("can't find path to dynamic linker: %q", err) + } + default: + ctx.ModuleErrorf("unknown dynamic linker") + } if flags.Toolchain.Is64Bit() { flags.DynamicLinker += "64" } diff --git a/cc/config/x86_linux_bionic_host.go b/cc/config/x86_linux_bionic_host.go new file mode 100644 index 000000000..bd6cd0e58 --- /dev/null +++ b/cc/config/x86_linux_bionic_host.go @@ -0,0 +1,168 @@ +// Copyright 2016 Google Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package config + +import ( + "strings" + + "android/soong/android" +) + +var ( + linuxBionicCflags = ClangFilterUnknownCflags([]string{ + "-fno-exceptions", // from build/core/combo/select.mk + "-Wno-multichar", // from build/core/combo/select.mk + + "-fdiagnostics-color", + + "-Wa,--noexecstack", + + "-fPIC", + "-no-canonical-prefixes", + + "-U_FORTIFY_SOURCE", + "-D_FORTIFY_SOURCE=2", + "-fstack-protector-strong", + + // From x86_64_device + "-ffunction-sections", + "-finline-functions", + "-finline-limit=300", + "-fno-short-enums", + "-funswitch-loops", + "-funwind-tables", + "-no-canonical-prefixes", + "-fno-canonical-system-headers", + + // HOST_RELEASE_CFLAGS + "-O2", // from build/core/combo/select.mk + "-g", // from build/core/combo/select.mk + "-fno-strict-aliasing", // from build/core/combo/select.mk + + // Tell clang where the gcc toolchain is + "--gcc-toolchain=${LinuxBionicGccRoot}", + + // TODO: We're not really android, but we don't have a triple yet b/31393676 + "-U__ANDROID__", + "-fno-emulated-tls", + + // This is normally in ClangExtraTargetCflags, but this is considered host + "-nostdlibinc", + }) + + linuxBionicLdflags = ClangFilterUnknownCflags([]string{ + "-Wl,-z,noexecstack", + "-Wl,-z,relro", + "-Wl,-z,now", + "-Wl,--build-id=md5", + "-Wl,--warn-shared-textrel", + "-Wl,--fatal-warnings", + "-Wl,--gc-sections", + "-Wl,--hash-style=gnu", + "-Wl,--no-undefined-version", + + // Use the device gcc toolchain + "--gcc-toolchain=${LinuxBionicGccRoot}", + }) +) + +func init() { + pctx.StaticVariable("LinuxBionicCflags", strings.Join(linuxBionicCflags, " ")) + pctx.StaticVariable("LinuxBionicLdflags", strings.Join(linuxBionicLdflags, " ")) + + pctx.StaticVariable("LinuxBionicIncludeFlags", bionicHeaders("x86_64", "x86")) + + // Use the device gcc toolchain for now + pctx.StaticVariable("LinuxBionicGccRoot", "${X86_64GccRoot}") +} + +type toolchainLinuxBionic struct { + toolchain64Bit +} + +func (t *toolchainLinuxBionic) Name() string { + return "x86_64" +} + +func (t *toolchainLinuxBionic) GccRoot() string { + return "${config.LinuxBionicGccRoot}" +} + +func (t *toolchainLinuxBionic) GccTriple() string { + return "x86_64-linux-android" +} + +func (t *toolchainLinuxBionic) GccVersion() string { + return "4.9" +} + +func (t *toolchainLinuxBionic) Cflags() string { + return "" +} + +func (t *toolchainLinuxBionic) Cppflags() string { + return "" +} + +func (t *toolchainLinuxBionic) Ldflags() string { + return "" +} + +func (t *toolchainLinuxBionic) IncludeFlags() string { + return "${config.LinuxBionicIncludeFlags}" +} + +func (t *toolchainLinuxBionic) ClangTriple() string { + // TODO: we don't have a triple yet b/31393676 + return "x86_64-linux-android" +} + +func (t *toolchainLinuxBionic) ClangCflags() string { + return "${config.LinuxBionicCflags}" +} + +func (t *toolchainLinuxBionic) ClangCppflags() string { + return "" +} + +func (t *toolchainLinuxBionic) ClangLdflags() string { + return "${config.LinuxBionicLdflags}" +} + +func (t *toolchainLinuxBionic) ToolchainClangCflags() string { + return "-m64 -march=x86-64" +} + +func (t *toolchainLinuxBionic) ToolchainClangLdflags() string { + return "-m64" +} + +func (t *toolchainLinuxBionic) AvailableLibraries() []string { + return nil +} + +func (t *toolchainLinuxBionic) Bionic() bool { + return true +} + +var toolchainLinuxBionicSingleton Toolchain = &toolchainLinuxBionic{} + +func linuxBionicToolchainFactory(arch android.Arch) Toolchain { + return toolchainLinuxBionicSingleton +} + +func init() { + registerToolchainFactory(android.LinuxBionic, android.X86_64, linuxBionicToolchainFactory) +} diff --git a/cc/library.go b/cc/library.go index b5512bb24..0ce84a195 100644 --- a/cc/library.go +++ b/cc/library.go @@ -246,7 +246,7 @@ func (library *libraryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Fla sharedFlag = "-shared" } var f []string - if ctx.Device() { + if ctx.toolchain().Bionic() { f = append(f, "-nostdlib", "-Wl,--gc-sections",