blob: 23c976ac05c1d9d40e8f10d2bffff1bb59934309 [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{
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 Willemsen7a0f8482016-01-12 16:22:40 -080039 "-fstack-protector-strong",
Colin Cross6371b382015-11-23 14:53:57 -080040 "-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 Willemsenc7e45972015-12-09 13:05:28 -080065 "-Wl,--no-undefined-version",
Colin Cross6371b382015-11-23 14:53:57 -080066 }
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 Willemsenb77bd792016-02-29 15:26:26 -080079 "-march=corei7",
Colin Cross6371b382015-11-23 14:53:57 -080080 },
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 Willemsen4ce47032016-05-06 17:20:53 -070091 "popcnt": []string{"-mpopcnt"},
Colin Cross6371b382015-11-23 14:53:57 -080092 "avx": []string{"-mavx"},
93 "aes_ni": []string{"-maes"},
94 }
95)
96
Dan Willemsen34fc3b12015-12-07 12:30:44 -080097const (
98 x86_64GccVersion = "4.9"
99)
100
Colin Cross6371b382015-11-23 14:53:57 -0800101func init() {
Colin Cross635c3b02016-05-18 15:37:25 -0700102 android.RegisterArchFeatures(android.X86_64, "",
Colin Cross6371b382015-11-23 14:53:57 -0800103 "ssse3",
104 "sse4",
105 "sse4_1",
106 "sse4_2",
107 "popcnt")
Colin Cross635c3b02016-05-18 15:37:25 -0700108 android.RegisterArchFeatures(android.X86_64, "haswell",
Colin Cross6371b382015-11-23 14:53:57 -0800109 "ssse3",
110 "sse4",
111 "sse4_1",
112 "sse4_2",
113 "aes_ni",
114 "avx",
115 "popcnt")
Colin Cross635c3b02016-05-18 15:37:25 -0700116 android.RegisterArchFeatures(android.X86_64, "ivybridge",
Colin Cross6371b382015-11-23 14:53:57 -0800117 "ssse3",
118 "sse4",
119 "sse4_1",
120 "sse4_2",
121 "aes_ni",
122 "avx",
123 "popcnt")
Colin Cross635c3b02016-05-18 15:37:25 -0700124 android.RegisterArchFeatures(android.X86_64, "sandybridge",
Colin Cross6371b382015-11-23 14:53:57 -0800125 "ssse3",
126 "sse4",
127 "sse4_1",
128 "sse4_2",
Colin Cross6371b382015-11-23 14:53:57 -0800129 "popcnt")
Colin Cross635c3b02016-05-18 15:37:25 -0700130 android.RegisterArchFeatures(android.X86_64, "silvermont",
Colin Cross6371b382015-11-23 14:53:57 -0800131 "ssse3",
132 "sse4",
133 "sse4_1",
134 "sse4_2",
135 "aes_ni",
136 "popcnt")
137
Dan Willemsen34fc3b12015-12-07 12:30:44 -0800138 pctx.StaticVariable("x86_64GccVersion", x86_64GccVersion)
Colin Cross6371b382015-11-23 14:53:57 -0800139
Colin Crossb98c8b02016-07-29 13:44:28 -0700140 pctx.SourcePathVariable("X86_64GccRoot",
Dan Willemsen34fc3b12015-12-07 12:30:44 -0800141 "prebuilts/gcc/${HostPrebuiltTag}/x86/x86_64-linux-android-${x86_64GccVersion}")
Colin Cross6371b382015-11-23 14:53:57 -0800142
Colin Crossb98c8b02016-07-29 13:44:28 -0700143 pctx.StaticVariable("X86_64ToolchainCflags", "-m64")
144 pctx.StaticVariable("X86_64ToolchainLdflags", "-m64")
Colin Cross6371b382015-11-23 14:53:57 -0800145
Colin Crossb98c8b02016-07-29 13:44:28 -0700146 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 Cross6371b382015-11-23 14:53:57 -0800150
151 // Clang cflags
Colin Crossb98c8b02016-07-29 13:44:28 -0700152 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 Cross6371b382015-11-23 14:53:57 -0800155
156 // Extended cflags
157
158 // Architecture variant cflags
159 for variant, cflags := range x86_64ArchVariantCflags {
Colin Crossb98c8b02016-07-29 13:44:28 -0700160 pctx.StaticVariable("X86_64"+variant+"VariantCflags", strings.Join(cflags, " "))
161 pctx.StaticVariable("X86_64"+variant+"VariantClangCflags",
162 strings.Join(ClangFilterUnknownCflags(cflags), " "))
Colin Cross6371b382015-11-23 14:53:57 -0800163 }
164}
165
166type toolchainX86_64 struct {
167 toolchain64Bit
168 toolchainCflags, toolchainClangCflags string
169}
170
171func (t *toolchainX86_64) Name() string {
172 return "x86_64"
173}
174
175func (t *toolchainX86_64) GccRoot() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700176 return "${config.X86_64GccRoot}"
Colin Cross6371b382015-11-23 14:53:57 -0800177}
178
179func (t *toolchainX86_64) GccTriple() string {
Dan Albert84f431f2016-07-20 14:44:26 -0700180 return "x86_64-linux-android"
Colin Cross6371b382015-11-23 14:53:57 -0800181}
182
183func (t *toolchainX86_64) GccVersion() string {
Dan Willemsen34fc3b12015-12-07 12:30:44 -0800184 return x86_64GccVersion
Colin Cross6371b382015-11-23 14:53:57 -0800185}
186
187func (t *toolchainX86_64) ToolchainLdflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700188 return "${config.X86_64ToolchainLdflags}"
Colin Cross6371b382015-11-23 14:53:57 -0800189}
190
191func (t *toolchainX86_64) ToolchainCflags() string {
192 return t.toolchainCflags
193}
194
195func (t *toolchainX86_64) Cflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700196 return "${config.X86_64Cflags}"
Colin Cross6371b382015-11-23 14:53:57 -0800197}
198
199func (t *toolchainX86_64) Cppflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700200 return "${config.X86_64Cppflags}"
Colin Cross6371b382015-11-23 14:53:57 -0800201}
202
203func (t *toolchainX86_64) Ldflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700204 return "${config.X86_64Ldflags}"
Colin Cross6371b382015-11-23 14:53:57 -0800205}
206
207func (t *toolchainX86_64) IncludeFlags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700208 return "${config.X86_64IncludeFlags}"
Colin Cross6371b382015-11-23 14:53:57 -0800209}
210
211func (t *toolchainX86_64) ClangTriple() string {
Dan Albert84f431f2016-07-20 14:44:26 -0700212 return t.GccTriple()
Colin Cross6371b382015-11-23 14:53:57 -0800213}
214
Dan Willemsen569b0fa2016-05-08 20:04:20 -0700215func (t *toolchainX86_64) ToolchainClangLdflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700216 return "${config.X86_64ToolchainLdflags}"
Dan Willemsen569b0fa2016-05-08 20:04:20 -0700217}
218
Colin Cross6371b382015-11-23 14:53:57 -0800219func (t *toolchainX86_64) ToolchainClangCflags() string {
220 return t.toolchainClangCflags
221}
222
223func (t *toolchainX86_64) ClangCflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700224 return "${config.X86_64ClangCflags}"
Colin Cross6371b382015-11-23 14:53:57 -0800225}
226
227func (t *toolchainX86_64) ClangCppflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700228 return "${config.X86_64ClangCppflags}"
Colin Cross6371b382015-11-23 14:53:57 -0800229}
230
231func (t *toolchainX86_64) ClangLdflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700232 return "${config.X86_64Ldflags}"
Colin Cross6371b382015-11-23 14:53:57 -0800233}
234
Evgenii Stepanovaf36db12016-08-15 14:18:24 -0700235func (toolchainX86_64) SanitizerRuntimeLibraryArch() string {
236 return "x86_64"
237}
238
Colin Cross635c3b02016-05-18 15:37:25 -0700239func x86_64ToolchainFactory(arch android.Arch) Toolchain {
Colin Cross6371b382015-11-23 14:53:57 -0800240 toolchainCflags := []string{
Colin Crossb98c8b02016-07-29 13:44:28 -0700241 "${config.X86_64ToolchainCflags}",
242 "${config.X86_64" + arch.ArchVariant + "VariantCflags}",
Colin Cross6371b382015-11-23 14:53:57 -0800243 }
244
245 toolchainClangCflags := []string{
Colin Crossb98c8b02016-07-29 13:44:28 -0700246 "${config.X86_64ToolchainCflags}",
247 "${config.X86_64" + arch.ArchVariant + "VariantClangCflags}",
Colin Cross6371b382015-11-23 14:53:57 -0800248 }
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
261func init() {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700262 registerToolchainFactory(android.Android, android.X86_64, x86_64ToolchainFactory)
Colin Cross6371b382015-11-23 14:53:57 -0800263}