Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 1 | // Copyright 2015 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 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 15 | package config |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 16 | |
| 17 | import ( |
| 18 | "strings" |
| 19 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 20 | "android/soong/android" |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 21 | ) |
| 22 | |
| 23 | var ( |
| 24 | x86_64Cflags = []string{ |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 25 | "-finline-functions", |
| 26 | "-finline-limit=300", |
| 27 | "-fno-short-enums", |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 28 | "-funswitch-loops", |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 29 | |
| 30 | // Help catch common 32/64-bit errors. |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 31 | "-Werror=implicit-function-declaration", |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | x86_64Cppflags = []string{} |
| 35 | |
| 36 | x86_64Ldflags = []string{ |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 37 | "-Wl,--hash-style=gnu", |
| 38 | } |
| 39 | |
| 40 | x86_64ArchVariantCflags = map[string][]string{ |
| 41 | "": []string{ |
| 42 | "-march=x86-64", |
| 43 | }, |
| 44 | "haswell": []string{ |
| 45 | "-march=core-avx2", |
| 46 | }, |
| 47 | "ivybridge": []string{ |
| 48 | "-march=core-avx-i", |
| 49 | }, |
| 50 | "sandybridge": []string{ |
Dan Willemsen | b77bd79 | 2016-02-29 15:26:26 -0800 | [diff] [blame] | 51 | "-march=corei7", |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 52 | }, |
| 53 | "silvermont": []string{ |
| 54 | "-march=slm", |
| 55 | }, |
| 56 | } |
| 57 | |
| 58 | x86_64ArchFeatureCflags = map[string][]string{ |
| 59 | "ssse3": []string{"-DUSE_SSSE3", "-mssse3"}, |
| 60 | "sse4": []string{"-msse4"}, |
| 61 | "sse4_1": []string{"-msse4.1"}, |
| 62 | "sse4_2": []string{"-msse4.2"}, |
Dan Willemsen | 4ce4703 | 2016-05-06 17:20:53 -0700 | [diff] [blame] | 63 | "popcnt": []string{"-mpopcnt"}, |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 64 | "avx": []string{"-mavx"}, |
| 65 | "aes_ni": []string{"-maes"}, |
| 66 | } |
| 67 | ) |
| 68 | |
Dan Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame] | 69 | const ( |
| 70 | x86_64GccVersion = "4.9" |
| 71 | ) |
| 72 | |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 73 | func init() { |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 74 | android.RegisterArchVariants(android.X86_64, |
| 75 | "haswell", |
| 76 | "ivybridge", |
| 77 | "sandybridge", |
| 78 | "silvermont") |
| 79 | android.RegisterArchFeatures(android.X86_64, |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 80 | "ssse3", |
| 81 | "sse4", |
| 82 | "sse4_1", |
| 83 | "sse4_2", |
| 84 | "aes_ni", |
| 85 | "avx", |
| 86 | "popcnt") |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 87 | android.RegisterArchVariantFeatures(android.X86_64, "", |
| 88 | "ssse3", |
| 89 | "sse4", |
| 90 | "sse4_1", |
| 91 | "sse4_2", |
| 92 | "popcnt") |
| 93 | android.RegisterArchVariantFeatures(android.X86_64, "haswell", |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 94 | "ssse3", |
| 95 | "sse4", |
| 96 | "sse4_1", |
| 97 | "sse4_2", |
| 98 | "aes_ni", |
| 99 | "avx", |
| 100 | "popcnt") |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 101 | android.RegisterArchVariantFeatures(android.X86_64, "ivybridge", |
| 102 | "ssse3", |
| 103 | "sse4", |
| 104 | "sse4_1", |
| 105 | "sse4_2", |
| 106 | "aes_ni", |
| 107 | "avx", |
| 108 | "popcnt") |
| 109 | android.RegisterArchVariantFeatures(android.X86_64, "sandybridge", |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 110 | "ssse3", |
| 111 | "sse4", |
| 112 | "sse4_1", |
| 113 | "sse4_2", |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 114 | "popcnt") |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 115 | android.RegisterArchVariantFeatures(android.X86_64, "silvermont", |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 116 | "ssse3", |
| 117 | "sse4", |
| 118 | "sse4_1", |
| 119 | "sse4_2", |
| 120 | "aes_ni", |
| 121 | "popcnt") |
| 122 | |
Dan Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame] | 123 | pctx.StaticVariable("x86_64GccVersion", x86_64GccVersion) |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 124 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 125 | pctx.SourcePathVariable("X86_64GccRoot", |
Dan Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame] | 126 | "prebuilts/gcc/${HostPrebuiltTag}/x86/x86_64-linux-android-${x86_64GccVersion}") |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 127 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 128 | pctx.StaticVariable("X86_64ToolchainCflags", "-m64") |
| 129 | pctx.StaticVariable("X86_64ToolchainLdflags", "-m64") |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 130 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 131 | pctx.StaticVariable("X86_64Cflags", strings.Join(x86_64Cflags, " ")) |
| 132 | pctx.StaticVariable("X86_64Ldflags", strings.Join(x86_64Ldflags, " ")) |
| 133 | pctx.StaticVariable("X86_64Cppflags", strings.Join(x86_64Cppflags, " ")) |
Elliott Hughes | de28deb | 2017-10-12 09:07:53 -0700 | [diff] [blame] | 134 | pctx.StaticVariable("X86_64IncludeFlags", bionicHeaders("x86")) |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 135 | |
| 136 | // Clang cflags |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 137 | pctx.StaticVariable("X86_64ClangCflags", strings.Join(ClangFilterUnknownCflags(x86_64Cflags), " ")) |
| 138 | pctx.StaticVariable("X86_64ClangLdflags", strings.Join(ClangFilterUnknownCflags(x86_64Ldflags), " ")) |
| 139 | pctx.StaticVariable("X86_64ClangCppflags", strings.Join(ClangFilterUnknownCflags(x86_64Cppflags), " ")) |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 140 | |
Colin Cross | 91e9004 | 2016-12-02 17:13:24 -0800 | [diff] [blame] | 141 | // Yasm flags |
| 142 | pctx.StaticVariable("X86_64YasmFlags", "-f elf64 -m amd64") |
| 143 | |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 144 | // Extended cflags |
| 145 | |
| 146 | // Architecture variant cflags |
| 147 | for variant, cflags := range x86_64ArchVariantCflags { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 148 | pctx.StaticVariable("X86_64"+variant+"VariantCflags", strings.Join(cflags, " ")) |
| 149 | pctx.StaticVariable("X86_64"+variant+"VariantClangCflags", |
| 150 | strings.Join(ClangFilterUnknownCflags(cflags), " ")) |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 151 | } |
| 152 | } |
| 153 | |
| 154 | type toolchainX86_64 struct { |
| 155 | toolchain64Bit |
| 156 | toolchainCflags, toolchainClangCflags string |
| 157 | } |
| 158 | |
| 159 | func (t *toolchainX86_64) Name() string { |
| 160 | return "x86_64" |
| 161 | } |
| 162 | |
| 163 | func (t *toolchainX86_64) GccRoot() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 164 | return "${config.X86_64GccRoot}" |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | func (t *toolchainX86_64) GccTriple() string { |
Dan Albert | 84f431f | 2016-07-20 14:44:26 -0700 | [diff] [blame] | 168 | return "x86_64-linux-android" |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | func (t *toolchainX86_64) GccVersion() string { |
Dan Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame] | 172 | return x86_64GccVersion |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | func (t *toolchainX86_64) ToolchainLdflags() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 176 | return "${config.X86_64ToolchainLdflags}" |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | func (t *toolchainX86_64) ToolchainCflags() string { |
| 180 | return t.toolchainCflags |
| 181 | } |
| 182 | |
| 183 | func (t *toolchainX86_64) Cflags() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 184 | return "${config.X86_64Cflags}" |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | func (t *toolchainX86_64) Cppflags() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 188 | return "${config.X86_64Cppflags}" |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | func (t *toolchainX86_64) Ldflags() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 192 | return "${config.X86_64Ldflags}" |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | func (t *toolchainX86_64) IncludeFlags() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 196 | return "${config.X86_64IncludeFlags}" |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | func (t *toolchainX86_64) ClangTriple() string { |
Dan Albert | 84f431f | 2016-07-20 14:44:26 -0700 | [diff] [blame] | 200 | return t.GccTriple() |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 201 | } |
| 202 | |
Dan Willemsen | 569b0fa | 2016-05-08 20:04:20 -0700 | [diff] [blame] | 203 | func (t *toolchainX86_64) ToolchainClangLdflags() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 204 | return "${config.X86_64ToolchainLdflags}" |
Dan Willemsen | 569b0fa | 2016-05-08 20:04:20 -0700 | [diff] [blame] | 205 | } |
| 206 | |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 207 | func (t *toolchainX86_64) ToolchainClangCflags() string { |
| 208 | return t.toolchainClangCflags |
| 209 | } |
| 210 | |
| 211 | func (t *toolchainX86_64) ClangCflags() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 212 | return "${config.X86_64ClangCflags}" |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | func (t *toolchainX86_64) ClangCppflags() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 216 | return "${config.X86_64ClangCppflags}" |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | func (t *toolchainX86_64) ClangLdflags() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 220 | return "${config.X86_64Ldflags}" |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 221 | } |
| 222 | |
Colin Cross | 91e9004 | 2016-12-02 17:13:24 -0800 | [diff] [blame] | 223 | func (t *toolchainX86_64) YasmFlags() string { |
| 224 | return "${config.X86_64YasmFlags}" |
| 225 | } |
| 226 | |
Evgenii Stepanov | af36db1 | 2016-08-15 14:18:24 -0700 | [diff] [blame] | 227 | func (toolchainX86_64) SanitizerRuntimeLibraryArch() string { |
| 228 | return "x86_64" |
| 229 | } |
| 230 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 231 | func x86_64ToolchainFactory(arch android.Arch) Toolchain { |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 232 | toolchainCflags := []string{ |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 233 | "${config.X86_64ToolchainCflags}", |
| 234 | "${config.X86_64" + arch.ArchVariant + "VariantCflags}", |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | toolchainClangCflags := []string{ |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 238 | "${config.X86_64ToolchainCflags}", |
| 239 | "${config.X86_64" + arch.ArchVariant + "VariantClangCflags}", |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | for _, feature := range arch.ArchFeatures { |
| 243 | toolchainCflags = append(toolchainCflags, x86_64ArchFeatureCflags[feature]...) |
| 244 | toolchainClangCflags = append(toolchainClangCflags, x86_64ArchFeatureCflags[feature]...) |
| 245 | } |
| 246 | |
| 247 | return &toolchainX86_64{ |
| 248 | toolchainCflags: strings.Join(toolchainCflags, " "), |
| 249 | toolchainClangCflags: strings.Join(toolchainClangCflags, " "), |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | func init() { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 254 | registerToolchainFactory(android.Android, android.X86_64, x86_64ToolchainFactory) |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 255 | } |