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{"-DUSE_SSSE3", "-mssse3"}, 67 "sse4": []string{"-msse4"}, 68 "sse4_1": []string{"-msse4.1"}, 69 "sse4_2": []string{"-msse4.2"}, 70 "popcnt": []string{"-mpopcnt"}, 71 "avx": []string{"-mavx"}, 72 "avx2": []string{"-mavx2"}, 73 "avx512": []string{"-mavx512"}, 74 "aes_ni": []string{"-maes"}, 75 } 76) 77 78const ( 79 x86_64GccVersion = "4.9" 80) 81 82func init() { 83 android.RegisterDefaultArchVariantFeatures(android.Android, android.X86_64, 84 "ssse3", 85 "sse4", 86 "sse4_1", 87 "sse4_2", 88 "popcnt") 89 90 pctx.StaticVariable("x86_64GccVersion", x86_64GccVersion) 91 92 pctx.SourcePathVariable("X86_64GccRoot", 93 "prebuilts/gcc/${HostPrebuiltTag}/x86/x86_64-linux-android-${x86_64GccVersion}") 94 95 pctx.StaticVariable("X86_64ToolchainCflags", "-m64") 96 pctx.StaticVariable("X86_64ToolchainLdflags", "-m64") 97 98 pctx.StaticVariable("X86_64Ldflags", strings.Join(x86_64Ldflags, " ")) 99 pctx.StaticVariable("X86_64Lldflags", strings.Join(x86_64Lldflags, " ")) 100 pctx.StaticVariable("X86_64IncludeFlags", bionicHeaders("x86")) 101 102 // Clang cflags 103 pctx.StaticVariable("X86_64ClangCflags", strings.Join(ClangFilterUnknownCflags(x86_64Cflags), " ")) 104 pctx.StaticVariable("X86_64ClangLdflags", strings.Join(ClangFilterUnknownCflags(x86_64Ldflags), " ")) 105 pctx.StaticVariable("X86_64ClangLldflags", strings.Join(ClangFilterUnknownCflags(x86_64Lldflags), " ")) 106 pctx.StaticVariable("X86_64ClangCppflags", strings.Join(ClangFilterUnknownCflags(x86_64Cppflags), " ")) 107 108 // Yasm flags 109 pctx.StaticVariable("X86_64YasmFlags", "-f elf64 -m amd64") 110 111 // Extended cflags 112 113 // Architecture variant cflags 114 for variant, cflags := range x86_64ArchVariantCflags { 115 pctx.StaticVariable("X86_64"+variant+"VariantClangCflags", 116 strings.Join(ClangFilterUnknownCflags(cflags), " ")) 117 } 118} 119 120type toolchainX86_64 struct { 121 toolchain64Bit 122 toolchainClangCflags string 123} 124 125func (t *toolchainX86_64) Name() string { 126 return "x86_64" 127} 128 129func (t *toolchainX86_64) GccRoot() string { 130 return "${config.X86_64GccRoot}" 131} 132 133func (t *toolchainX86_64) GccTriple() string { 134 return "x86_64-linux-android" 135} 136 137func (t *toolchainX86_64) GccVersion() string { 138 return x86_64GccVersion 139} 140 141func (t *toolchainX86_64) IncludeFlags() string { 142 return "${config.X86_64IncludeFlags}" 143} 144 145func (t *toolchainX86_64) ClangTriple() string { 146 return t.GccTriple() 147} 148 149func (t *toolchainX86_64) ToolchainClangLdflags() string { 150 return "${config.X86_64ToolchainLdflags}" 151} 152 153func (t *toolchainX86_64) ToolchainClangCflags() string { 154 return t.toolchainClangCflags 155} 156 157func (t *toolchainX86_64) ClangCflags() string { 158 return "${config.X86_64ClangCflags}" 159} 160 161func (t *toolchainX86_64) ClangCppflags() string { 162 return "${config.X86_64ClangCppflags}" 163} 164 165func (t *toolchainX86_64) ClangLdflags() string { 166 return "${config.X86_64Ldflags}" 167} 168 169func (t *toolchainX86_64) ClangLldflags() string { 170 return "${config.X86_64Lldflags}" 171} 172 173func (t *toolchainX86_64) YasmFlags() string { 174 return "${config.X86_64YasmFlags}" 175} 176 177func (toolchainX86_64) LibclangRuntimeLibraryArch() string { 178 return "x86_64" 179} 180 181func x86_64ToolchainFactory(arch android.Arch) Toolchain { 182 toolchainClangCflags := []string{ 183 "${config.X86_64ToolchainCflags}", 184 "${config.X86_64" + arch.ArchVariant + "VariantClangCflags}", 185 } 186 187 for _, feature := range arch.ArchFeatures { 188 toolchainClangCflags = append(toolchainClangCflags, x86_64ArchFeatureCflags[feature]...) 189 } 190 191 return &toolchainX86_64{ 192 toolchainClangCflags: strings.Join(toolchainClangCflags, " "), 193 } 194} 195 196func init() { 197 registerToolchainFactory(android.Android, android.X86_64, x86_64ToolchainFactory) 198} 199