blob: 23518b6ee21fc18d9a4f98827743a760d629f900 [file] [log] [blame]
Colin Crossb0cba6a2015-11-20 15:35:26 -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 Crossb0cba6a2015-11-20 15:35:26 -080016
17import (
18 "strings"
19
Colin Cross635c3b02016-05-18 15:37:25 -070020 "android/soong/android"
Colin Crossb0cba6a2015-11-20 15:35:26 -080021)
22
23var (
24 x86Cflags = []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 Crossb0cba6a2015-11-20 15:35:26 -080040 "-no-canonical-prefixes",
41 "-fno-canonical-system-headers",
42
43 // TARGET_RELEASE_CFLAGS from build/core/combo/select.mk
44 "-O2",
45 "-g",
46 "-fno-strict-aliasing",
47 }
48
Dan Willemsen569b0fa2016-05-08 20:04:20 -070049 x86ClangCflags = append(x86Cflags, []string{
50 "-msse3",
51
52 // -mstackrealign is needed to realign stack in native code
53 // that could be called from JNI, so that movaps instruction
54 // will work on assumed stack aligned local variables.
55 "-mstackrealign",
56 }...)
57
Colin Crossb0cba6a2015-11-20 15:35:26 -080058 x86Cppflags = []string{}
59
60 x86Ldflags = []string{
61 "-Wl,-z,noexecstack",
62 "-Wl,-z,relro",
63 "-Wl,-z,now",
64 "-Wl,--build-id=md5",
65 "-Wl,--warn-shared-textrel",
66 "-Wl,--fatal-warnings",
67 "-Wl,--gc-sections",
68 "-Wl,--hash-style=gnu",
Dan Willemsenc7e45972015-12-09 13:05:28 -080069 "-Wl,--no-undefined-version",
Colin Crossb0cba6a2015-11-20 15:35:26 -080070 }
71
72 x86ArchVariantCflags = map[string][]string{
73 "": []string{
74 "-march=prescott",
75 },
Dan Willemsen8a354052016-05-10 14:30:51 -070076 "x86_64": []string{
77 "-march=prescott",
78 },
Colin Crossb0cba6a2015-11-20 15:35:26 -080079 "atom": []string{
80 "-march=atom",
81 "-mfpmath=sse",
82 },
83 "haswell": []string{
84 "-march=core-avx2",
85 "-mfpmath=sse",
86 },
87 "ivybridge": []string{
88 "-march=core-avx-i",
89 "-mfpmath=sse",
90 },
91 "sandybridge": []string{
Dan Willemsenb77bd792016-02-29 15:26:26 -080092 "-march=corei7",
Colin Crossb0cba6a2015-11-20 15:35:26 -080093 "-mfpmath=sse",
94 },
95 "silvermont": []string{
96 "-march=slm",
97 "-mfpmath=sse",
98 },
99 }
100
101 x86ArchFeatureCflags = map[string][]string{
102 "ssse3": []string{"-DUSE_SSSE3", "-mssse3"},
103 "sse4": []string{"-msse4"},
104 "sse4_1": []string{"-msse4.1"},
105 "sse4_2": []string{"-msse4.2"},
106 "avx": []string{"-mavx"},
107 "aes_ni": []string{"-maes"},
108 }
109)
110
Dan Willemsen34fc3b12015-12-07 12:30:44 -0800111const (
112 x86GccVersion = "4.9"
113)
114
Colin Crossb0cba6a2015-11-20 15:35:26 -0800115func init() {
Dan Willemsenb1957a52016-06-23 23:44:54 -0700116 android.RegisterArchVariants(android.X86,
117 "atom",
118 "haswell",
119 "ivybridge",
120 "sandybridge",
121 "silvermont",
122 "x86_64")
123 android.RegisterArchFeatures(android.X86,
Colin Crossb0cba6a2015-11-20 15:35:26 -0800124 "ssse3",
125 "sse4",
126 "sse4_1",
127 "sse4_2",
128 "aes_ni",
129 "avx",
130 "popcnt",
131 "movbe")
Dan Willemsenb1957a52016-06-23 23:44:54 -0700132 android.RegisterArchVariantFeatures(android.X86, "x86_64",
133 "ssse3",
134 "sse4",
135 "sse4_1",
136 "sse4_2",
137 "popcnt")
138 android.RegisterArchVariantFeatures(android.X86, "atom",
139 "ssse3",
140 "movbe")
141 android.RegisterArchVariantFeatures(android.X86, "haswell",
142 "ssse3",
143 "sse4",
144 "sse4_1",
145 "sse4_2",
146 "aes_ni",
147 "avx",
148 "popcnt",
149 "movbe")
150 android.RegisterArchVariantFeatures(android.X86, "ivybridge",
Colin Crossb0cba6a2015-11-20 15:35:26 -0800151 "ssse3",
152 "sse4",
153 "sse4_1",
154 "sse4_2",
155 "aes_ni",
156 "avx",
157 "popcnt")
Dan Willemsenb1957a52016-06-23 23:44:54 -0700158 android.RegisterArchVariantFeatures(android.X86, "sandybridge",
Colin Crossb0cba6a2015-11-20 15:35:26 -0800159 "ssse3",
160 "sse4",
161 "sse4_1",
162 "sse4_2",
Colin Crossb0cba6a2015-11-20 15:35:26 -0800163 "popcnt")
Dan Willemsenb1957a52016-06-23 23:44:54 -0700164 android.RegisterArchVariantFeatures(android.X86, "silvermont",
Colin Crossb0cba6a2015-11-20 15:35:26 -0800165 "ssse3",
166 "sse4",
167 "sse4_1",
168 "sse4_2",
169 "aes_ni",
170 "popcnt",
171 "movbe")
172
Dan Willemsen34fc3b12015-12-07 12:30:44 -0800173 pctx.StaticVariable("x86GccVersion", x86GccVersion)
Colin Crossb0cba6a2015-11-20 15:35:26 -0800174
Colin Crossb98c8b02016-07-29 13:44:28 -0700175 pctx.SourcePathVariable("X86GccRoot",
Dan Willemsen34fc3b12015-12-07 12:30:44 -0800176 "prebuilts/gcc/${HostPrebuiltTag}/x86/x86_64-linux-android-${x86GccVersion}")
Colin Crossb0cba6a2015-11-20 15:35:26 -0800177
Colin Crossb98c8b02016-07-29 13:44:28 -0700178 pctx.StaticVariable("X86ToolchainCflags", "-m32")
179 pctx.StaticVariable("X86ToolchainLdflags", "-m32")
Colin Crossb0cba6a2015-11-20 15:35:26 -0800180
Colin Crossb98c8b02016-07-29 13:44:28 -0700181 pctx.StaticVariable("X86Cflags", strings.Join(x86Cflags, " "))
182 pctx.StaticVariable("X86Ldflags", strings.Join(x86Ldflags, " "))
183 pctx.StaticVariable("X86Cppflags", strings.Join(x86Cppflags, " "))
184 pctx.StaticVariable("X86IncludeFlags", bionicHeaders("x86", "x86"))
Colin Crossb0cba6a2015-11-20 15:35:26 -0800185
186 // Clang cflags
Colin Crossb98c8b02016-07-29 13:44:28 -0700187 pctx.StaticVariable("X86ClangCflags", strings.Join(ClangFilterUnknownCflags(x86ClangCflags), " "))
188 pctx.StaticVariable("X86ClangLdflags", strings.Join(ClangFilterUnknownCflags(x86Ldflags), " "))
189 pctx.StaticVariable("X86ClangCppflags", strings.Join(ClangFilterUnknownCflags(x86Cppflags), " "))
Colin Crossb0cba6a2015-11-20 15:35:26 -0800190
Colin Cross91e90042016-12-02 17:13:24 -0800191 // Yasm flags
192 pctx.StaticVariable("X86YasmFlags", "-f elf32 -m x86")
193
Colin Crossb0cba6a2015-11-20 15:35:26 -0800194 // Extended cflags
195
196 // Architecture variant cflags
197 for variant, cflags := range x86ArchVariantCflags {
Colin Crossb98c8b02016-07-29 13:44:28 -0700198 pctx.StaticVariable("X86"+variant+"VariantCflags", strings.Join(cflags, " "))
199 pctx.StaticVariable("X86"+variant+"VariantClangCflags",
200 strings.Join(ClangFilterUnknownCflags(cflags), " "))
Colin Crossb0cba6a2015-11-20 15:35:26 -0800201 }
202}
203
204type toolchainX86 struct {
205 toolchain32Bit
206 toolchainCflags, toolchainClangCflags string
207}
208
209func (t *toolchainX86) Name() string {
210 return "x86"
211}
212
213func (t *toolchainX86) GccRoot() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700214 return "${config.X86GccRoot}"
Colin Crossb0cba6a2015-11-20 15:35:26 -0800215}
216
217func (t *toolchainX86) GccTriple() string {
Dan Albert84f431f2016-07-20 14:44:26 -0700218 return "x86_64-linux-android"
Colin Crossb0cba6a2015-11-20 15:35:26 -0800219}
220
221func (t *toolchainX86) GccVersion() string {
Dan Willemsen34fc3b12015-12-07 12:30:44 -0800222 return x86GccVersion
Colin Crossb0cba6a2015-11-20 15:35:26 -0800223}
224
225func (t *toolchainX86) ToolchainLdflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700226 return "${config.X86ToolchainLdflags}"
Colin Crossb0cba6a2015-11-20 15:35:26 -0800227}
228
229func (t *toolchainX86) ToolchainCflags() string {
230 return t.toolchainCflags
231}
232
233func (t *toolchainX86) Cflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700234 return "${config.X86Cflags}"
Colin Crossb0cba6a2015-11-20 15:35:26 -0800235}
236
237func (t *toolchainX86) Cppflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700238 return "${config.X86Cppflags}"
Colin Crossb0cba6a2015-11-20 15:35:26 -0800239}
240
241func (t *toolchainX86) Ldflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700242 return "${config.X86Ldflags}"
Colin Crossb0cba6a2015-11-20 15:35:26 -0800243}
244
245func (t *toolchainX86) IncludeFlags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700246 return "${config.X86IncludeFlags}"
Colin Crossb0cba6a2015-11-20 15:35:26 -0800247}
248
249func (t *toolchainX86) ClangTriple() string {
Dan Willemsen569b0fa2016-05-08 20:04:20 -0700250 return "i686-linux-android"
251}
252
253func (t *toolchainX86) ToolchainClangLdflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700254 return "${config.X86ToolchainLdflags}"
Colin Crossb0cba6a2015-11-20 15:35:26 -0800255}
256
257func (t *toolchainX86) ToolchainClangCflags() string {
258 return t.toolchainClangCflags
259}
260
261func (t *toolchainX86) ClangCflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700262 return "${config.X86ClangCflags}"
Colin Crossb0cba6a2015-11-20 15:35:26 -0800263}
264
265func (t *toolchainX86) ClangCppflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700266 return "${config.X86ClangCppflags}"
Colin Crossb0cba6a2015-11-20 15:35:26 -0800267}
268
269func (t *toolchainX86) ClangLdflags() string {
Colin Crossb98c8b02016-07-29 13:44:28 -0700270 return "${config.X86Ldflags}"
Colin Crossb0cba6a2015-11-20 15:35:26 -0800271}
272
Colin Cross91e90042016-12-02 17:13:24 -0800273func (t *toolchainX86) YasmFlags() string {
274 return "${config.X86YasmFlags}"
275}
276
Evgenii Stepanovaf36db12016-08-15 14:18:24 -0700277func (toolchainX86) SanitizerRuntimeLibraryArch() string {
278 return "i686"
Colin Cross16b23492016-01-06 14:41:07 -0800279}
280
Colin Cross635c3b02016-05-18 15:37:25 -0700281func x86ToolchainFactory(arch android.Arch) Toolchain {
Colin Crossb0cba6a2015-11-20 15:35:26 -0800282 toolchainCflags := []string{
Colin Crossb98c8b02016-07-29 13:44:28 -0700283 "${config.X86ToolchainCflags}",
284 "${config.X86" + arch.ArchVariant + "VariantCflags}",
Colin Crossb0cba6a2015-11-20 15:35:26 -0800285 }
286
287 toolchainClangCflags := []string{
Colin Crossb98c8b02016-07-29 13:44:28 -0700288 "${config.X86ToolchainCflags}",
289 "${config.X86" + arch.ArchVariant + "VariantClangCflags}",
Colin Crossb0cba6a2015-11-20 15:35:26 -0800290 }
291
292 for _, feature := range arch.ArchFeatures {
293 toolchainCflags = append(toolchainCflags, x86ArchFeatureCflags[feature]...)
294 toolchainClangCflags = append(toolchainClangCflags, x86ArchFeatureCflags[feature]...)
295 }
296
297 return &toolchainX86{
298 toolchainCflags: strings.Join(toolchainCflags, " "),
299 toolchainClangCflags: strings.Join(toolchainClangCflags, " "),
300 }
301}
302
303func init() {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700304 registerToolchainFactory(android.Android, android.X86, x86ToolchainFactory)
Colin Crossb0cba6a2015-11-20 15:35:26 -0800305}