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