[llvm] [clang] [RISCV] Add support for RISC-V Pointer Masking (PR #79929)
https://github.com/jaidTw commented: Should you also update the `riscv32-toolchain-extra.c` and `riscv64-toolchain-extra.c`? LGTM otherwise https://github.com/llvm/llvm-project/pull/79929 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [RISCV] Add support for RISC-V Pointer Masking (PR #79929)
jaidTw wrote: > > Should you also update the riscv32-toolchain-extra.c and > > riscv64-toolchain-extra.c? > > It is not immediately obvious to me what you had in mind for changing those > tests. Could you please clarify? I found I messed up the configuration so there were some test errors on my end. It works after I fixed it, never mind https://github.com/llvm/llvm-project/pull/79929 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [RISCV] Add support for RISC-V Pointer Masking (PR #79929)
https://github.com/jaidTw approved this pull request. https://github.com/llvm/llvm-project/pull/79929 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [RISCV] Support Zama16b1p0 (PR #88474)
https://github.com/jaidTw created https://github.com/llvm/llvm-project/pull/88474 This patch adds the support for Zama16b version 1.0, which has been added to RVA23U64 optional extensions recently Ref: [rva23-profile](https://github.com/riscv/riscv-profiles/blob/097819c2c668cbf693c80b8d25085462826d07d4/rva23-profile.adoc) >From 59b52163ff321d39128006c37ee38380ef5f9eec Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Thu, 11 Apr 2024 23:05:23 -0700 Subject: [PATCH] [RISCV] Support Zama16b1p0 This patch adds the support for Zama16b, which has been added to RVA23U64 optional extensions recently --- clang/test/Preprocessor/riscv-target-features.c | 7 +++ llvm/lib/Support/RISCVISAInfo.cpp | 1 + llvm/lib/Target/RISCV/RISCVFeatures.td | 7 +++ llvm/test/CodeGen/RISCV/attributes.ll | 4 llvm/test/MC/RISCV/attribute-arch.s | 3 +++ llvm/unittests/Support/RISCVISAInfoTest.cpp | 1 + 6 files changed, 23 insertions(+) diff --git a/clang/test/Preprocessor/riscv-target-features.c b/clang/test/Preprocessor/riscv-target-features.c index ec7764bb538189..21ad0b4e3d762c 100644 --- a/clang/test/Preprocessor/riscv-target-features.c +++ b/clang/test/Preprocessor/riscv-target-features.c @@ -79,6 +79,7 @@ // CHECK-NOT: __riscv_za128rs {{.*$}} // CHECK-NOT: __riscv_za64rs {{.*$}} // CHECK-NOT: __riscv_zacas {{.*$}} +// CHECK-NOT: __riscv_zama16b {{.*$}} // CHECK-NOT: __riscv_zawrs {{.*$}} // CHECK-NOT: __riscv_zba {{.*$}} // CHECK-NOT: __riscv_zbb {{.*$}} @@ -704,6 +705,12 @@ // RUN: -o - | FileCheck --check-prefix=CHECK-ZACAS-EXT %s // CHECK-ZACAS-EXT: __riscv_zacas 100{{$}} +// RUN: %clang --target=riscv32 -march=rv32izama16b -x c -E -dM %s \ +// RUN: -o - | FileCheck --check-prefix=CHECK-ZAMA16B-EXT %s +// RUN: %clang --target=riscv64 -march=rv64izama16b -x c -E -dM %s \ +// RUN: -o - | FileCheck --check-prefix=CHECK-ZAMA16B-EXT %s +// CHECK-ZAMA16B-EXT: __riscv_zama16b 100{{$}} + // RUN: %clang --target=riscv32-unknown-linux-gnu \ // RUN: -march=rv32izawrs -E -dM %s \ // RUN: -o - | FileCheck --check-prefix=CHECK-ZAWRS-EXT %s diff --git a/llvm/lib/Support/RISCVISAInfo.cpp b/llvm/lib/Support/RISCVISAInfo.cpp index 7a19d24d1ff483..e047da1f9eeb3c 100644 --- a/llvm/lib/Support/RISCVISAInfo.cpp +++ b/llvm/lib/Support/RISCVISAInfo.cpp @@ -119,6 +119,7 @@ static const RISCVSupportedExtension SupportedExtensions[] = { {"za128rs", {1, 0}}, {"za64rs", {1, 0}}, {"zacas", {1, 0}}, +{"zama16b", {1, 0}}, {"zawrs", {1, 0}}, {"zba", {1, 0}}, diff --git a/llvm/lib/Target/RISCV/RISCVFeatures.td b/llvm/lib/Target/RISCV/RISCVFeatures.td index 794455aa730400..84d3176deeb952 100644 --- a/llvm/lib/Target/RISCV/RISCVFeatures.td +++ b/llvm/lib/Target/RISCV/RISCVFeatures.td @@ -208,6 +208,13 @@ def HasStdExtAOrZalrsc "'A' (Atomic Instructions) or " "'Zalrsc' (Load-Reserved/Store-Conditional)">; +def FeatureStdExtZama16b +: SubtargetFeature<"zama16b", "HasStdExtZama16b", "true", + "'Zama16b' (Atomic 16-byte misaligned loads, stores and AMOs)">; +def HasStdExtZama16b : Predicate<"Subtarget->hasStdExtZama16b()">, + AssemblerPredicate<(all_of FeatureStdExtZama16b), + "'Zama16b' (Atomic 16-byte misaligned loads, stores and AMOs)">; + def FeatureStdExtZawrs : SubtargetFeature<"zawrs", "HasStdExtZawrs", "true", "'Zawrs' (Wait on Reservation Set)">; def HasStdExtZawrs : Predicate<"Subtarget->hasStdExtZawrs()">, diff --git a/llvm/test/CodeGen/RISCV/attributes.ll b/llvm/test/CodeGen/RISCV/attributes.ll index 2326599bf35136..080783fdeec024 100644 --- a/llvm/test/CodeGen/RISCV/attributes.ll +++ b/llvm/test/CodeGen/RISCV/attributes.ll @@ -115,6 +115,7 @@ ; RUN: llc -mtriple=riscv32 -mattr=+zacas %s -o - | FileCheck --check-prefix=RV32ZACAS %s ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zalasr %s -o - | FileCheck --check-prefix=RV32ZALASR %s ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zalrsc %s -o - | FileCheck --check-prefix=RV32ZALRSC %s +; RUN: llc -mtriple=riscv32 -mattr=+zama16b %s -o - | FileCheck --check-prefixes=CHECK,RV32ZAMA16B %s ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zicfilp %s -o - | FileCheck --check-prefix=RV32ZICFILP %s ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zabha %s -o - | FileCheck --check-prefix=RV32ZABHA %s ; RUN: llc -mtriple=riscv32 -mattr=+experimental-ssnpm %s -o - | FileCheck --check-prefix=RV32SSNPM %s @@ -199,6 +200,7 @@ ; RUN: llc -mtriple=riscv64 -mattr=+xtheadvdot %s -o - | FileCheck --check-prefixes=CHECK,RV64XTHEADVDOT %s ; RUN: llc -mtriple=riscv64 -mattr=+za64rs %s -o - | FileCheck --check-prefixes=CHECK,RV64ZA64RS %s ; RUN: llc -mtriple=riscv64 -mattr=+za128rs %s -o - | FileCheck --check-prefixes=CHECK,RV64ZA128RS %s +; RUN: llc -mtriple=riscv64 -mattr=+zama16b %s -o - | Fil
[clang] [llvm] [RISCV] Support Zama16b1p0 (PR #88474)
https://github.com/jaidTw updated https://github.com/llvm/llvm-project/pull/88474 >From 59b52163ff321d39128006c37ee38380ef5f9eec Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Thu, 11 Apr 2024 23:05:23 -0700 Subject: [PATCH 1/2] [RISCV] Support Zama16b1p0 This patch adds the support for Zama16b, which has been added to RVA23U64 optional extensions recently --- clang/test/Preprocessor/riscv-target-features.c | 7 +++ llvm/lib/Support/RISCVISAInfo.cpp | 1 + llvm/lib/Target/RISCV/RISCVFeatures.td | 7 +++ llvm/test/CodeGen/RISCV/attributes.ll | 4 llvm/test/MC/RISCV/attribute-arch.s | 3 +++ llvm/unittests/Support/RISCVISAInfoTest.cpp | 1 + 6 files changed, 23 insertions(+) diff --git a/clang/test/Preprocessor/riscv-target-features.c b/clang/test/Preprocessor/riscv-target-features.c index ec7764bb538189..21ad0b4e3d762c 100644 --- a/clang/test/Preprocessor/riscv-target-features.c +++ b/clang/test/Preprocessor/riscv-target-features.c @@ -79,6 +79,7 @@ // CHECK-NOT: __riscv_za128rs {{.*$}} // CHECK-NOT: __riscv_za64rs {{.*$}} // CHECK-NOT: __riscv_zacas {{.*$}} +// CHECK-NOT: __riscv_zama16b {{.*$}} // CHECK-NOT: __riscv_zawrs {{.*$}} // CHECK-NOT: __riscv_zba {{.*$}} // CHECK-NOT: __riscv_zbb {{.*$}} @@ -704,6 +705,12 @@ // RUN: -o - | FileCheck --check-prefix=CHECK-ZACAS-EXT %s // CHECK-ZACAS-EXT: __riscv_zacas 100{{$}} +// RUN: %clang --target=riscv32 -march=rv32izama16b -x c -E -dM %s \ +// RUN: -o - | FileCheck --check-prefix=CHECK-ZAMA16B-EXT %s +// RUN: %clang --target=riscv64 -march=rv64izama16b -x c -E -dM %s \ +// RUN: -o - | FileCheck --check-prefix=CHECK-ZAMA16B-EXT %s +// CHECK-ZAMA16B-EXT: __riscv_zama16b 100{{$}} + // RUN: %clang --target=riscv32-unknown-linux-gnu \ // RUN: -march=rv32izawrs -E -dM %s \ // RUN: -o - | FileCheck --check-prefix=CHECK-ZAWRS-EXT %s diff --git a/llvm/lib/Support/RISCVISAInfo.cpp b/llvm/lib/Support/RISCVISAInfo.cpp index 7a19d24d1ff483..e047da1f9eeb3c 100644 --- a/llvm/lib/Support/RISCVISAInfo.cpp +++ b/llvm/lib/Support/RISCVISAInfo.cpp @@ -119,6 +119,7 @@ static const RISCVSupportedExtension SupportedExtensions[] = { {"za128rs", {1, 0}}, {"za64rs", {1, 0}}, {"zacas", {1, 0}}, +{"zama16b", {1, 0}}, {"zawrs", {1, 0}}, {"zba", {1, 0}}, diff --git a/llvm/lib/Target/RISCV/RISCVFeatures.td b/llvm/lib/Target/RISCV/RISCVFeatures.td index 794455aa730400..84d3176deeb952 100644 --- a/llvm/lib/Target/RISCV/RISCVFeatures.td +++ b/llvm/lib/Target/RISCV/RISCVFeatures.td @@ -208,6 +208,13 @@ def HasStdExtAOrZalrsc "'A' (Atomic Instructions) or " "'Zalrsc' (Load-Reserved/Store-Conditional)">; +def FeatureStdExtZama16b +: SubtargetFeature<"zama16b", "HasStdExtZama16b", "true", + "'Zama16b' (Atomic 16-byte misaligned loads, stores and AMOs)">; +def HasStdExtZama16b : Predicate<"Subtarget->hasStdExtZama16b()">, + AssemblerPredicate<(all_of FeatureStdExtZama16b), + "'Zama16b' (Atomic 16-byte misaligned loads, stores and AMOs)">; + def FeatureStdExtZawrs : SubtargetFeature<"zawrs", "HasStdExtZawrs", "true", "'Zawrs' (Wait on Reservation Set)">; def HasStdExtZawrs : Predicate<"Subtarget->hasStdExtZawrs()">, diff --git a/llvm/test/CodeGen/RISCV/attributes.ll b/llvm/test/CodeGen/RISCV/attributes.ll index 2326599bf35136..080783fdeec024 100644 --- a/llvm/test/CodeGen/RISCV/attributes.ll +++ b/llvm/test/CodeGen/RISCV/attributes.ll @@ -115,6 +115,7 @@ ; RUN: llc -mtriple=riscv32 -mattr=+zacas %s -o - | FileCheck --check-prefix=RV32ZACAS %s ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zalasr %s -o - | FileCheck --check-prefix=RV32ZALASR %s ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zalrsc %s -o - | FileCheck --check-prefix=RV32ZALRSC %s +; RUN: llc -mtriple=riscv32 -mattr=+zama16b %s -o - | FileCheck --check-prefixes=CHECK,RV32ZAMA16B %s ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zicfilp %s -o - | FileCheck --check-prefix=RV32ZICFILP %s ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zabha %s -o - | FileCheck --check-prefix=RV32ZABHA %s ; RUN: llc -mtriple=riscv32 -mattr=+experimental-ssnpm %s -o - | FileCheck --check-prefix=RV32SSNPM %s @@ -199,6 +200,7 @@ ; RUN: llc -mtriple=riscv64 -mattr=+xtheadvdot %s -o - | FileCheck --check-prefixes=CHECK,RV64XTHEADVDOT %s ; RUN: llc -mtriple=riscv64 -mattr=+za64rs %s -o - | FileCheck --check-prefixes=CHECK,RV64ZA64RS %s ; RUN: llc -mtriple=riscv64 -mattr=+za128rs %s -o - | FileCheck --check-prefixes=CHECK,RV64ZA128RS %s +; RUN: llc -mtriple=riscv64 -mattr=+zama16b %s -o - | FileCheck --check-prefixes=CHECK,RV64ZAMA16B %s ; RUN: llc -mtriple=riscv64 -mattr=+zawrs %s -o - | FileCheck --check-prefixes=CHECK,RV64ZAWRS %s ; RUN: llc -mtriple=riscv64 -mattr=+experimental-ztso %s -o - | FileCheck --check-prefixes=CH
[clang] [llvm] [RISCV] Support Zama16b1p0 (PR #88474)
https://github.com/jaidTw updated https://github.com/llvm/llvm-project/pull/88474 >From 59b52163ff321d39128006c37ee38380ef5f9eec Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Thu, 11 Apr 2024 23:05:23 -0700 Subject: [PATCH 1/3] [RISCV] Support Zama16b1p0 This patch adds the support for Zama16b, which has been added to RVA23U64 optional extensions recently --- clang/test/Preprocessor/riscv-target-features.c | 7 +++ llvm/lib/Support/RISCVISAInfo.cpp | 1 + llvm/lib/Target/RISCV/RISCVFeatures.td | 7 +++ llvm/test/CodeGen/RISCV/attributes.ll | 4 llvm/test/MC/RISCV/attribute-arch.s | 3 +++ llvm/unittests/Support/RISCVISAInfoTest.cpp | 1 + 6 files changed, 23 insertions(+) diff --git a/clang/test/Preprocessor/riscv-target-features.c b/clang/test/Preprocessor/riscv-target-features.c index ec7764bb538189..21ad0b4e3d762c 100644 --- a/clang/test/Preprocessor/riscv-target-features.c +++ b/clang/test/Preprocessor/riscv-target-features.c @@ -79,6 +79,7 @@ // CHECK-NOT: __riscv_za128rs {{.*$}} // CHECK-NOT: __riscv_za64rs {{.*$}} // CHECK-NOT: __riscv_zacas {{.*$}} +// CHECK-NOT: __riscv_zama16b {{.*$}} // CHECK-NOT: __riscv_zawrs {{.*$}} // CHECK-NOT: __riscv_zba {{.*$}} // CHECK-NOT: __riscv_zbb {{.*$}} @@ -704,6 +705,12 @@ // RUN: -o - | FileCheck --check-prefix=CHECK-ZACAS-EXT %s // CHECK-ZACAS-EXT: __riscv_zacas 100{{$}} +// RUN: %clang --target=riscv32 -march=rv32izama16b -x c -E -dM %s \ +// RUN: -o - | FileCheck --check-prefix=CHECK-ZAMA16B-EXT %s +// RUN: %clang --target=riscv64 -march=rv64izama16b -x c -E -dM %s \ +// RUN: -o - | FileCheck --check-prefix=CHECK-ZAMA16B-EXT %s +// CHECK-ZAMA16B-EXT: __riscv_zama16b 100{{$}} + // RUN: %clang --target=riscv32-unknown-linux-gnu \ // RUN: -march=rv32izawrs -E -dM %s \ // RUN: -o - | FileCheck --check-prefix=CHECK-ZAWRS-EXT %s diff --git a/llvm/lib/Support/RISCVISAInfo.cpp b/llvm/lib/Support/RISCVISAInfo.cpp index 7a19d24d1ff483..e047da1f9eeb3c 100644 --- a/llvm/lib/Support/RISCVISAInfo.cpp +++ b/llvm/lib/Support/RISCVISAInfo.cpp @@ -119,6 +119,7 @@ static const RISCVSupportedExtension SupportedExtensions[] = { {"za128rs", {1, 0}}, {"za64rs", {1, 0}}, {"zacas", {1, 0}}, +{"zama16b", {1, 0}}, {"zawrs", {1, 0}}, {"zba", {1, 0}}, diff --git a/llvm/lib/Target/RISCV/RISCVFeatures.td b/llvm/lib/Target/RISCV/RISCVFeatures.td index 794455aa730400..84d3176deeb952 100644 --- a/llvm/lib/Target/RISCV/RISCVFeatures.td +++ b/llvm/lib/Target/RISCV/RISCVFeatures.td @@ -208,6 +208,13 @@ def HasStdExtAOrZalrsc "'A' (Atomic Instructions) or " "'Zalrsc' (Load-Reserved/Store-Conditional)">; +def FeatureStdExtZama16b +: SubtargetFeature<"zama16b", "HasStdExtZama16b", "true", + "'Zama16b' (Atomic 16-byte misaligned loads, stores and AMOs)">; +def HasStdExtZama16b : Predicate<"Subtarget->hasStdExtZama16b()">, + AssemblerPredicate<(all_of FeatureStdExtZama16b), + "'Zama16b' (Atomic 16-byte misaligned loads, stores and AMOs)">; + def FeatureStdExtZawrs : SubtargetFeature<"zawrs", "HasStdExtZawrs", "true", "'Zawrs' (Wait on Reservation Set)">; def HasStdExtZawrs : Predicate<"Subtarget->hasStdExtZawrs()">, diff --git a/llvm/test/CodeGen/RISCV/attributes.ll b/llvm/test/CodeGen/RISCV/attributes.ll index 2326599bf35136..080783fdeec024 100644 --- a/llvm/test/CodeGen/RISCV/attributes.ll +++ b/llvm/test/CodeGen/RISCV/attributes.ll @@ -115,6 +115,7 @@ ; RUN: llc -mtriple=riscv32 -mattr=+zacas %s -o - | FileCheck --check-prefix=RV32ZACAS %s ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zalasr %s -o - | FileCheck --check-prefix=RV32ZALASR %s ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zalrsc %s -o - | FileCheck --check-prefix=RV32ZALRSC %s +; RUN: llc -mtriple=riscv32 -mattr=+zama16b %s -o - | FileCheck --check-prefixes=CHECK,RV32ZAMA16B %s ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zicfilp %s -o - | FileCheck --check-prefix=RV32ZICFILP %s ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zabha %s -o - | FileCheck --check-prefix=RV32ZABHA %s ; RUN: llc -mtriple=riscv32 -mattr=+experimental-ssnpm %s -o - | FileCheck --check-prefix=RV32SSNPM %s @@ -199,6 +200,7 @@ ; RUN: llc -mtriple=riscv64 -mattr=+xtheadvdot %s -o - | FileCheck --check-prefixes=CHECK,RV64XTHEADVDOT %s ; RUN: llc -mtriple=riscv64 -mattr=+za64rs %s -o - | FileCheck --check-prefixes=CHECK,RV64ZA64RS %s ; RUN: llc -mtriple=riscv64 -mattr=+za128rs %s -o - | FileCheck --check-prefixes=CHECK,RV64ZA128RS %s +; RUN: llc -mtriple=riscv64 -mattr=+zama16b %s -o - | FileCheck --check-prefixes=CHECK,RV64ZAMA16B %s ; RUN: llc -mtriple=riscv64 -mattr=+zawrs %s -o - | FileCheck --check-prefixes=CHECK,RV64ZAWRS %s ; RUN: llc -mtriple=riscv64 -mattr=+experimental-ztso %s -o - | FileCheck --check-prefixes=CH
[clang] [llvm] [RISCV] Support Zama16b1p0 (PR #88474)
https://github.com/jaidTw updated https://github.com/llvm/llvm-project/pull/88474 >From 59b52163ff321d39128006c37ee38380ef5f9eec Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Thu, 11 Apr 2024 23:05:23 -0700 Subject: [PATCH 1/4] [RISCV] Support Zama16b1p0 This patch adds the support for Zama16b, which has been added to RVA23U64 optional extensions recently --- clang/test/Preprocessor/riscv-target-features.c | 7 +++ llvm/lib/Support/RISCVISAInfo.cpp | 1 + llvm/lib/Target/RISCV/RISCVFeatures.td | 7 +++ llvm/test/CodeGen/RISCV/attributes.ll | 4 llvm/test/MC/RISCV/attribute-arch.s | 3 +++ llvm/unittests/Support/RISCVISAInfoTest.cpp | 1 + 6 files changed, 23 insertions(+) diff --git a/clang/test/Preprocessor/riscv-target-features.c b/clang/test/Preprocessor/riscv-target-features.c index ec7764bb538189..21ad0b4e3d762c 100644 --- a/clang/test/Preprocessor/riscv-target-features.c +++ b/clang/test/Preprocessor/riscv-target-features.c @@ -79,6 +79,7 @@ // CHECK-NOT: __riscv_za128rs {{.*$}} // CHECK-NOT: __riscv_za64rs {{.*$}} // CHECK-NOT: __riscv_zacas {{.*$}} +// CHECK-NOT: __riscv_zama16b {{.*$}} // CHECK-NOT: __riscv_zawrs {{.*$}} // CHECK-NOT: __riscv_zba {{.*$}} // CHECK-NOT: __riscv_zbb {{.*$}} @@ -704,6 +705,12 @@ // RUN: -o - | FileCheck --check-prefix=CHECK-ZACAS-EXT %s // CHECK-ZACAS-EXT: __riscv_zacas 100{{$}} +// RUN: %clang --target=riscv32 -march=rv32izama16b -x c -E -dM %s \ +// RUN: -o - | FileCheck --check-prefix=CHECK-ZAMA16B-EXT %s +// RUN: %clang --target=riscv64 -march=rv64izama16b -x c -E -dM %s \ +// RUN: -o - | FileCheck --check-prefix=CHECK-ZAMA16B-EXT %s +// CHECK-ZAMA16B-EXT: __riscv_zama16b 100{{$}} + // RUN: %clang --target=riscv32-unknown-linux-gnu \ // RUN: -march=rv32izawrs -E -dM %s \ // RUN: -o - | FileCheck --check-prefix=CHECK-ZAWRS-EXT %s diff --git a/llvm/lib/Support/RISCVISAInfo.cpp b/llvm/lib/Support/RISCVISAInfo.cpp index 7a19d24d1ff483..e047da1f9eeb3c 100644 --- a/llvm/lib/Support/RISCVISAInfo.cpp +++ b/llvm/lib/Support/RISCVISAInfo.cpp @@ -119,6 +119,7 @@ static const RISCVSupportedExtension SupportedExtensions[] = { {"za128rs", {1, 0}}, {"za64rs", {1, 0}}, {"zacas", {1, 0}}, +{"zama16b", {1, 0}}, {"zawrs", {1, 0}}, {"zba", {1, 0}}, diff --git a/llvm/lib/Target/RISCV/RISCVFeatures.td b/llvm/lib/Target/RISCV/RISCVFeatures.td index 794455aa730400..84d3176deeb952 100644 --- a/llvm/lib/Target/RISCV/RISCVFeatures.td +++ b/llvm/lib/Target/RISCV/RISCVFeatures.td @@ -208,6 +208,13 @@ def HasStdExtAOrZalrsc "'A' (Atomic Instructions) or " "'Zalrsc' (Load-Reserved/Store-Conditional)">; +def FeatureStdExtZama16b +: SubtargetFeature<"zama16b", "HasStdExtZama16b", "true", + "'Zama16b' (Atomic 16-byte misaligned loads, stores and AMOs)">; +def HasStdExtZama16b : Predicate<"Subtarget->hasStdExtZama16b()">, + AssemblerPredicate<(all_of FeatureStdExtZama16b), + "'Zama16b' (Atomic 16-byte misaligned loads, stores and AMOs)">; + def FeatureStdExtZawrs : SubtargetFeature<"zawrs", "HasStdExtZawrs", "true", "'Zawrs' (Wait on Reservation Set)">; def HasStdExtZawrs : Predicate<"Subtarget->hasStdExtZawrs()">, diff --git a/llvm/test/CodeGen/RISCV/attributes.ll b/llvm/test/CodeGen/RISCV/attributes.ll index 2326599bf35136..080783fdeec024 100644 --- a/llvm/test/CodeGen/RISCV/attributes.ll +++ b/llvm/test/CodeGen/RISCV/attributes.ll @@ -115,6 +115,7 @@ ; RUN: llc -mtriple=riscv32 -mattr=+zacas %s -o - | FileCheck --check-prefix=RV32ZACAS %s ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zalasr %s -o - | FileCheck --check-prefix=RV32ZALASR %s ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zalrsc %s -o - | FileCheck --check-prefix=RV32ZALRSC %s +; RUN: llc -mtriple=riscv32 -mattr=+zama16b %s -o - | FileCheck --check-prefixes=CHECK,RV32ZAMA16B %s ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zicfilp %s -o - | FileCheck --check-prefix=RV32ZICFILP %s ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zabha %s -o - | FileCheck --check-prefix=RV32ZABHA %s ; RUN: llc -mtriple=riscv32 -mattr=+experimental-ssnpm %s -o - | FileCheck --check-prefix=RV32SSNPM %s @@ -199,6 +200,7 @@ ; RUN: llc -mtriple=riscv64 -mattr=+xtheadvdot %s -o - | FileCheck --check-prefixes=CHECK,RV64XTHEADVDOT %s ; RUN: llc -mtriple=riscv64 -mattr=+za64rs %s -o - | FileCheck --check-prefixes=CHECK,RV64ZA64RS %s ; RUN: llc -mtriple=riscv64 -mattr=+za128rs %s -o - | FileCheck --check-prefixes=CHECK,RV64ZA128RS %s +; RUN: llc -mtriple=riscv64 -mattr=+zama16b %s -o - | FileCheck --check-prefixes=CHECK,RV64ZAMA16B %s ; RUN: llc -mtriple=riscv64 -mattr=+zawrs %s -o - | FileCheck --check-prefixes=CHECK,RV64ZAWRS %s ; RUN: llc -mtriple=riscv64 -mattr=+experimental-ztso %s -o - | FileCheck --check-prefixes=CH
[clang] [llvm] [RISCV] Support Zama16b1p0 (PR #88474)
@@ -119,6 +119,7 @@ on support follow. ``Za128rs`` Supported (`See note <#riscv-profiles-extensions-note>`__) ``Za64rs``Supported (`See note <#riscv-profiles-extensions-note>`__) ``Zacas`` Supported (`See note <#riscv-zacas-note>`__) + ``Zama16b`` Supported jaidTw wrote: Am I supposed to add the extension name into the list in `riscv-profiles-extensions-note`? Seems like not a extensions are listes there https://github.com/llvm/llvm-project/pull/88474 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [RISCV] Support Zama16b1p0 (PR #88474)
https://github.com/jaidTw edited https://github.com/llvm/llvm-project/pull/88474 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [RISCV] Support Zama16b1p0 (PR #88474)
https://github.com/jaidTw closed https://github.com/llvm/llvm-project/pull/88474 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [RISCV] Bump Pointer Masking extension version (PR #96715)
https://github.com/jaidTw approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/96715 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][RISCV] Support -fcf-protection=return for RISC-V (PR #112477)
https://github.com/jaidTw created https://github.com/llvm/llvm-project/pull/112477 This patches add a string attribute "hw-shadow-stack" to every function if `-fcf-protection=return` is set on RISC-V >From 2a7a6ef1b44f250abf840165bac4c91ca0af928b Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Sun, 13 Oct 2024 15:11:06 +0800 Subject: [PATCH] [Clang][RISCV] Support -fcf-protection=return for RISC-V --- clang/lib/Basic/Targets/RISCV.h | 6 ++ clang/lib/CodeGen/CodeGenFunction.cpp | 4 2 files changed, 10 insertions(+) diff --git a/clang/lib/Basic/Targets/RISCV.h b/clang/lib/Basic/Targets/RISCV.h index bf40edb8683b3e..3165623593fdf7 100644 --- a/clang/lib/Basic/Targets/RISCV.h +++ b/clang/lib/Basic/Targets/RISCV.h @@ -141,6 +141,12 @@ class RISCVTargetInfo : public TargetInfo { return true; } + bool checkCFProtectionReturnSupported(DiagnosticsEngine &Diags) const override { +if (ISAInfo->hasExtension("zimop")) + return true; +return TargetInfo::checkCFProtectionReturnSupported(Diags); + } + CFBranchLabelSchemeKind getDefaultCFBranchLabelScheme() const override { return CFBranchLabelSchemeKind::FuncSig; } diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index 2306043c90f406..d8f0f7c14f6b40 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -899,6 +899,10 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, if (CodeGenOpts.PointerAuth.IndirectGotos) Fn->addFnAttr("ptrauth-indirect-gotos"); + // Add return control flow integrity attributes. + if (CodeGenOpts.CFProtectionReturn) +Fn->addFnAttr("hw-shadow-stack"); + // Apply xray attributes to the function (as a string, for now) bool AlwaysXRayAttr = false; if (const auto *XRayAttr = D ? D->getAttr() : nullptr) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][RISCV] Support -fcf-protection=return for RISC-V (PR #112477)
https://github.com/jaidTw edited https://github.com/llvm/llvm-project/pull/112477 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][RISCV] Support -fcf-protection=return for RISC-V (PR #112477)
@@ -899,6 +899,10 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, if (CodeGenOpts.PointerAuth.IndirectGotos) Fn->addFnAttr("ptrauth-indirect-gotos"); + // Add return control flow integrity attributes. + if (CodeGenOpts.CFProtectionReturn) +Fn->addFnAttr("hw-shadow-stack"); + jaidTw wrote: Yeah nice catch, it definitely needs to check the arch https://github.com/llvm/llvm-project/pull/112477 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][RISCV] Support -fcf-protection=return for RISC-V (PR #112477)
https://github.com/jaidTw updated https://github.com/llvm/llvm-project/pull/112477 >From fe4a28fb691b69d9af384f1dc2f0667761adef44 Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Sun, 13 Oct 2024 15:11:06 +0800 Subject: [PATCH 1/2] [Clang][RISCV] Support -fcf-protection=return for RISC-V --- clang/lib/Basic/Targets/RISCV.h | 7 +++ clang/lib/CodeGen/CodeGenFunction.cpp | 4 2 files changed, 11 insertions(+) diff --git a/clang/lib/Basic/Targets/RISCV.h b/clang/lib/Basic/Targets/RISCV.h index bf40edb8683b3e..3f2cee72fc3731 100644 --- a/clang/lib/Basic/Targets/RISCV.h +++ b/clang/lib/Basic/Targets/RISCV.h @@ -141,6 +141,13 @@ class RISCVTargetInfo : public TargetInfo { return true; } + bool + checkCFProtectionReturnSupported(DiagnosticsEngine &Diags) const override { +if (ISAInfo->hasExtension("zimop")) + return true; +return TargetInfo::checkCFProtectionReturnSupported(Diags); + } + CFBranchLabelSchemeKind getDefaultCFBranchLabelScheme() const override { return CFBranchLabelSchemeKind::FuncSig; } diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index 2306043c90f406..d8f0f7c14f6b40 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -899,6 +899,10 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, if (CodeGenOpts.PointerAuth.IndirectGotos) Fn->addFnAttr("ptrauth-indirect-gotos"); + // Add return control flow integrity attributes. + if (CodeGenOpts.CFProtectionReturn) +Fn->addFnAttr("hw-shadow-stack"); + // Apply xray attributes to the function (as a string, for now) bool AlwaysXRayAttr = false; if (const auto *XRayAttr = D ? D->getAttr() : nullptr) { >From 7dc168af5758d130042c71ba5d6249c042bc356c Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Wed, 23 Oct 2024 14:42:35 +0800 Subject: [PATCH 2/2] [Clang][RISCV] Add RISCV check for hw-shadow-stack --- clang/lib/CodeGen/CodeGenFunction.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index d8f0f7c14f6b40..cca52f3769845e 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -899,8 +899,9 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, if (CodeGenOpts.PointerAuth.IndirectGotos) Fn->addFnAttr("ptrauth-indirect-gotos"); - // Add return control flow integrity attributes. - if (CodeGenOpts.CFProtectionReturn) + // Add return control flow integrity attributes for RISCV. + if (CodeGenOpts.CFProtectionReturn && + getContext().getTargetInfo().getTriple().isRISCV()) Fn->addFnAttr("hw-shadow-stack"); // Apply xray attributes to the function (as a string, for now) ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][RISCV] Support -fcf-protection=return for RISC-V (PR #112477)
https://github.com/jaidTw updated https://github.com/llvm/llvm-project/pull/112477 >From fe4a28fb691b69d9af384f1dc2f0667761adef44 Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Sun, 13 Oct 2024 15:11:06 +0800 Subject: [PATCH 1/2] [Clang][RISCV] Support -fcf-protection=return for RISC-V --- clang/lib/Basic/Targets/RISCV.h | 7 +++ clang/lib/CodeGen/CodeGenFunction.cpp | 4 2 files changed, 11 insertions(+) diff --git a/clang/lib/Basic/Targets/RISCV.h b/clang/lib/Basic/Targets/RISCV.h index bf40edb8683b3e..3f2cee72fc3731 100644 --- a/clang/lib/Basic/Targets/RISCV.h +++ b/clang/lib/Basic/Targets/RISCV.h @@ -141,6 +141,13 @@ class RISCVTargetInfo : public TargetInfo { return true; } + bool + checkCFProtectionReturnSupported(DiagnosticsEngine &Diags) const override { +if (ISAInfo->hasExtension("zimop")) + return true; +return TargetInfo::checkCFProtectionReturnSupported(Diags); + } + CFBranchLabelSchemeKind getDefaultCFBranchLabelScheme() const override { return CFBranchLabelSchemeKind::FuncSig; } diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index 2306043c90f406..d8f0f7c14f6b40 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -899,6 +899,10 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, if (CodeGenOpts.PointerAuth.IndirectGotos) Fn->addFnAttr("ptrauth-indirect-gotos"); + // Add return control flow integrity attributes. + if (CodeGenOpts.CFProtectionReturn) +Fn->addFnAttr("hw-shadow-stack"); + // Apply xray attributes to the function (as a string, for now) bool AlwaysXRayAttr = false; if (const auto *XRayAttr = D ? D->getAttr() : nullptr) { >From 449c0d9500243b76eeba32a4771a77f8c849542f Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Wed, 23 Oct 2024 14:42:35 +0800 Subject: [PATCH 2/2] [Clang][RISCV] Add RISCV check for hw-shadow-stack --- clang/lib/CodeGen/CodeGenFunction.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index d8f0f7c14f6b40..f25b9dc4752b4c 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -900,7 +900,8 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, Fn->addFnAttr("ptrauth-indirect-gotos"); // Add return control flow integrity attributes. - if (CodeGenOpts.CFProtectionReturn) + if (CodeGenOpts.CFProtectionReturn && + getContext().getTargetInfo().getTriple().isRISCV()) Fn->addFnAttr("hw-shadow-stack"); // Apply xray attributes to the function (as a string, for now) ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][RISCV] Support -fcf-protection=return for RISC-V (PR #112477)
https://github.com/jaidTw updated https://github.com/llvm/llvm-project/pull/112477 >From fe4a28fb691b69d9af384f1dc2f0667761adef44 Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Sun, 13 Oct 2024 15:11:06 +0800 Subject: [PATCH 1/4] [Clang][RISCV] Support -fcf-protection=return for RISC-V --- clang/lib/Basic/Targets/RISCV.h | 7 +++ clang/lib/CodeGen/CodeGenFunction.cpp | 4 2 files changed, 11 insertions(+) diff --git a/clang/lib/Basic/Targets/RISCV.h b/clang/lib/Basic/Targets/RISCV.h index bf40edb8683b3e..3f2cee72fc3731 100644 --- a/clang/lib/Basic/Targets/RISCV.h +++ b/clang/lib/Basic/Targets/RISCV.h @@ -141,6 +141,13 @@ class RISCVTargetInfo : public TargetInfo { return true; } + bool + checkCFProtectionReturnSupported(DiagnosticsEngine &Diags) const override { +if (ISAInfo->hasExtension("zimop")) + return true; +return TargetInfo::checkCFProtectionReturnSupported(Diags); + } + CFBranchLabelSchemeKind getDefaultCFBranchLabelScheme() const override { return CFBranchLabelSchemeKind::FuncSig; } diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index 2306043c90f406..d8f0f7c14f6b40 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -899,6 +899,10 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, if (CodeGenOpts.PointerAuth.IndirectGotos) Fn->addFnAttr("ptrauth-indirect-gotos"); + // Add return control flow integrity attributes. + if (CodeGenOpts.CFProtectionReturn) +Fn->addFnAttr("hw-shadow-stack"); + // Apply xray attributes to the function (as a string, for now) bool AlwaysXRayAttr = false; if (const auto *XRayAttr = D ? D->getAttr() : nullptr) { >From 7dc168af5758d130042c71ba5d6249c042bc356c Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Wed, 23 Oct 2024 14:42:35 +0800 Subject: [PATCH 2/4] [Clang][RISCV] Add RISCV check for hw-shadow-stack --- clang/lib/CodeGen/CodeGenFunction.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index d8f0f7c14f6b40..cca52f3769845e 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -899,8 +899,9 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, if (CodeGenOpts.PointerAuth.IndirectGotos) Fn->addFnAttr("ptrauth-indirect-gotos"); - // Add return control flow integrity attributes. - if (CodeGenOpts.CFProtectionReturn) + // Add return control flow integrity attributes for RISCV. + if (CodeGenOpts.CFProtectionReturn && + getContext().getTargetInfo().getTriple().isRISCV()) Fn->addFnAttr("hw-shadow-stack"); // Apply xray attributes to the function (as a string, for now) >From 42132c246058f6c1aaa646266847a3b8c854 Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Thu, 24 Oct 2024 15:39:07 +0800 Subject: [PATCH 3/4] [Clang][RISCV] Add function attribute in RISC-V specific code --- clang/lib/CodeGen/CodeGenFunction.cpp | 5 - clang/lib/CodeGen/Targets/RISCV.cpp | 7 +-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index cca52f3769845e..2306043c90f406 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -899,11 +899,6 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, if (CodeGenOpts.PointerAuth.IndirectGotos) Fn->addFnAttr("ptrauth-indirect-gotos"); - // Add return control flow integrity attributes for RISCV. - if (CodeGenOpts.CFProtectionReturn && - getContext().getTargetInfo().getTriple().isRISCV()) -Fn->addFnAttr("hw-shadow-stack"); - // Apply xray attributes to the function (as a string, for now) bool AlwaysXRayAttr = false; if (const auto *XRayAttr = D ? D->getAttr() : nullptr) { diff --git a/clang/lib/CodeGen/Targets/RISCV.cpp b/clang/lib/CodeGen/Targets/RISCV.cpp index fd72fe673b9b14..b04e436c665f52 100644 --- a/clang/lib/CodeGen/Targets/RISCV.cpp +++ b/clang/lib/CodeGen/Targets/RISCV.cpp @@ -594,6 +594,11 @@ class RISCVTargetCodeGenInfo : public TargetCodeGenInfo { const auto *FD = dyn_cast_or_null(D); if (!FD) return; +auto *Fn = cast(GV); + +if (CGM.getCodeGenOpts().CFProtectionReturn) + Fn->addFnAttr("hw-shadow-stack"); + const auto *Attr = FD->getAttr(); if (!Attr) return; @@ -604,8 +609,6 @@ class RISCVTargetCodeGenInfo : public TargetCodeGenInfo { case RISCVInterruptAttr::machine: Kind = "machine"; break; } -auto *Fn = cast(GV); - Fn->addFnAttr("interrupt", Kind); } }; >From 2b6bdc5e95043a0f481314c0c2e5441804addf06 Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Fri, 25 Oct 2024 14:13:45 +0800 Subject: [PATCH 4/4] [Clang] Add test for hw-shadodw-stack --- clang/test/CodeGen/RISCV/attr-hw-shadow-stack
[clang] [Clang][RISCV] Support -fcf-protection=return for RISC-V (PR #112477)
@@ -607,6 +607,9 @@ class RISCVTargetCodeGenInfo : public TargetCodeGenInfo { auto *Fn = cast(GV); Fn->addFnAttr("interrupt", Kind); + +if (CGM.getCodeGenOpts().CFProtectionReturn) jaidTw wrote: Fixed, thanks! https://github.com/llvm/llvm-project/pull/112477 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][RISCV] Support -fcf-protection=return for RISC-V (PR #112477)
jaidTw wrote: Addressed comments https://github.com/llvm/llvm-project/pull/112477 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][RISCV] Support -fcf-protection=return for RISC-V (PR #112477)
https://github.com/jaidTw updated https://github.com/llvm/llvm-project/pull/112477 >From fe4a28fb691b69d9af384f1dc2f0667761adef44 Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Sun, 13 Oct 2024 15:11:06 +0800 Subject: [PATCH 1/3] [Clang][RISCV] Support -fcf-protection=return for RISC-V --- clang/lib/Basic/Targets/RISCV.h | 7 +++ clang/lib/CodeGen/CodeGenFunction.cpp | 4 2 files changed, 11 insertions(+) diff --git a/clang/lib/Basic/Targets/RISCV.h b/clang/lib/Basic/Targets/RISCV.h index bf40edb8683b3e..3f2cee72fc3731 100644 --- a/clang/lib/Basic/Targets/RISCV.h +++ b/clang/lib/Basic/Targets/RISCV.h @@ -141,6 +141,13 @@ class RISCVTargetInfo : public TargetInfo { return true; } + bool + checkCFProtectionReturnSupported(DiagnosticsEngine &Diags) const override { +if (ISAInfo->hasExtension("zimop")) + return true; +return TargetInfo::checkCFProtectionReturnSupported(Diags); + } + CFBranchLabelSchemeKind getDefaultCFBranchLabelScheme() const override { return CFBranchLabelSchemeKind::FuncSig; } diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index 2306043c90f406..d8f0f7c14f6b40 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -899,6 +899,10 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, if (CodeGenOpts.PointerAuth.IndirectGotos) Fn->addFnAttr("ptrauth-indirect-gotos"); + // Add return control flow integrity attributes. + if (CodeGenOpts.CFProtectionReturn) +Fn->addFnAttr("hw-shadow-stack"); + // Apply xray attributes to the function (as a string, for now) bool AlwaysXRayAttr = false; if (const auto *XRayAttr = D ? D->getAttr() : nullptr) { >From 7dc168af5758d130042c71ba5d6249c042bc356c Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Wed, 23 Oct 2024 14:42:35 +0800 Subject: [PATCH 2/3] [Clang][RISCV] Add RISCV check for hw-shadow-stack --- clang/lib/CodeGen/CodeGenFunction.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index d8f0f7c14f6b40..cca52f3769845e 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -899,8 +899,9 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, if (CodeGenOpts.PointerAuth.IndirectGotos) Fn->addFnAttr("ptrauth-indirect-gotos"); - // Add return control flow integrity attributes. - if (CodeGenOpts.CFProtectionReturn) + // Add return control flow integrity attributes for RISCV. + if (CodeGenOpts.CFProtectionReturn && + getContext().getTargetInfo().getTriple().isRISCV()) Fn->addFnAttr("hw-shadow-stack"); // Apply xray attributes to the function (as a string, for now) >From 11e2e6fc0e06e220ab9f089267b9f691789aa104 Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Thu, 24 Oct 2024 15:39:07 +0800 Subject: [PATCH 3/3] [Clang][RISCV] Add function attribute in RISC-V specific code --- clang/lib/CodeGen/CodeGenFunction.cpp | 5 - clang/lib/CodeGen/Targets/RISCV.cpp | 4 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index cca52f3769845e..2306043c90f406 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -899,11 +899,6 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, if (CodeGenOpts.PointerAuth.IndirectGotos) Fn->addFnAttr("ptrauth-indirect-gotos"); - // Add return control flow integrity attributes for RISCV. - if (CodeGenOpts.CFProtectionReturn && - getContext().getTargetInfo().getTriple().isRISCV()) -Fn->addFnAttr("hw-shadow-stack"); - // Apply xray attributes to the function (as a string, for now) bool AlwaysXRayAttr = false; if (const auto *XRayAttr = D ? D->getAttr() : nullptr) { diff --git a/clang/lib/CodeGen/Targets/RISCV.cpp b/clang/lib/CodeGen/Targets/RISCV.cpp index fd72fe673b9b14..10779f397d1810 100644 --- a/clang/lib/CodeGen/Targets/RISCV.cpp +++ b/clang/lib/CodeGen/Targets/RISCV.cpp @@ -607,6 +607,10 @@ class RISCVTargetCodeGenInfo : public TargetCodeGenInfo { auto *Fn = cast(GV); Fn->addFnAttr("interrupt", Kind); + +if (CGM.getCodeGenOpts().CFProtectionReturn) + Fn->addFnAttr("hw-shadow-stack"); + } }; } // namespace ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Clang][RISCV] Support -fcf-protection=return for RISC-V (PR #112477)
@@ -0,0 +1,30 @@ +; ModuleID = '/home/jhuang4/workspace/test.c' jaidTw wrote: Yeah definitely, I'll remove it https://github.com/llvm/llvm-project/pull/112477 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Clang][RISCV] Support -fcf-protection=return for RISC-V (PR #112477)
@@ -607,6 +607,9 @@ class RISCVTargetCodeGenInfo : public TargetCodeGenInfo { auto *Fn = cast(GV); Fn->addFnAttr("interrupt", Kind); + +if (CGM.getCodeGenOpts().CFProtectionReturn) jaidTw wrote: I'm not quite familiar with the code here, is it safe to put at the beginning? Or I should put it after the FD check https://github.com/llvm/llvm-project/pull/112477 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][RISCV] Support -fcf-protection=return for RISC-V (PR #112477)
https://github.com/jaidTw closed https://github.com/llvm/llvm-project/pull/112477 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][RISCV] Support -fcf-protection=return for RISC-V (PR #112477)
jaidTw wrote: @mylai-mtk could you take a look at the latest version? I'm gonna merge it if it looks good to you too https://github.com/llvm/llvm-project/pull/112477 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][RISCV] Support -fcf-protection=return for RISC-V (PR #112477)
jaidTw wrote: After a meeting with Kito, I will change the requirement of both patches (this and 112478) to Zicfiss, and lift it in a future patch I'm encountering a problem that cc1 tests cannot recognize the option and working of a fix now https://github.com/llvm/llvm-project/pull/112477 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][RISCV] Support -fcf-protection=return for RISC-V (PR #112477)
https://github.com/jaidTw updated https://github.com/llvm/llvm-project/pull/112477 >From fe4a28fb691b69d9af384f1dc2f0667761adef44 Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Sun, 13 Oct 2024 15:11:06 +0800 Subject: [PATCH 1/5] [Clang][RISCV] Support -fcf-protection=return for RISC-V --- clang/lib/Basic/Targets/RISCV.h | 7 +++ clang/lib/CodeGen/CodeGenFunction.cpp | 4 2 files changed, 11 insertions(+) diff --git a/clang/lib/Basic/Targets/RISCV.h b/clang/lib/Basic/Targets/RISCV.h index bf40edb8683b3e..3f2cee72fc3731 100644 --- a/clang/lib/Basic/Targets/RISCV.h +++ b/clang/lib/Basic/Targets/RISCV.h @@ -141,6 +141,13 @@ class RISCVTargetInfo : public TargetInfo { return true; } + bool + checkCFProtectionReturnSupported(DiagnosticsEngine &Diags) const override { +if (ISAInfo->hasExtension("zimop")) + return true; +return TargetInfo::checkCFProtectionReturnSupported(Diags); + } + CFBranchLabelSchemeKind getDefaultCFBranchLabelScheme() const override { return CFBranchLabelSchemeKind::FuncSig; } diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index 2306043c90f406..d8f0f7c14f6b40 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -899,6 +899,10 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, if (CodeGenOpts.PointerAuth.IndirectGotos) Fn->addFnAttr("ptrauth-indirect-gotos"); + // Add return control flow integrity attributes. + if (CodeGenOpts.CFProtectionReturn) +Fn->addFnAttr("hw-shadow-stack"); + // Apply xray attributes to the function (as a string, for now) bool AlwaysXRayAttr = false; if (const auto *XRayAttr = D ? D->getAttr() : nullptr) { >From 7dc168af5758d130042c71ba5d6249c042bc356c Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Wed, 23 Oct 2024 14:42:35 +0800 Subject: [PATCH 2/5] [Clang][RISCV] Add RISCV check for hw-shadow-stack --- clang/lib/CodeGen/CodeGenFunction.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index d8f0f7c14f6b40..cca52f3769845e 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -899,8 +899,9 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, if (CodeGenOpts.PointerAuth.IndirectGotos) Fn->addFnAttr("ptrauth-indirect-gotos"); - // Add return control flow integrity attributes. - if (CodeGenOpts.CFProtectionReturn) + // Add return control flow integrity attributes for RISCV. + if (CodeGenOpts.CFProtectionReturn && + getContext().getTargetInfo().getTriple().isRISCV()) Fn->addFnAttr("hw-shadow-stack"); // Apply xray attributes to the function (as a string, for now) >From 42132c246058f6c1aaa646266847a3b8c854 Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Thu, 24 Oct 2024 15:39:07 +0800 Subject: [PATCH 3/5] [Clang][RISCV] Add function attribute in RISC-V specific code --- clang/lib/CodeGen/CodeGenFunction.cpp | 5 - clang/lib/CodeGen/Targets/RISCV.cpp | 7 +-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index cca52f3769845e..2306043c90f406 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -899,11 +899,6 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, if (CodeGenOpts.PointerAuth.IndirectGotos) Fn->addFnAttr("ptrauth-indirect-gotos"); - // Add return control flow integrity attributes for RISCV. - if (CodeGenOpts.CFProtectionReturn && - getContext().getTargetInfo().getTriple().isRISCV()) -Fn->addFnAttr("hw-shadow-stack"); - // Apply xray attributes to the function (as a string, for now) bool AlwaysXRayAttr = false; if (const auto *XRayAttr = D ? D->getAttr() : nullptr) { diff --git a/clang/lib/CodeGen/Targets/RISCV.cpp b/clang/lib/CodeGen/Targets/RISCV.cpp index fd72fe673b9b14..b04e436c665f52 100644 --- a/clang/lib/CodeGen/Targets/RISCV.cpp +++ b/clang/lib/CodeGen/Targets/RISCV.cpp @@ -594,6 +594,11 @@ class RISCVTargetCodeGenInfo : public TargetCodeGenInfo { const auto *FD = dyn_cast_or_null(D); if (!FD) return; +auto *Fn = cast(GV); + +if (CGM.getCodeGenOpts().CFProtectionReturn) + Fn->addFnAttr("hw-shadow-stack"); + const auto *Attr = FD->getAttr(); if (!Attr) return; @@ -604,8 +609,6 @@ class RISCVTargetCodeGenInfo : public TargetCodeGenInfo { case RISCVInterruptAttr::machine: Kind = "machine"; break; } -auto *Fn = cast(GV); - Fn->addFnAttr("interrupt", Kind); } }; >From 62dff012e1791bac6b3ed7725df86c1b2c60c1a1 Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Fri, 25 Oct 2024 14:13:45 +0800 Subject: [PATCH 4/5] [Clang] Add test for hw-shadodw-stack --- clang/test/CodeGen/RISCV/attr-hw-shadow-stack
[clang] [Clang][RISCV] Support -fcf-protection=return for RISC-V (PR #112477)
https://github.com/jaidTw updated https://github.com/llvm/llvm-project/pull/112477 >From fe4a28fb691b69d9af384f1dc2f0667761adef44 Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Sun, 13 Oct 2024 15:11:06 +0800 Subject: [PATCH 1/9] [Clang][RISCV] Support -fcf-protection=return for RISC-V --- clang/lib/Basic/Targets/RISCV.h | 7 +++ clang/lib/CodeGen/CodeGenFunction.cpp | 4 2 files changed, 11 insertions(+) diff --git a/clang/lib/Basic/Targets/RISCV.h b/clang/lib/Basic/Targets/RISCV.h index bf40edb8683b3e..3f2cee72fc3731 100644 --- a/clang/lib/Basic/Targets/RISCV.h +++ b/clang/lib/Basic/Targets/RISCV.h @@ -141,6 +141,13 @@ class RISCVTargetInfo : public TargetInfo { return true; } + bool + checkCFProtectionReturnSupported(DiagnosticsEngine &Diags) const override { +if (ISAInfo->hasExtension("zimop")) + return true; +return TargetInfo::checkCFProtectionReturnSupported(Diags); + } + CFBranchLabelSchemeKind getDefaultCFBranchLabelScheme() const override { return CFBranchLabelSchemeKind::FuncSig; } diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index 2306043c90f406..d8f0f7c14f6b40 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -899,6 +899,10 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, if (CodeGenOpts.PointerAuth.IndirectGotos) Fn->addFnAttr("ptrauth-indirect-gotos"); + // Add return control flow integrity attributes. + if (CodeGenOpts.CFProtectionReturn) +Fn->addFnAttr("hw-shadow-stack"); + // Apply xray attributes to the function (as a string, for now) bool AlwaysXRayAttr = false; if (const auto *XRayAttr = D ? D->getAttr() : nullptr) { >From 7dc168af5758d130042c71ba5d6249c042bc356c Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Wed, 23 Oct 2024 14:42:35 +0800 Subject: [PATCH 2/9] [Clang][RISCV] Add RISCV check for hw-shadow-stack --- clang/lib/CodeGen/CodeGenFunction.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index d8f0f7c14f6b40..cca52f3769845e 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -899,8 +899,9 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, if (CodeGenOpts.PointerAuth.IndirectGotos) Fn->addFnAttr("ptrauth-indirect-gotos"); - // Add return control flow integrity attributes. - if (CodeGenOpts.CFProtectionReturn) + // Add return control flow integrity attributes for RISCV. + if (CodeGenOpts.CFProtectionReturn && + getContext().getTargetInfo().getTriple().isRISCV()) Fn->addFnAttr("hw-shadow-stack"); // Apply xray attributes to the function (as a string, for now) >From 42132c246058f6c1aaa646266847a3b8c854 Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Thu, 24 Oct 2024 15:39:07 +0800 Subject: [PATCH 3/9] [Clang][RISCV] Add function attribute in RISC-V specific code --- clang/lib/CodeGen/CodeGenFunction.cpp | 5 - clang/lib/CodeGen/Targets/RISCV.cpp | 7 +-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index cca52f3769845e..2306043c90f406 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -899,11 +899,6 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, if (CodeGenOpts.PointerAuth.IndirectGotos) Fn->addFnAttr("ptrauth-indirect-gotos"); - // Add return control flow integrity attributes for RISCV. - if (CodeGenOpts.CFProtectionReturn && - getContext().getTargetInfo().getTriple().isRISCV()) -Fn->addFnAttr("hw-shadow-stack"); - // Apply xray attributes to the function (as a string, for now) bool AlwaysXRayAttr = false; if (const auto *XRayAttr = D ? D->getAttr() : nullptr) { diff --git a/clang/lib/CodeGen/Targets/RISCV.cpp b/clang/lib/CodeGen/Targets/RISCV.cpp index fd72fe673b9b14..b04e436c665f52 100644 --- a/clang/lib/CodeGen/Targets/RISCV.cpp +++ b/clang/lib/CodeGen/Targets/RISCV.cpp @@ -594,6 +594,11 @@ class RISCVTargetCodeGenInfo : public TargetCodeGenInfo { const auto *FD = dyn_cast_or_null(D); if (!FD) return; +auto *Fn = cast(GV); + +if (CGM.getCodeGenOpts().CFProtectionReturn) + Fn->addFnAttr("hw-shadow-stack"); + const auto *Attr = FD->getAttr(); if (!Attr) return; @@ -604,8 +609,6 @@ class RISCVTargetCodeGenInfo : public TargetCodeGenInfo { case RISCVInterruptAttr::machine: Kind = "machine"; break; } -auto *Fn = cast(GV); - Fn->addFnAttr("interrupt", Kind); } }; >From 2b6bdc5e95043a0f481314c0c2e5441804addf06 Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Fri, 25 Oct 2024 14:13:45 +0800 Subject: [PATCH 4/9] [Clang] Add test for hw-shadodw-stack --- clang/test/CodeGen/RISCV/attr-hw-shadow-stack
[clang] [Clang][RISCV] Support -fcf-protection=return for RISC-V (PR #112477)
https://github.com/jaidTw updated https://github.com/llvm/llvm-project/pull/112477 >From fe4a28fb691b69d9af384f1dc2f0667761adef44 Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Sun, 13 Oct 2024 15:11:06 +0800 Subject: [PATCH 1/7] [Clang][RISCV] Support -fcf-protection=return for RISC-V --- clang/lib/Basic/Targets/RISCV.h | 7 +++ clang/lib/CodeGen/CodeGenFunction.cpp | 4 2 files changed, 11 insertions(+) diff --git a/clang/lib/Basic/Targets/RISCV.h b/clang/lib/Basic/Targets/RISCV.h index bf40edb8683b3e..3f2cee72fc3731 100644 --- a/clang/lib/Basic/Targets/RISCV.h +++ b/clang/lib/Basic/Targets/RISCV.h @@ -141,6 +141,13 @@ class RISCVTargetInfo : public TargetInfo { return true; } + bool + checkCFProtectionReturnSupported(DiagnosticsEngine &Diags) const override { +if (ISAInfo->hasExtension("zimop")) + return true; +return TargetInfo::checkCFProtectionReturnSupported(Diags); + } + CFBranchLabelSchemeKind getDefaultCFBranchLabelScheme() const override { return CFBranchLabelSchemeKind::FuncSig; } diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index 2306043c90f406..d8f0f7c14f6b40 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -899,6 +899,10 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, if (CodeGenOpts.PointerAuth.IndirectGotos) Fn->addFnAttr("ptrauth-indirect-gotos"); + // Add return control flow integrity attributes. + if (CodeGenOpts.CFProtectionReturn) +Fn->addFnAttr("hw-shadow-stack"); + // Apply xray attributes to the function (as a string, for now) bool AlwaysXRayAttr = false; if (const auto *XRayAttr = D ? D->getAttr() : nullptr) { >From 7dc168af5758d130042c71ba5d6249c042bc356c Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Wed, 23 Oct 2024 14:42:35 +0800 Subject: [PATCH 2/7] [Clang][RISCV] Add RISCV check for hw-shadow-stack --- clang/lib/CodeGen/CodeGenFunction.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index d8f0f7c14f6b40..cca52f3769845e 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -899,8 +899,9 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, if (CodeGenOpts.PointerAuth.IndirectGotos) Fn->addFnAttr("ptrauth-indirect-gotos"); - // Add return control flow integrity attributes. - if (CodeGenOpts.CFProtectionReturn) + // Add return control flow integrity attributes for RISCV. + if (CodeGenOpts.CFProtectionReturn && + getContext().getTargetInfo().getTriple().isRISCV()) Fn->addFnAttr("hw-shadow-stack"); // Apply xray attributes to the function (as a string, for now) >From 42132c246058f6c1aaa646266847a3b8c854 Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Thu, 24 Oct 2024 15:39:07 +0800 Subject: [PATCH 3/7] [Clang][RISCV] Add function attribute in RISC-V specific code --- clang/lib/CodeGen/CodeGenFunction.cpp | 5 - clang/lib/CodeGen/Targets/RISCV.cpp | 7 +-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index cca52f3769845e..2306043c90f406 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -899,11 +899,6 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, if (CodeGenOpts.PointerAuth.IndirectGotos) Fn->addFnAttr("ptrauth-indirect-gotos"); - // Add return control flow integrity attributes for RISCV. - if (CodeGenOpts.CFProtectionReturn && - getContext().getTargetInfo().getTriple().isRISCV()) -Fn->addFnAttr("hw-shadow-stack"); - // Apply xray attributes to the function (as a string, for now) bool AlwaysXRayAttr = false; if (const auto *XRayAttr = D ? D->getAttr() : nullptr) { diff --git a/clang/lib/CodeGen/Targets/RISCV.cpp b/clang/lib/CodeGen/Targets/RISCV.cpp index fd72fe673b9b14..b04e436c665f52 100644 --- a/clang/lib/CodeGen/Targets/RISCV.cpp +++ b/clang/lib/CodeGen/Targets/RISCV.cpp @@ -594,6 +594,11 @@ class RISCVTargetCodeGenInfo : public TargetCodeGenInfo { const auto *FD = dyn_cast_or_null(D); if (!FD) return; +auto *Fn = cast(GV); + +if (CGM.getCodeGenOpts().CFProtectionReturn) + Fn->addFnAttr("hw-shadow-stack"); + const auto *Attr = FD->getAttr(); if (!Attr) return; @@ -604,8 +609,6 @@ class RISCVTargetCodeGenInfo : public TargetCodeGenInfo { case RISCVInterruptAttr::machine: Kind = "machine"; break; } -auto *Fn = cast(GV); - Fn->addFnAttr("interrupt", Kind); } }; >From 2b6bdc5e95043a0f481314c0c2e5441804addf06 Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Fri, 25 Oct 2024 14:13:45 +0800 Subject: [PATCH 4/7] [Clang] Add test for hw-shadodw-stack --- clang/test/CodeGen/RISCV/attr-hw-shadow-stack
[clang] [Clang][RISCV] Support -fcf-protection=return for RISC-V (PR #112477)
https://github.com/jaidTw updated https://github.com/llvm/llvm-project/pull/112477 >From fe4a28fb691b69d9af384f1dc2f0667761adef44 Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Sun, 13 Oct 2024 15:11:06 +0800 Subject: [PATCH 1/8] [Clang][RISCV] Support -fcf-protection=return for RISC-V --- clang/lib/Basic/Targets/RISCV.h | 7 +++ clang/lib/CodeGen/CodeGenFunction.cpp | 4 2 files changed, 11 insertions(+) diff --git a/clang/lib/Basic/Targets/RISCV.h b/clang/lib/Basic/Targets/RISCV.h index bf40edb8683b3e..3f2cee72fc3731 100644 --- a/clang/lib/Basic/Targets/RISCV.h +++ b/clang/lib/Basic/Targets/RISCV.h @@ -141,6 +141,13 @@ class RISCVTargetInfo : public TargetInfo { return true; } + bool + checkCFProtectionReturnSupported(DiagnosticsEngine &Diags) const override { +if (ISAInfo->hasExtension("zimop")) + return true; +return TargetInfo::checkCFProtectionReturnSupported(Diags); + } + CFBranchLabelSchemeKind getDefaultCFBranchLabelScheme() const override { return CFBranchLabelSchemeKind::FuncSig; } diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index 2306043c90f406..d8f0f7c14f6b40 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -899,6 +899,10 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, if (CodeGenOpts.PointerAuth.IndirectGotos) Fn->addFnAttr("ptrauth-indirect-gotos"); + // Add return control flow integrity attributes. + if (CodeGenOpts.CFProtectionReturn) +Fn->addFnAttr("hw-shadow-stack"); + // Apply xray attributes to the function (as a string, for now) bool AlwaysXRayAttr = false; if (const auto *XRayAttr = D ? D->getAttr() : nullptr) { >From 7dc168af5758d130042c71ba5d6249c042bc356c Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Wed, 23 Oct 2024 14:42:35 +0800 Subject: [PATCH 2/8] [Clang][RISCV] Add RISCV check for hw-shadow-stack --- clang/lib/CodeGen/CodeGenFunction.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index d8f0f7c14f6b40..cca52f3769845e 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -899,8 +899,9 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, if (CodeGenOpts.PointerAuth.IndirectGotos) Fn->addFnAttr("ptrauth-indirect-gotos"); - // Add return control flow integrity attributes. - if (CodeGenOpts.CFProtectionReturn) + // Add return control flow integrity attributes for RISCV. + if (CodeGenOpts.CFProtectionReturn && + getContext().getTargetInfo().getTriple().isRISCV()) Fn->addFnAttr("hw-shadow-stack"); // Apply xray attributes to the function (as a string, for now) >From 42132c246058f6c1aaa646266847a3b8c854 Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Thu, 24 Oct 2024 15:39:07 +0800 Subject: [PATCH 3/8] [Clang][RISCV] Add function attribute in RISC-V specific code --- clang/lib/CodeGen/CodeGenFunction.cpp | 5 - clang/lib/CodeGen/Targets/RISCV.cpp | 7 +-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index cca52f3769845e..2306043c90f406 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -899,11 +899,6 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, if (CodeGenOpts.PointerAuth.IndirectGotos) Fn->addFnAttr("ptrauth-indirect-gotos"); - // Add return control flow integrity attributes for RISCV. - if (CodeGenOpts.CFProtectionReturn && - getContext().getTargetInfo().getTriple().isRISCV()) -Fn->addFnAttr("hw-shadow-stack"); - // Apply xray attributes to the function (as a string, for now) bool AlwaysXRayAttr = false; if (const auto *XRayAttr = D ? D->getAttr() : nullptr) { diff --git a/clang/lib/CodeGen/Targets/RISCV.cpp b/clang/lib/CodeGen/Targets/RISCV.cpp index fd72fe673b9b14..b04e436c665f52 100644 --- a/clang/lib/CodeGen/Targets/RISCV.cpp +++ b/clang/lib/CodeGen/Targets/RISCV.cpp @@ -594,6 +594,11 @@ class RISCVTargetCodeGenInfo : public TargetCodeGenInfo { const auto *FD = dyn_cast_or_null(D); if (!FD) return; +auto *Fn = cast(GV); + +if (CGM.getCodeGenOpts().CFProtectionReturn) + Fn->addFnAttr("hw-shadow-stack"); + const auto *Attr = FD->getAttr(); if (!Attr) return; @@ -604,8 +609,6 @@ class RISCVTargetCodeGenInfo : public TargetCodeGenInfo { case RISCVInterruptAttr::machine: Kind = "machine"; break; } -auto *Fn = cast(GV); - Fn->addFnAttr("interrupt", Kind); } }; >From 2b6bdc5e95043a0f481314c0c2e5441804addf06 Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Fri, 25 Oct 2024 14:13:45 +0800 Subject: [PATCH 4/8] [Clang] Add test for hw-shadodw-stack --- clang/test/CodeGen/RISCV/attr-hw-shadow-stack
[clang] [Clang][RISCV] Support -fcf-protection=return for RISC-V (PR #112477)
https://github.com/jaidTw updated https://github.com/llvm/llvm-project/pull/112477 >From fe4a28fb691b69d9af384f1dc2f0667761adef44 Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Sun, 13 Oct 2024 15:11:06 +0800 Subject: [PATCH 1/3] [Clang][RISCV] Support -fcf-protection=return for RISC-V --- clang/lib/Basic/Targets/RISCV.h | 7 +++ clang/lib/CodeGen/CodeGenFunction.cpp | 4 2 files changed, 11 insertions(+) diff --git a/clang/lib/Basic/Targets/RISCV.h b/clang/lib/Basic/Targets/RISCV.h index bf40edb8683b3e..3f2cee72fc3731 100644 --- a/clang/lib/Basic/Targets/RISCV.h +++ b/clang/lib/Basic/Targets/RISCV.h @@ -141,6 +141,13 @@ class RISCVTargetInfo : public TargetInfo { return true; } + bool + checkCFProtectionReturnSupported(DiagnosticsEngine &Diags) const override { +if (ISAInfo->hasExtension("zimop")) + return true; +return TargetInfo::checkCFProtectionReturnSupported(Diags); + } + CFBranchLabelSchemeKind getDefaultCFBranchLabelScheme() const override { return CFBranchLabelSchemeKind::FuncSig; } diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index 2306043c90f406..d8f0f7c14f6b40 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -899,6 +899,10 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, if (CodeGenOpts.PointerAuth.IndirectGotos) Fn->addFnAttr("ptrauth-indirect-gotos"); + // Add return control flow integrity attributes. + if (CodeGenOpts.CFProtectionReturn) +Fn->addFnAttr("hw-shadow-stack"); + // Apply xray attributes to the function (as a string, for now) bool AlwaysXRayAttr = false; if (const auto *XRayAttr = D ? D->getAttr() : nullptr) { >From 7dc168af5758d130042c71ba5d6249c042bc356c Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Wed, 23 Oct 2024 14:42:35 +0800 Subject: [PATCH 2/3] [Clang][RISCV] Add RISCV check for hw-shadow-stack --- clang/lib/CodeGen/CodeGenFunction.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index d8f0f7c14f6b40..cca52f3769845e 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -899,8 +899,9 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, if (CodeGenOpts.PointerAuth.IndirectGotos) Fn->addFnAttr("ptrauth-indirect-gotos"); - // Add return control flow integrity attributes. - if (CodeGenOpts.CFProtectionReturn) + // Add return control flow integrity attributes for RISCV. + if (CodeGenOpts.CFProtectionReturn && + getContext().getTargetInfo().getTriple().isRISCV()) Fn->addFnAttr("hw-shadow-stack"); // Apply xray attributes to the function (as a string, for now) >From 42132c246058f6c1aaa646266847a3b8c854 Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Thu, 24 Oct 2024 15:39:07 +0800 Subject: [PATCH 3/3] [Clang][RISCV] Add function attribute in RISC-V specific code --- clang/lib/CodeGen/CodeGenFunction.cpp | 5 - clang/lib/CodeGen/Targets/RISCV.cpp | 7 +-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index cca52f3769845e..2306043c90f406 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -899,11 +899,6 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, if (CodeGenOpts.PointerAuth.IndirectGotos) Fn->addFnAttr("ptrauth-indirect-gotos"); - // Add return control flow integrity attributes for RISCV. - if (CodeGenOpts.CFProtectionReturn && - getContext().getTargetInfo().getTriple().isRISCV()) -Fn->addFnAttr("hw-shadow-stack"); - // Apply xray attributes to the function (as a string, for now) bool AlwaysXRayAttr = false; if (const auto *XRayAttr = D ? D->getAttr() : nullptr) { diff --git a/clang/lib/CodeGen/Targets/RISCV.cpp b/clang/lib/CodeGen/Targets/RISCV.cpp index fd72fe673b9b14..b04e436c665f52 100644 --- a/clang/lib/CodeGen/Targets/RISCV.cpp +++ b/clang/lib/CodeGen/Targets/RISCV.cpp @@ -594,6 +594,11 @@ class RISCVTargetCodeGenInfo : public TargetCodeGenInfo { const auto *FD = dyn_cast_or_null(D); if (!FD) return; +auto *Fn = cast(GV); + +if (CGM.getCodeGenOpts().CFProtectionReturn) + Fn->addFnAttr("hw-shadow-stack"); + const auto *Attr = FD->getAttr(); if (!Attr) return; @@ -604,8 +609,6 @@ class RISCVTargetCodeGenInfo : public TargetCodeGenInfo { case RISCVInterruptAttr::machine: Kind = "machine"; break; } -auto *Fn = cast(GV); - Fn->addFnAttr("interrupt", Kind); } }; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][RISCV] Support -fcf-protection=return for RISC-V (PR #112477)
@@ -899,6 +899,11 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, if (CodeGenOpts.PointerAuth.IndirectGotos) Fn->addFnAttr("ptrauth-indirect-gotos"); + // Add return control flow integrity attributes for RISCV. + if (CodeGenOpts.CFProtectionReturn && jaidTw wrote: `cf-protection-return` on RISC-V could be controlled at a per-function granularity (i.e. use function attributes to suppress the instruction generation for some functions), so we still need a function attribute to tag it. I moved it to `setTargetAttributes` for RISC-V, thanks for the advice. https://github.com/llvm/llvm-project/pull/112477 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][RISCV] Support -fcf-protection=return for RISC-V (PR #112477)
https://github.com/jaidTw updated https://github.com/llvm/llvm-project/pull/112477 >From fe4a28fb691b69d9af384f1dc2f0667761adef44 Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Sun, 13 Oct 2024 15:11:06 +0800 Subject: [PATCH 1/6] [Clang][RISCV] Support -fcf-protection=return for RISC-V --- clang/lib/Basic/Targets/RISCV.h | 7 +++ clang/lib/CodeGen/CodeGenFunction.cpp | 4 2 files changed, 11 insertions(+) diff --git a/clang/lib/Basic/Targets/RISCV.h b/clang/lib/Basic/Targets/RISCV.h index bf40edb8683b3e..3f2cee72fc3731 100644 --- a/clang/lib/Basic/Targets/RISCV.h +++ b/clang/lib/Basic/Targets/RISCV.h @@ -141,6 +141,13 @@ class RISCVTargetInfo : public TargetInfo { return true; } + bool + checkCFProtectionReturnSupported(DiagnosticsEngine &Diags) const override { +if (ISAInfo->hasExtension("zimop")) + return true; +return TargetInfo::checkCFProtectionReturnSupported(Diags); + } + CFBranchLabelSchemeKind getDefaultCFBranchLabelScheme() const override { return CFBranchLabelSchemeKind::FuncSig; } diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index 2306043c90f406..d8f0f7c14f6b40 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -899,6 +899,10 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, if (CodeGenOpts.PointerAuth.IndirectGotos) Fn->addFnAttr("ptrauth-indirect-gotos"); + // Add return control flow integrity attributes. + if (CodeGenOpts.CFProtectionReturn) +Fn->addFnAttr("hw-shadow-stack"); + // Apply xray attributes to the function (as a string, for now) bool AlwaysXRayAttr = false; if (const auto *XRayAttr = D ? D->getAttr() : nullptr) { >From 7dc168af5758d130042c71ba5d6249c042bc356c Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Wed, 23 Oct 2024 14:42:35 +0800 Subject: [PATCH 2/6] [Clang][RISCV] Add RISCV check for hw-shadow-stack --- clang/lib/CodeGen/CodeGenFunction.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index d8f0f7c14f6b40..cca52f3769845e 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -899,8 +899,9 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, if (CodeGenOpts.PointerAuth.IndirectGotos) Fn->addFnAttr("ptrauth-indirect-gotos"); - // Add return control flow integrity attributes. - if (CodeGenOpts.CFProtectionReturn) + // Add return control flow integrity attributes for RISCV. + if (CodeGenOpts.CFProtectionReturn && + getContext().getTargetInfo().getTriple().isRISCV()) Fn->addFnAttr("hw-shadow-stack"); // Apply xray attributes to the function (as a string, for now) >From 42132c246058f6c1aaa646266847a3b8c854 Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Thu, 24 Oct 2024 15:39:07 +0800 Subject: [PATCH 3/6] [Clang][RISCV] Add function attribute in RISC-V specific code --- clang/lib/CodeGen/CodeGenFunction.cpp | 5 - clang/lib/CodeGen/Targets/RISCV.cpp | 7 +-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index cca52f3769845e..2306043c90f406 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -899,11 +899,6 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, if (CodeGenOpts.PointerAuth.IndirectGotos) Fn->addFnAttr("ptrauth-indirect-gotos"); - // Add return control flow integrity attributes for RISCV. - if (CodeGenOpts.CFProtectionReturn && - getContext().getTargetInfo().getTriple().isRISCV()) -Fn->addFnAttr("hw-shadow-stack"); - // Apply xray attributes to the function (as a string, for now) bool AlwaysXRayAttr = false; if (const auto *XRayAttr = D ? D->getAttr() : nullptr) { diff --git a/clang/lib/CodeGen/Targets/RISCV.cpp b/clang/lib/CodeGen/Targets/RISCV.cpp index fd72fe673b9b14..b04e436c665f52 100644 --- a/clang/lib/CodeGen/Targets/RISCV.cpp +++ b/clang/lib/CodeGen/Targets/RISCV.cpp @@ -594,6 +594,11 @@ class RISCVTargetCodeGenInfo : public TargetCodeGenInfo { const auto *FD = dyn_cast_or_null(D); if (!FD) return; +auto *Fn = cast(GV); + +if (CGM.getCodeGenOpts().CFProtectionReturn) + Fn->addFnAttr("hw-shadow-stack"); + const auto *Attr = FD->getAttr(); if (!Attr) return; @@ -604,8 +609,6 @@ class RISCVTargetCodeGenInfo : public TargetCodeGenInfo { case RISCVInterruptAttr::machine: Kind = "machine"; break; } -auto *Fn = cast(GV); - Fn->addFnAttr("interrupt", Kind); } }; >From 2b6bdc5e95043a0f481314c0c2e5441804addf06 Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Fri, 25 Oct 2024 14:13:45 +0800 Subject: [PATCH 4/6] [Clang] Add test for hw-shadodw-stack --- clang/test/CodeGen/RISCV/attr-hw-shadow-stack
[clang] [Clang][RISCV] Remove forced-sw-shadow-stack (PR #115355)
https://github.com/jaidTw created https://github.com/llvm/llvm-project/pull/115355 This option was used to override the behavior of `-fsanitize=shadowcallstack` on RISC-V backend, which by default use a hardware implementation if possible, to use the software implementation instead. After https://github.com/llvm/llvm-project/pull/112477 and https://github.com/llvm/llvm-project/pull/112478, now two implementation is represented by independent options and we no longer need it. >From d9203fbbcacf509defab5b7e8fb7816d2819f121 Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Fri, 8 Nov 2024 01:34:20 +0800 Subject: [PATCH] [Clang][RISCV] Remove forced-sw-shadow-stack After the separation of hardware and software shadow stack options, we no longer need this option. --- clang/docs/ShadowCallStack.rst| 9 - clang/include/clang/Driver/Options.td | 4 clang/test/Driver/riscv-features.c| 6 -- 3 files changed, 4 insertions(+), 15 deletions(-) diff --git a/clang/docs/ShadowCallStack.rst b/clang/docs/ShadowCallStack.rst index d7ece11b352606..fc8bea83e11452 100644 --- a/clang/docs/ShadowCallStack.rst +++ b/clang/docs/ShadowCallStack.rst @@ -59,11 +59,10 @@ and destruction would need to be intercepted by the application. The instrumentation makes use of the platform register ``x18`` on AArch64, ``x3`` (``gp``) on RISC-V with software shadow stack and ``ssp`` on RISC-V with -hardware shadow stack, which needs `Zicfiss`_ and ``-mno-forced-sw-shadow-stack`` -(default option). Note that with ``Zicfiss``_ the RISC-V backend will default to -the hardware based shadow call stack. Users can force the RISC-V backend to -generate the software shadow call stack with ``Zicfiss``_ by passing -``-mforced-sw-shadow-stack``. +hardware shadow stack, which needs `Zicfiss`_ and ``-fcf-protection=return``. +Users can choose between the software and hardware based shadow stack +implementation on RISC-V backend by passing ``-fsanitize=shadowcallstack`` +or ``Zicfiss`` with ``-fcf-protection=return``. For simplicity we will refer to this as the ``SCSReg``. On some platforms, ``SCSReg`` is reserved, and on others, it is designated as a scratch register. This generally means that any code that may run on the same thread as code diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 805b79491e6ea4..8887e0c1495d2a 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -4930,10 +4930,6 @@ def msave_restore : Flag<["-"], "msave-restore">, Group, HelpText<"Enable using library calls for save and restore">; def mno_save_restore : Flag<["-"], "mno-save-restore">, Group, HelpText<"Disable using library calls for save and restore">; -def mforced_sw_shadow_stack : Flag<["-"], "mforced-sw-shadow-stack">, Group, - HelpText<"Force using software shadow stack when shadow-stack enabled">; -def mno_forced_sw_shadow_stack : Flag<["-"], "mno-forced-sw-shadow-stack">, Group, - HelpText<"Not force using software shadow stack when shadow-stack enabled">; } // let Flags = [TargetSpecific] let Flags = [TargetSpecific] in { def menable_experimental_extensions : Flag<["-"], "menable-experimental-extensions">, Group, diff --git a/clang/test/Driver/riscv-features.c b/clang/test/Driver/riscv-features.c index b4fad5177c5f76..b58ec3b523e5c1 100644 --- a/clang/test/Driver/riscv-features.c +++ b/clang/test/Driver/riscv-features.c @@ -29,12 +29,6 @@ // DEFAULT-NOT: "-target-feature" "-save-restore" // DEFAULT-NOT: "-target-feature" "+save-restore" -// RUN: %clang --target=riscv32-unknown-elf -### %s -mforced-sw-shadow-stack 2>&1 | FileCheck %s -check-prefix=FORCE-SW-SCS -// RUN: %clang --target=riscv32-unknown-elf -### %s -mno-forced-sw-shadow-stack 2>&1 | FileCheck %s -check-prefix=NO-FORCE-SW-SCS -// FORCE-SW-SCS: "-target-feature" "+forced-sw-shadow-stack" -// NO-FORCE-SW-SCS: "-target-feature" "-forced-sw-shadow-stack" -// DEFAULT-NOT: "-target-feature" "+forced-sw-shadow-stack" - // RUN: %clang --target=riscv32-unknown-elf -### %s -mno-strict-align 2>&1 | FileCheck %s -check-prefixes=FAST-SCALAR-UNALIGNED-ACCESS,FAST-VECTOR-UNALIGNED-ACCESS // RUN: %clang --target=riscv32-unknown-elf -### %s -mstrict-align 2>&1 | FileCheck %s -check-prefixes=NO-FAST-SCALAR-UNALIGNED-ACCESS,NO-FAST-VECTOR-UNALIGNED-ACCESS // RUN: %clang --target=riscv32-unknown-elf -### %s -mno-scalar-strict-align 2>&1 | FileCheck %s -check-prefix=FAST-SCALAR-UNALIGNED-ACCESS ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][RISCV] Support -fcf-protection=return for RISC-V (PR #112477)
https://github.com/jaidTw updated https://github.com/llvm/llvm-project/pull/112477 >From fe4a28fb691b69d9af384f1dc2f0667761adef44 Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Sun, 13 Oct 2024 15:11:06 +0800 Subject: [PATCH 1/3] [Clang][RISCV] Support -fcf-protection=return for RISC-V --- clang/lib/Basic/Targets/RISCV.h | 7 +++ clang/lib/CodeGen/CodeGenFunction.cpp | 4 2 files changed, 11 insertions(+) diff --git a/clang/lib/Basic/Targets/RISCV.h b/clang/lib/Basic/Targets/RISCV.h index bf40edb8683b3e..3f2cee72fc3731 100644 --- a/clang/lib/Basic/Targets/RISCV.h +++ b/clang/lib/Basic/Targets/RISCV.h @@ -141,6 +141,13 @@ class RISCVTargetInfo : public TargetInfo { return true; } + bool + checkCFProtectionReturnSupported(DiagnosticsEngine &Diags) const override { +if (ISAInfo->hasExtension("zimop")) + return true; +return TargetInfo::checkCFProtectionReturnSupported(Diags); + } + CFBranchLabelSchemeKind getDefaultCFBranchLabelScheme() const override { return CFBranchLabelSchemeKind::FuncSig; } diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index 2306043c90f406..d8f0f7c14f6b40 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -899,6 +899,10 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, if (CodeGenOpts.PointerAuth.IndirectGotos) Fn->addFnAttr("ptrauth-indirect-gotos"); + // Add return control flow integrity attributes. + if (CodeGenOpts.CFProtectionReturn) +Fn->addFnAttr("hw-shadow-stack"); + // Apply xray attributes to the function (as a string, for now) bool AlwaysXRayAttr = false; if (const auto *XRayAttr = D ? D->getAttr() : nullptr) { >From 7dc168af5758d130042c71ba5d6249c042bc356c Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Wed, 23 Oct 2024 14:42:35 +0800 Subject: [PATCH 2/3] [Clang][RISCV] Add RISCV check for hw-shadow-stack --- clang/lib/CodeGen/CodeGenFunction.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index d8f0f7c14f6b40..cca52f3769845e 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -899,8 +899,9 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, if (CodeGenOpts.PointerAuth.IndirectGotos) Fn->addFnAttr("ptrauth-indirect-gotos"); - // Add return control flow integrity attributes. - if (CodeGenOpts.CFProtectionReturn) + // Add return control flow integrity attributes for RISCV. + if (CodeGenOpts.CFProtectionReturn && + getContext().getTargetInfo().getTriple().isRISCV()) Fn->addFnAttr("hw-shadow-stack"); // Apply xray attributes to the function (as a string, for now) >From bb59a7064d2a5dc11c690b9262d09202c6942189 Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Thu, 24 Oct 2024 15:39:07 +0800 Subject: [PATCH 3/3] [Clang][RISCV] Add function attribute in RISC-V specific code --- clang/lib/CodeGen/CodeGenFunction.cpp | 5 - clang/lib/CodeGen/Targets/RISCV.cpp | 4 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index cca52f3769845e..2306043c90f406 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -899,11 +899,6 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, if (CodeGenOpts.PointerAuth.IndirectGotos) Fn->addFnAttr("ptrauth-indirect-gotos"); - // Add return control flow integrity attributes for RISCV. - if (CodeGenOpts.CFProtectionReturn && - getContext().getTargetInfo().getTriple().isRISCV()) -Fn->addFnAttr("hw-shadow-stack"); - // Apply xray attributes to the function (as a string, for now) bool AlwaysXRayAttr = false; if (const auto *XRayAttr = D ? D->getAttr() : nullptr) { diff --git a/clang/lib/CodeGen/Targets/RISCV.cpp b/clang/lib/CodeGen/Targets/RISCV.cpp index fd72fe673b9b14..10779f397d1810 100644 --- a/clang/lib/CodeGen/Targets/RISCV.cpp +++ b/clang/lib/CodeGen/Targets/RISCV.cpp @@ -607,6 +607,10 @@ class RISCVTargetCodeGenInfo : public TargetCodeGenInfo { auto *Fn = cast(GV); Fn->addFnAttr("interrupt", Kind); + +if (CGM.getCodeGenOpts().CFProtectionReturn) + Fn->addFnAttr("hw-shadow-stack"); + } }; } // namespace ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [Clang][RISCV] Support -fcf-protection=return for RISC-V (PR #112477)
https://github.com/jaidTw updated https://github.com/llvm/llvm-project/pull/112477 >From fe4a28fb691b69d9af384f1dc2f0667761adef44 Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Sun, 13 Oct 2024 15:11:06 +0800 Subject: [PATCH 1/3] [Clang][RISCV] Support -fcf-protection=return for RISC-V --- clang/lib/Basic/Targets/RISCV.h | 7 +++ clang/lib/CodeGen/CodeGenFunction.cpp | 4 2 files changed, 11 insertions(+) diff --git a/clang/lib/Basic/Targets/RISCV.h b/clang/lib/Basic/Targets/RISCV.h index bf40edb8683b3e..3f2cee72fc3731 100644 --- a/clang/lib/Basic/Targets/RISCV.h +++ b/clang/lib/Basic/Targets/RISCV.h @@ -141,6 +141,13 @@ class RISCVTargetInfo : public TargetInfo { return true; } + bool + checkCFProtectionReturnSupported(DiagnosticsEngine &Diags) const override { +if (ISAInfo->hasExtension("zimop")) + return true; +return TargetInfo::checkCFProtectionReturnSupported(Diags); + } + CFBranchLabelSchemeKind getDefaultCFBranchLabelScheme() const override { return CFBranchLabelSchemeKind::FuncSig; } diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index 2306043c90f406..d8f0f7c14f6b40 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -899,6 +899,10 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, if (CodeGenOpts.PointerAuth.IndirectGotos) Fn->addFnAttr("ptrauth-indirect-gotos"); + // Add return control flow integrity attributes. + if (CodeGenOpts.CFProtectionReturn) +Fn->addFnAttr("hw-shadow-stack"); + // Apply xray attributes to the function (as a string, for now) bool AlwaysXRayAttr = false; if (const auto *XRayAttr = D ? D->getAttr() : nullptr) { >From 7dc168af5758d130042c71ba5d6249c042bc356c Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Wed, 23 Oct 2024 14:42:35 +0800 Subject: [PATCH 2/3] [Clang][RISCV] Add RISCV check for hw-shadow-stack --- clang/lib/CodeGen/CodeGenFunction.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index d8f0f7c14f6b40..cca52f3769845e 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -899,8 +899,9 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, if (CodeGenOpts.PointerAuth.IndirectGotos) Fn->addFnAttr("ptrauth-indirect-gotos"); - // Add return control flow integrity attributes. - if (CodeGenOpts.CFProtectionReturn) + // Add return control flow integrity attributes for RISCV. + if (CodeGenOpts.CFProtectionReturn && + getContext().getTargetInfo().getTriple().isRISCV()) Fn->addFnAttr("hw-shadow-stack"); // Apply xray attributes to the function (as a string, for now) >From 3cdb6c584bc1c7714b43fc15fe31a44200710262 Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Thu, 24 Oct 2024 15:39:07 +0800 Subject: [PATCH 3/3] [Clang][RISCV] Add function attribute in RISC-V specific code --- clang/lib/CodeGen/CodeGenFunction.cpp | 5 - clang/lib/CodeGen/Targets/RISCV.cpp | 3 +++ test.ll | 30 +++ 3 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 test.ll diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index cca52f3769845e..2306043c90f406 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -899,11 +899,6 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, if (CodeGenOpts.PointerAuth.IndirectGotos) Fn->addFnAttr("ptrauth-indirect-gotos"); - // Add return control flow integrity attributes for RISCV. - if (CodeGenOpts.CFProtectionReturn && - getContext().getTargetInfo().getTriple().isRISCV()) -Fn->addFnAttr("hw-shadow-stack"); - // Apply xray attributes to the function (as a string, for now) bool AlwaysXRayAttr = false; if (const auto *XRayAttr = D ? D->getAttr() : nullptr) { diff --git a/clang/lib/CodeGen/Targets/RISCV.cpp b/clang/lib/CodeGen/Targets/RISCV.cpp index fd72fe673b9b14..998a1e8de17dce 100644 --- a/clang/lib/CodeGen/Targets/RISCV.cpp +++ b/clang/lib/CodeGen/Targets/RISCV.cpp @@ -607,6 +607,9 @@ class RISCVTargetCodeGenInfo : public TargetCodeGenInfo { auto *Fn = cast(GV); Fn->addFnAttr("interrupt", Kind); + +if (CGM.getCodeGenOpts().CFProtectionReturn) + Fn->addFnAttr("hw-shadow-stack"); } }; } // namespace diff --git a/test.ll b/test.ll new file mode 100644 index 00..3157c4df34da58 --- /dev/null +++ b/test.ll @@ -0,0 +1,30 @@ +; ModuleID = '/home/jhuang4/workspace/test.c' +source_filename = "/home/jhuang4/workspace/test.c" +target datalayout = "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128" +target triple = "riscv64-unknown-unknown" + +; Function Attrs: noinline nounwind optnone +define dso_local void @foo(ptr noundef %str) #0 { +en
[clang] [Clang][RISCV] Support -fcf-protection=return for RISC-V (PR #112477)
https://github.com/jaidTw updated https://github.com/llvm/llvm-project/pull/112477 >From fe4a28fb691b69d9af384f1dc2f0667761adef44 Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Sun, 13 Oct 2024 15:11:06 +0800 Subject: [PATCH 1/3] [Clang][RISCV] Support -fcf-protection=return for RISC-V --- clang/lib/Basic/Targets/RISCV.h | 7 +++ clang/lib/CodeGen/CodeGenFunction.cpp | 4 2 files changed, 11 insertions(+) diff --git a/clang/lib/Basic/Targets/RISCV.h b/clang/lib/Basic/Targets/RISCV.h index bf40edb8683b3e..3f2cee72fc3731 100644 --- a/clang/lib/Basic/Targets/RISCV.h +++ b/clang/lib/Basic/Targets/RISCV.h @@ -141,6 +141,13 @@ class RISCVTargetInfo : public TargetInfo { return true; } + bool + checkCFProtectionReturnSupported(DiagnosticsEngine &Diags) const override { +if (ISAInfo->hasExtension("zimop")) + return true; +return TargetInfo::checkCFProtectionReturnSupported(Diags); + } + CFBranchLabelSchemeKind getDefaultCFBranchLabelScheme() const override { return CFBranchLabelSchemeKind::FuncSig; } diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index 2306043c90f406..d8f0f7c14f6b40 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -899,6 +899,10 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, if (CodeGenOpts.PointerAuth.IndirectGotos) Fn->addFnAttr("ptrauth-indirect-gotos"); + // Add return control flow integrity attributes. + if (CodeGenOpts.CFProtectionReturn) +Fn->addFnAttr("hw-shadow-stack"); + // Apply xray attributes to the function (as a string, for now) bool AlwaysXRayAttr = false; if (const auto *XRayAttr = D ? D->getAttr() : nullptr) { >From 7dc168af5758d130042c71ba5d6249c042bc356c Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Wed, 23 Oct 2024 14:42:35 +0800 Subject: [PATCH 2/3] [Clang][RISCV] Add RISCV check for hw-shadow-stack --- clang/lib/CodeGen/CodeGenFunction.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index d8f0f7c14f6b40..cca52f3769845e 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -899,8 +899,9 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, if (CodeGenOpts.PointerAuth.IndirectGotos) Fn->addFnAttr("ptrauth-indirect-gotos"); - // Add return control flow integrity attributes. - if (CodeGenOpts.CFProtectionReturn) + // Add return control flow integrity attributes for RISCV. + if (CodeGenOpts.CFProtectionReturn && + getContext().getTargetInfo().getTriple().isRISCV()) Fn->addFnAttr("hw-shadow-stack"); // Apply xray attributes to the function (as a string, for now) >From b2108ed1b9d32efe100d5258a458e684e1fb8826 Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Thu, 24 Oct 2024 15:39:07 +0800 Subject: [PATCH 3/3] [Clang][RISCV] Add function attribute in RISC-V specific code --- clang/lib/CodeGen/Targets/RISCV.cpp | 4 1 file changed, 4 insertions(+) diff --git a/clang/lib/CodeGen/Targets/RISCV.cpp b/clang/lib/CodeGen/Targets/RISCV.cpp index fd72fe673b9b14..10779f397d1810 100644 --- a/clang/lib/CodeGen/Targets/RISCV.cpp +++ b/clang/lib/CodeGen/Targets/RISCV.cpp @@ -607,6 +607,10 @@ class RISCVTargetCodeGenInfo : public TargetCodeGenInfo { auto *Fn = cast(GV); Fn->addFnAttr("interrupt", Kind); + +if (CGM.getCodeGenOpts().CFProtectionReturn) + Fn->addFnAttr("hw-shadow-stack"); + } }; } // namespace ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][RISCV] Support -fcf-protection=return for RISC-V (PR #112477)
@@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -triple riscv64-linux-unknown -target-feature +zimop -emit-llvm -o - %s -fcf-protection=return | FileCheck -check-prefix=NOTIGNORELISTED %s +// RUN: %clang_cc1 -triple riscv64-linux-unknown -target-feature +zimop -emit-llvm -o - %s | FileCheck -check-prefix=IGNORELISTED %s + +int foo(int *a) { return *a; } + +// CHECK: define i32 @foo(ptr %a) + +// IGNORELISTED-NOT: attributes {{.*}}"hw-shadow-stack"{{.*}} +// NOTIGNORELISTED: attributes {{.*}}"hw-shadow-stack"{{.*}} jaidTw wrote: Changed to a more descriptive name https://github.com/llvm/llvm-project/pull/112477 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][RISCV] Support -fcf-protection=return for RISC-V (PR #112477)
@@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -triple riscv64-linux-unknown -target-feature +zimop -emit-llvm -o - %s -fcf-protection=return | FileCheck -check-prefix=NOTIGNORELISTED %s +// RUN: %clang_cc1 -triple riscv64-linux-unknown -target-feature +zimop -emit-llvm -o - %s | FileCheck -check-prefix=IGNORELISTED %s + +int foo(int *a) { return *a; } + +// CHECK: define i32 @foo(ptr %a) jaidTw wrote: It's surely not used so I've removed it (This test is modified from `clang/test/CodeGen/shadowcallstack-attr.c`, so as the line, but seems like it isn't used in the original file either) https://github.com/llvm/llvm-project/pull/112477 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][RISCV] Support -fcf-protection=return for RISC-V (PR #112477)
https://github.com/jaidTw updated https://github.com/llvm/llvm-project/pull/112477 >From fe4a28fb691b69d9af384f1dc2f0667761adef44 Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Sun, 13 Oct 2024 15:11:06 +0800 Subject: [PATCH 1/5] [Clang][RISCV] Support -fcf-protection=return for RISC-V --- clang/lib/Basic/Targets/RISCV.h | 7 +++ clang/lib/CodeGen/CodeGenFunction.cpp | 4 2 files changed, 11 insertions(+) diff --git a/clang/lib/Basic/Targets/RISCV.h b/clang/lib/Basic/Targets/RISCV.h index bf40edb8683b3e..3f2cee72fc3731 100644 --- a/clang/lib/Basic/Targets/RISCV.h +++ b/clang/lib/Basic/Targets/RISCV.h @@ -141,6 +141,13 @@ class RISCVTargetInfo : public TargetInfo { return true; } + bool + checkCFProtectionReturnSupported(DiagnosticsEngine &Diags) const override { +if (ISAInfo->hasExtension("zimop")) + return true; +return TargetInfo::checkCFProtectionReturnSupported(Diags); + } + CFBranchLabelSchemeKind getDefaultCFBranchLabelScheme() const override { return CFBranchLabelSchemeKind::FuncSig; } diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index 2306043c90f406..d8f0f7c14f6b40 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -899,6 +899,10 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, if (CodeGenOpts.PointerAuth.IndirectGotos) Fn->addFnAttr("ptrauth-indirect-gotos"); + // Add return control flow integrity attributes. + if (CodeGenOpts.CFProtectionReturn) +Fn->addFnAttr("hw-shadow-stack"); + // Apply xray attributes to the function (as a string, for now) bool AlwaysXRayAttr = false; if (const auto *XRayAttr = D ? D->getAttr() : nullptr) { >From 7dc168af5758d130042c71ba5d6249c042bc356c Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Wed, 23 Oct 2024 14:42:35 +0800 Subject: [PATCH 2/5] [Clang][RISCV] Add RISCV check for hw-shadow-stack --- clang/lib/CodeGen/CodeGenFunction.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index d8f0f7c14f6b40..cca52f3769845e 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -899,8 +899,9 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, if (CodeGenOpts.PointerAuth.IndirectGotos) Fn->addFnAttr("ptrauth-indirect-gotos"); - // Add return control flow integrity attributes. - if (CodeGenOpts.CFProtectionReturn) + // Add return control flow integrity attributes for RISCV. + if (CodeGenOpts.CFProtectionReturn && + getContext().getTargetInfo().getTriple().isRISCV()) Fn->addFnAttr("hw-shadow-stack"); // Apply xray attributes to the function (as a string, for now) >From 42132c246058f6c1aaa646266847a3b8c854 Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Thu, 24 Oct 2024 15:39:07 +0800 Subject: [PATCH 3/5] [Clang][RISCV] Add function attribute in RISC-V specific code --- clang/lib/CodeGen/CodeGenFunction.cpp | 5 - clang/lib/CodeGen/Targets/RISCV.cpp | 7 +-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index cca52f3769845e..2306043c90f406 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -899,11 +899,6 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy, if (CodeGenOpts.PointerAuth.IndirectGotos) Fn->addFnAttr("ptrauth-indirect-gotos"); - // Add return control flow integrity attributes for RISCV. - if (CodeGenOpts.CFProtectionReturn && - getContext().getTargetInfo().getTriple().isRISCV()) -Fn->addFnAttr("hw-shadow-stack"); - // Apply xray attributes to the function (as a string, for now) bool AlwaysXRayAttr = false; if (const auto *XRayAttr = D ? D->getAttr() : nullptr) { diff --git a/clang/lib/CodeGen/Targets/RISCV.cpp b/clang/lib/CodeGen/Targets/RISCV.cpp index fd72fe673b9b14..b04e436c665f52 100644 --- a/clang/lib/CodeGen/Targets/RISCV.cpp +++ b/clang/lib/CodeGen/Targets/RISCV.cpp @@ -594,6 +594,11 @@ class RISCVTargetCodeGenInfo : public TargetCodeGenInfo { const auto *FD = dyn_cast_or_null(D); if (!FD) return; +auto *Fn = cast(GV); + +if (CGM.getCodeGenOpts().CFProtectionReturn) + Fn->addFnAttr("hw-shadow-stack"); + const auto *Attr = FD->getAttr(); if (!Attr) return; @@ -604,8 +609,6 @@ class RISCVTargetCodeGenInfo : public TargetCodeGenInfo { case RISCVInterruptAttr::machine: Kind = "machine"; break; } -auto *Fn = cast(GV); - Fn->addFnAttr("interrupt", Kind); } }; >From 2b6bdc5e95043a0f481314c0c2e5441804addf06 Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Fri, 25 Oct 2024 14:13:45 +0800 Subject: [PATCH 4/5] [Clang] Add test for hw-shadodw-stack --- clang/test/CodeGen/RISCV/attr-hw-shadow-stack
[clang] [Clang][RISCV] Remove forced-sw-shadow-stack (PR #115355)
https://github.com/jaidTw closed https://github.com/llvm/llvm-project/pull/115355 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [RISCV] Implement the implications of C extension (PR #132259)
@@ -378,6 +370,14 @@ def FeatureStdExtZca "part of the C extension, excluding compressed " "floating point loads/stores">; +def FeatureStdExtC +: RISCVExtension<2, 0, "Compressed Instructions", [FeatureStdExtZca]>, + RISCVExtensionBitmask<0, 2>; +def HasStdExtC : Predicate<"Subtarget->hasStdExtC()">, + AssemblerPredicate<(all_of FeatureStdExtC), +"'C' (Compressed Instructions)">; + + def HasStdExtCOrZca : Predicate<"Subtarget->hasStdExtCOrZca()">, AssemblerPredicate<(any_of FeatureStdExtC, FeatureStdExtZca), jaidTw wrote: Thanks for the pointer, I will take a look on it https://github.com/llvm/llvm-project/pull/132259 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [RISCV] Implement the implications of C extension (PR #132259)
https://github.com/jaidTw closed https://github.com/llvm/llvm-project/pull/132259 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [RISCV] Implement the implications of C extension (PR #132259)
https://github.com/jaidTw updated https://github.com/llvm/llvm-project/pull/132259 >From e147dd68477b7e5ec9e6363a45fd7568fe595b04 Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Thu, 20 Mar 2025 10:34:14 -0700 Subject: [PATCH 1/2] [RISCV] Implement the implications of C extension --- .../CodeGen/RISCV/riscv-func-attr-target.c| 4 +-- clang/test/CodeGen/attr-target-clones-riscv.c | 2 +- .../test/CodeGen/attr-target-version-riscv.c | 2 +- .../CodeGenCXX/attr-target-clones-riscv.cpp | 2 +- .../CodeGenCXX/attr-target-version-riscv.cpp | 2 +- llvm/lib/Target/RISCV/RISCVFeatures.td| 16 +-- llvm/lib/TargetParser/RISCVISAInfo.cpp| 13 + llvm/test/CodeGen/RISCV/attributes.ll | 28 --- llvm/test/MC/RISCV/attribute-arch.s | 12 llvm/test/MC/RISCV/attribute.s| 2 +- llvm/test/MC/RISCV/option-arch.s | 12 .../TargetParser/RISCVISAInfoTest.cpp | 19 + 12 files changed, 71 insertions(+), 43 deletions(-) diff --git a/clang/test/CodeGen/RISCV/riscv-func-attr-target.c b/clang/test/CodeGen/RISCV/riscv-func-attr-target.c index cd83876ec5f90..c5189d6aab28f 100644 --- a/clang/test/CodeGen/RISCV/riscv-func-attr-target.c +++ b/clang/test/CodeGen/RISCV/riscv-func-attr-target.c @@ -85,11 +85,11 @@ int test_vsetvlmax_e64m1() { // CHECK: attributes #2 = { {{.*}}"target-features"="+64bit,+a,+m,+save-restore,+zaamo,+zalrsc,+zbb,+zifencei,+zmmul,-relax,-zfa" } // CHECK: attributes #3 = { {{.*}}"target-features"="+64bit,+a,+d,+f,+m,+save-restore,+v,+zaamo,+zalrsc,+zbb,+zicond,+zicsr,+zifencei,+zmmul,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b,-relax,-zfa" } // Make sure we append negative features if we override the arch -// CHECK: attributes #4 = { {{.*}}"target-features"="+64bit,+a,+c,+d,+f,+m,+save-restore,+zaamo,+zalrsc,+zbb,+zicsr,+zifencei,+zmmul,{{(-[[:alnum:]-]+)(,-[[:alnum:]-]+)*}}" } +// CHECK: attributes #4 = { {{.*}}"target-features"="+64bit,+a,+c,+d,+f,+m,+save-restore,+zaamo,+zalrsc,+zbb,+zca,+zcd,+zicsr,+zifencei,+zmmul,{{(-[[:alnum:]-]+)(,-[[:alnum:]-]+)*}}" } // CHECK: attributes #5 = { {{.*}}"target-features"="+64bit,+m,+save-restore,+zmmul,{{(-[[:alnum:]-]+)(,-[[:alnum:]-]+)*}}" } // CHECK: attributes #6 = { {{.*}}"target-cpu"="sifive-u54" "target-features"="+64bit,+a,+m,+save-restore,+zaamo,+zalrsc,+zbb,+zifencei,+zmmul,-relax,-zfa" } // CHECK: attributes #7 = { {{.*}}"target-cpu"="sifive-u54" "target-features"="+64bit,+m,+save-restore,+zmmul,{{(-[[:alnum:]-]+)(,-[[:alnum:]-]+)*}}" } -// CHECK: attributes #8 = { {{.*}}"target-cpu"="sifive-u54" "target-features"="+64bit,+a,+c,+d,+f,+m,+save-restore,+zaamo,+zalrsc,+zicsr,+zifencei,+zmmul,{{(-[[:alnum:]-]+)(,-[[:alnum:]-]+)*}}" } +// CHECK: attributes #8 = { {{.*}}"target-cpu"="sifive-u54" "target-features"="+64bit,+a,+c,+d,+f,+m,+save-restore,+zaamo,+zalrsc,+zca,+zcd,+zicsr,+zifencei,+zmmul,{{(-[[:alnum:]-]+)(,-[[:alnum:]-]+)*}}" } // CHECK: attributes #9 = { {{.*}}"target-features"="+64bit,+a,+m,+save-restore,+zaamo,+zalrsc,+zicsr,+zifencei,+zmmul,+zve32x,+zvl32b,-relax,-zbb,-zfa" } // CHECK: attributes #11 = { {{.*}}"target-features"="+64bit,+a,+f,+m,+save-restore,+zaamo,+zalrsc,+zicsr,+zifencei,+zmmul,+zve32f,+zve32x,+zvl32b,-relax,-zbb,-zfa" } // CHECK: attributes #12 = { {{.*}}"target-features"="+64bit,+a,+d,+f,+m,+save-restore,+zaamo,+zalrsc,+zicsr,+zifencei,+zmmul,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl32b,+zvl64b,-relax,-zbb,-zfa" } diff --git a/clang/test/CodeGen/attr-target-clones-riscv.c b/clang/test/CodeGen/attr-target-clones-riscv.c index 2e8018c707d96..642302ba9d229 100644 --- a/clang/test/CodeGen/attr-target-clones-riscv.c +++ b/clang/test/CodeGen/attr-target-clones-riscv.c @@ -370,7 +370,7 @@ int bar() { return foo1() + foo2() + foo3() + foo4() + foo5() + foo6() + foo7() // CHECK: attributes #[[ATTR0]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+64bit,+i" } // CHECK: attributes #[[ATTR1]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+64bit,+i,+m,+zmmul" } // CHECK: attributes #[[ATTR2]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+64bit,+i,+zbb" } -// CHECK: attributes #[[ATTR3]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+64bit,+c,+i,+zbb" } +// CHECK: attributes #[[ATTR3]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+64bit,+c,+i,+zbb,+zca" } // CHECK: attributes #[[ATTR4]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+64bit,+d,+f,+i,+v,+zbb,+zicsr,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b" } // CHECK: attributes
[clang] [llvm] [RISCV] Implement the implications of C extension (PR #132259)
@@ -25,8 +25,8 @@ addi a0, a1, 0 # CHECK: # encoding: [0xe0,0x1f] addi s0, sp, 1020 -# CHECK: .option arch, -c -.option arch, -c +# CHECK: .option arch, -c, -zca +.option arch, -c, -zca jaidTw wrote: I tried but failed, seems like both are required https://github.com/llvm/llvm-project/pull/132259 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [RISCV] Implement the implications of C extension (PR #132259)
https://github.com/jaidTw created https://github.com/llvm/llvm-project/pull/132259 Implement the following implications according to the [Zc spec](https://github.com/riscvarchive/riscv-code-size-reduction/blob/main/Zc-specification/Zc.adoc#13-c) > As C defines the same instructions as Zca, Zcf and Zcd, the rule is that: > * C always implies Zca > * C+F implies Zcf (RV32 only) > * C+D implies Zcd >From e147dd68477b7e5ec9e6363a45fd7568fe595b04 Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Thu, 20 Mar 2025 10:34:14 -0700 Subject: [PATCH] [RISCV] Implement the implications of C extension --- .../CodeGen/RISCV/riscv-func-attr-target.c| 4 +-- clang/test/CodeGen/attr-target-clones-riscv.c | 2 +- .../test/CodeGen/attr-target-version-riscv.c | 2 +- .../CodeGenCXX/attr-target-clones-riscv.cpp | 2 +- .../CodeGenCXX/attr-target-version-riscv.cpp | 2 +- llvm/lib/Target/RISCV/RISCVFeatures.td| 16 +-- llvm/lib/TargetParser/RISCVISAInfo.cpp| 13 + llvm/test/CodeGen/RISCV/attributes.ll | 28 --- llvm/test/MC/RISCV/attribute-arch.s | 12 llvm/test/MC/RISCV/attribute.s| 2 +- llvm/test/MC/RISCV/option-arch.s | 12 .../TargetParser/RISCVISAInfoTest.cpp | 19 + 12 files changed, 71 insertions(+), 43 deletions(-) diff --git a/clang/test/CodeGen/RISCV/riscv-func-attr-target.c b/clang/test/CodeGen/RISCV/riscv-func-attr-target.c index cd83876ec5f90..c5189d6aab28f 100644 --- a/clang/test/CodeGen/RISCV/riscv-func-attr-target.c +++ b/clang/test/CodeGen/RISCV/riscv-func-attr-target.c @@ -85,11 +85,11 @@ int test_vsetvlmax_e64m1() { // CHECK: attributes #2 = { {{.*}}"target-features"="+64bit,+a,+m,+save-restore,+zaamo,+zalrsc,+zbb,+zifencei,+zmmul,-relax,-zfa" } // CHECK: attributes #3 = { {{.*}}"target-features"="+64bit,+a,+d,+f,+m,+save-restore,+v,+zaamo,+zalrsc,+zbb,+zicond,+zicsr,+zifencei,+zmmul,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b,-relax,-zfa" } // Make sure we append negative features if we override the arch -// CHECK: attributes #4 = { {{.*}}"target-features"="+64bit,+a,+c,+d,+f,+m,+save-restore,+zaamo,+zalrsc,+zbb,+zicsr,+zifencei,+zmmul,{{(-[[:alnum:]-]+)(,-[[:alnum:]-]+)*}}" } +// CHECK: attributes #4 = { {{.*}}"target-features"="+64bit,+a,+c,+d,+f,+m,+save-restore,+zaamo,+zalrsc,+zbb,+zca,+zcd,+zicsr,+zifencei,+zmmul,{{(-[[:alnum:]-]+)(,-[[:alnum:]-]+)*}}" } // CHECK: attributes #5 = { {{.*}}"target-features"="+64bit,+m,+save-restore,+zmmul,{{(-[[:alnum:]-]+)(,-[[:alnum:]-]+)*}}" } // CHECK: attributes #6 = { {{.*}}"target-cpu"="sifive-u54" "target-features"="+64bit,+a,+m,+save-restore,+zaamo,+zalrsc,+zbb,+zifencei,+zmmul,-relax,-zfa" } // CHECK: attributes #7 = { {{.*}}"target-cpu"="sifive-u54" "target-features"="+64bit,+m,+save-restore,+zmmul,{{(-[[:alnum:]-]+)(,-[[:alnum:]-]+)*}}" } -// CHECK: attributes #8 = { {{.*}}"target-cpu"="sifive-u54" "target-features"="+64bit,+a,+c,+d,+f,+m,+save-restore,+zaamo,+zalrsc,+zicsr,+zifencei,+zmmul,{{(-[[:alnum:]-]+)(,-[[:alnum:]-]+)*}}" } +// CHECK: attributes #8 = { {{.*}}"target-cpu"="sifive-u54" "target-features"="+64bit,+a,+c,+d,+f,+m,+save-restore,+zaamo,+zalrsc,+zca,+zcd,+zicsr,+zifencei,+zmmul,{{(-[[:alnum:]-]+)(,-[[:alnum:]-]+)*}}" } // CHECK: attributes #9 = { {{.*}}"target-features"="+64bit,+a,+m,+save-restore,+zaamo,+zalrsc,+zicsr,+zifencei,+zmmul,+zve32x,+zvl32b,-relax,-zbb,-zfa" } // CHECK: attributes #11 = { {{.*}}"target-features"="+64bit,+a,+f,+m,+save-restore,+zaamo,+zalrsc,+zicsr,+zifencei,+zmmul,+zve32f,+zve32x,+zvl32b,-relax,-zbb,-zfa" } // CHECK: attributes #12 = { {{.*}}"target-features"="+64bit,+a,+d,+f,+m,+save-restore,+zaamo,+zalrsc,+zicsr,+zifencei,+zmmul,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl32b,+zvl64b,-relax,-zbb,-zfa" } diff --git a/clang/test/CodeGen/attr-target-clones-riscv.c b/clang/test/CodeGen/attr-target-clones-riscv.c index 2e8018c707d96..642302ba9d229 100644 --- a/clang/test/CodeGen/attr-target-clones-riscv.c +++ b/clang/test/CodeGen/attr-target-clones-riscv.c @@ -370,7 +370,7 @@ int bar() { return foo1() + foo2() + foo3() + foo4() + foo5() + foo6() + foo7() // CHECK: attributes #[[ATTR0]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+64bit,+i" } // CHECK: attributes #[[ATTR1]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+64bit,+i,+m,+zmmul" } // CHECK: attributes #[[ATTR2]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+64bit,+i,+zbb" } -// CHECK: attributes #[[ATTR3]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+64bit,+c,+i,+zbb" } +// CHECK: attributes #[[ATTR3]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"=