Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 1 | // 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 | |
| 15 | package config |
| 16 | |
| 17 | import ( |
| 18 | "strings" |
| 19 | |
| 20 | "android/soong/android" |
| 21 | ) |
| 22 | |
| 23 | var ( |
| 24 | Arm64RustFlags = []string{} |
| 25 | Arm64ArchFeatureRustFlags = map[string][]string{} |
Ivan Lozano | 6d45a98 | 2020-09-09 09:08:44 -0400 | [diff] [blame] | 26 | Arm64LinkFlags = []string{} |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 27 | |
| 28 | Arm64ArchVariantRustFlags = map[string][]string{ |
Ivan Lozano | 2797e87 | 2023-07-25 14:05:48 -0400 | [diff] [blame] | 29 | "armv8-a": []string{}, |
| 30 | "armv8-a-branchprot": []string{ |
| 31 | // branch-protection=bti,pac-ret is equivalent to Clang's mbranch-protection=standard |
| 32 | "-Z branch-protection=bti,pac-ret", |
| 33 | }, |
| 34 | "armv8-2a": []string{}, |
| 35 | "armv8-2a-dotprod": []string{}, |
| 36 | "armv9-a": []string{ |
| 37 | // branch-protection=bti,pac-ret is equivalent to Clang's mbranch-protection=standard |
| 38 | "-Z branch-protection=bti,pac-ret", |
| 39 | "-Z stack-protector=none", |
| 40 | }, |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 41 | } |
| 42 | ) |
| 43 | |
| 44 | func init() { |
| 45 | registerToolchainFactory(android.Android, android.Arm64, Arm64ToolchainFactory) |
| 46 | |
| 47 | pctx.StaticVariable("Arm64ToolchainRustFlags", strings.Join(Arm64RustFlags, " ")) |
| 48 | pctx.StaticVariable("Arm64ToolchainLinkFlags", strings.Join(Arm64LinkFlags, " ")) |
| 49 | |
| 50 | for variant, rustFlags := range Arm64ArchVariantRustFlags { |
| 51 | pctx.StaticVariable("Arm64"+variant+"VariantRustFlags", |
| 52 | strings.Join(rustFlags, " ")) |
| 53 | } |
| 54 | |
| 55 | } |
| 56 | |
| 57 | type toolchainArm64 struct { |
| 58 | toolchain64Bit |
| 59 | toolchainRustFlags string |
| 60 | } |
| 61 | |
| 62 | func (t *toolchainArm64) RustTriple() string { |
| 63 | return "aarch64-linux-android" |
| 64 | } |
| 65 | |
| 66 | func (t *toolchainArm64) ToolchainLinkFlags() string { |
Ivan Lozano | 6d45a98 | 2020-09-09 09:08:44 -0400 | [diff] [blame] | 67 | // Prepend the lld flags from cc_config so we stay in sync with cc |
| 68 | return "${config.DeviceGlobalLinkFlags} ${cc_config.Arm64Lldflags} ${config.Arm64ToolchainLinkFlags}" |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | func (t *toolchainArm64) ToolchainRustFlags() string { |
| 72 | return t.toolchainRustFlags |
| 73 | } |
| 74 | |
| 75 | func (t *toolchainArm64) RustFlags() string { |
| 76 | return "${config.Arm64ToolchainRustFlags}" |
| 77 | } |
| 78 | |
| 79 | func (t *toolchainArm64) Supported() bool { |
| 80 | return true |
| 81 | } |
| 82 | |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 83 | func (toolchainArm64) LibclangRuntimeLibraryArch() string { |
| 84 | return "aarch64" |
| 85 | } |
| 86 | |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 87 | func Arm64ToolchainFactory(arch android.Arch) Toolchain { |
Jiyong Park | 4afa2e2 | 2020-07-13 15:43:45 +0900 | [diff] [blame] | 88 | archVariant := arch.ArchVariant |
| 89 | if archVariant == "" { |
| 90 | // arch variants defaults to armv8-a. This is mostly for |
| 91 | // the host target which borrows toolchain configs from here. |
| 92 | archVariant = "armv8-a" |
| 93 | } |
| 94 | |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 95 | toolchainRustFlags := []string{ |
| 96 | "${config.Arm64ToolchainRustFlags}", |
Jiyong Park | 4afa2e2 | 2020-07-13 15:43:45 +0900 | [diff] [blame] | 97 | "${config.Arm64" + archVariant + "VariantRustFlags}", |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | toolchainRustFlags = append(toolchainRustFlags, deviceGlobalRustFlags...) |
| 101 | |
| 102 | for _, feature := range arch.ArchFeatures { |
| 103 | toolchainRustFlags = append(toolchainRustFlags, Arm64ArchFeatureRustFlags[feature]...) |
| 104 | } |
| 105 | |
| 106 | return &toolchainArm64{ |
| 107 | toolchainRustFlags: strings.Join(toolchainRustFlags, " "), |
| 108 | } |
| 109 | } |