[clang] [compiler-rt] [Sanitizers] the access size (8 bytes) exceeds the max lock-free size (4 bytes) for 32-bit (PR #125388)
Honey Goyal via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 3 15:11:51 PST 2025
https://github.com/honeygoyal updated https://github.com/llvm/llvm-project/pull/125388
>From f9d8e7f9c0df6beb8b4a63a01ebbc3b3ab93d091 Mon Sep 17 00:00:00 2001
From: Honey Goyal <honey.goyal3 at ibm.com>
Date: Sun, 2 Feb 2025 14:27:01 +0530
Subject: [PATCH 1/8] Test Cases for adding -latomic (the access size (8 bytes)
exceeds the max lock-free size
---
clang/test/Driver/aix-ld.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/clang/test/Driver/aix-ld.c b/clang/test/Driver/aix-ld.c
index 7e0f2bf91e06ee..de65597bcf5d91 100644
--- a/clang/test/Driver/aix-ld.c
+++ b/clang/test/Driver/aix-ld.c
@@ -1120,3 +1120,21 @@
// RUN: -c \
// RUN: | FileCheck --check-prefixes=CHECK-K-UNUSED %s
// CHECK-K-UNUSED: clang: warning: -K: 'linker' input unused [-Wunused-command-line-argument]
+
+// Check No Sanitizer on 32-bit AIX
+// RUN: %if target={{.*aix.*}} %{ \
+// RUN: %clang -target powerpc-ibm-aix -m32 %s -### 2>&1 \
+// RUN: | FileCheck -check-prefix=CHECK-LD32-NO-SANITIZER %s \
+// RUN: %}
+// %if target={{.*aix.*}} %{
+// CHECK-LD32-NO-SANITIZER-NOT: "-latomic"
+// %}
+
+// Check enable AddressSanitizer on 32-bit AIX
+// RUN: %if target={{.*aix.*}} %{ \
+// RUN: %clang -target powerpc-ibm-aix -m32 -fsanitize=address %s -### 2>&1 \
+// RUN: | FileCheck -check-prefix=CHECK-LD32-ASAN %s \
+// RUN: %}
+// %if target={{.*aix.*}} %{
+// CHECK-LD32-ASAN: "-latomic"
+// %}
>From 1b7439e43798c8a1663e9cb72d61a1625b391cec Mon Sep 17 00:00:00 2001
From: Honey Goyal <honey.goyal3 at ibm.com>
Date: Sun, 2 Feb 2025 14:37:11 +0530
Subject: [PATCH 2/8] Added -latomic when sanitizer flag is enabled and
processor is 32-bit
---
clang/lib/Driver/ToolChains/AIX.cpp | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/clang/lib/Driver/ToolChains/AIX.cpp b/clang/lib/Driver/ToolChains/AIX.cpp
index 09a8dc2f4fa5dd..493983468b0bcf 100644
--- a/clang/lib/Driver/ToolChains/AIX.cpp
+++ b/clang/lib/Driver/ToolChains/AIX.cpp
@@ -232,7 +232,7 @@ void aix::Linker::ConstructJob(Compilation &C, const JobAction &JA,
// Specify linker input file(s).
AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);
-
+ const SanitizerArgs &Sanitize = ToolChain.getSanitizerArgs(Args);
if (D.isUsingLTO()) {
assert(!Inputs.empty() && "Must have at least one input.");
// Find the first filename InputInfo object.
@@ -338,6 +338,10 @@ void aix::Linker::ConstructJob(Compilation &C, const JobAction &JA,
CmdArgs.push_back("-lpthread");
}
const char *Exec = Args.MakeArgString(ToolChain.GetLinkerPath());
+
+ if (Sanitize.hasAnySanitizer() && IsArch32Bit) {
+ CmdArgs.push_back("-latomic");
+ }
C.addCommand(std::make_unique<Command>(JA, *this, ResponseFileSupport::None(),
Exec, CmdArgs, Inputs, Output));
}
>From 84d973a841ce1069c941b26f7466330e813797e3 Mon Sep 17 00:00:00 2001
From: Honey Goyal <honey.goyal3 at ibm.com>
Date: Sun, 2 Feb 2025 14:38:49 +0530
Subject: [PATCH 3/8] Suppress -Watomic-alignment warnings by not treating them
as errors
---
compiler-rt/lib/sanitizer_common/CMakeLists.txt | 3 +++
1 file changed, 3 insertions(+)
diff --git a/compiler-rt/lib/sanitizer_common/CMakeLists.txt b/compiler-rt/lib/sanitizer_common/CMakeLists.txt
index 09391e4f5f3704..79eeb31c035a28 100644
--- a/compiler-rt/lib/sanitizer_common/CMakeLists.txt
+++ b/compiler-rt/lib/sanitizer_common/CMakeLists.txt
@@ -239,6 +239,9 @@ append_list_if(SANITIZER_LIMIT_FRAME_SIZE -Wframe-larger-than=570
append_list_if(COMPILER_RT_HAS_WGLOBAL_CONSTRUCTORS_FLAG -Wglobal-constructors
SANITIZER_CFLAGS)
+# Suppress -Watomic-alignment warnings by not treating them as errors
+list(APPEND SANITIZER_CFLAGS "-Wno-error=atomic-alignment")
+
if(APPLE)
set(OS_OPTION OS ${SANITIZER_COMMON_SUPPORTED_OS})
endif()
>From 3addb864505ae401c9be99eee6031dea2908f949 Mon Sep 17 00:00:00 2001
From: Honey Goyal <honeygoyal24 at gmail.com>
Date: Mon, 3 Feb 2025 14:06:24 +0530
Subject: [PATCH 4/8] Update clang/test/Driver/aix-ld.c
Co-authored-by: Hubert Tong <hubert.reinterpretcast at gmail.com>
---
clang/test/Driver/aix-ld.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/clang/test/Driver/aix-ld.c b/clang/test/Driver/aix-ld.c
index de65597bcf5d91..85e8ea1aded3e0 100644
--- a/clang/test/Driver/aix-ld.c
+++ b/clang/test/Driver/aix-ld.c
@@ -1126,9 +1126,7 @@
// RUN: %clang -target powerpc-ibm-aix -m32 %s -### 2>&1 \
// RUN: | FileCheck -check-prefix=CHECK-LD32-NO-SANITIZER %s \
// RUN: %}
-// %if target={{.*aix.*}} %{
// CHECK-LD32-NO-SANITIZER-NOT: "-latomic"
-// %}
// Check enable AddressSanitizer on 32-bit AIX
// RUN: %if target={{.*aix.*}} %{ \
>From b0b9c5ab175d64002440b3b50e99e696d29b6b39 Mon Sep 17 00:00:00 2001
From: Honey Goyal <honeygoyal24 at gmail.com>
Date: Mon, 3 Feb 2025 14:06:35 +0530
Subject: [PATCH 5/8] Update clang/test/Driver/aix-ld.c
Co-authored-by: Hubert Tong <hubert.reinterpretcast at gmail.com>
---
clang/test/Driver/aix-ld.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/clang/test/Driver/aix-ld.c b/clang/test/Driver/aix-ld.c
index 85e8ea1aded3e0..d18279e009c63e 100644
--- a/clang/test/Driver/aix-ld.c
+++ b/clang/test/Driver/aix-ld.c
@@ -1133,6 +1133,4 @@
// RUN: %clang -target powerpc-ibm-aix -m32 -fsanitize=address %s -### 2>&1 \
// RUN: | FileCheck -check-prefix=CHECK-LD32-ASAN %s \
// RUN: %}
-// %if target={{.*aix.*}} %{
// CHECK-LD32-ASAN: "-latomic"
-// %}
>From 317f5ca4ff2ea5dc3f40292c912aae5daeddc546 Mon Sep 17 00:00:00 2001
From: Honey Goyal <honey.goyal3 at ibm.com>
Date: Tue, 4 Feb 2025 04:04:10 +0530
Subject: [PATCH 6/8] Added Comments Required for 64-bit atomic operations used
in sanitizer runtimes
---
clang/lib/Driver/ToolChains/AIX.cpp | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/clang/lib/Driver/ToolChains/AIX.cpp b/clang/lib/Driver/ToolChains/AIX.cpp
index 493983468b0bcf..bdd73497a2893b 100644
--- a/clang/lib/Driver/ToolChains/AIX.cpp
+++ b/clang/lib/Driver/ToolChains/AIX.cpp
@@ -338,7 +338,10 @@ void aix::Linker::ConstructJob(Compilation &C, const JobAction &JA,
CmdArgs.push_back("-lpthread");
}
const char *Exec = Args.MakeArgString(ToolChain.GetLinkerPath());
-
+
+// Required for 64-bit atomic operations used in sanitizer runtimes
+// (e.g., sanitizer_common's atomic utilities). On 32-bit AIX, these
+// are not natively supported, necessitating linkage with -latomic.
if (Sanitize.hasAnySanitizer() && IsArch32Bit) {
CmdArgs.push_back("-latomic");
}
>From 2bae0814b0066b8016e507e16432d4a1f5fb095a Mon Sep 17 00:00:00 2001
From: Honey Goyal <honey.goyal3 at ibm.com>
Date: Tue, 4 Feb 2025 04:12:05 +0530
Subject: [PATCH 7/8] Added Comments in aix-id.c test
---
clang/test/Driver/aix-ld.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/clang/test/Driver/aix-ld.c b/clang/test/Driver/aix-ld.c
index d18279e009c63e..8c26d922ec7106 100644
--- a/clang/test/Driver/aix-ld.c
+++ b/clang/test/Driver/aix-ld.c
@@ -1121,6 +1121,13 @@
// RUN: | FileCheck --check-prefixes=CHECK-K-UNUSED %s
// CHECK-K-UNUSED: clang: warning: -K: 'linker' input unused [-Wunused-command-line-argument]
+
+// This check is only applicable to AIX targets.
+// AIX-specific link behavior requires `-latomic` for 32-bit sanitizer libraries,
+// Running this test on non-AIX targets will result in an unrelated error
+// (e.g., missing atomic support on certain architectures),
+// which is outside the scope of this bug and is addressed separately.
+
// Check No Sanitizer on 32-bit AIX
// RUN: %if target={{.*aix.*}} %{ \
// RUN: %clang -target powerpc-ibm-aix -m32 %s -### 2>&1 \
@@ -1134,3 +1141,4 @@
// RUN: | FileCheck -check-prefix=CHECK-LD32-ASAN %s \
// RUN: %}
// CHECK-LD32-ASAN: "-latomic"
+
>From 0b737c92995bac35f2045157d7222c7ad327e7ca Mon Sep 17 00:00:00 2001
From: Honey Goyal <honey.goyal3 at ibm.com>
Date: Tue, 4 Feb 2025 04:40:03 +0530
Subject: [PATCH 8/8] Added Check specific to AIX and 32 bit processor in
CMakeLists.txt
---
compiler-rt/lib/sanitizer_common/CMakeLists.txt | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/compiler-rt/lib/sanitizer_common/CMakeLists.txt b/compiler-rt/lib/sanitizer_common/CMakeLists.txt
index 79eeb31c035a28..c2b106917d9c58 100644
--- a/compiler-rt/lib/sanitizer_common/CMakeLists.txt
+++ b/compiler-rt/lib/sanitizer_common/CMakeLists.txt
@@ -240,7 +240,9 @@ append_list_if(COMPILER_RT_HAS_WGLOBAL_CONSTRUCTORS_FLAG -Wglobal-constructors
SANITIZER_CFLAGS)
# Suppress -Watomic-alignment warnings by not treating them as errors
-list(APPEND SANITIZER_CFLAGS "-Wno-error=atomic-alignment")
+if (CMAKE_SIZEOF_VOID_P EQUAL 4 AND CMAKE_SYSTEM_NAME STREQUAL "AIX")
+ list(APPEND SANITIZER_CFLAGS "-Wno-error=atomic-alignment")
+endif()
if(APPLE)
set(OS_OPTION OS ${SANITIZER_COMMON_SUPPORTED_OS})
More information about the llvm-commits
mailing list