[clang] [compiler-rt] Issue 17812: [Atomic] the access size (8 bytes) exceeds the max lock-free size (4 bytes) for 32-bit (PR #125388)

via llvm-commits llvm-commits at lists.llvm.org
Sun Feb 2 01:16:39 PST 2025


https://github.com/honeygoyal created https://github.com/llvm/llvm-project/pull/125388

## Description
[Atomic] the access size (8 bytes) exceeds the max lock-free size (4 bytes) for 32-bit.
- Suppress -Watomic-alignment warnings by not treating them as errors
- Added -latomic when sanitizer flag is enabled and processor is 32-bit
- Adding the -latomic flag is essential for ensuring that atomic operations required by sanitizers are properly linked on 32-bit AIX systems. 
- This change addresses linker warnings, enhances build stability, and ensures the reliable functioning of sanitizers, thereby improving the overall quality and robustness of the build process.

Driver Test Case (AIX.cpp) -
Test Case 1: Sanitizer enabled on 32-bit AIX – -latomic should be added with diagnostic.
Test Case 2: Sanitizer disabled on 32-bit AIX – -latomic should not be added.

>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/3] 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 7e0f2bf91e06ee5..de65597bcf5d914 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/3] 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 09a8dc2f4fa5dd8..493983468b0bcf9 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/3] 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 09391e4f5f3704b..79eeb31c035a282 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()



More information about the llvm-commits mailing list