Colin Cross | b0cba6a | 2015-11-20 15:35:26 -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 | b0cba6a | 2015-11-20 15:35:26 -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 | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 21 | ) |
| 22 | |
| 23 | var ( |
| 24 | x86Cflags = []string{ |
| 25 | "-fno-exceptions", // from build/core/combo/select.mk |
| 26 | "-Wno-multichar", // from build/core/combo/select.mk |
| 27 | "-O2", |
| 28 | "-Wa,--noexecstack", |
| 29 | "-Werror=format-security", |
| 30 | "-D_FORTIFY_SOURCE=2", |
| 31 | "-Wstrict-aliasing=2", |
| 32 | "-ffunction-sections", |
| 33 | "-finline-functions", |
| 34 | "-finline-limit=300", |
| 35 | "-fno-short-enums", |
| 36 | "-fstrict-aliasing", |
| 37 | "-funswitch-loops", |
| 38 | "-funwind-tables", |
Dan Willemsen | 7a0f848 | 2016-01-12 16:22:40 -0800 | [diff] [blame] | 39 | "-fstack-protector-strong", |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 40 | "-no-canonical-prefixes", |
| 41 | "-fno-canonical-system-headers", |
| 42 | |
| 43 | // TARGET_RELEASE_CFLAGS from build/core/combo/select.mk |
| 44 | "-O2", |
| 45 | "-g", |
| 46 | "-fno-strict-aliasing", |
| 47 | } |
| 48 | |
Dan Willemsen | 569b0fa | 2016-05-08 20:04:20 -0700 | [diff] [blame] | 49 | x86ClangCflags = append(x86Cflags, []string{ |
| 50 | "-msse3", |
| 51 | |
| 52 | // -mstackrealign is needed to realign stack in native code |
| 53 | // that could be called from JNI, so that movaps instruction |
| 54 | // will work on assumed stack aligned local variables. |
| 55 | "-mstackrealign", |
| 56 | }...) |
| 57 | |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 58 | x86Cppflags = []string{} |
| 59 | |
| 60 | x86Ldflags = []string{ |
| 61 | "-Wl,-z,noexecstack", |
| 62 | "-Wl,-z,relro", |
| 63 | "-Wl,-z,now", |
| 64 | "-Wl,--build-id=md5", |
| 65 | "-Wl,--warn-shared-textrel", |
| 66 | "-Wl,--fatal-warnings", |
| 67 | "-Wl,--gc-sections", |
| 68 | "-Wl,--hash-style=gnu", |
Dan Willemsen | c7e4597 | 2015-12-09 13:05:28 -0800 | [diff] [blame] | 69 | "-Wl,--no-undefined-version", |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | x86ArchVariantCflags = map[string][]string{ |
| 73 | "": []string{ |
| 74 | "-march=prescott", |
| 75 | }, |
Dan Willemsen | 8a35405 | 2016-05-10 14:30:51 -0700 | [diff] [blame] | 76 | "x86_64": []string{ |
| 77 | "-march=prescott", |
| 78 | }, |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 79 | "atom": []string{ |
| 80 | "-march=atom", |
| 81 | "-mfpmath=sse", |
| 82 | }, |
| 83 | "haswell": []string{ |
| 84 | "-march=core-avx2", |
| 85 | "-mfpmath=sse", |
| 86 | }, |
| 87 | "ivybridge": []string{ |
| 88 | "-march=core-avx-i", |
| 89 | "-mfpmath=sse", |
| 90 | }, |
| 91 | "sandybridge": []string{ |
Dan Willemsen | b77bd79 | 2016-02-29 15:26:26 -0800 | [diff] [blame] | 92 | "-march=corei7", |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 93 | "-mfpmath=sse", |
| 94 | }, |
| 95 | "silvermont": []string{ |
| 96 | "-march=slm", |
| 97 | "-mfpmath=sse", |
| 98 | }, |
| 99 | } |
| 100 | |
| 101 | x86ArchFeatureCflags = map[string][]string{ |
| 102 | "ssse3": []string{"-DUSE_SSSE3", "-mssse3"}, |
| 103 | "sse4": []string{"-msse4"}, |
| 104 | "sse4_1": []string{"-msse4.1"}, |
| 105 | "sse4_2": []string{"-msse4.2"}, |
| 106 | "avx": []string{"-mavx"}, |
| 107 | "aes_ni": []string{"-maes"}, |
| 108 | } |
| 109 | ) |
| 110 | |
Dan Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame] | 111 | const ( |
| 112 | x86GccVersion = "4.9" |
| 113 | ) |
| 114 | |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 115 | func init() { |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 116 | android.RegisterArchVariants(android.X86, |
| 117 | "atom", |
| 118 | "haswell", |
| 119 | "ivybridge", |
| 120 | "sandybridge", |
| 121 | "silvermont", |
| 122 | "x86_64") |
| 123 | android.RegisterArchFeatures(android.X86, |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 124 | "ssse3", |
| 125 | "sse4", |
| 126 | "sse4_1", |
| 127 | "sse4_2", |
| 128 | "aes_ni", |
| 129 | "avx", |
| 130 | "popcnt", |
| 131 | "movbe") |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 132 | android.RegisterArchVariantFeatures(android.X86, "x86_64", |
| 133 | "ssse3", |
| 134 | "sse4", |
| 135 | "sse4_1", |
| 136 | "sse4_2", |
| 137 | "popcnt") |
| 138 | android.RegisterArchVariantFeatures(android.X86, "atom", |
| 139 | "ssse3", |
| 140 | "movbe") |
| 141 | android.RegisterArchVariantFeatures(android.X86, "haswell", |
| 142 | "ssse3", |
| 143 | "sse4", |
| 144 | "sse4_1", |
| 145 | "sse4_2", |
| 146 | "aes_ni", |
| 147 | "avx", |
| 148 | "popcnt", |
| 149 | "movbe") |
| 150 | android.RegisterArchVariantFeatures(android.X86, "ivybridge", |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 151 | "ssse3", |
| 152 | "sse4", |
| 153 | "sse4_1", |
| 154 | "sse4_2", |
| 155 | "aes_ni", |
| 156 | "avx", |
| 157 | "popcnt") |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 158 | android.RegisterArchVariantFeatures(android.X86, "sandybridge", |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 159 | "ssse3", |
| 160 | "sse4", |
| 161 | "sse4_1", |
| 162 | "sse4_2", |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 163 | "popcnt") |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 164 | android.RegisterArchVariantFeatures(android.X86, "silvermont", |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 165 | "ssse3", |
| 166 | "sse4", |
| 167 | "sse4_1", |
| 168 | "sse4_2", |
| 169 | "aes_ni", |
| 170 | "popcnt", |
| 171 | "movbe") |
| 172 | |
Dan Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame] | 173 | pctx.StaticVariable("x86GccVersion", x86GccVersion) |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 174 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 175 | pctx.SourcePathVariable("X86GccRoot", |
Dan Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame] | 176 | "prebuilts/gcc/${HostPrebuiltTag}/x86/x86_64-linux-android-${x86GccVersion}") |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 177 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 178 | pctx.StaticVariable("X86ToolchainCflags", "-m32") |
| 179 | pctx.StaticVariable("X86ToolchainLdflags", "-m32") |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 180 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 181 | pctx.StaticVariable("X86Cflags", strings.Join(x86Cflags, " ")) |
| 182 | pctx.StaticVariable("X86Ldflags", strings.Join(x86Ldflags, " ")) |
| 183 | pctx.StaticVariable("X86Cppflags", strings.Join(x86Cppflags, " ")) |
| 184 | pctx.StaticVariable("X86IncludeFlags", bionicHeaders("x86", "x86")) |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 185 | |
| 186 | // Clang cflags |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 187 | pctx.StaticVariable("X86ClangCflags", strings.Join(ClangFilterUnknownCflags(x86ClangCflags), " ")) |
| 188 | pctx.StaticVariable("X86ClangLdflags", strings.Join(ClangFilterUnknownCflags(x86Ldflags), " ")) |
| 189 | pctx.StaticVariable("X86ClangCppflags", strings.Join(ClangFilterUnknownCflags(x86Cppflags), " ")) |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 190 | |
Colin Cross | 91e9004 | 2016-12-02 17:13:24 -0800 | [diff] [blame^] | 191 | // Yasm flags |
| 192 | pctx.StaticVariable("X86YasmFlags", "-f elf32 -m x86") |
| 193 | |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 194 | // Extended cflags |
| 195 | |
| 196 | // Architecture variant cflags |
| 197 | for variant, cflags := range x86ArchVariantCflags { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 198 | pctx.StaticVariable("X86"+variant+"VariantCflags", strings.Join(cflags, " ")) |
| 199 | pctx.StaticVariable("X86"+variant+"VariantClangCflags", |
| 200 | strings.Join(ClangFilterUnknownCflags(cflags), " ")) |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 201 | } |
| 202 | } |
| 203 | |
| 204 | type toolchainX86 struct { |
| 205 | toolchain32Bit |
| 206 | toolchainCflags, toolchainClangCflags string |
| 207 | } |
| 208 | |
| 209 | func (t *toolchainX86) Name() string { |
| 210 | return "x86" |
| 211 | } |
| 212 | |
| 213 | func (t *toolchainX86) GccRoot() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 214 | return "${config.X86GccRoot}" |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | func (t *toolchainX86) GccTriple() string { |
Dan Albert | 84f431f | 2016-07-20 14:44:26 -0700 | [diff] [blame] | 218 | return "x86_64-linux-android" |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | func (t *toolchainX86) GccVersion() string { |
Dan Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame] | 222 | return x86GccVersion |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | func (t *toolchainX86) ToolchainLdflags() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 226 | return "${config.X86ToolchainLdflags}" |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | func (t *toolchainX86) ToolchainCflags() string { |
| 230 | return t.toolchainCflags |
| 231 | } |
| 232 | |
| 233 | func (t *toolchainX86) Cflags() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 234 | return "${config.X86Cflags}" |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | func (t *toolchainX86) Cppflags() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 238 | return "${config.X86Cppflags}" |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | func (t *toolchainX86) Ldflags() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 242 | return "${config.X86Ldflags}" |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | func (t *toolchainX86) IncludeFlags() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 246 | return "${config.X86IncludeFlags}" |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | func (t *toolchainX86) ClangTriple() string { |
Dan Willemsen | 569b0fa | 2016-05-08 20:04:20 -0700 | [diff] [blame] | 250 | return "i686-linux-android" |
| 251 | } |
| 252 | |
| 253 | func (t *toolchainX86) ToolchainClangLdflags() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 254 | return "${config.X86ToolchainLdflags}" |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | func (t *toolchainX86) ToolchainClangCflags() string { |
| 258 | return t.toolchainClangCflags |
| 259 | } |
| 260 | |
| 261 | func (t *toolchainX86) ClangCflags() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 262 | return "${config.X86ClangCflags}" |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | func (t *toolchainX86) ClangCppflags() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 266 | return "${config.X86ClangCppflags}" |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | func (t *toolchainX86) ClangLdflags() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 270 | return "${config.X86Ldflags}" |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 271 | } |
| 272 | |
Colin Cross | 91e9004 | 2016-12-02 17:13:24 -0800 | [diff] [blame^] | 273 | func (t *toolchainX86) YasmFlags() string { |
| 274 | return "${config.X86YasmFlags}" |
| 275 | } |
| 276 | |
Evgenii Stepanov | af36db1 | 2016-08-15 14:18:24 -0700 | [diff] [blame] | 277 | func (toolchainX86) SanitizerRuntimeLibraryArch() string { |
| 278 | return "i686" |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 279 | } |
| 280 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 281 | func x86ToolchainFactory(arch android.Arch) Toolchain { |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 282 | toolchainCflags := []string{ |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 283 | "${config.X86ToolchainCflags}", |
| 284 | "${config.X86" + arch.ArchVariant + "VariantCflags}", |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | toolchainClangCflags := []string{ |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 288 | "${config.X86ToolchainCflags}", |
| 289 | "${config.X86" + arch.ArchVariant + "VariantClangCflags}", |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | for _, feature := range arch.ArchFeatures { |
| 293 | toolchainCflags = append(toolchainCflags, x86ArchFeatureCflags[feature]...) |
| 294 | toolchainClangCflags = append(toolchainClangCflags, x86ArchFeatureCflags[feature]...) |
| 295 | } |
| 296 | |
| 297 | return &toolchainX86{ |
| 298 | toolchainCflags: strings.Join(toolchainCflags, " "), |
| 299 | toolchainClangCflags: strings.Join(toolchainClangCflags, " "), |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | func init() { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 304 | registerToolchainFactory(android.Android, android.X86, x86ToolchainFactory) |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 305 | } |