• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 cc
16
17import (
18	"strings"
19
20	"android/soong/common"
21)
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",
39		"-fstack-protector-strong",
40		"-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",
65		"-Wl,--no-undefined-version",
66	}
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{
79			"-march=corei7",
80		},
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"},
91		"avx":    []string{"-mavx"},
92		"aes_ni": []string{"-maes"},
93	}
94)
95
96const (
97	x86_64GccVersion = "4.9"
98)
99
100func init() {
101	common.RegisterArchFeatures(common.X86_64, "",
102		"ssse3",
103		"sse4",
104		"sse4_1",
105		"sse4_2",
106		"popcnt")
107	common.RegisterArchFeatures(common.X86_64, "haswell",
108		"ssse3",
109		"sse4",
110		"sse4_1",
111		"sse4_2",
112		"aes_ni",
113		"avx",
114		"popcnt")
115	common.RegisterArchFeatures(common.X86_64, "ivybridge",
116		"ssse3",
117		"sse4",
118		"sse4_1",
119		"sse4_2",
120		"aes_ni",
121		"avx",
122		"popcnt")
123	common.RegisterArchFeatures(common.X86_64, "sandybridge",
124		"ssse3",
125		"sse4",
126		"sse4_1",
127		"sse4_2",
128		"popcnt")
129	common.RegisterArchFeatures(common.X86_64, "silvermont",
130		"ssse3",
131		"sse4",
132		"sse4_1",
133		"sse4_2",
134		"aes_ni",
135		"popcnt")
136
137	pctx.StaticVariable("x86_64GccVersion", x86_64GccVersion)
138
139	pctx.SourcePathVariable("x86_64GccRoot",
140		"prebuilts/gcc/${HostPrebuiltTag}/x86/x86_64-linux-android-${x86_64GccVersion}")
141
142	pctx.StaticVariable("x86_64GccTriple", "x86_64-linux-android")
143
144	pctx.StaticVariable("x86_64ToolchainCflags", "-m64")
145	pctx.StaticVariable("x86_64ToolchainLdflags", "-m64")
146
147	pctx.StaticVariable("x86_64Cflags", strings.Join(x86_64Cflags, " "))
148	pctx.StaticVariable("x86_64Ldflags", strings.Join(x86_64Ldflags, " "))
149	pctx.StaticVariable("x86_64Cppflags", strings.Join(x86_64Cppflags, " "))
150	pctx.StaticVariable("x86_64IncludeFlags", strings.Join([]string{
151		"-isystem ${LibcRoot}/arch-x86_64/include",
152		"-isystem ${LibcRoot}/include",
153		"-isystem ${LibcRoot}/kernel/uapi",
154		"-isystem ${LibcRoot}/kernel/uapi/asm-x86",
155		"-isystem ${LibmRoot}/include",
156		"-isystem ${LibmRoot}/include/amd64",
157	}, " "))
158
159	// Clang cflags
160	pctx.StaticVariable("x86_64ClangCflags", strings.Join(clangFilterUnknownCflags(x86_64Cflags), " "))
161	pctx.StaticVariable("x86_64ClangLdflags", strings.Join(clangFilterUnknownCflags(x86_64Ldflags), " "))
162	pctx.StaticVariable("x86_64ClangCppflags", strings.Join(clangFilterUnknownCflags(x86_64Cppflags), " "))
163
164	// Extended cflags
165
166	// Architecture variant cflags
167	for variant, cflags := range x86_64ArchVariantCflags {
168		pctx.StaticVariable("x86_64"+variant+"VariantCflags", strings.Join(cflags, " "))
169		pctx.StaticVariable("x86_64"+variant+"VariantClangCflags",
170			strings.Join(clangFilterUnknownCflags(cflags), " "))
171	}
172}
173
174type toolchainX86_64 struct {
175	toolchain64Bit
176	toolchainCflags, toolchainClangCflags string
177}
178
179func (t *toolchainX86_64) Name() string {
180	return "x86_64"
181}
182
183func (t *toolchainX86_64) GccRoot() string {
184	return "${x86_64GccRoot}"
185}
186
187func (t *toolchainX86_64) GccTriple() string {
188	return "${x86_64GccTriple}"
189}
190
191func (t *toolchainX86_64) GccVersion() string {
192	return x86_64GccVersion
193}
194
195func (t *toolchainX86_64) ToolchainLdflags() string {
196	return "${x86_64ToolchainLdflags}"
197}
198
199func (t *toolchainX86_64) ToolchainCflags() string {
200	return t.toolchainCflags
201}
202
203func (t *toolchainX86_64) Cflags() string {
204	return "${x86_64Cflags}"
205}
206
207func (t *toolchainX86_64) Cppflags() string {
208	return "${x86_64Cppflags}"
209}
210
211func (t *toolchainX86_64) Ldflags() string {
212	return "${x86_64Ldflags}"
213}
214
215func (t *toolchainX86_64) IncludeFlags() string {
216	return "${x86_64IncludeFlags}"
217}
218
219func (t *toolchainX86_64) ClangTriple() string {
220	return "${x86_64GccTriple}"
221}
222
223func (t *toolchainX86_64) ToolchainClangCflags() string {
224	return t.toolchainClangCflags
225}
226
227func (t *toolchainX86_64) ClangCflags() string {
228	return "${x86_64ClangCflags}"
229}
230
231func (t *toolchainX86_64) ClangCppflags() string {
232	return "${x86_64ClangCppflags}"
233}
234
235func (t *toolchainX86_64) ClangLdflags() string {
236	return "${x86_64Ldflags}"
237}
238
239func x86_64ToolchainFactory(arch common.Arch) Toolchain {
240	toolchainCflags := []string{
241		"${x86_64ToolchainCflags}",
242		"${x86_64" + arch.ArchVariant + "VariantCflags}",
243	}
244
245	toolchainClangCflags := []string{
246		"${x86_64ToolchainCflags}",
247		"${x86_64" + arch.ArchVariant + "VariantClangCflags}",
248	}
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() {
262	registerDeviceToolchainFactory(common.X86_64, x86_64ToolchainFactory)
263}
264