Colin Cross | f05b0d3 | 2022-07-14 18:10:34 -0700 | [diff] [blame] | 1 | // Copyright 2022 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 | |
| 15 | package config |
| 16 | |
| 17 | import ( |
| 18 | "fmt" |
| 19 | "strings" |
| 20 | |
| 21 | "android/soong/android" |
| 22 | ) |
| 23 | |
| 24 | var ( |
| 25 | riscv64Cflags = []string{ |
Elliott Hughes | c260046 | 2024-03-18 19:37:13 +0000 | [diff] [blame] | 26 | // Help catch common 32/64-bit errors. (This is duplicated in all 64-bit |
| 27 | // architectures' cflags.) |
Colin Cross | f05b0d3 | 2022-07-14 18:10:34 -0700 | [diff] [blame] | 28 | "-Werror=implicit-function-declaration", |
Elliott Hughes | c260046 | 2024-03-18 19:37:13 +0000 | [diff] [blame] | 29 | // This is already the driver's Android default, but duplicated here (and |
| 30 | // below) for ease of experimentation with additional extensions. |
Elliott Hughes | 726b001 | 2023-09-14 18:12:18 +0000 | [diff] [blame] | 31 | "-march=rv64gcv_zba_zbb_zbs", |
Elliott Hughes | c260046 | 2024-03-18 19:37:13 +0000 | [diff] [blame] | 32 | // TODO: move to driver (https://github.com/google/android-riscv64/issues/111) |
Pirama Arumuga Nainar | 0593537 | 2024-03-18 18:12:43 +0000 | [diff] [blame^] | 33 | "-mno-strict-align", |
Elliott Hughes | c260046 | 2024-03-18 19:37:13 +0000 | [diff] [blame] | 34 | // TODO: remove when qemu V works (https://gitlab.com/qemu-project/qemu/-/issues/1976) |
| 35 | // (Note that we'll probably want to wait for berberis to be good enough |
| 36 | // that most people don't care about qemu's V performance either!) |
Elliott Hughes | 6c93f69 | 2024-01-22 11:00:52 -0800 | [diff] [blame] | 37 | "-mno-implicit-float", |
Elliott Hughes | c260046 | 2024-03-18 19:37:13 +0000 | [diff] [blame] | 38 | // TODO: remove when clang default changed (https://github.com/google/android-riscv64/issues/124) |
AdityaK | 431c0b9 | 2024-01-19 07:31:29 -0800 | [diff] [blame] | 39 | "-mllvm -jump-is-expensive=false", |
Colin Cross | f05b0d3 | 2022-07-14 18:10:34 -0700 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | riscv64ArchVariantCflags = map[string][]string{} |
| 43 | |
| 44 | riscv64Ldflags = []string{ |
Elliott Hughes | c260046 | 2024-03-18 19:37:13 +0000 | [diff] [blame] | 45 | // TODO: sysv hashes are the default for other architectures because gnu |
| 46 | // hashes weren't supported until api level 23, but riscv64 didn't exist |
| 47 | // back then, and could move today... |
| 48 | // https://android.googlesource.com/platform/bionic/+/main/android-changes-for-ndk-developers.md#gnu-hashes-availible-in-api-level-23 |
Colin Cross | f05b0d3 | 2022-07-14 18:10:34 -0700 | [diff] [blame] | 49 | "-Wl,--hash-style=gnu", |
Elliott Hughes | c260046 | 2024-03-18 19:37:13 +0000 | [diff] [blame] | 50 | // This is already the driver's Android default, but duplicated here (and |
| 51 | // above) for ease of experimentation with additional extensions. |
Elliott Hughes | 726b001 | 2023-09-14 18:12:18 +0000 | [diff] [blame] | 52 | "-march=rv64gcv_zba_zbb_zbs", |
Elliott Hughes | c260046 | 2024-03-18 19:37:13 +0000 | [diff] [blame] | 53 | // TODO: move to driver (https://github.com/google/android-riscv64/issues/111) |
Pirama Arumuga Nainar | 0593537 | 2024-03-18 18:12:43 +0000 | [diff] [blame^] | 54 | "-mno-strict-align", |
Elliott Hughes | c260046 | 2024-03-18 19:37:13 +0000 | [diff] [blame] | 55 | // TODO: remove when clang default changed (https://github.com/google/android-riscv64/issues/124) |
AdityaK | 431c0b9 | 2024-01-19 07:31:29 -0800 | [diff] [blame] | 56 | "-Wl,-mllvm -Wl,-jump-is-expensive=false", |
Colin Cross | f05b0d3 | 2022-07-14 18:10:34 -0700 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | riscv64Lldflags = append(riscv64Ldflags, |
AdityaK | f7c0afd | 2023-02-10 09:50:39 -0800 | [diff] [blame] | 60 | "-Wl,-z,max-page-size=4096", |
AdityaK | f7c0afd | 2023-02-10 09:50:39 -0800 | [diff] [blame] | 61 | ) |
Colin Cross | f05b0d3 | 2022-07-14 18:10:34 -0700 | [diff] [blame] | 62 | |
| 63 | riscv64Cppflags = []string{} |
| 64 | |
| 65 | riscv64CpuVariantCflags = map[string][]string{} |
| 66 | ) |
| 67 | |
| 68 | const () |
| 69 | |
| 70 | func init() { |
| 71 | |
| 72 | exportedVars.ExportStringListStaticVariable("Riscv64Ldflags", riscv64Ldflags) |
| 73 | exportedVars.ExportStringListStaticVariable("Riscv64Lldflags", riscv64Lldflags) |
| 74 | |
| 75 | exportedVars.ExportStringListStaticVariable("Riscv64Cflags", riscv64Cflags) |
| 76 | exportedVars.ExportStringListStaticVariable("Riscv64Cppflags", riscv64Cppflags) |
| 77 | |
| 78 | exportedVars.ExportVariableReferenceDict("Riscv64ArchVariantCflags", riscv64ArchVariantCflagsVar) |
| 79 | exportedVars.ExportVariableReferenceDict("Riscv64CpuVariantCflags", riscv64CpuVariantCflagsVar) |
| 80 | exportedVars.ExportVariableReferenceDict("Riscv64CpuVariantLdflags", riscv64CpuVariantLdflags) |
| 81 | } |
| 82 | |
| 83 | var ( |
| 84 | riscv64ArchVariantCflagsVar = map[string]string{} |
| 85 | |
| 86 | riscv64CpuVariantCflagsVar = map[string]string{} |
| 87 | |
| 88 | riscv64CpuVariantLdflags = map[string]string{} |
| 89 | ) |
| 90 | |
| 91 | type toolchainRiscv64 struct { |
| 92 | toolchainBionic |
| 93 | toolchain64Bit |
| 94 | |
| 95 | ldflags string |
| 96 | lldflags string |
| 97 | toolchainCflags string |
| 98 | } |
| 99 | |
| 100 | func (t *toolchainRiscv64) Name() string { |
| 101 | return "riscv64" |
| 102 | } |
| 103 | |
| 104 | func (t *toolchainRiscv64) IncludeFlags() string { |
| 105 | return "" |
| 106 | } |
| 107 | |
| 108 | func (t *toolchainRiscv64) ClangTriple() string { |
| 109 | return "riscv64-linux-android" |
| 110 | } |
| 111 | |
| 112 | func (t *toolchainRiscv64) Cflags() string { |
| 113 | return "${config.Riscv64Cflags}" |
| 114 | } |
| 115 | |
| 116 | func (t *toolchainRiscv64) Cppflags() string { |
| 117 | return "${config.Riscv64Cppflags}" |
| 118 | } |
| 119 | |
| 120 | func (t *toolchainRiscv64) Ldflags() string { |
| 121 | return t.ldflags |
| 122 | } |
| 123 | |
| 124 | func (t *toolchainRiscv64) Lldflags() string { |
| 125 | return t.lldflags |
| 126 | } |
| 127 | |
| 128 | func (t *toolchainRiscv64) ToolchainCflags() string { |
| 129 | return t.toolchainCflags |
| 130 | } |
| 131 | |
| 132 | func (toolchainRiscv64) LibclangRuntimeLibraryArch() string { |
| 133 | return "riscv64" |
| 134 | } |
| 135 | |
| 136 | func riscv64ToolchainFactory(arch android.Arch) Toolchain { |
| 137 | switch arch.ArchVariant { |
| 138 | case "": |
| 139 | default: |
| 140 | panic(fmt.Sprintf("Unknown Riscv64 architecture version: %q", arch.ArchVariant)) |
| 141 | } |
| 142 | |
| 143 | toolchainCflags := []string{riscv64ArchVariantCflagsVar[arch.ArchVariant]} |
| 144 | toolchainCflags = append(toolchainCflags, |
| 145 | variantOrDefault(riscv64CpuVariantCflagsVar, arch.CpuVariant)) |
| 146 | |
| 147 | extraLdflags := variantOrDefault(riscv64CpuVariantLdflags, arch.CpuVariant) |
| 148 | return &toolchainRiscv64{ |
| 149 | ldflags: strings.Join([]string{ |
| 150 | "${config.Riscv64Ldflags}", |
| 151 | extraLdflags, |
| 152 | }, " "), |
| 153 | lldflags: strings.Join([]string{ |
| 154 | "${config.Riscv64Lldflags}", |
| 155 | extraLdflags, |
| 156 | }, " "), |
| 157 | toolchainCflags: strings.Join(toolchainCflags, " "), |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | func init() { |
| 162 | registerToolchainFactory(android.Android, android.Riscv64, riscv64ToolchainFactory) |
| 163 | } |