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 | |
| 15 | package cc |
| 16 | |
| 17 | import ( |
| 18 | "strings" |
| 19 | |
| 20 | "android/soong/common" |
| 21 | ) |
| 22 | |
| 23 | var ( |
| 24 | x86_64Cflags = []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 | // Help catch common 32/64-bit errors. |
| 44 | "-Werror=pointer-to-int-cast", |
| 45 | "-Werror=int-to-pointer-cast", |
| 46 | "-Werror=implicit-function-declaration", |
| 47 | |
| 48 | // TARGET_RELEASE_CFLAGS from build/core/combo/select.mk |
| 49 | "-O2", |
| 50 | "-g", |
| 51 | "-fno-strict-aliasing", |
| 52 | } |
| 53 | |
| 54 | x86_64Cppflags = []string{} |
| 55 | |
| 56 | x86_64Ldflags = []string{ |
| 57 | "-Wl,-z,noexecstack", |
| 58 | "-Wl,-z,relro", |
| 59 | "-Wl,-z,now", |
| 60 | "-Wl,--build-id=md5", |
| 61 | "-Wl,--warn-shared-textrel", |
| 62 | "-Wl,--fatal-warnings", |
| 63 | "-Wl,--gc-sections", |
| 64 | "-Wl,--hash-style=gnu", |
| 65 | } |
| 66 | |
| 67 | x86_64ArchVariantCflags = map[string][]string{ |
| 68 | "": []string{ |
| 69 | "-march=x86-64", |
| 70 | }, |
| 71 | "haswell": []string{ |
| 72 | "-march=core-avx2", |
| 73 | }, |
| 74 | "ivybridge": []string{ |
| 75 | "-march=core-avx-i", |
| 76 | }, |
| 77 | "sandybridge": []string{ |
| 78 | "-march=corei7-avx", |
| 79 | }, |
| 80 | "silvermont": []string{ |
| 81 | "-march=slm", |
| 82 | }, |
| 83 | } |
| 84 | |
| 85 | x86_64ArchFeatureCflags = map[string][]string{ |
| 86 | "ssse3": []string{"-DUSE_SSSE3", "-mssse3"}, |
| 87 | "sse4": []string{"-msse4"}, |
| 88 | "sse4_1": []string{"-msse4.1"}, |
| 89 | "sse4_2": []string{"-msse4.2"}, |
| 90 | "avx": []string{"-mavx"}, |
| 91 | "aes_ni": []string{"-maes"}, |
| 92 | } |
| 93 | ) |
| 94 | |
| 95 | func init() { |
| 96 | common.RegisterArchFeatures(common.X86_64, "", |
| 97 | "ssse3", |
| 98 | "sse4", |
| 99 | "sse4_1", |
| 100 | "sse4_2", |
| 101 | "popcnt") |
| 102 | common.RegisterArchFeatures(common.X86_64, "haswell", |
| 103 | "ssse3", |
| 104 | "sse4", |
| 105 | "sse4_1", |
| 106 | "sse4_2", |
| 107 | "aes_ni", |
| 108 | "avx", |
| 109 | "popcnt") |
| 110 | common.RegisterArchFeatures(common.X86_64, "ivybridge", |
| 111 | "ssse3", |
| 112 | "sse4", |
| 113 | "sse4_1", |
| 114 | "sse4_2", |
| 115 | "aes_ni", |
| 116 | "avx", |
| 117 | "popcnt") |
| 118 | common.RegisterArchFeatures(common.X86_64, "sandybridge", |
| 119 | "ssse3", |
| 120 | "sse4", |
| 121 | "sse4_1", |
| 122 | "sse4_2", |
| 123 | "aes_ni", |
| 124 | "avx", |
| 125 | "popcnt") |
| 126 | common.RegisterArchFeatures(common.X86_64, "silvermont", |
| 127 | "ssse3", |
| 128 | "sse4", |
| 129 | "sse4_1", |
| 130 | "sse4_2", |
| 131 | "aes_ni", |
| 132 | "popcnt") |
| 133 | |
| 134 | pctx.StaticVariable("x86_64GccVersion", "4.9") |
| 135 | |
| 136 | pctx.StaticVariable("x86_64GccRoot", |
| 137 | "prebuilts/gcc/${HostPrebuiltTag}/x86/x86_64-linux-android-${armGccVersion}") |
| 138 | |
| 139 | pctx.StaticVariable("x86_64GccTriple", "x86_64-linux-android") |
| 140 | |
| 141 | pctx.StaticVariable("x86_64ToolchainCflags", "-m64") |
| 142 | pctx.StaticVariable("x86_64ToolchainLdflags", "-m64") |
| 143 | |
| 144 | pctx.StaticVariable("x86_64Cflags", strings.Join(x86_64Cflags, " ")) |
| 145 | pctx.StaticVariable("x86_64Ldflags", strings.Join(x86_64Ldflags, " ")) |
| 146 | pctx.StaticVariable("x86_64Cppflags", strings.Join(x86_64Cppflags, " ")) |
| 147 | pctx.StaticVariable("x86_64IncludeFlags", strings.Join([]string{ |
| 148 | "-isystem ${LibcRoot}/arch-x86_64/include", |
| 149 | "-isystem ${LibcRoot}/include", |
| 150 | "-isystem ${LibcRoot}/kernel/uapi", |
| 151 | "-isystem ${LibcRoot}/kernel/uapi/asm-x86", |
| 152 | "-isystem ${LibmRoot}/include", |
| 153 | "-isystem ${LibmRoot}/include/amd64", |
| 154 | }, " ")) |
| 155 | |
| 156 | // Clang cflags |
| 157 | pctx.StaticVariable("x86_64ClangCflags", strings.Join(clangFilterUnknownCflags(x86_64Cflags), " ")) |
| 158 | pctx.StaticVariable("x86_64ClangLdflags", strings.Join(clangFilterUnknownCflags(x86_64Ldflags), " ")) |
| 159 | pctx.StaticVariable("x86_64ClangCppflags", strings.Join(clangFilterUnknownCflags(x86_64Cppflags), " ")) |
| 160 | |
| 161 | // Extended cflags |
| 162 | |
| 163 | // Architecture variant cflags |
| 164 | for variant, cflags := range x86_64ArchVariantCflags { |
| 165 | pctx.StaticVariable("x86_64"+variant+"VariantCflags", strings.Join(cflags, " ")) |
| 166 | pctx.StaticVariable("x86_64"+variant+"VariantClangCflags", |
| 167 | strings.Join(clangFilterUnknownCflags(cflags), " ")) |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | type toolchainX86_64 struct { |
| 172 | toolchain64Bit |
| 173 | toolchainCflags, toolchainClangCflags string |
| 174 | } |
| 175 | |
| 176 | func (t *toolchainX86_64) Name() string { |
| 177 | return "x86_64" |
| 178 | } |
| 179 | |
| 180 | func (t *toolchainX86_64) GccRoot() string { |
| 181 | return "${x86_64GccRoot}" |
| 182 | } |
| 183 | |
| 184 | func (t *toolchainX86_64) GccTriple() string { |
| 185 | return "${x86_64GccTriple}" |
| 186 | } |
| 187 | |
| 188 | func (t *toolchainX86_64) GccVersion() string { |
| 189 | return "${x86_64GccVersion}" |
| 190 | } |
| 191 | |
| 192 | func (t *toolchainX86_64) ToolchainLdflags() string { |
| 193 | return "${x86_64ToolchainLdflags}" |
| 194 | } |
| 195 | |
| 196 | func (t *toolchainX86_64) ToolchainCflags() string { |
| 197 | return t.toolchainCflags |
| 198 | } |
| 199 | |
| 200 | func (t *toolchainX86_64) Cflags() string { |
| 201 | return "${x86_64Cflags}" |
| 202 | } |
| 203 | |
| 204 | func (t *toolchainX86_64) Cppflags() string { |
| 205 | return "${x86_64Cppflags}" |
| 206 | } |
| 207 | |
| 208 | func (t *toolchainX86_64) Ldflags() string { |
| 209 | return "${x86_64Ldflags}" |
| 210 | } |
| 211 | |
| 212 | func (t *toolchainX86_64) IncludeFlags() string { |
| 213 | return "${x86_64IncludeFlags}" |
| 214 | } |
| 215 | |
| 216 | func (t *toolchainX86_64) ClangTriple() string { |
| 217 | return "${x86_64GccTriple}" |
| 218 | } |
| 219 | |
| 220 | func (t *toolchainX86_64) ToolchainClangCflags() string { |
| 221 | return t.toolchainClangCflags |
| 222 | } |
| 223 | |
| 224 | func (t *toolchainX86_64) ClangCflags() string { |
| 225 | return "${x86_64ClangCflags}" |
| 226 | } |
| 227 | |
| 228 | func (t *toolchainX86_64) ClangCppflags() string { |
| 229 | return "${x86_64ClangCppflags}" |
| 230 | } |
| 231 | |
| 232 | func (t *toolchainX86_64) ClangLdflags() string { |
| 233 | return "${x86_64Ldflags}" |
| 234 | } |
| 235 | |
| 236 | func x86_64ToolchainFactory(arch common.Arch) Toolchain { |
| 237 | toolchainCflags := []string{ |
| 238 | "${x86_64ToolchainCflags}", |
| 239 | "${x86_64" + arch.ArchVariant + "VariantCflags}", |
| 240 | } |
| 241 | |
| 242 | toolchainClangCflags := []string{ |
| 243 | "${x86_64ToolchainCflags}", |
| 244 | "${x86_64" + arch.ArchVariant + "VariantClangCflags}", |
| 245 | } |
| 246 | |
| 247 | for _, feature := range arch.ArchFeatures { |
| 248 | toolchainCflags = append(toolchainCflags, x86_64ArchFeatureCflags[feature]...) |
| 249 | toolchainClangCflags = append(toolchainClangCflags, x86_64ArchFeatureCflags[feature]...) |
| 250 | } |
| 251 | |
| 252 | return &toolchainX86_64{ |
| 253 | toolchainCflags: strings.Join(toolchainCflags, " "), |
| 254 | toolchainClangCflags: strings.Join(toolchainClangCflags, " "), |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | func init() { |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 259 | registerDeviceToolchainFactory(common.X86_64, x86_64ToolchainFactory) |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 260 | } |