llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang-driver Author: Brian Cain (androm3da) <details> <summary>Changes</summary> Enable -fsanitize=cfi-icall for Hexagon targets: - Add Hexagon to the CFI-ICall allow-list in the Clang driver. - Add Hexagon jump table support in LowerTypeTests: 4-byte entries using the `jump` instruction, and route Hexagon through the native function bit-set builder. --- Full diff: https://github.com/llvm/llvm-project/pull/191754.diff 5 Files Affected: - (modified) clang/lib/Driver/ToolChain.cpp (+2-1) - (modified) clang/test/Driver/fsanitize-cfi.c (+4) - (modified) llvm/lib/Transforms/IPO/LowerTypeTests.cpp (+6-1) - (modified) llvm/test/Transforms/LowerTypeTests/function-weak.ll (+2) - (modified) llvm/test/Transforms/LowerTypeTests/function.ll (+6) ``````````diff diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp index 945037369e4ee..66cbd32de4ff7 100644 --- a/clang/lib/Driver/ToolChain.cpp +++ b/clang/lib/Driver/ToolChain.cpp @@ -1664,7 +1664,8 @@ SanitizerMask ToolChain::getSupportedSanitizers() const { getTriple().getArch() == llvm::Triple::arm || getTriple().getArch() == llvm::Triple::thumb || getTriple().isWasm() || getTriple().isAArch64() || getTriple().isRISCV() || - getTriple().isLoongArch64()) + getTriple().isLoongArch64() || + getTriple().getArch() == llvm::Triple::hexagon) Res |= SanitizerKind::CFIICall; if (getTriple().getArch() == llvm::Triple::x86_64 || getTriple().isAArch64(64) || getTriple().isRISCV()) diff --git a/clang/test/Driver/fsanitize-cfi.c b/clang/test/Driver/fsanitize-cfi.c index 5886dc370730b..c58ad3b8c2f1c 100644 --- a/clang/test/Driver/fsanitize-cfi.c +++ b/clang/test/Driver/fsanitize-cfi.c @@ -37,6 +37,10 @@ // RUN: not %clang --target=mips-unknown-linux -fsanitize=cfi-icall %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI-ICALL-MIPS // CHECK-CFI-ICALL-MIPS: error: unsupported option '-fsanitize=cfi-icall' for target 'mips-unknown-linux' +// RUN: %clang --target=hexagon-unknown-linux-musl -fsanitize=cfi-icall -fvisibility=hidden -flto -c -resource-dir=%S/Inputs/resource_dir %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI-ICALL-HEXAGON +// CHECK-CFI-ICALL-HEXAGON: "-emit-llvm-bc" +// CHECK-CFI-ICALL-HEXAGON-NOT: error: unsupported option + // RUN: not %clang --target=x86_64-apple-darwin10 -mmacos-version-min=10.7 -flto -fsanitize=cfi-vcall -fno-sanitize-trap=cfi -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CFI-NOTRAP-OLD-MACOS // CHECK-CFI-NOTRAP-OLD-MACOS: error: unsupported option '-fno-sanitize-trap=cfi-vcall' for target 'x86_64-apple-darwin10' diff --git a/llvm/lib/Transforms/IPO/LowerTypeTests.cpp b/llvm/lib/Transforms/IPO/LowerTypeTests.cpp index b3d317b1690c3..643907543c8e2 100644 --- a/llvm/lib/Transforms/IPO/LowerTypeTests.cpp +++ b/llvm/lib/Transforms/IPO/LowerTypeTests.cpp @@ -1266,6 +1266,7 @@ static const unsigned kARMBTIJumpTableEntrySize = 8; static const unsigned kARMv6MJumpTableEntrySize = 16; static const unsigned kRISCVJumpTableEntrySize = 8; static const unsigned kLOONGARCH64JumpTableEntrySize = 8; +static const unsigned kHexagonJumpTableEntrySize = 4; bool LowerTypeTestsModule::hasBranchTargetEnforcement() { if (HasBranchTargetEnforcement == -1) { @@ -1309,6 +1310,8 @@ LowerTypeTestsModule::getJumpTableEntrySize(Triple::ArchType JumpTableArch) { return kRISCVJumpTableEntrySize; case Triple::loongarch64: return kLOONGARCH64JumpTableEntrySize; + case Triple::hexagon: + return kHexagonJumpTableEntrySize; default: report_fatal_error("Unsupported architecture for jump tables"); } @@ -1375,6 +1378,8 @@ LowerTypeTestsModule::createJumpTableEntryAsm(Triple::ArchType JumpTableArch) { } else if (JumpTableArch == Triple::loongarch64) { AsmOS << "pcalau12i $$t0, %pc_hi20($0)\n" << "jirl $$r0, $$t0, %pc_lo12($0)\n"; + } else if (JumpTableArch == Triple::hexagon) { + AsmOS << "jump $0\n"; } else { report_fatal_error("Unsupported architecture for jump tables"); } @@ -1392,7 +1397,7 @@ void LowerTypeTestsModule::buildBitSetsFromFunctions( if (Arch == Triple::x86 || Arch == Triple::x86_64 || Arch == Triple::arm || Arch == Triple::thumb || Arch == Triple::aarch64 || Arch == Triple::riscv32 || Arch == Triple::riscv64 || - Arch == Triple::loongarch64) + Arch == Triple::loongarch64 || Arch == Triple::hexagon) buildBitSetsFromFunctionsNative(TypeIds, Functions); else if (Arch == Triple::wasm32 || Arch == Triple::wasm64) buildBitSetsFromFunctionsWASM(TypeIds, Functions); diff --git a/llvm/test/Transforms/LowerTypeTests/function-weak.ll b/llvm/test/Transforms/LowerTypeTests/function-weak.ll index dbbe8fa4a0a9a..e7eb8e150a727 100644 --- a/llvm/test/Transforms/LowerTypeTests/function-weak.ll +++ b/llvm/test/Transforms/LowerTypeTests/function-weak.ll @@ -5,6 +5,7 @@ ; RUN: opt -S -passes=lowertypetests -mtriple=riscv32-unknown-linux-gnu %s | FileCheck --check-prefixes=CHECK,RISCV %s ; RUN: opt -S -passes=lowertypetests -mtriple=riscv64-unknown-linux-gnu %s | FileCheck --check-prefixes=CHECK,RISCV %s ; RUN: opt -S -passes=lowertypetests -mtriple=loongarch64-unknown-linux-gnu %s | FileCheck --check-prefixes=CHECK,LOONGARCH64 %s +; RUN: opt -S -passes=lowertypetests -mtriple=hexagon-unknown-linux-musl %s | FileCheck --check-prefixes=CHECK,HEXAGON %s target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-unknown-linux-gnu" @@ -137,6 +138,7 @@ define i1 @foo(ptr %p) { ; ARM: define private void @[[JT]]() #{{.*}} align 4 { ; RISCV: define private void @[[JT]]() #{{.*}} align 8 { ; LOONGARCH64: define private void @[[JT]]() #{{.*}} align 8 { +; HEXAGON: define private void @[[JT]]() #{{.*}} align 4 { ; CHECK-LABEL: define internal void @__cfi_global_var_init() section ".text.startup" { ; CHECK-NEXT: entry: diff --git a/llvm/test/Transforms/LowerTypeTests/function.ll b/llvm/test/Transforms/LowerTypeTests/function.ll index fa7c7bbcdabd3..14dc415314dd9 100644 --- a/llvm/test/Transforms/LowerTypeTests/function.ll +++ b/llvm/test/Transforms/LowerTypeTests/function.ll @@ -16,6 +16,7 @@ ; RUN: %if arm-registered-target %{ opt -S -passes=lowertypetests -mtriple=thumbv6m-unknown-linux-gnu %s | FileCheck --check-prefixes=THUMBV6M,NATIVE,JT16 %s %} ; RUN: %if arm-registered-target %{ opt -S -passes=lowertypetests -mtriple=thumbv5-unknown-linux-gnu %s | FileCheck --check-prefixes=ARM,NATIVE,JT4 %s %} ; RUN: %if arm-registered-target %{ opt -S -passes=lowertypetests -mtriple=aarch64-unknown-linux-gnu %s | FileCheck --check-prefixes=ARM,NATIVE,JT4 %s %} +; RUN: opt -S -passes=lowertypetests -mtriple=hexagon-unknown-linux-musl %s | FileCheck --check-prefixes=HEXAGON,NATIVE,JT4 %s ; Tests that we correctly handle bitsets containing 2 or more functions. @@ -73,6 +74,8 @@ define i1 @foo(ptr %p) { ; ARM: b $0 +; HEXAGON: jump $0 + ; THUMB: b.w $0 ; THUMBV6M: push {r0,r1} @@ -97,6 +100,8 @@ define i1 @foo(ptr %p) { ; ARM-NEXT: b $0 +; HEXAGON-NEXT: jump $0 + ; THUMB-NEXT: b.w $0 ; THUMBV6M-NEXT: push {r0,r1} @@ -120,6 +125,7 @@ define i1 @foo(ptr %p) { ; THUMBV6M: attributes #[[ATTR]] = { naked noinline "target-features"="+thumb-mode" } ; RISCV: attributes #[[ATTR]] = { naked noinline "target-features"="-c,-relax" } ; LOONGARCH64: attributes #[[ATTR]] = { naked noinline } +; HEXAGON: attributes #[[ATTR]] = { naked noinline } ; WASM32: ![[I0]] = !{i64 1} ; WASM32: ![[I1]] = !{i64 2} `````````` </details> https://github.com/llvm/llvm-project/pull/191754 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
