Skip to content

[asan] Implement address sanitizer on AIX: platform support #139587

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jakeegan
Copy link
Member

@jakeegan jakeegan commented May 12, 2025

Adds some general changes for supporting asan on AIX.

Issue: #138916

Copy link

github-actions bot commented May 12, 2025

✅ With the latest revision this PR passed the Python code formatter.

@jakeegan jakeegan changed the title asan [asan] Implement address sanitizer on AIX: platform specific support May 13, 2025
@jakeegan jakeegan changed the title [asan] Implement address sanitizer on AIX: platform specific support [asan] Implement address sanitizer on AIX: platform support May 13, 2025
@jakeegan jakeegan marked this pull request as ready for review May 13, 2025 02:11
@llvmbot
Copy link
Member

llvmbot commented May 13, 2025

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Jake Egan (jakeegan)

Changes

Adds some general changes for supporting asan on AIX.


Full diff: https://github.com/llvm/llvm-project/pull/139587.diff

4 Files Affected:

  • (modified) compiler-rt/lib/asan/CMakeLists.txt (+1)
  • (added) compiler-rt/lib/asan/asan_aix.cpp (+48)
  • (modified) compiler-rt/lib/asan/asan_posix.cpp (+5-1)
  • (modified) compiler-rt/lib/asan/scripts/asan_symbolize.py (+9-1)
diff --git a/compiler-rt/lib/asan/CMakeLists.txt b/compiler-rt/lib/asan/CMakeLists.txt
index e2f39f224df9c..f26a8c1d52a26 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 058a1614b55e6..7cff87b6c9bc9 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

Comment on lines +19 to +21
# define tid_t tid_t_temp
# include <pthread.h>
# undef tid_t
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be a hack, and the comment does not establish how it is okay to allow other potential usages of tid_t in the AIX headers included later to pick up the "wrong" tid_t definition.

The use of tid_t by AIX is conforming according to POSIX (https://pubs.opengroup.org/onlinepubs/9799919799/functions/V2_chap02.html):

Implementations may add symbols to the headers shown in the following table [ ... ]

A separate PR to have the sanitizers rename its tid_t appears appropriate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants