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 15 package config 16 17 import ( 18 "strings" 19 20 "android/soong/android" 21 ) 22 23 var ( 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 66 func init() { 67 pctx.StaticVariable("LinuxBionicCflags", strings.Join(linuxBionicCflags, " ")) 68 pctx.StaticVariable("LinuxBionicLdflags", strings.Join(linuxBionicLdflags, " ")) 69 70 pctx.StaticVariable("LinuxBionicIncludeFlags", bionicHeaders("x86")) 71 72 // Use the device gcc toolchain for now 73 pctx.StaticVariable("LinuxBionicGccRoot", "${X86_64GccRoot}") 74 } 75 76 type toolchainLinuxBionic struct { 77 toolchain64Bit 78 } 79 80 func (t *toolchainLinuxBionic) Name() string { 81 return "x86_64" 82 } 83 84 func (t *toolchainLinuxBionic) GccRoot() string { 85 return "${config.LinuxBionicGccRoot}" 86 } 87 88 func (t *toolchainLinuxBionic) GccTriple() string { 89 return "x86_64-linux-android" 90 } 91 92 func (t *toolchainLinuxBionic) GccVersion() string { 93 return "4.9" 94 } 95 96 func (t *toolchainLinuxBionic) Cflags() string { 97 return "" 98 } 99 100 func (t *toolchainLinuxBionic) Cppflags() string { 101 return "" 102 } 103 104 func (t *toolchainLinuxBionic) Ldflags() string { 105 return "" 106 } 107 108 func (t *toolchainLinuxBionic) IncludeFlags() string { 109 return "${config.LinuxBionicIncludeFlags}" 110 } 111 112 func (t *toolchainLinuxBionic) ClangTriple() string { 113 // TODO: we don't have a triple yet b/31393676 114 return "x86_64-linux-android" 115 } 116 117 func (t *toolchainLinuxBionic) ClangCflags() string { 118 return "${config.LinuxBionicCflags}" 119 } 120 121 func (t *toolchainLinuxBionic) ClangCppflags() string { 122 return "" 123 } 124 125 func (t *toolchainLinuxBionic) ClangLdflags() string { 126 return "${config.LinuxBionicLdflags}" 127 } 128 129 func (t *toolchainLinuxBionic) ToolchainClangCflags() string { 130 return "-m64 -march=x86-64" + 131 // TODO: We're not really android, but we don't have a triple yet b/31393676 132 " -U__ANDROID__ -fno-emulated-tls" 133 } 134 135 func (t *toolchainLinuxBionic) ToolchainClangLdflags() string { 136 return "-m64" 137 } 138 139 func (t *toolchainLinuxBionic) AvailableLibraries() []string { 140 return nil 141 } 142 143 func (t *toolchainLinuxBionic) Bionic() bool { 144 return true 145 } 146 147 var toolchainLinuxBionicSingleton Toolchain = &toolchainLinuxBionic{} 148 149 func linuxBionicToolchainFactory(arch android.Arch) Toolchain { 150 return toolchainLinuxBionicSingleton 151 } 152 153 func init() { 154 registerToolchainFactory(android.LinuxBionic, android.X86_64, linuxBionicToolchainFactory) 155 } 156