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 | |
| 15 | package cc |
| 16 | |
| 17 | import ( |
| 18 | "strings" |
| 19 | |
| 20 | "android/soong/common" |
| 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 | }, |
| 76 | "atom": []string{ |
| 77 | "-march=atom", |
| 78 | "-mfpmath=sse", |
| 79 | }, |
| 80 | "haswell": []string{ |
| 81 | "-march=core-avx2", |
| 82 | "-mfpmath=sse", |
| 83 | }, |
| 84 | "ivybridge": []string{ |
| 85 | "-march=core-avx-i", |
| 86 | "-mfpmath=sse", |
| 87 | }, |
| 88 | "sandybridge": []string{ |
Dan Willemsen | b77bd79 | 2016-02-29 15:26:26 -0800 | [diff] [blame] | 89 | "-march=corei7", |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 90 | "-mfpmath=sse", |
| 91 | }, |
| 92 | "silvermont": []string{ |
| 93 | "-march=slm", |
| 94 | "-mfpmath=sse", |
| 95 | }, |
| 96 | } |
| 97 | |
| 98 | x86ArchFeatureCflags = map[string][]string{ |
| 99 | "ssse3": []string{"-DUSE_SSSE3", "-mssse3"}, |
| 100 | "sse4": []string{"-msse4"}, |
| 101 | "sse4_1": []string{"-msse4.1"}, |
| 102 | "sse4_2": []string{"-msse4.2"}, |
| 103 | "avx": []string{"-mavx"}, |
| 104 | "aes_ni": []string{"-maes"}, |
| 105 | } |
| 106 | ) |
| 107 | |
Dan Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame] | 108 | const ( |
| 109 | x86GccVersion = "4.9" |
| 110 | ) |
| 111 | |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 112 | func init() { |
| 113 | common.RegisterArchFeatures(common.X86, "atom", |
| 114 | "ssse3", |
| 115 | "movbe") |
| 116 | common.RegisterArchFeatures(common.X86, "haswell", |
| 117 | "ssse3", |
| 118 | "sse4", |
| 119 | "sse4_1", |
| 120 | "sse4_2", |
| 121 | "aes_ni", |
| 122 | "avx", |
| 123 | "popcnt", |
| 124 | "movbe") |
| 125 | common.RegisterArchFeatures(common.X86, "ivybridge", |
| 126 | "ssse3", |
| 127 | "sse4", |
| 128 | "sse4_1", |
| 129 | "sse4_2", |
| 130 | "aes_ni", |
| 131 | "avx", |
| 132 | "popcnt") |
| 133 | common.RegisterArchFeatures(common.X86, "sandybridge", |
| 134 | "ssse3", |
| 135 | "sse4", |
| 136 | "sse4_1", |
| 137 | "sse4_2", |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 138 | "popcnt") |
| 139 | common.RegisterArchFeatures(common.X86, "silvermont", |
| 140 | "ssse3", |
| 141 | "sse4", |
| 142 | "sse4_1", |
| 143 | "sse4_2", |
| 144 | "aes_ni", |
| 145 | "popcnt", |
| 146 | "movbe") |
| 147 | |
Dan Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame] | 148 | pctx.StaticVariable("x86GccVersion", x86GccVersion) |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 149 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 150 | pctx.SourcePathVariable("x86GccRoot", |
Dan Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame] | 151 | "prebuilts/gcc/${HostPrebuiltTag}/x86/x86_64-linux-android-${x86GccVersion}") |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 152 | |
| 153 | pctx.StaticVariable("x86GccTriple", "x86_64-linux-android") |
| 154 | |
| 155 | pctx.StaticVariable("x86ToolchainCflags", "-m32") |
| 156 | pctx.StaticVariable("x86ToolchainLdflags", "-m32") |
| 157 | |
| 158 | pctx.StaticVariable("x86Cflags", strings.Join(x86Cflags, " ")) |
| 159 | pctx.StaticVariable("x86Ldflags", strings.Join(x86Ldflags, " ")) |
| 160 | pctx.StaticVariable("x86Cppflags", strings.Join(x86Cppflags, " ")) |
| 161 | pctx.StaticVariable("x86IncludeFlags", strings.Join([]string{ |
| 162 | "-isystem ${LibcRoot}/arch-x86/include", |
| 163 | "-isystem ${LibcRoot}/include", |
| 164 | "-isystem ${LibcRoot}/kernel/uapi", |
| 165 | "-isystem ${LibcRoot}/kernel/uapi/asm-x86", |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 166 | }, " ")) |
| 167 | |
| 168 | // Clang cflags |
Dan Willemsen | 569b0fa | 2016-05-08 20:04:20 -0700 | [diff] [blame] | 169 | pctx.StaticVariable("x86ClangCflags", strings.Join(clangFilterUnknownCflags(x86ClangCflags), " ")) |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 170 | pctx.StaticVariable("x86ClangLdflags", strings.Join(clangFilterUnknownCflags(x86Ldflags), " ")) |
| 171 | pctx.StaticVariable("x86ClangCppflags", strings.Join(clangFilterUnknownCflags(x86Cppflags), " ")) |
| 172 | |
| 173 | // Extended cflags |
| 174 | |
| 175 | // Architecture variant cflags |
| 176 | for variant, cflags := range x86ArchVariantCflags { |
| 177 | pctx.StaticVariable("x86"+variant+"VariantCflags", strings.Join(cflags, " ")) |
| 178 | pctx.StaticVariable("x86"+variant+"VariantClangCflags", |
| 179 | strings.Join(clangFilterUnknownCflags(cflags), " ")) |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | type toolchainX86 struct { |
| 184 | toolchain32Bit |
| 185 | toolchainCflags, toolchainClangCflags string |
| 186 | } |
| 187 | |
| 188 | func (t *toolchainX86) Name() string { |
| 189 | return "x86" |
| 190 | } |
| 191 | |
| 192 | func (t *toolchainX86) GccRoot() string { |
| 193 | return "${x86GccRoot}" |
| 194 | } |
| 195 | |
| 196 | func (t *toolchainX86) GccTriple() string { |
| 197 | return "${x86GccTriple}" |
| 198 | } |
| 199 | |
| 200 | func (t *toolchainX86) GccVersion() string { |
Dan Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame] | 201 | return x86GccVersion |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | func (t *toolchainX86) ToolchainLdflags() string { |
| 205 | return "${x86ToolchainLdflags}" |
| 206 | } |
| 207 | |
| 208 | func (t *toolchainX86) ToolchainCflags() string { |
| 209 | return t.toolchainCflags |
| 210 | } |
| 211 | |
| 212 | func (t *toolchainX86) Cflags() string { |
| 213 | return "${x86Cflags}" |
| 214 | } |
| 215 | |
| 216 | func (t *toolchainX86) Cppflags() string { |
| 217 | return "${x86Cppflags}" |
| 218 | } |
| 219 | |
| 220 | func (t *toolchainX86) Ldflags() string { |
| 221 | return "${x86Ldflags}" |
| 222 | } |
| 223 | |
| 224 | func (t *toolchainX86) IncludeFlags() string { |
| 225 | return "${x86IncludeFlags}" |
| 226 | } |
| 227 | |
| 228 | func (t *toolchainX86) ClangTriple() string { |
Dan Willemsen | 569b0fa | 2016-05-08 20:04:20 -0700 | [diff] [blame] | 229 | return "i686-linux-android" |
| 230 | } |
| 231 | |
| 232 | func (t *toolchainX86) ToolchainClangLdflags() string { |
| 233 | return "${x86ToolchainLdflags}" |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | func (t *toolchainX86) ToolchainClangCflags() string { |
| 237 | return t.toolchainClangCflags |
| 238 | } |
| 239 | |
| 240 | func (t *toolchainX86) ClangCflags() string { |
| 241 | return "${x86ClangCflags}" |
| 242 | } |
| 243 | |
| 244 | func (t *toolchainX86) ClangCppflags() string { |
| 245 | return "${x86ClangCppflags}" |
| 246 | } |
| 247 | |
| 248 | func (t *toolchainX86) ClangLdflags() string { |
| 249 | return "${x86Ldflags}" |
| 250 | } |
| 251 | |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 252 | func (toolchainX86) AddressSanitizerRuntimeLibrary() string { |
| 253 | return "libclang_rt.asan-i686-android.so" |
| 254 | } |
| 255 | |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 256 | func x86ToolchainFactory(arch common.Arch) Toolchain { |
| 257 | toolchainCflags := []string{ |
| 258 | "${x86ToolchainCflags}", |
| 259 | "${x86" + arch.ArchVariant + "VariantCflags}", |
| 260 | } |
| 261 | |
| 262 | toolchainClangCflags := []string{ |
| 263 | "${x86ToolchainCflags}", |
| 264 | "${x86" + arch.ArchVariant + "VariantClangCflags}", |
| 265 | } |
| 266 | |
| 267 | for _, feature := range arch.ArchFeatures { |
| 268 | toolchainCflags = append(toolchainCflags, x86ArchFeatureCflags[feature]...) |
| 269 | toolchainClangCflags = append(toolchainClangCflags, x86ArchFeatureCflags[feature]...) |
| 270 | } |
| 271 | |
| 272 | return &toolchainX86{ |
| 273 | toolchainCflags: strings.Join(toolchainCflags, " "), |
| 274 | toolchainClangCflags: strings.Join(toolchainClangCflags, " "), |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | func init() { |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 279 | registerDeviceToolchainFactory(common.X86, x86ToolchainFactory) |
Colin Cross | b0cba6a | 2015-11-20 15:35:26 -0800 | [diff] [blame] | 280 | } |