Add rust musl arm and arm64 toolchains

Add rust toolchain configurations for arm-linux-musleabihf and
aarch64-linux-musl.

Bug: 236052820
Test: builds with linux musl arm64 host cross configured
Change-Id: Icfa73a75eac710e955f71a073cb4b7bb1cdfcc7a
This commit is contained in:
Colin Cross 2022-06-24 18:42:32 -07:00
parent 88a029f710
commit 1faf82305a
3 changed files with 154 additions and 6 deletions

View file

@ -11,6 +11,7 @@ bootstrap_go_package {
],
srcs: [
"arm_device.go",
"arm_linux_host.go",
"arm64_device.go",
"global.go",
"lints.go",

View file

@ -0,0 +1,147 @@
// Copyright 2022 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package config
import (
"strings"
"android/soong/android"
)
var (
linuxArmRustflags = []string{}
linuxArmLinkflags = []string{}
linuxArm64Rustflags = []string{}
linuxArm64Linkflags = []string{}
)
func init() {
registerToolchainFactory(android.LinuxMusl, android.Arm64, linuxMuslArm64ToolchainFactory)
registerToolchainFactory(android.LinuxMusl, android.Arm, linuxMuslArmToolchainFactory)
pctx.StaticVariable("LinuxToolchainArmRustFlags", strings.Join(linuxArmRustflags, " "))
pctx.StaticVariable("LinuxToolchainArmLinkFlags", strings.Join(linuxArmLinkflags, " "))
pctx.StaticVariable("LinuxToolchainArm64RustFlags", strings.Join(linuxArm64Rustflags, " "))
pctx.StaticVariable("LinuxToolchainArm64LinkFlags", strings.Join(linuxArm64Linkflags, " "))
}
// Base 64-bit linux rust toolchain
type toolchainLinuxArm64 struct {
toolchain64Bit
}
func (toolchainLinuxArm64) Supported() bool {
return true
}
func (toolchainLinuxArm64) Bionic() bool {
return false
}
func (t *toolchainLinuxArm64) Name() string {
return "arm64"
}
func (t *toolchainLinuxArm64) ToolchainLinkFlags() string {
// Prepend the lld flags from cc_config so we stay in sync with cc
return "${cc_config.LinuxLldflags} ${cc_config.LinuxArm64Lldflags} " +
"${config.LinuxToolchainLinkFlags} ${config.LinuxToolchainArm64LinkFlags}"
}
func (t *toolchainLinuxArm64) ToolchainRustFlags() string {
return "${config.LinuxToolchainRustFlags} ${config.LinuxToolchainArm64RustFlags}"
}
// Specialization of the 64-bit linux rust toolchain for musl. Adds the musl rust triple and
// linker flags to avoid using the host sysroot.
type toolchainLinuxMuslArm64 struct {
toolchainLinuxArm64
}
func (t *toolchainLinuxMuslArm64) RustTriple() string {
return "aarch64-unknown-linux-musl"
}
func (t *toolchainLinuxMuslArm64) ToolchainLinkFlags() string {
return t.toolchainLinuxArm64.ToolchainLinkFlags() + " " + "${config.LinuxMuslToolchainLinkFlags}"
}
func (t *toolchainLinuxMuslArm64) ToolchainRustFlags() string {
return t.toolchainLinuxArm64.ToolchainRustFlags() + " " + "${config.LinuxMuslToolchainRustFlags}"
}
func linuxMuslArm64ToolchainFactory(arch android.Arch) Toolchain {
return toolchainLinuxMuslArm64Singleton
}
// Base 32-bit linux rust toolchain
type toolchainLinuxArm struct {
toolchain32Bit
}
func (toolchainLinuxArm) Supported() bool {
return true
}
func (toolchainLinuxArm) Bionic() bool {
return false
}
func (t *toolchainLinuxArm) Name() string {
return "arm"
}
func (toolchainLinuxArm) LibclangRuntimeLibraryArch() string {
return "arm"
}
func (toolchainLinuxArm64) LibclangRuntimeLibraryArch() string {
return "arm64"
}
func (t *toolchainLinuxArm) ToolchainLinkFlags() string {
// Prepend the lld flags from cc_config so we stay in sync with cc
return "${cc_config.LinuxLldflags} ${cc_config.LinuxArmLldflags} " +
"${config.LinuxToolchainLinkFlags} ${config.LinuxToolchainArmLinkFlags}"
}
func (t *toolchainLinuxArm) ToolchainRustFlags() string {
return "${config.LinuxToolchainRustFlags} ${config.LinuxToolchainArmRustFlags}"
}
// Specialization of the 32-bit linux rust toolchain for musl. Adds the musl rust triple and
// linker flags to avoid using the host sysroot.
type toolchainLinuxMuslArm struct {
toolchainLinuxArm
}
func (t *toolchainLinuxMuslArm) RustTriple() string {
return "arm-unknown-linux-musleabihf"
}
func (t *toolchainLinuxMuslArm) ToolchainLinkFlags() string {
return t.toolchainLinuxArm.ToolchainLinkFlags() + " " + "${config.LinuxMuslToolchainLinkFlags}"
}
func (t *toolchainLinuxMuslArm) ToolchainRustFlags() string {
return t.toolchainLinuxArm.ToolchainRustFlags() + " " + "${config.LinuxMuslToolchainRustFlags}"
}
func linuxMuslArmToolchainFactory(arch android.Arch) Toolchain {
return toolchainLinuxMuslArmSingleton
}
var toolchainLinuxMuslArm64Singleton Toolchain = &toolchainLinuxMuslArm64{}
var toolchainLinuxMuslArmSingleton Toolchain = &toolchainLinuxMuslArm{}

View file

@ -174,7 +174,7 @@ func (sanitize *sanitize) begin(ctx BaseModuleContext) {
}
// Enable Memtag for all components in the include paths (for Aarch64 only)
if ctx.Arch().ArchType == android.Arm64 {
if ctx.Arch().ArchType == android.Arm64 && ctx.Os().Bionic() {
if ctx.Config().MemtagHeapSyncEnabledForPath(ctx.ModuleDir()) {
if s.Memtag_heap == nil {
s.Memtag_heap = proptools.BoolPtr(true)
@ -200,7 +200,7 @@ func (sanitize *sanitize) begin(ctx BaseModuleContext) {
}
// HWASan requires AArch64 hardware feature (top-byte-ignore).
if ctx.Arch().ArchType != android.Arm64 {
if ctx.Arch().ArchType != android.Arm64 || !ctx.Os().Bionic() {
s.Hwaddress = nil
}
@ -215,7 +215,7 @@ func (sanitize *sanitize) begin(ctx BaseModuleContext) {
}
// Memtag_heap is only implemented on AArch64.
if ctx.Arch().ArchType != android.Arm64 {
if ctx.Arch().ArchType != android.Arm64 || !ctx.Os().Bionic() {
s.Memtag_heap = nil
}
@ -234,7 +234,7 @@ func (sanitize *sanitize) flags(ctx ModuleContext, flags Flags, deps PathDeps) (
}
if Bool(sanitize.Properties.Sanitize.Fuzzer) {
flags.RustFlags = append(flags.RustFlags, fuzzerFlags...)
if ctx.Arch().ArchType == android.Arm64 {
if ctx.Arch().ArchType == android.Arm64 && ctx.Os().Bionic() {
flags.RustFlags = append(flags.RustFlags, hwasanFlags...)
} else {
flags.RustFlags = append(flags.RustFlags, asanFlags...)
@ -282,13 +282,13 @@ func rustSanitizerRuntimeMutator(mctx android.BottomUpMutatorContext) {
var deps []string
if mod.IsSanitizerEnabled(cc.Asan) ||
(mod.IsSanitizerEnabled(cc.Fuzzer) && mctx.Arch().ArchType != android.Arm64) {
(mod.IsSanitizerEnabled(cc.Fuzzer) && (mctx.Arch().ArchType != android.Arm64 || !mctx.Os().Bionic())) {
variations = append(variations,
blueprint.Variation{Mutator: "link", Variation: "shared"})
depTag = cc.SharedDepTag()
deps = []string{config.LibclangRuntimeLibrary(mod.toolchain(mctx), "asan")}
} else if mod.IsSanitizerEnabled(cc.Hwasan) ||
(mod.IsSanitizerEnabled(cc.Fuzzer) && mctx.Arch().ArchType == android.Arm64) {
(mod.IsSanitizerEnabled(cc.Fuzzer) && mctx.Arch().ArchType == android.Arm64 && mctx.Os().Bionic()) {
// TODO(b/204776996): HWASan for static Rust binaries isn't supported yet.
if binary, ok := mod.compiler.(binaryInterface); ok {
if binary.staticallyLinked() {