1// Copyright 2016 Google Inc. All rights reserved. 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15package config 16 17import ( 18 "strings" 19 20 "android/soong/android" 21) 22 23var ( 24 linuxBionicCflags = ClangFilterUnknownCflags([]string{ 25 "-fdiagnostics-color", 26 27 "-Wa,--noexecstack", 28 29 "-fPIC", 30 31 "-U_FORTIFY_SOURCE", 32 "-D_FORTIFY_SOURCE=2", 33 "-fstack-protector-strong", 34 35 // From x86_64_device 36 "-ffunction-sections", 37 "-finline-functions", 38 "-finline-limit=300", 39 "-fno-short-enums", 40 "-funswitch-loops", 41 "-funwind-tables", 42 "-fno-canonical-system-headers", 43 44 // Tell clang where the gcc toolchain is 45 "--gcc-toolchain=${LinuxBionicGccRoot}", 46 47 // This is normally in ClangExtraTargetCflags, but this is considered host 48 "-nostdlibinc", 49 }) 50 51 linuxBionicLdflags = ClangFilterUnknownCflags([]string{ 52 "-Wl,-z,noexecstack", 53 "-Wl,-z,relro", 54 "-Wl,-z,now", 55 "-Wl,--build-id=md5", 56 "-Wl,--warn-shared-textrel", 57 "-Wl,--fatal-warnings", 58 "-Wl,--hash-style=gnu", 59 "-Wl,--no-undefined-version", 60 61 // Use the device gcc toolchain 62 "--gcc-toolchain=${LinuxBionicGccRoot}", 63 }) 64 65 linuxBionicLldflags = ClangFilterUnknownLldflags(linuxBionicLdflags) 66) 67 68func init() { 69 pctx.StaticVariable("LinuxBionicCflags", strings.Join(linuxBionicCflags, " ")) 70 pctx.StaticVariable("LinuxBionicLdflags", strings.Join(linuxBionicLdflags, " ")) 71 pctx.StaticVariable("LinuxBionicLldflags", strings.Join(linuxBionicLldflags, " ")) 72 73 // Use the device gcc toolchain for now 74 pctx.StaticVariable("LinuxBionicGccRoot", "${X86_64GccRoot}") 75} 76 77type toolchainLinuxBionic struct { 78 toolchain64Bit 79} 80 81func (t *toolchainLinuxBionic) Name() string { 82 return "x86_64" 83} 84 85func (t *toolchainLinuxBionic) GccRoot() string { 86 return "${config.LinuxBionicGccRoot}" 87} 88 89func (t *toolchainLinuxBionic) GccTriple() string { 90 return "x86_64-linux-android" 91} 92 93func (t *toolchainLinuxBionic) GccVersion() string { 94 return "4.9" 95} 96 97func (t *toolchainLinuxBionic) IncludeFlags() string { 98 return "" 99} 100 101func (t *toolchainLinuxBionic) ClangTriple() string { 102 // TODO: we don't have a triple yet b/31393676 103 return "x86_64-linux-android" 104} 105 106func (t *toolchainLinuxBionic) ClangCflags() string { 107 return "${config.LinuxBionicCflags}" 108} 109 110func (t *toolchainLinuxBionic) ClangCppflags() string { 111 return "" 112} 113 114func (t *toolchainLinuxBionic) ClangLdflags() string { 115 return "${config.LinuxBionicLdflags}" 116} 117 118func (t *toolchainLinuxBionic) ClangLldflags() string { 119 return "${config.LinuxBionicLldflags}" 120} 121 122func (t *toolchainLinuxBionic) ToolchainClangCflags() string { 123 return "-m64 -march=x86-64" + 124 // TODO: We're not really android, but we don't have a triple yet b/31393676 125 " -U__ANDROID__" 126} 127 128func (t *toolchainLinuxBionic) ToolchainClangLdflags() string { 129 return "-m64" 130} 131 132func (t *toolchainLinuxBionic) AvailableLibraries() []string { 133 return nil 134} 135 136func (t *toolchainLinuxBionic) Bionic() bool { 137 return true 138} 139 140func (toolchainLinuxBionic) LibclangRuntimeLibraryArch() string { 141 return "x86_64" 142} 143 144var toolchainLinuxBionicSingleton Toolchain = &toolchainLinuxBionic{} 145 146func linuxBionicToolchainFactory(arch android.Arch) Toolchain { 147 return toolchainLinuxBionicSingleton 148} 149 150func init() { 151 registerToolchainFactory(android.LinuxBionic, android.X86_64, linuxBionicToolchainFactory) 152} 153