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 15package config 16 17import ( 18 "strings" 19 20 "android/soong/android" 21) 22 23var ( 24 x86_64Cflags = []string{ 25 // Help catch common 32/64-bit errors. 26 "-Werror=implicit-function-declaration", 27 } 28 29 x86_64Cppflags = []string{} 30 31 x86_64Ldflags = []string{ 32 "-Wl,--hash-style=gnu", 33 } 34 35 x86_64Lldflags = ClangFilterUnknownLldflags(x86_64Ldflags) 36 37 x86_64ArchVariantCflags = map[string][]string{ 38 "": []string{ 39 "-march=x86-64", 40 }, 41 "broadwell": []string{ 42 "-march=broadwell", 43 }, 44 45 "haswell": []string{ 46 "-march=core-avx2", 47 }, 48 "ivybridge": []string{ 49 "-march=core-avx-i", 50 }, 51 "sandybridge": []string{ 52 "-march=corei7", 53 }, 54 "silvermont": []string{ 55 "-march=slm", 56 }, 57 "skylake": []string{ 58 "-march=skylake", 59 }, 60 "stoneyridge": []string{ 61 "-march=bdver4", 62 }, 63 } 64 65 x86_64ArchFeatureCflags = map[string][]string{ 66 "ssse3": []string{"-mssse3"}, 67 "sse4": []string{"-msse4"}, 68 "sse4_1": []string{"-msse4.1"}, 69 "sse4_2": []string{"-msse4.2"}, 70 71 // Not all cases there is performance gain by enabling -mavx -mavx2 72 // flags so these flags are not enabled by default. 73 // if there is performance gain in individual library components, 74 // the compiler flags can be set in corresponding bp files. 75 // "avx": []string{"-mavx"}, 76 // "avx2": []string{"-mavx2"}, 77 // "avx512": []string{"-mavx512"} 78 79 "popcnt": []string{"-mpopcnt"}, 80 "aes_ni": []string{"-maes"}, 81 } 82) 83 84const ( 85 x86_64GccVersion = "4.9" 86) 87 88func init() { 89 android.RegisterDefaultArchVariantFeatures(android.Android, android.X86_64, 90 "ssse3", 91 "sse4", 92 "sse4_1", 93 "sse4_2", 94 "popcnt") 95 96 pctx.StaticVariable("x86_64GccVersion", x86_64GccVersion) 97 98 pctx.SourcePathVariable("X86_64GccRoot", 99 "prebuilts/gcc/${HostPrebuiltTag}/x86/x86_64-linux-android-${x86_64GccVersion}") 100 101 pctx.StaticVariable("X86_64ToolchainCflags", "-m64") 102 pctx.StaticVariable("X86_64ToolchainLdflags", "-m64") 103 104 pctx.StaticVariable("X86_64Ldflags", strings.Join(x86_64Ldflags, " ")) 105 pctx.StaticVariable("X86_64Lldflags", strings.Join(x86_64Lldflags, " ")) 106 107 // Clang cflags 108 pctx.StaticVariable("X86_64ClangCflags", strings.Join(ClangFilterUnknownCflags(x86_64Cflags), " ")) 109 pctx.StaticVariable("X86_64ClangLdflags", strings.Join(ClangFilterUnknownCflags(x86_64Ldflags), " ")) 110 pctx.StaticVariable("X86_64ClangLldflags", strings.Join(ClangFilterUnknownCflags(x86_64Lldflags), " ")) 111 pctx.StaticVariable("X86_64ClangCppflags", strings.Join(ClangFilterUnknownCflags(x86_64Cppflags), " ")) 112 113 // Yasm flags 114 pctx.StaticVariable("X86_64YasmFlags", "-f elf64 -m amd64") 115 116 // Extended cflags 117 118 // Architecture variant cflags 119 for variant, cflags := range x86_64ArchVariantCflags { 120 pctx.StaticVariable("X86_64"+variant+"VariantClangCflags", 121 strings.Join(ClangFilterUnknownCflags(cflags), " ")) 122 } 123} 124 125type toolchainX86_64 struct { 126 toolchain64Bit 127 toolchainClangCflags string 128} 129 130func (t *toolchainX86_64) Name() string { 131 return "x86_64" 132} 133 134func (t *toolchainX86_64) GccRoot() string { 135 return "${config.X86_64GccRoot}" 136} 137 138func (t *toolchainX86_64) GccTriple() string { 139 return "x86_64-linux-android" 140} 141 142func (t *toolchainX86_64) GccVersion() string { 143 return x86_64GccVersion 144} 145 146func (t *toolchainX86_64) IncludeFlags() string { 147 return "" 148} 149 150func (t *toolchainX86_64) ClangTriple() string { 151 return t.GccTriple() 152} 153 154func (t *toolchainX86_64) ToolchainClangLdflags() string { 155 return "${config.X86_64ToolchainLdflags}" 156} 157 158func (t *toolchainX86_64) ToolchainClangCflags() string { 159 return t.toolchainClangCflags 160} 161 162func (t *toolchainX86_64) ClangCflags() string { 163 return "${config.X86_64ClangCflags}" 164} 165 166func (t *toolchainX86_64) ClangCppflags() string { 167 return "${config.X86_64ClangCppflags}" 168} 169 170func (t *toolchainX86_64) ClangLdflags() string { 171 return "${config.X86_64Ldflags}" 172} 173 174func (t *toolchainX86_64) ClangLldflags() string { 175 return "${config.X86_64Lldflags}" 176} 177 178func (t *toolchainX86_64) YasmFlags() string { 179 return "${config.X86_64YasmFlags}" 180} 181 182func (toolchainX86_64) LibclangRuntimeLibraryArch() string { 183 return "x86_64" 184} 185 186func x86_64ToolchainFactory(arch android.Arch) Toolchain { 187 toolchainClangCflags := []string{ 188 "${config.X86_64ToolchainCflags}", 189 "${config.X86_64" + arch.ArchVariant + "VariantClangCflags}", 190 } 191 192 for _, feature := range arch.ArchFeatures { 193 toolchainClangCflags = append(toolchainClangCflags, x86_64ArchFeatureCflags[feature]...) 194 } 195 196 return &toolchainX86_64{ 197 toolchainClangCflags: strings.Join(toolchainClangCflags, " "), 198 } 199} 200 201func init() { 202 registerToolchainFactory(android.Android, android.X86_64, x86_64ToolchainFactory) 203} 204