From e4793bc73f077191226d189996b7189ebced4add Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Thu, 9 Feb 2023 21:15:47 +0000 Subject: [PATCH] Allow SCS for riscv64 too. Bug: https://github.com/google/android-riscv64/issues/55 Test: treehugger Change-Id: I319fc662c1dd6083757f78b8d91ec2775ef94a46 --- cc/config/riscv64_device.go | 4 ++++ cc/sanitize.go | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/cc/config/riscv64_device.go b/cc/config/riscv64_device.go index 67208b261..194b242ed 100644 --- a/cc/config/riscv64_device.go +++ b/cc/config/riscv64_device.go @@ -26,12 +26,16 @@ var ( // Help catch common 32/64-bit errors. "-Werror=implicit-function-declaration", "-fno-emulated-tls", + // For -fsanitize=shadow-call-stack. + "-ffixed-x18", } riscv64ArchVariantCflags = map[string][]string{} riscv64Ldflags = []string{ "-Wl,--hash-style=gnu", + // For -fsanitize=shadow-call-stack. + "-ffixed-x18", } riscv64Lldflags = append(riscv64Ldflags, diff --git a/cc/sanitize.go b/cc/sanitize.go index 66f459abe..a31a35895 100644 --- a/cc/sanitize.go +++ b/cc/sanitize.go @@ -254,7 +254,7 @@ type SanitizeUserProps struct { // This should not be used in Android 11+ : https://source.android.com/devices/tech/debug/scudo // deprecated Scudo *bool `android:"arch_variant"` - // shadow-call-stack sanitizer, only available on arm64 + // shadow-call-stack sanitizer, only available on arm64/riscv64. Scs *bool `android:"arch_variant"` // Memory-tagging, only available on arm64 // if diag.memtag unset or false, enables async memory tagging @@ -593,8 +593,8 @@ func (sanitize *sanitize) begin(ctx BaseModuleContext) { s.Hwaddress = nil } - // SCS is only implemented on AArch64. - if ctx.Arch().ArchType != android.Arm64 || !ctx.toolchain().Bionic() { + // SCS is only implemented on AArch64/riscv64. + if (ctx.Arch().ArchType != android.Arm64 && ctx.Arch().ArchType != android.Riscv64) || !ctx.toolchain().Bionic() { s.Scs = nil }