blob: 1eab9dd650d6fa664a70269230815bd9235dc44d [file] [log] [blame]
Colin Cross6371b382015-11-23 14:53:57 -08001// 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 Crossb98c8b02016-07-29 13:44:28 -070015package config
Colin Cross6371b382015-11-23 14:53:57 -080016
17import (
18 "strings"
19
Colin Cross635c3b02016-05-18 15:37:25 -070020 "android/soong/android"
Colin Cross6371b382015-11-23 14:53:57 -080021)
22
23var (
24 x86_64Cflags = []string{
Colin Cross6371b382015-11-23 14:53:57 -080025 "-finline-functions",
26 "-finline-limit=300",
27 "-fno-short-enums",
Colin Cross6371b382015-11-23 14:53:57 -080028 "-funswitch-loops",
Colin Cross6371b382015-11-23 14:53:57 -080029
30 // Help catch common 32/64-bit errors.
Colin Cross6371b382015-11-23 14:53:57 -080031 "-Werror=implicit-function-declaration",
Colin Cross6371b382015-11-23 14:53:57 -080032 }
33
34 x86_64Cppflags = []string{}
35
36 x86_64Ldflags = []string{
Colin Cross6371b382015-11-23 14:53:57 -080037 "-Wl,--hash-style=gnu",
38 }
39
40 x86_64ArchVariantCflags = map[string][]string{
41 "": []string{
42 "-march=x86-64",
43 },
44 "haswell": []string{
45 "-march=core-avx2",
46 },
47 "ivybridge": []string{
48 "-march=core-avx-i",
49 },
50 "sandybridge": []string{
Dan Willemsenb77bd792016-02-29 15:26:26 -080051 "-march=corei7",
Colin Cross6371b382015-11-23 14:53:57 -080052 },
53 "silvermont": []string{
54 "-march=slm",
55 },
56 }
57
58 x86_64ArchFeatureCflags = map[string][]string{
59 "ssse3": []string{"-DUSE_SSSE3", "-mssse3"},
60 "sse4": []string{"-msse4"},
61 "sse4_1": []string{"-msse4.1"},
62 "sse4_2": []string{"-msse4.2"},
Dan Willemsen4ce47032016-05-06 17:20:53 -070063 "popcnt": []string{"-mpopcnt"},
Colin Cross6371b382015-11-23 14:53:57 -080064 "avx": []string{"-mavx"},
65 "aes_ni": []string{"-maes"},
66 }
67)
68
Dan Willemsen34fc3b12015-12-07 12:30:44 -080069const (
70 x86_64GccVersion = "4.9"
71)
72
Colin Cross6371b382015-11-23 14:53:57 -080073func init() {
Dan Willemsenb1957a52016-06-23 23:44:54 -070074 android.RegisterArchVariants(android.X86_64,
75 "haswell",
76 "ivybridge",
77 "sandybridge",
78 "silvermont")
79 android.RegisterArchFeatures(android.X86_64,
Colin Cross6371b382015-11-23 14:53:57 -080080 "ssse3",
81 "sse4",
82 "sse4_1",
83 "sse4_2",
84 "aes_ni",
85 "avx",
86 "popcnt")
Dan Willemsenb1957a52016-06-23 23:44:54 -070087 android.RegisterArchVariantFeatures(android.X86_64, "",
88 "ssse3",
89 "sse4",
90 "sse4_1",
91 "sse4_2",
92 "popcnt")
93 android.RegisterArchVariantFeatures(android.X86_64, "haswell",
Colin Cross6371b382015-11-23 14:53:57 -080094 "ssse3",
95 "sse4",
96 "sse4_1",
97 "sse4_2",
98 "aes_ni",
99 "avx",
100 "popcnt")
Dan Willemsenb1957a52016-06-23 23:44:54 -0700101 android.RegisterArchVariantFeatures(android.X86_64, "ivybridge",
102 "ssse3",
103 "sse4",
104 "sse4_1",
105 "sse4_2",
106 "aes_ni",
107 "avx",
108 "popcnt")
109 android.RegisterArchVariantFeatures(android.X86_64, "sandybridge",
Colin Cross6371b382015-11-23 14:53:57 -0800110 "ssse3",
111 "sse4",
112 "sse4_1",
113 "sse4_2",
Colin Cross6371b382015-11-23 14:53:57 -0800114 "popcnt")
Dan Willemsenb1957a52016-06-23 23:44:54 -0700115 android.RegisterArchVariantFeatures(android.X86_64, "silvermont",
Colin Cross6371b382015-11-23 14:53:57 -0800116 "ssse3",
117 "sse4",
118 "sse4_1",
119 "sse4_2",
120 "aes_ni",
121 "popcnt")
122
Dan Willemsen34fc3b12015-12-07 12:30:44 -0800123 pctx.StaticVariable("x86_64GccVersion", x86_64GccVersion)
Colin Cross6371b382015-11-23 14:53:57 -0800124
Colin Crossb98c8b02016-07-29 13:44:28 -0700125 pctx.SourcePathVariable("X86_64GccRoot",
Dan Willemsen34fc3b12015-12-07 12:30:44 -0800126 "prebuilts/gcc/${HostPrebuiltTag}/x86/x86_64-linux-android-${x86_64GccVersion}")
Colin Cross6371b382015-11-23 14:53:57 -0800127
Colin Crossb98c8b02016-07-29 13:44:28 -0700128 pctx.StaticVariable("X86_64ToolchainCflags", "-m64")
129 pctx.StaticVariable("X86_64ToolchainLdflags", "-m64")
Colin Cross6371b382015-11-23 14:53:57 -0800130
Colin Crossb98c8b02016-07-29 13:44:28 -0700131 pctx.StaticVariable("X86_64Cflags", strings.Join(x86_64Cflags, " "))
132 pctx.StaticVariable("X86_64Ldflags", strings.Join(x86_64Ldflags, " "))
133 pctx.StaticVariable("X86_64Cppflags", strings.Join(x86_64Cppflags, " "))
Elliott Hughesde28deb2017-10-12 09:07:53 -0700134 pctx.StaticVariable("X86_64IncludeFlags", bionicHeaders("x86"))
Colin Cross6371b382015-11-23 14:53:57 -0800135
136 // Clang cflags
Colin Crossb98c8b02016-07-29 13:44:28 -0700137 pctx.StaticVariable("X86_64ClangCflags", strings.Join(ClangFilterUnknownCflags(x86_64Cflags), " "))
138 pctx.StaticVariable("X86_64ClangLdflags", strings.Join(ClangFilterUnknownCflags(x86_64Ldflags), " "))
139 pctx.StaticVariable("X86_64ClangCppflags", strings.Join(ClangFilterUnknownCflags(x86_64Cppflags), " "))
Colin Cross6371b382015-11-23 14:53:57 -0800140
Colin Cross91e90042016-12-02 17:13:24 -0800141 // Yasm flags
142 pctx.StaticVariable("X86_64YasmFlags", "-f elf64 -m amd64")
143
Colin Cross6371b382015-11-23 14:53:57 -0800144 // Extended cflags
145
146 // Architecture variant cflags
147 for variant, cflags := range x86_64ArchVariantCflags {
Colin Crossb98c8b02016-07-29 13:44:28 -0700148 pctx.StaticVariable("X86_64"+variant+"VariantCflags", strings.Join(cflags, " "))
149 pctx.StaticVariable("X86_64"+variant+"VariantClangCflags",
150 strings.Join(ClangFilterUnknownCflags(cflags), " "))
Colin Cross6371b382015-11-23 14:53:57 -0800151 }
152}
153
154type toolchainX86_64 struct {
155 toolchain64Bit
156 toolchainCflags, toolchainClangCflags string
157}
158
159func (t *toolchainX86_64) Name() string {
160 return "x86_64"
161}
162
163func (t *toolchainX86_64) GccRoot() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700164 return "${config.X86_64GccRoot}"
Colin Cross6371b382015-11-23 14:53:57 -0800165}
166
167func (t *toolchainX86_64) GccTriple() string {
Dan Albert84f431f2016-07-20 14:44:26 -0700168 return "x86_64-linux-android"
Colin Cross6371b382015-11-23 14:53:57 -0800169}
170
171func (t *toolchainX86_64) GccVersion() string {
Dan Willemsen34fc3b12015-12-07 12:30:44 -0800172 return x86_64GccVersion
Colin Cross6371b382015-11-23 14:53:57 -0800173}
174
175func (t *toolchainX86_64) ToolchainLdflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700176 return "${config.X86_64ToolchainLdflags}"
Colin Cross6371b382015-11-23 14:53:57 -0800177}
178
179func (t *toolchainX86_64) ToolchainCflags() string {
180 return t.toolchainCflags
181}
182
183func (t *toolchainX86_64) Cflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700184 return "${config.X86_64Cflags}"
Colin Cross6371b382015-11-23 14:53:57 -0800185}
186
187func (t *toolchainX86_64) Cppflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700188 return "${config.X86_64Cppflags}"
Colin Cross6371b382015-11-23 14:53:57 -0800189}
190
191func (t *toolchainX86_64) Ldflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700192 return "${config.X86_64Ldflags}"
Colin Cross6371b382015-11-23 14:53:57 -0800193}
194
195func (t *toolchainX86_64) IncludeFlags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700196 return "${config.X86_64IncludeFlags}"
Colin Cross6371b382015-11-23 14:53:57 -0800197}
198
199func (t *toolchainX86_64) ClangTriple() string {
Dan Albert84f431f2016-07-20 14:44:26 -0700200 return t.GccTriple()
Colin Cross6371b382015-11-23 14:53:57 -0800201}
202
Dan Willemsen569b0fa2016-05-08 20:04:20 -0700203func (t *toolchainX86_64) ToolchainClangLdflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700204 return "${config.X86_64ToolchainLdflags}"
Dan Willemsen569b0fa2016-05-08 20:04:20 -0700205}
206
Colin Cross6371b382015-11-23 14:53:57 -0800207func (t *toolchainX86_64) ToolchainClangCflags() string {
208 return t.toolchainClangCflags
209}
210
211func (t *toolchainX86_64) ClangCflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700212 return "${config.X86_64ClangCflags}"
Colin Cross6371b382015-11-23 14:53:57 -0800213}
214
215func (t *toolchainX86_64) ClangCppflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700216 return "${config.X86_64ClangCppflags}"
Colin Cross6371b382015-11-23 14:53:57 -0800217}
218
219func (t *toolchainX86_64) ClangLdflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700220 return "${config.X86_64Ldflags}"
Colin Cross6371b382015-11-23 14:53:57 -0800221}
222
Colin Cross91e90042016-12-02 17:13:24 -0800223func (t *toolchainX86_64) YasmFlags() string {
224 return "${config.X86_64YasmFlags}"
225}
226
Evgenii Stepanovaf36db12016-08-15 14:18:24 -0700227func (toolchainX86_64) SanitizerRuntimeLibraryArch() string {
228 return "x86_64"
229}
230
Colin Cross635c3b02016-05-18 15:37:25 -0700231func x86_64ToolchainFactory(arch android.Arch) Toolchain {
Colin Cross6371b382015-11-23 14:53:57 -0800232 toolchainCflags := []string{
Colin Crossb98c8b02016-07-29 13:44:28 -0700233 "${config.X86_64ToolchainCflags}",
234 "${config.X86_64" + arch.ArchVariant + "VariantCflags}",
Colin Cross6371b382015-11-23 14:53:57 -0800235 }
236
237 toolchainClangCflags := []string{
Colin Crossb98c8b02016-07-29 13:44:28 -0700238 "${config.X86_64ToolchainCflags}",
239 "${config.X86_64" + arch.ArchVariant + "VariantClangCflags}",
Colin Cross6371b382015-11-23 14:53:57 -0800240 }
241
242 for _, feature := range arch.ArchFeatures {
243 toolchainCflags = append(toolchainCflags, x86_64ArchFeatureCflags[feature]...)
244 toolchainClangCflags = append(toolchainClangCflags, x86_64ArchFeatureCflags[feature]...)
245 }
246
247 return &toolchainX86_64{
248 toolchainCflags: strings.Join(toolchainCflags, " "),
249 toolchainClangCflags: strings.Join(toolchainClangCflags, " "),
250 }
251}
252
253func init() {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700254 registerToolchainFactory(android.Android, android.X86_64, x86_64ToolchainFactory)
Colin Cross6371b382015-11-23 14:53:57 -0800255}