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{ |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 25 | // Help catch common 32/64-bit errors. |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 26 | "-Werror=implicit-function-declaration", |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | x86_64Cppflags = []string{} |
| 30 | |
| 31 | x86_64Ldflags = []string{ |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 32 | "-Wl,--hash-style=gnu", |
| 33 | } |
| 34 | |
Chih-Hung Hsieh | 02b4da5 | 2018-04-03 11:33:34 -0700 | [diff] [blame] | 35 | x86_64Lldflags = ClangFilterUnknownLldflags(x86_64Ldflags) |
| 36 | |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 37 | x86_64ArchVariantCflags = map[string][]string{ |
| 38 | "": []string{ |
| 39 | "-march=x86-64", |
| 40 | }, |
Shalini Salomi Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 41 | "broadwell": []string{ |
| 42 | "-march=broadwell", |
| 43 | }, |
| 44 | |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 45 | "haswell": []string{ |
| 46 | "-march=core-avx2", |
| 47 | }, |
| 48 | "ivybridge": []string{ |
| 49 | "-march=core-avx-i", |
| 50 | }, |
| 51 | "sandybridge": []string{ |
Dan Willemsen | b77bd79 | 2016-02-29 15:26:26 -0800 | [diff] [blame] | 52 | "-march=corei7", |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 53 | }, |
| 54 | "silvermont": []string{ |
| 55 | "-march=slm", |
| 56 | }, |
Shalini Salomi Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 57 | "skylake": []string{ |
| 58 | "-march=skylake", |
| 59 | }, |
Benjamin Gordon | 87e7f2f | 2019-02-14 10:59:48 -0700 | [diff] [blame^] | 60 | "stoneyridge": []string{ |
| 61 | "-march=bdver4", |
| 62 | }, |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | x86_64ArchFeatureCflags = map[string][]string{ |
| 66 | "ssse3": []string{"-DUSE_SSSE3", "-mssse3"}, |
| 67 | "sse4": []string{"-msse4"}, |
| 68 | "sse4_1": []string{"-msse4.1"}, |
| 69 | "sse4_2": []string{"-msse4.2"}, |
Dan Willemsen | 4ce4703 | 2016-05-06 17:20:53 -0700 | [diff] [blame] | 70 | "popcnt": []string{"-mpopcnt"}, |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 71 | "avx": []string{"-mavx"}, |
Shalini Salomi Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 72 | "avx2": []string{"-mavx2"}, |
| 73 | "avx512": []string{"-mavx512"}, |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 74 | "aes_ni": []string{"-maes"}, |
| 75 | } |
| 76 | ) |
| 77 | |
Dan Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame] | 78 | const ( |
| 79 | x86_64GccVersion = "4.9" |
| 80 | ) |
| 81 | |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 82 | func init() { |
Dan Willemsen | 01a3c25 | 2019-01-11 19:02:16 -0800 | [diff] [blame] | 83 | android.RegisterDefaultArchVariantFeatures(android.Android, android.X86_64, |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 84 | "ssse3", |
| 85 | "sse4", |
| 86 | "sse4_1", |
| 87 | "sse4_2", |
| 88 | "popcnt") |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 89 | |
Dan Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame] | 90 | pctx.StaticVariable("x86_64GccVersion", x86_64GccVersion) |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 91 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 92 | pctx.SourcePathVariable("X86_64GccRoot", |
Dan Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame] | 93 | "prebuilts/gcc/${HostPrebuiltTag}/x86/x86_64-linux-android-${x86_64GccVersion}") |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 94 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 95 | pctx.StaticVariable("X86_64ToolchainCflags", "-m64") |
| 96 | pctx.StaticVariable("X86_64ToolchainLdflags", "-m64") |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 97 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 98 | pctx.StaticVariable("X86_64Ldflags", strings.Join(x86_64Ldflags, " ")) |
Chih-Hung Hsieh | 02b4da5 | 2018-04-03 11:33:34 -0700 | [diff] [blame] | 99 | pctx.StaticVariable("X86_64Lldflags", strings.Join(x86_64Lldflags, " ")) |
Elliott Hughes | de28deb | 2017-10-12 09:07:53 -0700 | [diff] [blame] | 100 | pctx.StaticVariable("X86_64IncludeFlags", bionicHeaders("x86")) |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 101 | |
| 102 | // Clang cflags |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 103 | pctx.StaticVariable("X86_64ClangCflags", strings.Join(ClangFilterUnknownCflags(x86_64Cflags), " ")) |
| 104 | pctx.StaticVariable("X86_64ClangLdflags", strings.Join(ClangFilterUnknownCflags(x86_64Ldflags), " ")) |
Chih-Hung Hsieh | 02b4da5 | 2018-04-03 11:33:34 -0700 | [diff] [blame] | 105 | pctx.StaticVariable("X86_64ClangLldflags", strings.Join(ClangFilterUnknownCflags(x86_64Lldflags), " ")) |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 106 | pctx.StaticVariable("X86_64ClangCppflags", strings.Join(ClangFilterUnknownCflags(x86_64Cppflags), " ")) |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 107 | |
Colin Cross | 91e9004 | 2016-12-02 17:13:24 -0800 | [diff] [blame] | 108 | // Yasm flags |
| 109 | pctx.StaticVariable("X86_64YasmFlags", "-f elf64 -m amd64") |
| 110 | |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 111 | // Extended cflags |
| 112 | |
| 113 | // Architecture variant cflags |
| 114 | for variant, cflags := range x86_64ArchVariantCflags { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 115 | pctx.StaticVariable("X86_64"+variant+"VariantClangCflags", |
| 116 | strings.Join(ClangFilterUnknownCflags(cflags), " ")) |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 117 | } |
| 118 | } |
| 119 | |
| 120 | type toolchainX86_64 struct { |
| 121 | toolchain64Bit |
Dan Willemsen | bd4abf5 | 2018-10-07 21:06:36 -0700 | [diff] [blame] | 122 | toolchainClangCflags string |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | func (t *toolchainX86_64) Name() string { |
| 126 | return "x86_64" |
| 127 | } |
| 128 | |
| 129 | func (t *toolchainX86_64) GccRoot() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 130 | return "${config.X86_64GccRoot}" |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | func (t *toolchainX86_64) GccTriple() string { |
Dan Albert | 84f431f | 2016-07-20 14:44:26 -0700 | [diff] [blame] | 134 | return "x86_64-linux-android" |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | func (t *toolchainX86_64) GccVersion() string { |
Dan Willemsen | 34fc3b1 | 2015-12-07 12:30:44 -0800 | [diff] [blame] | 138 | return x86_64GccVersion |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 139 | } |
| 140 | |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 141 | func (t *toolchainX86_64) IncludeFlags() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 142 | return "${config.X86_64IncludeFlags}" |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | func (t *toolchainX86_64) ClangTriple() string { |
Dan Albert | 84f431f | 2016-07-20 14:44:26 -0700 | [diff] [blame] | 146 | return t.GccTriple() |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 147 | } |
| 148 | |
Dan Willemsen | 569b0fa | 2016-05-08 20:04:20 -0700 | [diff] [blame] | 149 | func (t *toolchainX86_64) ToolchainClangLdflags() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 150 | return "${config.X86_64ToolchainLdflags}" |
Dan Willemsen | 569b0fa | 2016-05-08 20:04:20 -0700 | [diff] [blame] | 151 | } |
| 152 | |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 153 | func (t *toolchainX86_64) ToolchainClangCflags() string { |
| 154 | return t.toolchainClangCflags |
| 155 | } |
| 156 | |
| 157 | func (t *toolchainX86_64) ClangCflags() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 158 | return "${config.X86_64ClangCflags}" |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | func (t *toolchainX86_64) ClangCppflags() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 162 | return "${config.X86_64ClangCppflags}" |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | func (t *toolchainX86_64) ClangLdflags() string { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 166 | return "${config.X86_64Ldflags}" |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 167 | } |
| 168 | |
Chih-Hung Hsieh | 02b4da5 | 2018-04-03 11:33:34 -0700 | [diff] [blame] | 169 | func (t *toolchainX86_64) ClangLldflags() string { |
| 170 | return "${config.X86_64Lldflags}" |
| 171 | } |
| 172 | |
Colin Cross | 91e9004 | 2016-12-02 17:13:24 -0800 | [diff] [blame] | 173 | func (t *toolchainX86_64) YasmFlags() string { |
| 174 | return "${config.X86_64YasmFlags}" |
| 175 | } |
| 176 | |
Yi Kong | 924adc4 | 2018-08-31 14:27:44 -0700 | [diff] [blame] | 177 | func (toolchainX86_64) LibclangRuntimeLibraryArch() string { |
Evgenii Stepanov | af36db1 | 2016-08-15 14:18:24 -0700 | [diff] [blame] | 178 | return "x86_64" |
| 179 | } |
| 180 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 181 | func x86_64ToolchainFactory(arch android.Arch) Toolchain { |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 182 | toolchainClangCflags := []string{ |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 183 | "${config.X86_64ToolchainCflags}", |
| 184 | "${config.X86_64" + arch.ArchVariant + "VariantClangCflags}", |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | for _, feature := range arch.ArchFeatures { |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 188 | toolchainClangCflags = append(toolchainClangCflags, x86_64ArchFeatureCflags[feature]...) |
| 189 | } |
| 190 | |
| 191 | return &toolchainX86_64{ |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 192 | toolchainClangCflags: strings.Join(toolchainClangCflags, " "), |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | func init() { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 197 | registerToolchainFactory(android.Android, android.X86_64, x86_64ToolchainFactory) |
Colin Cross | 6371b38 | 2015-11-23 14:53:57 -0800 | [diff] [blame] | 198 | } |