https://github.com/androm3da updated https://github.com/llvm/llvm-project/pull/241091
>From 7ae0460ce3c1bb46f6cfe3b1aac63fd9019d86d3 Mon Sep 17 00:00:00 2001 From: Brian Cain <[email protected]> Date: Mon, 9 Nov 2026 20:14:11 -0600 Subject: [PATCH 1/2] [csan] Restrict host offload interceptors to supported runtime targets Build host offload objects and archives only for architectures that the common host offload runtime (RTSanitizerOffload) supports, using the same list_intersect pattern as the UBSan offload interceptors. This keeps CPU-only targets from referencing an unavailable common offload runtime. --- compiler-rt/lib/csan/offload/CMakeLists.txt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/compiler-rt/lib/csan/offload/CMakeLists.txt b/compiler-rt/lib/csan/offload/CMakeLists.txt index 76330eae549cf4..0c91a3bb9b36f4 100644 --- a/compiler-rt/lib/csan/offload/CMakeLists.txt +++ b/compiler-rt/lib/csan/offload/CMakeLists.txt @@ -3,6 +3,11 @@ if(NOT OS_NAME MATCHES "Linux" OR NOT TARGET llvm-libc-common-utilities) return() endif() +set(ALL_CSAN_OFFLOAD_SUPPORTED_ARCH ${X86_64} ${ARM64} ${PPC64}) +list_intersect(CSAN_OFFLOAD_SUPPORTED_ARCH + CSAN_SUPPORTED_ARCH + ALL_CSAN_OFFLOAD_SUPPORTED_ARCH) + set(CSAN_OFFLOAD_SOURCES csan_offload_hsa_interceptors.cpp csan_offload_report.cpp @@ -15,11 +20,11 @@ set(CSAN_OFFLOAD_HEADERS ) add_compiler_rt_object_libraries(RTCsan_offload - ARCHS ${CSAN_SUPPORTED_ARCH} + ARCHS ${CSAN_OFFLOAD_SUPPORTED_ARCH} SOURCES ${CSAN_OFFLOAD_SOURCES} ADDITIONAL_HEADERS ${CSAN_OFFLOAD_HEADERS} CFLAGS ${CSAN_CFLAGS}) -foreach(arch ${CSAN_SUPPORTED_ARCH}) +foreach(arch ${CSAN_OFFLOAD_SUPPORTED_ARCH}) target_link_libraries(RTCsan_offload.${arch} PRIVATE llvm-libc-common-utilities) endforeach() @@ -28,7 +33,7 @@ endforeach() # for static runtimes and is pulled in with -u. add_compiler_rt_runtime(clang_rt.csan_offload STATIC - ARCHS ${CSAN_SUPPORTED_ARCH} + ARCHS ${CSAN_OFFLOAD_SUPPORTED_ARCH} OBJECT_LIBS RTCsan_offload RTSanitizerOffload CFLAGS ${CSAN_CFLAGS} @@ -36,7 +41,7 @@ add_compiler_rt_runtime(clang_rt.csan_offload add_compiler_rt_runtime(clang_rt.csan_offload-preinit STATIC - ARCHS ${CSAN_SUPPORTED_ARCH} + ARCHS ${CSAN_OFFLOAD_SUPPORTED_ARCH} SOURCES csan_offload_preinit.cpp ADDITIONAL_HEADERS ${CSAN_OFFLOAD_HEADERS} CFLAGS ${CSAN_CFLAGS} >From 724176bc2e7ab7ad05927bff6806d625197d194e Mon Sep 17 00:00:00 2001 From: Brian Cain <[email protected]> Date: Mon, 9 Nov 2026 20:14:14 -0600 Subject: [PATCH 2/2] [csan] Support Linux Hexagon hosts Enable the CSan runtime build and Clang driver support for Linux Hexagon. --- clang/docs/ConcurrencySanitizer.md | 3 ++- clang/lib/Driver/ToolChains/Linux.cpp | 2 +- clang/test/Driver/fsanitize.c | 17 +++++++++++++++++ .../cmake/Modules/AllSupportedArchDefs.cmake | 2 +- .../ConcurrencySanitizer/32-bit.ll | 18 ++++++++++++++++++ 5 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 llvm/test/Instrumentation/ConcurrencySanitizer/32-bit.ll diff --git a/clang/docs/ConcurrencySanitizer.md b/clang/docs/ConcurrencySanitizer.md index ca255a7f079ae9..5a9d2b1edabbcb 100644 --- a/clang/docs/ConcurrencySanitizer.md +++ b/clang/docs/ConcurrencySanitizer.md @@ -29,11 +29,12 @@ cmake ../llvm -G Ninja \ CSan currently supports: -- Linux on x86-64. +- Linux on x86-64 and Hexagon. - AMDGPU devices on Linux through the HSA runtime. Support for other hosts and GPU targets is not currently implemented. + ## Usage Compile and link the complete program with `-fsanitize=concurrency`. Use `-g` diff --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp index 3e1a81aec74ab2..5e0994de5ddf76 100644 --- a/clang/lib/Driver/ToolChains/Linux.cpp +++ b/clang/lib/Driver/ToolChains/Linux.cpp @@ -1007,7 +1007,7 @@ Linux::getSupportedSanitizers(BoundArch BA, if (IsX86_64 || IsMIPS64 || IsAArch64 || IsPowerPC64 || IsSystemZ || IsLoongArch64 || IsRISCV64) Res |= SanitizerKind::Thread; - if (IsX86_64 && !IsAndroid) + if ((IsX86_64 || (IsHexagon && getTriple().isOSLinux())) && !IsAndroid) Res |= SanitizerKind::Concurrency; if (IsX86_64 || IsAArch64 || IsSystemZ || IsHexagon) Res |= SanitizerKind::Type; diff --git a/clang/test/Driver/fsanitize.c b/clang/test/Driver/fsanitize.c index adf2811fac8420..db12e069204755 100644 --- a/clang/test/Driver/fsanitize.c +++ b/clang/test/Driver/fsanitize.c @@ -58,6 +58,23 @@ // RUN: not %clang --target=x86_64-linux-android -fsanitize=concurrency %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SANC-ANDROID // CHECK-SANC-ANDROID: unsupported option '-fsanitize=concurrency' for target 'x86_64-unknown-linux-android' +// RUN: %clang --target=hexagon-unknown-linux-musl -fsanitize=concurrency %s -### 2>&1 \ +// RUN: | FileCheck %s --check-prefix=CHECK-SANC-HEXAGON +// CHECK-SANC-HEXAGON-NOT: error: +// CHECK-SANC-HEXAGON: "-fsanitize=concurrency" +// CHECK-SANC-HEXAGON: "--whole-archive" "{{.*}}libclang_rt.csan{{.*}}.a" "--no-whole-archive" +// CHECK-SANC-HEXAGON-NOT: csan_offload + +// RUN: %clang --target=hexagon-unknown-linux-musl -fsanitize=concurrency -shared-libsan %s -### 2>&1 \ +// RUN: | FileCheck %s --check-prefix=CHECK-SANC-HEXAGON-SHARED +// CHECK-SANC-HEXAGON-SHARED-NOT: error: +// CHECK-SANC-HEXAGON-SHARED: "-fsanitize=concurrency" +// CHECK-SANC-HEXAGON-SHARED: libclang_rt.csan{{.*}}.so +// CHECK-SANC-HEXAGON-SHARED-NOT: csan_offload + +// RUN: not %clang --target=hexagon-unknown-none-elf -fsanitize=concurrency %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SANC-HEXAGON-BAREMETAL +// CHECK-SANC-HEXAGON-BAREMETAL: unsupported option '-fsanitize=concurrency' + // RUN: not %clang --target=r600 -mcpu=cypress -nogpulib -fsanitize=concurrency %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SANC-R600 // CHECK-SANC-R600: unsupported option '-fsanitize=concurrency' for target 'r600' // RUN: not %clang --target=amdgpu-amd-amdpal -mcpu=gfx900 -nogpulib -fsanitize=concurrency %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SANC-PAL diff --git a/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake b/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake index dfb6eafff58c61..6584f0180b7c36 100644 --- a/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake +++ b/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake @@ -104,7 +104,7 @@ else() set(ALL_TSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64} ${PPC64} ${S390X} ${LOONGARCH64} ${RISCV64}) endif() -set(ALL_CSAN_SUPPORTED_ARCH ${X86_64} ${AMDGPU}) +set(ALL_CSAN_SUPPORTED_ARCH ${X86_64} ${HEXAGON} ${AMDGPU}) set(ALL_TYSAN_SUPPORTED_ARCH ${X86_64} ${ARM64} ${S390X} ${HEXAGON}) set(ALL_UBSAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${RISCV64} ${MIPS32} ${MIPS64} ${PPC64} ${S390X} ${SPARC} ${SPARCV9} ${HEXAGON} diff --git a/llvm/test/Instrumentation/ConcurrencySanitizer/32-bit.ll b/llvm/test/Instrumentation/ConcurrencySanitizer/32-bit.ll new file mode 100644 index 00000000000000..798e7f1bcf18c5 --- /dev/null +++ b/llvm/test/Instrumentation/ConcurrencySanitizer/32-bit.ll @@ -0,0 +1,18 @@ +; RUN: opt < %s -passes='csan' -S | FileCheck %s + +target datalayout = "e-m:e-p:32:32-i64:64-a:0-n16:32" +target triple = "hexagon-unknown-linux-musl" + +define void @access(ptr %src, ptr %dst, i32 %n) sanitize_concurrency { +; CHECK-LABEL: define void @access( +; CHECK: call void @__csan_read4(ptr %src, i32 0) +; CHECK: call void @__csan_write4(ptr %dst, i32 0) +; CHECK: call void @__csan_read_range(ptr %src, i32 %n, i32 0) +; CHECK: call void @__csan_write_range(ptr %dst, i32 %n, i32 0) + %v = load i32, ptr %src, align 4 + store i32 %v, ptr %dst, align 4 + call void @llvm.memcpy.p0.p0.i32(ptr %dst, ptr %src, i32 %n, i1 false) + ret void +} + +declare void @llvm.memcpy.p0.p0.i32(ptr, ptr, i32, i1) _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
