blob: c1bdfd55bdb56aaa46ea2d5d35d179a978fa8621 [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
15package cc
16
17import (
18 "strings"
19
20 "android/soong/common"
21)
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 },
76 "atom": []string{
77 "-march=atom",
78 "-mfpmath=sse",
79 },
80 "haswell": []string{
81 "-march=core-avx2",
82 "-mfpmath=sse",
83 },
84 "ivybridge": []string{
85 "-march=core-avx-i",
86 "-mfpmath=sse",
87 },
88 "sandybridge": []string{
Dan Willemsenb77bd792016-02-29 15:26:26 -080089 "-march=corei7",
Colin Crossb0cba6a2015-11-20 15:35:26 -080090 "-mfpmath=sse",
91 },
92 "silvermont": []string{
93 "-march=slm",
94 "-mfpmath=sse",
95 },
96 }
97
98 x86ArchFeatureCflags = map[string][]string{
99 "ssse3": []string{"-DUSE_SSSE3", "-mssse3"},
100 "sse4": []string{"-msse4"},
101 "sse4_1": []string{"-msse4.1"},
102 "sse4_2": []string{"-msse4.2"},
103 "avx": []string{"-mavx"},
104 "aes_ni": []string{"-maes"},
105 }
106)
107
Dan Willemsen34fc3b12015-12-07 12:30:44 -0800108const (
109 x86GccVersion = "4.9"
110)
111
Colin Crossb0cba6a2015-11-20 15:35:26 -0800112func init() {
113 common.RegisterArchFeatures(common.X86, "atom",
114 "ssse3",
115 "movbe")
116 common.RegisterArchFeatures(common.X86, "haswell",
117 "ssse3",
118 "sse4",
119 "sse4_1",
120 "sse4_2",
121 "aes_ni",
122 "avx",
123 "popcnt",
124 "movbe")
125 common.RegisterArchFeatures(common.X86, "ivybridge",
126 "ssse3",
127 "sse4",
128 "sse4_1",
129 "sse4_2",
130 "aes_ni",
131 "avx",
132 "popcnt")
133 common.RegisterArchFeatures(common.X86, "sandybridge",
134 "ssse3",
135 "sse4",
136 "sse4_1",
137 "sse4_2",
Colin Crossb0cba6a2015-11-20 15:35:26 -0800138 "popcnt")
139 common.RegisterArchFeatures(common.X86, "silvermont",
140 "ssse3",
141 "sse4",
142 "sse4_1",
143 "sse4_2",
144 "aes_ni",
145 "popcnt",
146 "movbe")
147
Dan Willemsen34fc3b12015-12-07 12:30:44 -0800148 pctx.StaticVariable("x86GccVersion", x86GccVersion)
Colin Crossb0cba6a2015-11-20 15:35:26 -0800149
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700150 pctx.SourcePathVariable("x86GccRoot",
Dan Willemsen34fc3b12015-12-07 12:30:44 -0800151 "prebuilts/gcc/${HostPrebuiltTag}/x86/x86_64-linux-android-${x86GccVersion}")
Colin Crossb0cba6a2015-11-20 15:35:26 -0800152
153 pctx.StaticVariable("x86GccTriple", "x86_64-linux-android")
154
155 pctx.StaticVariable("x86ToolchainCflags", "-m32")
156 pctx.StaticVariable("x86ToolchainLdflags", "-m32")
157
158 pctx.StaticVariable("x86Cflags", strings.Join(x86Cflags, " "))
159 pctx.StaticVariable("x86Ldflags", strings.Join(x86Ldflags, " "))
160 pctx.StaticVariable("x86Cppflags", strings.Join(x86Cppflags, " "))
161 pctx.StaticVariable("x86IncludeFlags", strings.Join([]string{
162 "-isystem ${LibcRoot}/arch-x86/include",
163 "-isystem ${LibcRoot}/include",
164 "-isystem ${LibcRoot}/kernel/uapi",
165 "-isystem ${LibcRoot}/kernel/uapi/asm-x86",
Colin Crossb0cba6a2015-11-20 15:35:26 -0800166 }, " "))
167
168 // Clang cflags
Dan Willemsen569b0fa2016-05-08 20:04:20 -0700169 pctx.StaticVariable("x86ClangCflags", strings.Join(clangFilterUnknownCflags(x86ClangCflags), " "))
Colin Crossb0cba6a2015-11-20 15:35:26 -0800170 pctx.StaticVariable("x86ClangLdflags", strings.Join(clangFilterUnknownCflags(x86Ldflags), " "))
171 pctx.StaticVariable("x86ClangCppflags", strings.Join(clangFilterUnknownCflags(x86Cppflags), " "))
172
173 // Extended cflags
174
175 // Architecture variant cflags
176 for variant, cflags := range x86ArchVariantCflags {
177 pctx.StaticVariable("x86"+variant+"VariantCflags", strings.Join(cflags, " "))
178 pctx.StaticVariable("x86"+variant+"VariantClangCflags",
179 strings.Join(clangFilterUnknownCflags(cflags), " "))
180 }
181}
182
183type toolchainX86 struct {
184 toolchain32Bit
185 toolchainCflags, toolchainClangCflags string
186}
187
188func (t *toolchainX86) Name() string {
189 return "x86"
190}
191
192func (t *toolchainX86) GccRoot() string {
193 return "${x86GccRoot}"
194}
195
196func (t *toolchainX86) GccTriple() string {
197 return "${x86GccTriple}"
198}
199
200func (t *toolchainX86) GccVersion() string {
Dan Willemsen34fc3b12015-12-07 12:30:44 -0800201 return x86GccVersion
Colin Crossb0cba6a2015-11-20 15:35:26 -0800202}
203
204func (t *toolchainX86) ToolchainLdflags() string {
205 return "${x86ToolchainLdflags}"
206}
207
208func (t *toolchainX86) ToolchainCflags() string {
209 return t.toolchainCflags
210}
211
212func (t *toolchainX86) Cflags() string {
213 return "${x86Cflags}"
214}
215
216func (t *toolchainX86) Cppflags() string {
217 return "${x86Cppflags}"
218}
219
220func (t *toolchainX86) Ldflags() string {
221 return "${x86Ldflags}"
222}
223
224func (t *toolchainX86) IncludeFlags() string {
225 return "${x86IncludeFlags}"
226}
227
228func (t *toolchainX86) ClangTriple() string {
Dan Willemsen569b0fa2016-05-08 20:04:20 -0700229 return "i686-linux-android"
230}
231
232func (t *toolchainX86) ToolchainClangLdflags() string {
233 return "${x86ToolchainLdflags}"
Colin Crossb0cba6a2015-11-20 15:35:26 -0800234}
235
236func (t *toolchainX86) ToolchainClangCflags() string {
237 return t.toolchainClangCflags
238}
239
240func (t *toolchainX86) ClangCflags() string {
241 return "${x86ClangCflags}"
242}
243
244func (t *toolchainX86) ClangCppflags() string {
245 return "${x86ClangCppflags}"
246}
247
248func (t *toolchainX86) ClangLdflags() string {
249 return "${x86Ldflags}"
250}
251
Colin Cross16b23492016-01-06 14:41:07 -0800252func (toolchainX86) AddressSanitizerRuntimeLibrary() string {
253 return "libclang_rt.asan-i686-android.so"
254}
255
Colin Crossb0cba6a2015-11-20 15:35:26 -0800256func x86ToolchainFactory(arch common.Arch) Toolchain {
257 toolchainCflags := []string{
258 "${x86ToolchainCflags}",
259 "${x86" + arch.ArchVariant + "VariantCflags}",
260 }
261
262 toolchainClangCflags := []string{
263 "${x86ToolchainCflags}",
264 "${x86" + arch.ArchVariant + "VariantClangCflags}",
265 }
266
267 for _, feature := range arch.ArchFeatures {
268 toolchainCflags = append(toolchainCflags, x86ArchFeatureCflags[feature]...)
269 toolchainClangCflags = append(toolchainClangCflags, x86ArchFeatureCflags[feature]...)
270 }
271
272 return &toolchainX86{
273 toolchainCflags: strings.Join(toolchainCflags, " "),
274 toolchainClangCflags: strings.Join(toolchainClangCflags, " "),
275 }
276}
277
278func init() {
Dan Willemsen490fd492015-11-24 17:53:15 -0800279 registerDeviceToolchainFactory(common.X86, x86ToolchainFactory)
Colin Crossb0cba6a2015-11-20 15:35:26 -0800280}