[compiler-rt] [asan] Implement address sanitizer on AIX: platform support (PR #139587)
Jake Egan via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 18 08:58:48 PST 2025
https://github.com/jakeegan updated https://github.com/llvm/llvm-project/pull/139587
>From cd8232be07b1be7c5f890155fb3b26ee53c65d60 Mon Sep 17 00:00:00 2001
From: Jake Egan <jake.egan at ibm.com>
Date: Mon, 12 May 2025 13:18:38 -0400
Subject: [PATCH 1/4] asan
---
compiler-rt/lib/asan/CMakeLists.txt | 1 +
compiler-rt/lib/asan/asan_aix.cpp | 48 +++++++++++++++++++
compiler-rt/lib/asan/asan_posix.cpp | 6 ++-
.../lib/asan/scripts/asan_symbolize.py | 10 +++-
4 files changed, 63 insertions(+), 2 deletions(-)
create mode 100644 compiler-rt/lib/asan/asan_aix.cpp
diff --git a/compiler-rt/lib/asan/CMakeLists.txt b/compiler-rt/lib/asan/CMakeLists.txt
index 7d07ec765c005..232bb2574a778 100644
--- a/compiler-rt/lib/asan/CMakeLists.txt
+++ b/compiler-rt/lib/asan/CMakeLists.txt
@@ -1,6 +1,7 @@
# Build for the AddressSanitizer runtime support library.
set(ASAN_SOURCES
+ asan_aix.cpp
asan_allocator.cpp
asan_activation.cpp
asan_debugging.cpp
diff --git a/compiler-rt/lib/asan/asan_aix.cpp b/compiler-rt/lib/asan/asan_aix.cpp
new file mode 100644
index 0000000000000..24edc5cf90228
--- /dev/null
+++ b/compiler-rt/lib/asan/asan_aix.cpp
@@ -0,0 +1,48 @@
+//===-- asan_aix.cpp ------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file is a part of AddressSanitizer, an address sanity checker.
+//
+// AIX-specific details.
+//===----------------------------------------------------------------------===//
+
+#include "sanitizer_common/sanitizer_platform.h"
+
+#if SANITIZER_AIX
+# include "asan_mapping.h"
+# include "sanitizer_common/sanitizer_internal_defs.h"
+
+namespace __asan {
+
+void TryReExecWithoutASLR() {
+ // Allowed to fail and do nothing.
+}
+
+void AsanCheckIncompatibleRT() {}
+
+void AsanCheckDynamicRTPrereqs() {}
+
+void InitializePlatformExceptionHandlers() {}
+
+void *AsanDoesNotSupportStaticLinkage() { return 0; }
+
+void InitializePlatformInterceptors() {}
+void AsanApplyToGlobals(globals_op_fptr op, const void *needle) {}
+
+uptr FindDynamicShadowStart() {
+ UNREACHABLE("AIX does not use dynamic shadow offset!");
+ return 0;
+}
+
+void FlushUnneededASanShadowMemory(uptr p, uptr size) {
+ ReleaseMemoryPagesToOS(MemToShadow(p), MemToShadow(p + size));
+}
+
+} // namespace __asan
+
+#endif // SANITIZER_AIX
diff --git a/compiler-rt/lib/asan/asan_posix.cpp b/compiler-rt/lib/asan/asan_posix.cpp
index fb66c871ea8a5..c2f85099a3e36 100644
--- a/compiler-rt/lib/asan/asan_posix.cpp
+++ b/compiler-rt/lib/asan/asan_posix.cpp
@@ -14,7 +14,11 @@
#include "sanitizer_common/sanitizer_platform.h"
#if SANITIZER_POSIX
+// tid_t is also defined in AIX header /usr/include/sys/types.h which is
+// included by system pthread.h
+# define tid_t tid_t_temp
# include <pthread.h>
+# undef tid_t
# include <signal.h>
# include <stdlib.h>
# include <sys/resource.h>
@@ -180,7 +184,7 @@ static void AfterFork(bool fork_child) {
void InstallAtForkHandler() {
# if SANITIZER_SOLARIS || SANITIZER_NETBSD || SANITIZER_APPLE || \
- (SANITIZER_LINUX && SANITIZER_SPARC) || SANITIZER_HAIKU
+ (SANITIZER_LINUX && SANITIZER_SPARC) || SANITIZER_HAIKU || SANITIZER_AIX
// While other Linux targets use clone in internal_fork which doesn't
// trigger pthread_atfork handlers, Linux/sparc64 uses __fork, causing a
// hang.
diff --git a/compiler-rt/lib/asan/scripts/asan_symbolize.py b/compiler-rt/lib/asan/scripts/asan_symbolize.py
index 8ecd66c745119..50053b3879e0d 100755
--- a/compiler-rt/lib/asan/scripts/asan_symbolize.py
+++ b/compiler-rt/lib/asan/scripts/asan_symbolize.py
@@ -59,6 +59,7 @@ def is_valid_arch(s):
"armv7s",
"armv7k",
"arm64",
+ "powerpc",
"powerpc64",
"powerpc64le",
"s390x",
@@ -449,7 +450,14 @@ def __init__(self, plugin_proxy=None, dsym_hint_producer=None):
# E.g. in Chrome several binaries may share a single .dSYM.
self.dsym_hint_producer = dsym_hint_producer
self.system = os.uname()[0]
- if self.system not in ["Linux", "Darwin", "FreeBSD", "NetBSD", "SunOS"]:
+ if self.system not in [
+ "Linux",
+ "Darwin",
+ "FreeBSD",
+ "NetBSD",
+ "SunOS",
+ "AIX",
+ ]:
raise Exception("Unknown system")
self.llvm_symbolizers = {}
self.last_llvm_symbolizer = None
>From 25c07b4325694970980b935d92ae7c65e8fca1f4 Mon Sep 17 00:00:00 2001
From: Jake Egan <jake.egan at ibm.com>
Date: Mon, 12 May 2025 16:43:09 -0400
Subject: [PATCH 2/4] Fix formatting
---
compiler-rt/lib/asan/scripts/asan_symbolize.py | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/compiler-rt/lib/asan/scripts/asan_symbolize.py b/compiler-rt/lib/asan/scripts/asan_symbolize.py
index 50053b3879e0d..88bf698ce490b 100755
--- a/compiler-rt/lib/asan/scripts/asan_symbolize.py
+++ b/compiler-rt/lib/asan/scripts/asan_symbolize.py
@@ -451,13 +451,13 @@ def __init__(self, plugin_proxy=None, dsym_hint_producer=None):
self.dsym_hint_producer = dsym_hint_producer
self.system = os.uname()[0]
if self.system not in [
- "Linux",
- "Darwin",
- "FreeBSD",
- "NetBSD",
- "SunOS",
- "AIX",
- ]:
+ "Linux",
+ "Darwin",
+ "FreeBSD",
+ "NetBSD",
+ "SunOS",
+ "AIX",
+ ]:
raise Exception("Unknown system")
self.llvm_symbolizers = {}
self.last_llvm_symbolizer = None
>From 01ad344e2c81df5cb96a04ccf3443c781f780f08 Mon Sep 17 00:00:00 2001
From: Jake Egan <jake.egan at ibm.com>
Date: Fri, 17 Oct 2025 15:24:41 -0400
Subject: [PATCH 3/4] Remove hack
---
compiler-rt/lib/asan/asan_posix.cpp | 4 ----
1 file changed, 4 deletions(-)
diff --git a/compiler-rt/lib/asan/asan_posix.cpp b/compiler-rt/lib/asan/asan_posix.cpp
index c2f85099a3e36..598a55d89bdd2 100644
--- a/compiler-rt/lib/asan/asan_posix.cpp
+++ b/compiler-rt/lib/asan/asan_posix.cpp
@@ -14,11 +14,7 @@
#include "sanitizer_common/sanitizer_platform.h"
#if SANITIZER_POSIX
-// tid_t is also defined in AIX header /usr/include/sys/types.h which is
-// included by system pthread.h
-# define tid_t tid_t_temp
# include <pthread.h>
-# undef tid_t
# include <signal.h>
# include <stdlib.h>
# include <sys/resource.h>
>From e9b8c7b7cd6bd937760d5e1cdce1bec9d3f07153 Mon Sep 17 00:00:00 2001
From: Jake Egan <jake.egan at ibm.com>
Date: Fri, 17 Oct 2025 15:48:00 -0400
Subject: [PATCH 4/4] Fix formatting
---
compiler-rt/lib/asan/asan_aix.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/compiler-rt/lib/asan/asan_aix.cpp b/compiler-rt/lib/asan/asan_aix.cpp
index 24edc5cf90228..58a79ea5e7479 100644
--- a/compiler-rt/lib/asan/asan_aix.cpp
+++ b/compiler-rt/lib/asan/asan_aix.cpp
@@ -29,10 +29,10 @@ void AsanCheckDynamicRTPrereqs() {}
void InitializePlatformExceptionHandlers() {}
-void *AsanDoesNotSupportStaticLinkage() { return 0; }
+void* AsanDoesNotSupportStaticLinkage() { return 0; }
void InitializePlatformInterceptors() {}
-void AsanApplyToGlobals(globals_op_fptr op, const void *needle) {}
+void AsanApplyToGlobals(globals_op_fptr op, const void* needle) {}
uptr FindDynamicShadowStart() {
UNREACHABLE("AIX does not use dynamic shadow offset!");
More information about the llvm-commits
mailing list