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