blob: 94a4457006ca2e77f0d7e103c2cdc8f514d628fd [file] [log] [blame]
Ivan Lozanof1c84332019-09-20 11:00:37 -07001// Copyright 2019 The Android Open Source Project
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 "strings"
19
20 "android/soong/android"
21)
22
23var (
Ivan Lozano085efff2023-09-12 12:33:42 -040024 Arm64RustFlags = []string{
25 "-C force-frame-pointers=y",
26 }
Ivan Lozanof1c84332019-09-20 11:00:37 -070027 Arm64ArchFeatureRustFlags = map[string][]string{}
Ivan Lozano6d45a982020-09-09 09:08:44 -040028 Arm64LinkFlags = []string{}
Ivan Lozanof1c84332019-09-20 11:00:37 -070029
30 Arm64ArchVariantRustFlags = map[string][]string{
Ivan Lozano2797e872023-07-25 14:05:48 -040031 "armv8-a": []string{},
32 "armv8-a-branchprot": []string{
33 // branch-protection=bti,pac-ret is equivalent to Clang's mbranch-protection=standard
34 "-Z branch-protection=bti,pac-ret",
35 },
36 "armv8-2a": []string{},
37 "armv8-2a-dotprod": []string{},
Krzysztof Kosiński9aa98382024-09-19 00:08:16 +000038
39 // branch-protection=bti,pac-ret is equivalent to Clang's mbranch-protection=standard
Ivan Lozano2797e872023-07-25 14:05:48 -040040 "armv9-a": []string{
Krzysztof Kosiński9aa98382024-09-19 00:08:16 +000041 "-Z branch-protection=bti,pac-ret",
42 "-Z stack-protector=none",
43 },
44 "armv9-2a": []string{
Ivan Lozano2797e872023-07-25 14:05:48 -040045 "-Z branch-protection=bti,pac-ret",
46 "-Z stack-protector=none",
47 },
Ivan Lozanof1c84332019-09-20 11:00:37 -070048 }
49)
50
51func init() {
52 registerToolchainFactory(android.Android, android.Arm64, Arm64ToolchainFactory)
53
54 pctx.StaticVariable("Arm64ToolchainRustFlags", strings.Join(Arm64RustFlags, " "))
55 pctx.StaticVariable("Arm64ToolchainLinkFlags", strings.Join(Arm64LinkFlags, " "))
56
57 for variant, rustFlags := range Arm64ArchVariantRustFlags {
58 pctx.StaticVariable("Arm64"+variant+"VariantRustFlags",
59 strings.Join(rustFlags, " "))
60 }
61
Cole Faust8982b1c2024-04-08 16:54:45 -070062 pctx.StaticVariable("DEVICE_ARM64_RUSTC_FLAGS", strings.Join(Arm64RustFlags, " "))
Ivan Lozanof1c84332019-09-20 11:00:37 -070063}
64
65type toolchainArm64 struct {
66 toolchain64Bit
67 toolchainRustFlags string
68}
69
70func (t *toolchainArm64) RustTriple() string {
71 return "aarch64-linux-android"
72}
73
74func (t *toolchainArm64) ToolchainLinkFlags() string {
Ivan Lozano6d45a982020-09-09 09:08:44 -040075 // Prepend the lld flags from cc_config so we stay in sync with cc
76 return "${config.DeviceGlobalLinkFlags} ${cc_config.Arm64Lldflags} ${config.Arm64ToolchainLinkFlags}"
Ivan Lozanof1c84332019-09-20 11:00:37 -070077}
78
79func (t *toolchainArm64) ToolchainRustFlags() string {
80 return t.toolchainRustFlags
81}
82
83func (t *toolchainArm64) RustFlags() string {
84 return "${config.Arm64ToolchainRustFlags}"
85}
86
87func (t *toolchainArm64) Supported() bool {
88 return true
89}
90
Ivan Lozano6cd99e62020-02-11 08:24:25 -050091func (toolchainArm64) LibclangRuntimeLibraryArch() string {
92 return "aarch64"
93}
94
Ivan Lozanof1c84332019-09-20 11:00:37 -070095func Arm64ToolchainFactory(arch android.Arch) Toolchain {
Jiyong Park4afa2e22020-07-13 15:43:45 +090096 archVariant := arch.ArchVariant
97 if archVariant == "" {
98 // arch variants defaults to armv8-a. This is mostly for
99 // the host target which borrows toolchain configs from here.
100 archVariant = "armv8-a"
101 }
102
Ivan Lozanof1c84332019-09-20 11:00:37 -0700103 toolchainRustFlags := []string{
104 "${config.Arm64ToolchainRustFlags}",
Jiyong Park4afa2e22020-07-13 15:43:45 +0900105 "${config.Arm64" + archVariant + "VariantRustFlags}",
Ivan Lozanof1c84332019-09-20 11:00:37 -0700106 }
107
108 toolchainRustFlags = append(toolchainRustFlags, deviceGlobalRustFlags...)
109
110 for _, feature := range arch.ArchFeatures {
111 toolchainRustFlags = append(toolchainRustFlags, Arm64ArchFeatureRustFlags[feature]...)
112 }
113
114 return &toolchainArm64{
115 toolchainRustFlags: strings.Join(toolchainRustFlags, " "),
116 }
117}