• 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 config
16
17import (
18	"fmt"
19	"strings"
20
21	"android/soong/android"
22)
23
24var (
25	arm64Cflags = []string{
26		// Help catch common 32/64-bit errors.
27		"-Werror=implicit-function-declaration",
28	}
29
30	arm64ArchVariantCflags = map[string][]string{
31		"armv8-a": []string{
32			"-march=armv8-a",
33		},
34		"armv8-2a": []string{
35			"-march=armv8.2a",
36		},
37	}
38
39	arm64Ldflags = []string{
40		"-Wl,-m,aarch64_elf64_le_vec",
41		"-Wl,--hash-style=gnu",
42		"-fuse-ld=gold",
43		"-Wl,--icf=safe",
44	}
45
46	arm64Lldflags = append(ClangFilterUnknownLldflags(arm64Ldflags),
47		"-Wl,-z,max-page-size=4096")
48
49	arm64Cppflags = []string{}
50
51	arm64ClangCpuVariantCflags = map[string][]string{
52		"cortex-a53": []string{
53			"-mcpu=cortex-a53",
54		},
55		"cortex-a55": []string{
56			"-mcpu=cortex-a55",
57		},
58		"cortex-a75": []string{
59			// Use the cortex-a55 since it is similar to the little
60			// core (cortex-a55) and is sensitive to ordering.
61			"-mcpu=cortex-a55",
62		},
63		"cortex-a76": []string{
64			// Use the cortex-a55 since it is similar to the little
65			// core (cortex-a55) and is sensitive to ordering.
66			"-mcpu=cortex-a55",
67		},
68		"kryo": []string{
69			"-mcpu=kryo",
70		},
71		"kryo385": []string{
72			// Use cortex-a53 because kryo385 is not supported in GCC/clang.
73			"-mcpu=cortex-a53",
74		},
75		"exynos-m1": []string{
76			"-mcpu=exynos-m1",
77		},
78		"exynos-m2": []string{
79			"-mcpu=exynos-m2",
80		},
81	}
82)
83
84const (
85	arm64GccVersion = "4.9"
86)
87
88func init() {
89	pctx.StaticVariable("arm64GccVersion", arm64GccVersion)
90
91	pctx.SourcePathVariable("Arm64GccRoot",
92		"prebuilts/gcc/${HostPrebuiltTag}/aarch64/aarch64-linux-android-${arm64GccVersion}")
93
94	pctx.StaticVariable("Arm64Ldflags", strings.Join(arm64Ldflags, " "))
95	pctx.StaticVariable("Arm64Lldflags", strings.Join(arm64Lldflags, " "))
96	pctx.StaticVariable("Arm64IncludeFlags", bionicHeaders("arm64"))
97
98	pctx.StaticVariable("Arm64ClangCflags", strings.Join(ClangFilterUnknownCflags(arm64Cflags), " "))
99	pctx.StaticVariable("Arm64ClangLdflags", strings.Join(ClangFilterUnknownCflags(arm64Ldflags), " "))
100	pctx.StaticVariable("Arm64ClangLldflags", strings.Join(ClangFilterUnknownCflags(arm64Lldflags), " "))
101	pctx.StaticVariable("Arm64ClangCppflags", strings.Join(ClangFilterUnknownCflags(arm64Cppflags), " "))
102
103	pctx.StaticVariable("Arm64ClangArmv8ACflags", strings.Join(arm64ArchVariantCflags["armv8-a"], " "))
104	pctx.StaticVariable("Arm64ClangArmv82ACflags", strings.Join(arm64ArchVariantCflags["armv8-2a"], " "))
105
106	pctx.StaticVariable("Arm64ClangCortexA53Cflags",
107		strings.Join(arm64ClangCpuVariantCflags["cortex-a53"], " "))
108
109	pctx.StaticVariable("Arm64ClangCortexA55Cflags",
110		strings.Join(arm64ClangCpuVariantCflags["cortex-a55"], " "))
111
112	pctx.StaticVariable("Arm64ClangKryoCflags",
113		strings.Join(arm64ClangCpuVariantCflags["kryo"], " "))
114
115	pctx.StaticVariable("Arm64ClangExynosM1Cflags",
116		strings.Join(arm64ClangCpuVariantCflags["exynos-m1"], " "))
117
118	pctx.StaticVariable("Arm64ClangExynosM2Cflags",
119		strings.Join(arm64ClangCpuVariantCflags["exynos-m2"], " "))
120}
121
122var (
123	arm64ClangArchVariantCflagsVar = map[string]string{
124		"armv8-a":  "${config.Arm64ClangArmv8ACflags}",
125		"armv8-2a": "${config.Arm64ClangArmv82ACflags}",
126	}
127
128	arm64ClangCpuVariantCflagsVar = map[string]string{
129		"":           "",
130		"cortex-a53": "${config.Arm64ClangCortexA53Cflags}",
131		"cortex-a55": "${config.Arm64ClangCortexA55Cflags}",
132		"cortex-a72": "${config.Arm64ClangCortexA53Cflags}",
133		"cortex-a73": "${config.Arm64ClangCortexA53Cflags}",
134		"cortex-a75": "${config.Arm64ClangCortexA55Cflags}",
135		"cortex-a76": "${config.Arm64ClangCortexA55Cflags}",
136		"kryo":       "${config.Arm64ClangKryoCflags}",
137		"kryo385":    "${config.Arm64ClangCortexA53Cflags}",
138		"exynos-m1":  "${config.Arm64ClangExynosM1Cflags}",
139		"exynos-m2":  "${config.Arm64ClangExynosM2Cflags}",
140	}
141)
142
143type toolchainArm64 struct {
144	toolchain64Bit
145
146	ldflags              string
147	lldflags             string
148	toolchainClangCflags string
149}
150
151func (t *toolchainArm64) Name() string {
152	return "arm64"
153}
154
155func (t *toolchainArm64) GccRoot() string {
156	return "${config.Arm64GccRoot}"
157}
158
159func (t *toolchainArm64) GccTriple() string {
160	return "aarch64-linux-android"
161}
162
163func (t *toolchainArm64) GccVersion() string {
164	return arm64GccVersion
165}
166
167func (t *toolchainArm64) IncludeFlags() string {
168	return "${config.Arm64IncludeFlags}"
169}
170
171func (t *toolchainArm64) ClangTriple() string {
172	return t.GccTriple()
173}
174
175func (t *toolchainArm64) ClangCflags() string {
176	return "${config.Arm64ClangCflags}"
177}
178
179func (t *toolchainArm64) ClangCppflags() string {
180	return "${config.Arm64ClangCppflags}"
181}
182
183func (t *toolchainArm64) ClangLdflags() string {
184	return t.ldflags
185}
186
187func (t *toolchainArm64) ClangLldflags() string {
188	return t.lldflags
189}
190
191func (t *toolchainArm64) ToolchainClangCflags() string {
192	return t.toolchainClangCflags
193}
194
195func (toolchainArm64) LibclangRuntimeLibraryArch() string {
196	return "aarch64"
197}
198
199func arm64ToolchainFactory(arch android.Arch) Toolchain {
200	switch arch.ArchVariant {
201	case "armv8-a":
202	case "armv8-2a":
203		// Nothing extra for armv8-a/armv8-2a
204	default:
205		panic(fmt.Sprintf("Unknown ARM architecture version: %q", arch.ArchVariant))
206	}
207
208	toolchainClangCflags := []string{arm64ClangArchVariantCflagsVar[arch.ArchVariant]}
209	toolchainClangCflags = append(toolchainClangCflags,
210		variantOrDefault(arm64ClangCpuVariantCflagsVar, arch.CpuVariant))
211
212	var extraLdflags string
213	switch arch.CpuVariant {
214	case "cortex-a53", "cortex-a72", "cortex-a73", "kryo", "exynos-m1", "exynos-m2":
215		extraLdflags = "-Wl,--fix-cortex-a53-843419"
216	}
217
218	return &toolchainArm64{
219		ldflags: strings.Join([]string{
220			"${config.Arm64Ldflags}",
221			extraLdflags,
222		}, " "),
223		lldflags: strings.Join([]string{
224			"${config.Arm64Lldflags}",
225			extraLdflags,
226		}, " "),
227		toolchainClangCflags: strings.Join(toolchainClangCflags, " "),
228	}
229}
230
231func init() {
232	registerToolchainFactory(android.Android, android.Arm64, arm64ToolchainFactory)
233}
234