• 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-a-branchprot": []string{
35			"-march=armv8-a",
36			"-mbranch-protection=standard",
37		},
38		"armv8-2a": []string{
39			"-march=armv8.2-a",
40		},
41		"armv8-2a-dotprod": []string{
42			"-march=armv8.2-a+dotprod",
43		},
44	}
45
46	arm64Ldflags = []string{
47		"-Wl,--hash-style=gnu",
48		"-Wl,-z,separate-code",
49	}
50
51	arm64Lldflags = append(arm64Ldflags,
52		"-Wl,-z,max-page-size=4096")
53
54	arm64Cppflags = []string{}
55
56	arm64CpuVariantCflags = map[string][]string{
57		"cortex-a53": []string{
58			"-mcpu=cortex-a53",
59		},
60		"cortex-a55": []string{
61			"-mcpu=cortex-a55",
62		},
63		"cortex-a75": []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		"cortex-a76": []string{
69			// Use the cortex-a55 since it is similar to the little
70			// core (cortex-a55) and is sensitive to ordering.
71			"-mcpu=cortex-a55",
72		},
73		"kryo": []string{
74			"-mcpu=kryo",
75		},
76		"kryo385": []string{
77			// Use cortex-a53 because kryo385 is not supported in GCC/clang.
78			"-mcpu=cortex-a53",
79		},
80		"exynos-m1": []string{
81			"-mcpu=exynos-m1",
82		},
83		"exynos-m2": []string{
84			"-mcpu=exynos-m2",
85		},
86	}
87)
88
89const (
90	arm64GccVersion = "4.9"
91)
92
93func init() {
94	pctx.StaticVariable("arm64GccVersion", arm64GccVersion)
95
96	pctx.SourcePathVariable("Arm64GccRoot",
97		"prebuilts/gcc/${HostPrebuiltTag}/aarch64/aarch64-linux-android-${arm64GccVersion}")
98
99	exportedVars.ExportStringListStaticVariable("Arm64Ldflags", arm64Ldflags)
100	exportedVars.ExportStringListStaticVariable("Arm64Lldflags", arm64Lldflags)
101
102	exportedVars.ExportStringListStaticVariable("Arm64Cflags", arm64Cflags)
103	exportedVars.ExportStringListStaticVariable("Arm64Cppflags", arm64Cppflags)
104
105	exportedVars.ExportVariableReferenceDict("Arm64ArchVariantCflags", arm64ArchVariantCflagsVar)
106	exportedVars.ExportVariableReferenceDict("Arm64CpuVariantCflags", arm64CpuVariantCflagsVar)
107	exportedVars.ExportVariableReferenceDict("Arm64CpuVariantLdflags", arm64CpuVariantLdflags)
108
109	exportedVars.ExportStringListStaticVariable("Arm64Armv8ACflags", arm64ArchVariantCflags["armv8-a"])
110	exportedVars.ExportStringListStaticVariable("Arm64Armv8ABranchProtCflags", arm64ArchVariantCflags["armv8-a-branchprot"])
111	exportedVars.ExportStringListStaticVariable("Arm64Armv82ACflags", arm64ArchVariantCflags["armv8-2a"])
112	exportedVars.ExportStringListStaticVariable("Arm64Armv82ADotprodCflags", arm64ArchVariantCflags["armv8-2a-dotprod"])
113
114	exportedVars.ExportStringListStaticVariable("Arm64CortexA53Cflags", arm64CpuVariantCflags["cortex-a53"])
115	exportedVars.ExportStringListStaticVariable("Arm64CortexA55Cflags", arm64CpuVariantCflags["cortex-a55"])
116	exportedVars.ExportStringListStaticVariable("Arm64KryoCflags", arm64CpuVariantCflags["kryo"])
117	exportedVars.ExportStringListStaticVariable("Arm64ExynosM1Cflags", arm64CpuVariantCflags["exynos-m1"])
118	exportedVars.ExportStringListStaticVariable("Arm64ExynosM2Cflags", arm64CpuVariantCflags["exynos-m2"])
119
120	exportedVars.ExportStringListStaticVariable("Arm64FixCortexA53Ldflags", []string{"-Wl,--fix-cortex-a53-843419"})
121}
122
123var (
124	arm64ArchVariantCflagsVar = map[string]string{
125		"armv8-a":            "${config.Arm64Armv8ACflags}",
126		"armv8-a-branchprot": "${config.Arm64Armv8ABranchProtCflags}",
127		"armv8-2a":           "${config.Arm64Armv82ACflags}",
128		"armv8-2a-dotprod":   "${config.Arm64Armv82ADotprodCflags}",
129	}
130
131	arm64CpuVariantCflagsVar = map[string]string{
132		"cortex-a53": "${config.Arm64CortexA53Cflags}",
133		"cortex-a55": "${config.Arm64CortexA55Cflags}",
134		"cortex-a72": "${config.Arm64CortexA53Cflags}",
135		"cortex-a73": "${config.Arm64CortexA53Cflags}",
136		"cortex-a75": "${config.Arm64CortexA55Cflags}",
137		"cortex-a76": "${config.Arm64CortexA55Cflags}",
138		"kryo":       "${config.Arm64KryoCflags}",
139		"kryo385":    "${config.Arm64CortexA53Cflags}",
140		"exynos-m1":  "${config.Arm64ExynosM1Cflags}",
141		"exynos-m2":  "${config.Arm64ExynosM2Cflags}",
142	}
143
144	arm64CpuVariantLdflags = map[string]string{
145		"cortex-a53": "${config.Arm64FixCortexA53Ldflags}",
146		"cortex-a72": "${config.Arm64FixCortexA53Ldflags}",
147		"cortex-a73": "${config.Arm64FixCortexA53Ldflags}",
148		"kryo":       "${config.Arm64FixCortexA53Ldflags}",
149		"exynos-m1":  "${config.Arm64FixCortexA53Ldflags}",
150		"exynos-m2":  "${config.Arm64FixCortexA53Ldflags}",
151	}
152)
153
154type toolchainArm64 struct {
155	toolchainBionic
156	toolchain64Bit
157
158	ldflags         string
159	lldflags        string
160	toolchainCflags string
161}
162
163func (t *toolchainArm64) Name() string {
164	return "arm64"
165}
166
167func (t *toolchainArm64) GccRoot() string {
168	return "${config.Arm64GccRoot}"
169}
170
171func (t *toolchainArm64) GccTriple() string {
172	return "aarch64-linux-android"
173}
174
175func (t *toolchainArm64) GccVersion() string {
176	return arm64GccVersion
177}
178
179func (t *toolchainArm64) IncludeFlags() string {
180	return ""
181}
182
183func (t *toolchainArm64) ClangTriple() string {
184	return t.GccTriple()
185}
186
187func (t *toolchainArm64) Cflags() string {
188	return "${config.Arm64Cflags}"
189}
190
191func (t *toolchainArm64) Cppflags() string {
192	return "${config.Arm64Cppflags}"
193}
194
195func (t *toolchainArm64) Ldflags() string {
196	return t.ldflags
197}
198
199func (t *toolchainArm64) Lldflags() string {
200	return t.lldflags
201}
202
203func (t *toolchainArm64) ToolchainCflags() string {
204	return t.toolchainCflags
205}
206
207func (toolchainArm64) LibclangRuntimeLibraryArch() string {
208	return "aarch64"
209}
210
211func arm64ToolchainFactory(arch android.Arch) Toolchain {
212	switch arch.ArchVariant {
213	case "armv8-a":
214	case "armv8-a-branchprot":
215	case "armv8-2a":
216	case "armv8-2a-dotprod":
217		// Nothing extra for armv8-a/armv8-2a
218	default:
219		panic(fmt.Sprintf("Unknown ARM architecture version: %q", arch.ArchVariant))
220	}
221
222	toolchainCflags := []string{arm64ArchVariantCflagsVar[arch.ArchVariant]}
223	toolchainCflags = append(toolchainCflags,
224		variantOrDefault(arm64CpuVariantCflagsVar, arch.CpuVariant))
225
226	extraLdflags := variantOrDefault(arm64CpuVariantLdflags, arch.CpuVariant)
227	return &toolchainArm64{
228		ldflags: strings.Join([]string{
229			"${config.Arm64Ldflags}",
230			extraLdflags,
231		}, " "),
232		lldflags: strings.Join([]string{
233			"${config.Arm64Lldflags}",
234			extraLdflags,
235		}, " "),
236		toolchainCflags: strings.Join(toolchainCflags, " "),
237	}
238}
239
240func init() {
241	registerToolchainFactory(android.Android, android.Arm64, arm64ToolchainFactory)
242}
243