Skip to content

[compiler-rt] Implement address sanitizer on AIX #130028

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

Closed
wants to merge 1 commit into from

Conversation

jakeegan
Copy link
Member

@jakeegan jakeegan commented Mar 6, 2025

The PR includes compiler-rt changes needed for the address sanitizer on AIX.

clang PR: #129925
llvm PR: #129926

@llvmbot
Copy link
Member

llvmbot commented Mar 6, 2025

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

Author: Jake Egan (jakeegan)

Changes

The PR includes compiler-rt changes needed for the address sanitizer on AIX.

clang PR: #129925
llvm PR: #129926


Patch is 227.53 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/130028.diff

192 Files Affected:

  • (modified) compiler-rt/cmake/Modules/AddCompilerRT.cmake (+17)
  • (modified) compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake (+2-2)
  • (modified) compiler-rt/cmake/base-config-ix.cmake (+5-1)
  • (modified) compiler-rt/cmake/config-ix.cmake (+2-1)
  • (modified) compiler-rt/lib/asan/CMakeLists.txt (+12)
  • (added) compiler-rt/lib/asan/asan.link_with_main_exec.txt (+115)
  • (added) compiler-rt/lib/asan/asan_aix.cpp (+44)
  • (modified) compiler-rt/lib/asan/asan_allocator.cpp (+10-3)
  • (modified) compiler-rt/lib/asan/asan_allocator.h (+4)
  • (added) compiler-rt/lib/asan/asan_cxx.link_with_main_exec.txt (+21)
  • (modified) compiler-rt/lib/asan/asan_descriptions.cpp (+13-8)
  • (modified) compiler-rt/lib/asan/asan_interceptors.cpp (+44-1)
  • (modified) compiler-rt/lib/asan/asan_interceptors.h (+26-2)
  • (modified) compiler-rt/lib/asan/asan_interceptors_memintrinsics.cpp (+3-1)
  • (modified) compiler-rt/lib/asan/asan_malloc_linux.cpp (+20-1)
  • (modified) compiler-rt/lib/asan/asan_mapping.h (+9-1)
  • (added) compiler-rt/lib/asan/asan_mapping_aix64.h (+184)
  • (modified) compiler-rt/lib/asan/asan_poisoning.h (+3-1)
  • (modified) compiler-rt/lib/asan/asan_posix.cpp (+5-1)
  • (modified) compiler-rt/lib/asan/asan_rtl.cpp (+42-3)
  • (modified) compiler-rt/lib/asan/asan_shadow_setup.cpp (+20-3)
  • (modified) compiler-rt/lib/asan/scripts/asan_symbolize.py (+2-1)
  • (modified) compiler-rt/lib/asan/tests/CMakeLists.txt (+7-1)
  • (modified) compiler-rt/lib/interception/CMakeLists.txt (+2)
  • (modified) compiler-rt/lib/interception/interception.h (+17-2)
  • (added) compiler-rt/lib/interception/interception_aix.cpp (+45)
  • (added) compiler-rt/lib/interception/interception_aix.h (+36)
  • (modified) compiler-rt/lib/sanitizer_common/CMakeLists.txt (+9)
  • (added) compiler-rt/lib/sanitizer_common/sanitizer_aix.cpp (+499)
  • (added) compiler-rt/lib/sanitizer_common/sanitizer_aix.h (+47)
  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_allocator_internal.h (+5)
  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary32.h (+1)
  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_common.cpp (+6)
  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_common.h (+6-1)
  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc (+40-12)
  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc (+2)
  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_memintrinsics.inc (+2)
  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cpp (+6-1)
  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_errno.h (+2)
  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_file.cpp (+2-2)
  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_file.h (+2-1)
  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_flags.inc (+3)
  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_platform.h (+11-3)
  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h (+33-19)
  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp (+54-14)
  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h (+75-19)
  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp (+1-1)
  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_posix.h (+5)
  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp (+26-3)
  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_procmaps.h (+2-1)
  • (added) compiler-rt/lib/sanitizer_common/sanitizer_procmaps_aix.cpp (+212)
  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_procmaps_common.cpp (+6-1)
  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_redefine_builtins.h (+1-1)
  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cpp (+4-3)
  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_symbolizer.cpp (+4-1)
  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_libcdep.cpp (+8-1)
  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cpp (+29-3)
  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_win.cpp (+1-1)
  • (added) compiler-rt/lib/sanitizer_common/sanitizer_unwind_aix.cpp (+66)
  • (modified) compiler-rt/lib/sanitizer_common/tests/CMakeLists.txt (+4)
  • (modified) compiler-rt/lib/sanitizer_common/tests/sanitizer_test_utils.h (+1-1)
  • (modified) compiler-rt/test/asan/CMakeLists.txt (+1-1)
  • (modified) compiler-rt/test/asan/TestCases/Posix/asan-symbolize-bad-path.cpp (+4)
  • (modified) compiler-rt/test/asan/TestCases/Posix/asan-symbolize-sanity-test.cpp (+4-4)
  • (modified) compiler-rt/test/asan/TestCases/Posix/asan_symbolize_script/plugin_wrong_frame_number_bug.cpp (+2-2)
  • (modified) compiler-rt/test/asan/TestCases/Posix/asprintf.cpp (+3)
  • (modified) compiler-rt/test/asan/TestCases/Posix/closed-fds.cpp (+1-1)
  • (modified) compiler-rt/test/asan/TestCases/Posix/coverage-fork.cpp (+2)
  • (modified) compiler-rt/test/asan/TestCases/Posix/coverage-module-unloaded.cpp (+3)
  • (modified) compiler-rt/test/asan/TestCases/Posix/coverage-reset.cpp (+2)
  • (modified) compiler-rt/test/asan/TestCases/Posix/coverage.cpp (+3)
  • (modified) compiler-rt/test/asan/TestCases/Posix/deep_call_stack.cpp (+2-1)
  • (modified) compiler-rt/test/asan/TestCases/Posix/fake_stack_gc.cpp (+3)
  • (modified) compiler-rt/test/asan/TestCases/Posix/fgets_fputs.cpp (+3-3)
  • (modified) compiler-rt/test/asan/TestCases/Posix/fread_fwrite.cpp (+2-2)
  • (modified) compiler-rt/test/asan/TestCases/Posix/interception-in-shared-lib-test.cpp (+1-1)
  • (modified) compiler-rt/test/asan/TestCases/Posix/invalid-pointer-pairs-threads.cpp (+12-2)
  • (modified) compiler-rt/test/asan/TestCases/Posix/ioctl.cpp (+1-1)
  • (modified) compiler-rt/test/asan/TestCases/Posix/new_array_cookie_test.cpp (+1-1)
  • (modified) compiler-rt/test/asan/TestCases/Posix/no_asan_gen_globals.c (+4-1)
  • (modified) compiler-rt/test/asan/TestCases/Posix/shared-lib-test.cpp (+2-2)
  • (modified) compiler-rt/test/asan/TestCases/Posix/stack-overflow.cpp (+2)
  • (modified) compiler-rt/test/asan/TestCases/Posix/start-deactivated.cpp (+15-11)
  • (modified) compiler-rt/test/asan/TestCases/Posix/unpoison-alternate-stack.cpp (+3)
  • (modified) compiler-rt/test/asan/TestCases/Posix/wait.cpp (+2-2)
  • (modified) compiler-rt/test/asan/TestCases/Posix/wait3.cpp (+2-2)
  • (modified) compiler-rt/test/asan/TestCases/Posix/wait4.cpp (+2-2)
  • (modified) compiler-rt/test/asan/TestCases/Posix/waitid.cpp (+2-2)
  • (modified) compiler-rt/test/asan/TestCases/calloc-overflow.cpp (+1-1)
  • (modified) compiler-rt/test/asan/TestCases/coverage-disabled.cpp (+3)
  • (modified) compiler-rt/test/asan/TestCases/debug_double_free.cpp (+1-1)
  • (modified) compiler-rt/test/asan/TestCases/debug_locate.cpp (+4)
  • (modified) compiler-rt/test/asan/TestCases/debug_ppc64_mapping.cpp (+1-1)
  • (modified) compiler-rt/test/asan/TestCases/debug_report.cpp (+1-1)
  • (modified) compiler-rt/test/asan/TestCases/double-free.cpp (+2-2)
  • (modified) compiler-rt/test/asan/TestCases/frexp_interceptor.cpp (+3)
  • (modified) compiler-rt/test/asan/TestCases/frexpf_interceptor.cpp (+3)
  • (modified) compiler-rt/test/asan/TestCases/frexpl_interceptor.cpp (+4)
  • (modified) compiler-rt/test/asan/TestCases/global-location-nodebug.cpp (+2-1)
  • (modified) compiler-rt/test/asan/TestCases/global-overflow.cpp (+1-1)
  • (modified) compiler-rt/test/asan/TestCases/global-underflow.cpp (+5)
  • (modified) compiler-rt/test/asan/TestCases/heap-overflow.cpp (+1-1)
  • (modified) compiler-rt/test/asan/TestCases/heavy_uar_test.cpp (+1-1)
  • (modified) compiler-rt/test/asan/TestCases/initialization-bug.cpp (+1-1)
  • (modified) compiler-rt/test/asan/TestCases/intercept-rethrow-exception.cpp (+4)
  • (modified) compiler-rt/test/asan/TestCases/invalid-free.cpp (+6-3)
  • (modified) compiler-rt/test/asan/TestCases/invalid-pointer-pairs-compare-errors.cpp (+18-18)
  • (modified) compiler-rt/test/asan/TestCases/invalid-pointer-pairs-subtract-errors.cpp (+6-6)
  • (modified) compiler-rt/test/asan/TestCases/invalid-pointer-pairs.cpp (+3-3)
  • (modified) compiler-rt/test/asan/TestCases/large_func_test.cpp (+6-2)
  • (modified) compiler-rt/test/asan/TestCases/malloc-size-too-big.cpp (+1-1)
  • (modified) compiler-rt/test/asan/TestCases/malloc_context_size.cpp (+5-3)
  • (modified) compiler-rt/test/asan/TestCases/memset_test.cpp (+20-18)
  • (modified) compiler-rt/test/asan/TestCases/null_deref.cpp (+1-1)
  • (modified) compiler-rt/test/asan/TestCases/print_summary.cpp (+1-1)
  • (modified) compiler-rt/test/asan/TestCases/replaceable_new_delete_shared.cpp (+2-1)
  • (modified) compiler-rt/test/asan/TestCases/set_shadow_test.c (+4)
  • (modified) compiler-rt/test/asan/TestCases/stack-buffer-overflow.cpp (+1-1)
  • (modified) compiler-rt/test/asan/TestCases/strcasestr-1.c (+3)
  • (modified) compiler-rt/test/asan/TestCases/strcasestr-2.c (+3)
  • (modified) compiler-rt/test/asan/TestCases/strcasestr_strict.c (+3)
  • (modified) compiler-rt/test/asan/TestCases/strcat_strict.c (+3)
  • (modified) compiler-rt/test/asan/TestCases/strcmp.c (+3)
  • (modified) compiler-rt/test/asan/TestCases/strcmp_strict.c (+3)
  • (modified) compiler-rt/test/asan/TestCases/strcpy-overlap.cpp (+3)
  • (modified) compiler-rt/test/asan/TestCases/strip_path_prefix.c (+1-1)
  • (modified) compiler-rt/test/asan/TestCases/strncat-overlap.cpp (+3)
  • (modified) compiler-rt/test/asan/TestCases/strncat_strict.c (+3)
  • (modified) compiler-rt/test/asan/TestCases/strncmp_strict.c (+3)
  • (modified) compiler-rt/test/asan/TestCases/strncpy-overflow.cpp (+3)
  • (modified) compiler-rt/test/asan/TestCases/strncpy-overlap.cpp (+3)
  • (modified) compiler-rt/test/asan/TestCases/suppressions-library.cpp (+6)
  • (modified) compiler-rt/test/asan/TestCases/use-after-delete.cpp (+8-4)
  • (modified) compiler-rt/test/asan/TestCases/use-after-free-right.cpp (+3-3)
  • (modified) compiler-rt/test/asan/TestCases/use-after-free.cpp (+3-3)
  • (modified) compiler-rt/test/asan/TestCases/use-after-scope-dtor-order.cpp (+1-1)
  • (modified) compiler-rt/test/asan/TestCases/use-after-scope-if.cpp (+1-1)
  • (modified) compiler-rt/test/asan/TestCases/use-after-scope-inlined.cpp (+2-2)
  • (modified) compiler-rt/test/asan/TestCases/use-after-scope-loop-bug.cpp (+1-1)
  • (modified) compiler-rt/test/asan/TestCases/use-after-scope-loop-removed.cpp (+1-1)
  • (modified) compiler-rt/test/asan/TestCases/use-after-scope-loop.cpp (+1-1)
  • (modified) compiler-rt/test/asan/TestCases/use-after-scope-temp.cpp (+1-1)
  • (modified) compiler-rt/test/asan/TestCases/use-after-scope-temp2.cpp (+1-1)
  • (modified) compiler-rt/test/asan/TestCases/use-after-scope-types.cpp (+1-1)
  • (modified) compiler-rt/test/asan/TestCases/use-after-scope.cpp (+1-1)
  • (modified) compiler-rt/test/asan/TestCases/zero_page_pc.cpp (+3)
  • (modified) compiler-rt/test/asan/lit.cfg.py (+1-1)
  • (modified) compiler-rt/test/lit.common.cfg.py (+24-6)
  • (modified) compiler-rt/test/sanitizer_common/TestCases/Posix/arc4random.cpp (+2-1)
  • (modified) compiler-rt/test/sanitizer_common/TestCases/Posix/create_thread_fail.cpp (+3)
  • (modified) compiler-rt/test/sanitizer_common/TestCases/Posix/dedup_token_length_test.cpp (+3-3)
  • (modified) compiler-rt/test/sanitizer_common/TestCases/Posix/devname.cpp (+2-1)
  • (modified) compiler-rt/test/sanitizer_common/TestCases/Posix/devname_r.cpp (+2-1)
  • (modified) compiler-rt/test/sanitizer_common/TestCases/Posix/fgetln.cpp (+1-1)
  • (modified) compiler-rt/test/sanitizer_common/TestCases/Posix/fseek.cpp (+2-1)
  • (modified) compiler-rt/test/sanitizer_common/TestCases/Posix/fts.cpp (+2-1)
  • (modified) compiler-rt/test/sanitizer_common/TestCases/Posix/funopen.cpp (+2-1)
  • (modified) compiler-rt/test/sanitizer_common/TestCases/Posix/getcpuclockid.c (+2-1)
  • (modified) compiler-rt/test/sanitizer_common/TestCases/Posix/getfsent.cpp (+2-1)
  • (modified) compiler-rt/test/sanitizer_common/TestCases/Posix/getmntinfo.cpp (+2-1)
  • (modified) compiler-rt/test/sanitizer_common/TestCases/Posix/getpass.cpp (+2-1)
  • (modified) compiler-rt/test/sanitizer_common/TestCases/Posix/getpw_getgr.cpp (+1-1)
  • (modified) compiler-rt/test/sanitizer_common/TestCases/Posix/huge_malloc.c (+3)
  • (modified) compiler-rt/test/sanitizer_common/TestCases/Posix/illegal_read_test.cpp (+1-1)
  • (modified) compiler-rt/test/sanitizer_common/TestCases/Posix/illegal_write_test.cpp (+1-1)
  • (modified) compiler-rt/test/sanitizer_common/TestCases/Posix/posix_spawn.c (+3)
  • (modified) compiler-rt/test/sanitizer_common/TestCases/Posix/setvbuf.cpp (+3)
  • (modified) compiler-rt/test/sanitizer_common/TestCases/Posix/signal.cpp (+3)
  • (modified) compiler-rt/test/sanitizer_common/TestCases/Posix/sl_add.cpp (+2-1)
  • (modified) compiler-rt/test/sanitizer_common/TestCases/Posix/strlcat.cpp (+2-1)
  • (modified) compiler-rt/test/sanitizer_common/TestCases/Posix/strlcpy.cpp (+2-1)
  • (modified) compiler-rt/test/sanitizer_common/TestCases/Posix/strtonum.cpp (+2-1)
  • (modified) compiler-rt/test/sanitizer_common/TestCases/Posix/sysctl.cpp (+2-1)
  • (modified) compiler-rt/test/sanitizer_common/TestCases/Posix/vis.cpp (+2-1)
  • (modified) compiler-rt/test/sanitizer_common/TestCases/Posix/wcsdup.c (+7)
  • (modified) compiler-rt/test/sanitizer_common/TestCases/Posix/weak_hook_test.cpp (+3)
  • (modified) compiler-rt/test/sanitizer_common/TestCases/allocator_returns_null.cpp (+3)
  • (modified) compiler-rt/test/sanitizer_common/TestCases/hard_rss_limit_mb_test.cpp (+3)
  • (modified) compiler-rt/test/sanitizer_common/TestCases/max_allocation_size.cpp (+3)
  • (modified) compiler-rt/test/sanitizer_common/TestCases/print-stack-trace.cpp (+5-5)
  • (modified) compiler-rt/test/sanitizer_common/TestCases/sanitizer_coverage_allowlist_ignorelist.cpp (+3)
  • (modified) compiler-rt/test/sanitizer_common/TestCases/sanitizer_coverage_control_flow.cpp (+2)
  • (modified) compiler-rt/test/sanitizer_common/TestCases/sanitizer_coverage_inline8bit_counter.cpp (+2)
  • (modified) compiler-rt/test/sanitizer_common/TestCases/sanitizer_coverage_inline_bool_flag.cpp (+2)
  • (modified) compiler-rt/test/sanitizer_common/TestCases/sanitizer_coverage_stack_depth.cpp (+2)
  • (modified) compiler-rt/test/sanitizer_common/TestCases/sanitizer_coverage_trace_pc_guard-dso.cpp (+3)
  • (modified) compiler-rt/test/sanitizer_common/TestCases/sanitizer_coverage_trace_pc_guard.cpp (+3)
  • (modified) compiler-rt/test/sanitizer_common/TestCases/strcasestr.c (+3)
  • (modified) compiler-rt/test/sanitizer_common/TestCases/suffix-log-path_test.c (+1-1)
  • (modified) compiler-rt/test/sanitizer_common/TestCases/symbolize_pc.cpp (+3-3)
  • (modified) compiler-rt/test/sanitizer_common/TestCases/symbolize_pc_demangle.cpp (+2-2)
  • (modified) compiler-rt/test/sanitizer_common/TestCases/symbolize_pc_inline.cpp (+2-2)
diff --git a/compiler-rt/cmake/Modules/AddCompilerRT.cmake b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
index c3e734f72392f..beccaa15bcca9 100644
--- a/compiler-rt/cmake/Modules/AddCompilerRT.cmake
+++ b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
@@ -582,6 +582,23 @@ macro(add_compiler_rt_script name)
     DESTINATION ${COMPILER_RT_INSTALL_BINARY_DIR})
 endmacro(add_compiler_rt_script src name)
 
+macro(add_compiler_rt_cfg target_name file_name component)
+  set(src_file "${CMAKE_CURRENT_SOURCE_DIR}/${file_name}")
+  get_compiler_rt_output_dir(${COMPILER_RT_DEFAULT_TARGET_ARCH} output_dir)
+  set(dst_file "${output_dir}/${file_name}")
+  add_custom_command(OUTPUT ${dst_file}
+    DEPENDS ${src_file}
+    COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src_file} ${dst_file}
+    COMMENT "Copying ${file_name}...")
+  add_custom_target(${target_name} DEPENDS ${dst_file})
+  install(FILES ${file_name}
+    DESTINATION ${COMPILER_RT_INSTALL_LIBRARY_DIR}
+    COMPONENT ${component})
+  add_dependencies(${component} ${target_name})
+
+  set_target_properties(${target_name} PROPERTIES FOLDER "Compiler-RT Misc")
+endmacro()
+
 # Builds custom version of libc++ and installs it in <prefix>.
 # Can be used to build sanitized versions of libc++ for running unit tests.
 # add_custom_libcxx(<name> <prefix>
diff --git a/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake b/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
index 2683259e93e37..0816a05a7fbbd 100644
--- a/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
+++ b/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
@@ -28,11 +28,11 @@ if(WIN32)
   set(ARM32 ${ARM32} armv7)
 endif()
 
-set(ALL_SANITIZER_COMMON_SUPPORTED_ARCH ${X86} ${X86_64} ${PPC64} ${RISCV64}
+set(ALL_SANITIZER_COMMON_SUPPORTED_ARCH ${X86} ${X86_64} ${PPC32} ${PPC64} ${RISCV64}
     ${ARM32} ${ARM64} ${MIPS32} ${MIPS64} ${S390X} ${SPARC} ${SPARCV9}
     ${HEXAGON} ${LOONGARCH64})
 set(ALL_ASAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${RISCV64}
-    ${MIPS32} ${MIPS64} ${PPC64} ${S390X} ${SPARC} ${SPARCV9} ${HEXAGON}
+    ${MIPS32} ${MIPS64} ${PPC32} ${PPC64} ${S390X} ${SPARC} ${SPARCV9} ${HEXAGON}
     ${LOONGARCH64})
 set(ALL_ASAN_ABI_SUPPORTED_ARCH ${X86_64} ${ARM64} ${ARM64_32})
 set(ALL_DFSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64} ${LOONGARCH64})
diff --git a/compiler-rt/cmake/base-config-ix.cmake b/compiler-rt/cmake/base-config-ix.cmake
index d92bc0e71fa1a..953fa3983ecfc 100644
--- a/compiler-rt/cmake/base-config-ix.cmake
+++ b/compiler-rt/cmake/base-config-ix.cmake
@@ -14,7 +14,11 @@ include(CompilerRTDarwinUtils)
 check_include_file(unwind.h HAVE_UNWIND_H)
 
 # Used by sanitizer_common and tests.
-check_include_file(rpc/xdr.h HAVE_RPC_XDR_H)
+if (${CMAKE_SYSTEM_NAME} MATCHES AIX)
+  check_include_file(tirpc/rpc/xdr.h HAVE_RPC_XDR_H)
+else()
+  check_include_file(rpc/xdr.h HAVE_RPC_XDR_H)
+endif()
 if (NOT HAVE_RPC_XDR_H)
   set(HAVE_RPC_XDR_H 0)
 endif()
diff --git a/compiler-rt/cmake/config-ix.cmake b/compiler-rt/cmake/config-ix.cmake
index cf729c3adb1f5..075493feeadbd 100644
--- a/compiler-rt/cmake/config-ix.cmake
+++ b/compiler-rt/cmake/config-ix.cmake
@@ -141,6 +141,7 @@ check_cxx_compiler_flag("-Werror -Wgnu"                COMPILER_RT_HAS_WGNU_FLAG
 check_cxx_compiler_flag("-Werror -Wgnu-anonymous-struct" COMPILER_RT_HAS_WGNU_ANONYMOUS_STRUCT_FLAG)
 check_cxx_compiler_flag("-Werror -Wvariadic-macros"    COMPILER_RT_HAS_WVARIADIC_MACROS_FLAG)
 check_cxx_compiler_flag("-Werror -Wunused-parameter"   COMPILER_RT_HAS_WUNUSED_PARAMETER_FLAG)
+check_cxx_compiler_flag("-Werror -Watomic-alignment" COMPILER_RT_HAS_WATOMIC_ALIGNMENT_FLAG)
 check_cxx_compiler_flag("-Werror -Wcovered-switch-default" COMPILER_RT_HAS_WCOVERED_SWITCH_DEFAULT_FLAG)
 check_cxx_compiler_flag("-Werror -Wsuggest-override"   COMPILER_RT_HAS_WSUGGEST_OVERRIDE_FLAG)
 check_cxx_compiler_flag("-Werror -Wthread-safety" COMPILER_RT_HAS_WTHREAD_SAFETY_FLAG)
@@ -760,7 +761,7 @@ set(COMPILER_RT_SANITIZERS_TO_BUILD all CACHE STRING
 list_replace(COMPILER_RT_SANITIZERS_TO_BUILD all "${ALL_SANITIZERS}")
 
 if (SANITIZER_COMMON_SUPPORTED_ARCH AND NOT LLVM_USE_SANITIZER AND
-    (OS_NAME MATCHES "Android|Darwin|Linux|FreeBSD|NetBSD|Fuchsia|SunOS" OR
+    (OS_NAME MATCHES "Android|Darwin|Linux|FreeBSD|NetBSD|Fuchsia|SunOS|AIX" OR
     (OS_NAME MATCHES "Windows" AND NOT CYGWIN AND
         (NOT MINGW OR CMAKE_CXX_COMPILER_ID MATCHES "Clang"))))
   set(COMPILER_RT_HAS_SANITIZER_COMMON TRUE)
diff --git a/compiler-rt/lib/asan/CMakeLists.txt b/compiler-rt/lib/asan/CMakeLists.txt
index e2f39f224df9c..6999180139562 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
@@ -281,6 +282,9 @@ else()
       PARENT_TARGET asan)
   endif()
 
+  # On AIX, we only need the static libraries.
+  if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "AIX")
+
   foreach(arch ${ASAN_SUPPORTED_ARCH})
     if (COMPILER_RT_HAS_VERSION_SCRIPT)
       if(WIN32)
@@ -382,10 +386,18 @@ else()
       endif()
     endif()
   endforeach()
+  endif()
 endif()
 
 add_compiler_rt_resource_file(asan_ignorelist asan_ignorelist.txt asan)
 
+# On AIX, we need to put asan.link_with_main_exec.txt and asan_cxx.link_with_main_exec.txt
+# to the build and install dir.
+if (${CMAKE_SYSTEM_NAME} MATCHES "AIX")
+  add_compiler_rt_cfg(asan_symbols asan.link_with_main_exec.txt asan)
+  add_compiler_rt_cfg(asan_cxx_symbols asan_cxx.link_with_main_exec.txt asan)
+endif()
+
 add_subdirectory(scripts)
 
 if(COMPILER_RT_INCLUDE_TESTS)
diff --git a/compiler-rt/lib/asan/asan.link_with_main_exec.txt b/compiler-rt/lib/asan/asan.link_with_main_exec.txt
new file mode 100644
index 0000000000000..5efc48c262369
--- /dev/null
+++ b/compiler-rt/lib/asan/asan.link_with_main_exec.txt
@@ -0,0 +1,115 @@
+#! .
+__asan_report_load_n
+__asan_loadN
+__asan_report_load1
+__asan_load1
+__asan_report_load2
+__asan_load2
+__asan_report_load4
+__asan_load4
+__asan_report_load8
+__asan_load8
+__asan_report_load16
+__asan_load16
+__asan_report_store_n
+__asan_storeN
+__asan_report_store1
+__asan_store1
+__asan_report_store2
+__asan_store2
+__asan_report_store4
+__asan_store4
+__asan_report_store8
+__asan_store8
+__asan_report_store16
+__asan_store16
+__asan_report_exp_load_n
+__asan_exp_loadN
+__asan_report_exp_load1
+__asan_exp_load1
+__asan_report_exp_load2
+__asan_exp_load2
+__asan_report_exp_load4
+__asan_exp_load4
+__asan_report_exp_load8
+__asan_exp_load8
+__asan_report_exp_load16
+__asan_exp_load16
+__asan_report_exp_store_n
+__asan_exp_storeN
+__asan_report_exp_store1
+__asan_exp_store1
+__asan_report_exp_store2
+__asan_exp_store2
+__asan_report_exp_store4
+__asan_exp_store4
+__asan_report_exp_store8
+__asan_exp_store8
+__asan_report_exp_store16
+__asan_exp_store16
+__asan_memmove
+__asan_memcpy
+__asan_memset
+__asan_handle_no_return
+__sanitizer_ptr_cmp
+__sanitizer_ptr_sub
+__asan_before_dynamic_init
+__asan_after_dynamic_init
+__asan_register_globals
+__asan_unregister_globals
+__asan_register_image_globals
+__asan_unregister_image_globals
+__asan_register_elf_globals
+__asan_unregister_elf_globals
+__asan_init
+__asan_version_mismatch_check_v8
+__asan_stack_malloc_0
+__asan_stack_malloc_1
+__asan_stack_malloc_2
+__asan_stack_malloc_3
+__asan_stack_malloc_4
+__asan_stack_malloc_5
+__asan_stack_malloc_6
+__asan_stack_malloc_7
+__asan_stack_malloc_8
+__asan_stack_malloc_9
+__asan_stack_malloc_10
+__asan_stack_malloc_always_0
+__asan_stack_malloc_always_1
+__asan_stack_malloc_always_2
+__asan_stack_malloc_always_3
+__asan_stack_malloc_always_4
+__asan_stack_malloc_always_5
+__asan_stack_malloc_always_6
+__asan_stack_malloc_always_7
+__asan_stack_malloc_always_8
+__asan_stack_malloc_always_9
+__asan_stack_malloc_always_10
+__asan_stack_free_0
+__asan_stack_free_1
+__asan_stack_free_2
+__asan_stack_free_3
+__asan_stack_free_4
+__asan_stack_free_5
+__asan_stack_free_6
+__asan_stack_free_7
+__asan_stack_free_8
+__asan_stack_free_9
+__asan_stack_free_10
+__asan_set_shadow_00
+__asan_set_shadow_01
+__asan_set_shadow_02
+__asan_set_shadow_03
+__asan_set_shadow_04
+__asan_set_shadow_05
+__asan_set_shadow_06
+__asan_set_shadow_07
+__asan_set_shadow_f1
+__asan_set_shadow_f2
+__asan_set_shadow_f3
+__asan_set_shadow_f5
+__asan_set_shadow_f8
+__asan_poison_stack_memory
+__asan_unpoison_stack_memory
+__asan_option_detect_stack_use_after_return
+__asan_shadow_memory_dynamic_address
diff --git a/compiler-rt/lib/asan/asan_aix.cpp b/compiler-rt/lib/asan/asan_aix.cpp
new file mode 100644
index 0000000000000..d1a8a5ac8e59d
--- /dev/null
+++ b/compiler-rt/lib/asan/asan_aix.cpp
@@ -0,0 +1,44 @@
+//===-- 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 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_allocator.cpp b/compiler-rt/lib/asan/asan_allocator.cpp
index 3a55c2af65653..fc826f6448325 100644
--- a/compiler-rt/lib/asan/asan_allocator.cpp
+++ b/compiler-rt/lib/asan/asan_allocator.cpp
@@ -770,11 +770,16 @@ struct Allocator {
       u8 chunk_state = atomic_load(&m->chunk_state, memory_order_acquire);
       if (chunk_state != CHUNK_ALLOCATED)
         ReportInvalidFree(old_ptr, chunk_state, stack);
-      CHECK_NE(REAL(memcpy), nullptr);
       uptr memcpy_size = Min(new_size, m->UsedSize());
       // If realloc() races with free(), we may start copying freed memory.
       // However, we will report racy double-free later anyway.
+#if !SANITIZER_AIX
+      CHECK_NE(REAL(memcpy), nullptr);
       REAL(memcpy)(new_ptr, old_ptr, memcpy_size);
+#else
+      // AIX does not intercept memcpy, we have to use internal_memcpy here.
+      internal_memcpy(new_ptr, old_ptr, memcpy_size);
+#endif
       Deallocate(old_ptr, 0, 0, stack, FROM_MALLOC);
     }
     return new_ptr;
@@ -797,8 +802,10 @@ struct Allocator {
   void ReportInvalidFree(void *ptr, u8 chunk_state, BufferedStackTrace *stack) {
     if (chunk_state == CHUNK_QUARANTINE)
       ReportDoubleFree((uptr)ptr, stack);
-    else
-      ReportFreeNotMalloced((uptr)ptr, stack);
+    else {
+      if (common_flags()->enable_unmalloced_free_check)
+        ReportFreeNotMalloced((uptr)ptr, stack);
+    }
   }
 
   void CommitBack(AsanThreadLocalMallocStorage *ms, BufferedStackTrace *stack) {
diff --git a/compiler-rt/lib/asan/asan_allocator.h b/compiler-rt/lib/asan/asan_allocator.h
index db8dc3bebfc62..46cd7b118cd9a 100644
--- a/compiler-rt/lib/asan/asan_allocator.h
+++ b/compiler-rt/lib/asan/asan_allocator.h
@@ -197,7 +197,11 @@ const uptr kAllocatorSpace = ~(uptr)0;
 #    endif  // SANITIZER_APPLE
 
 #    if defined(__powerpc64__)
+#if SANITIZER_AIX
+const uptr kAllocatorSize  =  1ULL << 38;  // 256G.
+#else
 const uptr kAllocatorSize  =  0x20000000000ULL;  // 2T.
+#endif
 typedef DefaultSizeClassMap SizeClassMap;
 #    elif defined(__aarch64__) && SANITIZER_ANDROID
 // Android needs to support 39, 42 and 48 bit VMA.
diff --git a/compiler-rt/lib/asan/asan_cxx.link_with_main_exec.txt b/compiler-rt/lib/asan/asan_cxx.link_with_main_exec.txt
new file mode 100644
index 0000000000000..7387f8173e859
--- /dev/null
+++ b/compiler-rt/lib/asan/asan_cxx.link_with_main_exec.txt
@@ -0,0 +1,21 @@
+#! .
+_ZdaPv
+_ZdaPvRKSt9nothrow_t
+_ZdaPvSt11align_val_t
+_ZdaPvSt11align_val_tRKSt9nothrow_t
+_ZdaPvm
+_ZdaPvmSt11align_val_t
+_ZdlPv
+_ZdlPvRKSt9nothrow_t
+_ZdlPvSt11align_val_t
+_ZdlPvSt11align_val_tRKSt9nothrow_t
+_ZdlPvm
+_ZdlPvmSt11align_val_t
+_Znam
+_ZnamRKSt9nothrow_t
+_ZnamSt11align_val_t
+_ZnamSt11align_val_tRKSt9nothrow_t
+_Znwm
+_ZnwmRKSt9nothrow_t
+_ZnwmSt11align_val_t
+_ZnwmSt11align_val_tRKSt9nothrow_t
diff --git a/compiler-rt/lib/asan/asan_descriptions.cpp b/compiler-rt/lib/asan/asan_descriptions.cpp
index c9f3e4d682d95..6488d51b89a14 100644
--- a/compiler-rt/lib/asan/asan_descriptions.cpp
+++ b/compiler-rt/lib/asan/asan_descriptions.cpp
@@ -211,10 +211,10 @@ bool GetStackAddressInformation(uptr addr, uptr access_size,
   descr->frame_pc = access.frame_pc;
   descr->frame_descr = access.frame_descr;
 
-#if SANITIZER_PPC64V1
-  // On PowerPC64 ELFv1, the address of a function actually points to a
-  // three-doubleword data structure with the first field containing
-  // the address of the function's code.
+#if SANITIZER_PPC64V1 || SANITIZER_AIX
+  // On PowerPC64 ELFv1 or AIX, the address of a function actually points to a
+  // three-doubleword (or three-word for 32-bit AIX) data structure with the
+  // first field containing the address of the function's code.
   descr->frame_pc = *reinterpret_cast<uptr *>(descr->frame_pc);
 #endif
   descr->frame_pc += 16;
@@ -444,6 +444,15 @@ AddressDescription::AddressDescription(uptr addr, uptr access_size,
     data.kind = kAddressKindShadow;
     return;
   }
+
+  // Check global first. On AIX, some global data defined in shared libraries
+  // are put to the STACK region for unknown reasons. Check global first can
+  // workaround this issue.
+  if (GetGlobalAddressInformation(addr, access_size, &data.global)) {
+    data.kind = kAddressKindGlobal;
+    return;
+  }
+
   if (GetHeapAddressInformation(addr, access_size, &data.heap)) {
     data.kind = kAddressKindHeap;
     return;
@@ -461,10 +470,6 @@ AddressDescription::AddressDescription(uptr addr, uptr access_size,
     return;
   }
 
-  if (GetGlobalAddressInformation(addr, access_size, &data.global)) {
-    data.kind = kAddressKindGlobal;
-    return;
-  }
   data.kind = kAddressKindWild;
   data.wild.addr = addr;
   data.wild.access_size = access_size;
diff --git a/compiler-rt/lib/asan/asan_interceptors.cpp b/compiler-rt/lib/asan/asan_interceptors.cpp
index 247ea1b92f1f4..d55ebedafb086 100644
--- a/compiler-rt/lib/asan/asan_interceptors.cpp
+++ b/compiler-rt/lib/asan/asan_interceptors.cpp
@@ -56,6 +56,7 @@ namespace __asan {
 #  define ASAN_READ_STRING(ctx, s, n) \
     ASAN_READ_STRING_OF_LEN((ctx), (s), internal_strlen(s), (n))
 
+#if SANITIZER_INTERCEPT_STRCAT || SANITIZER_INTERCEPT_STRCPY
 static inline uptr MaybeRealStrnlen(const char *s, uptr maxlen) {
 #if SANITIZER_INTERCEPT_STRNLEN
   if (REAL(strnlen)) {
@@ -64,6 +65,7 @@ static inline uptr MaybeRealStrnlen(const char *s, uptr maxlen) {
 #endif
   return internal_strnlen(s, maxlen);
 }
+#endif
 
 void SetThreadName(const char *name) {
   AsanThread *t = GetCurrentThread();
@@ -275,7 +277,12 @@ INTERCEPTOR(int, pthread_create, void *thread, void *attr,
 #    endif
     asanThreadArgRetval().Create(detached, {start_routine, arg}, [&]() -> uptr {
       result = REAL(pthread_create)(thread, attr, asan_thread_start, t);
+// AIX pthread_t is unsigned int.
+#if SANITIZER_AIX
+      return result ? 0 : *(unsigned int *)(thread);
+#else
       return result ? 0 : *(uptr *)(thread);
+#endif
     });
   }
   if (result != 0) {
@@ -432,10 +439,12 @@ INTERCEPTOR(int, swapcontext, struct ucontext_t *oucp,
 #define siglongjmp __siglongjmp14
 #endif
 
+#if ASAN_INTERCEPT_LONGJMP
 INTERCEPTOR(void, longjmp, void *env, int val) {
   __asan_handle_no_return();
   REAL(longjmp)(env, val);
 }
+#endif
 
 #if ASAN_INTERCEPT__LONGJMP
 INTERCEPTOR(void, _longjmp, void *env, int val) {
@@ -508,6 +517,7 @@ DEFINE_REAL(char*, index, const char *string, int c)
 
 // For both strcat() and strncat() we need to check the validity of |to|
 // argument irrespective of the |from| length.
+#if SANITIZER_INTERCEPT_STRCAT
   INTERCEPTOR(char *, strcat, char *to, const char *from) {
     void *ctx;
     ASAN_INTERCEPTOR_ENTER(ctx, strcat);
@@ -547,7 +557,9 @@ INTERCEPTOR(char*, strncat, char *to, const char *from, usize size) {
   }
   return REAL(strncat)(to, from, size);
 }
+#endif
 
+#if SANITIZER_INTERCEPT_STRCPY
 INTERCEPTOR(char *, strcpy, char *to, const char *from) {
   void *ctx;
   ASAN_INTERCEPTOR_ENTER(ctx, strcpy);
@@ -569,6 +581,7 @@ INTERCEPTOR(char *, strcpy, char *to, const char *from) {
   }
   return REAL(strcpy)(to, from);
 }
+#endif
 
 // Windows doesn't always define the strdup identifier,
 // and when it does it's a macro defined to either _strdup
@@ -596,7 +609,13 @@ INTERCEPTOR(char*, strdup, const char *s) {
   GET_STACK_TRACE_MALLOC;
   void *new_mem = asan_malloc(length + 1, &stack);
   if (new_mem) {
+#  if SANITIZER_AIX
+    // memcpy is a static function defined in libc.a on AIX. It can not be
+    // intercepted, so REAL(memcpy) is null on AIX. Use internal_memcpy instead.
+    internal_memcpy(new_mem, s, length + 1);
+#  else
     REAL(memcpy)(new_mem, s, length + 1);
+#  endif
   }
   return reinterpret_cast<char*>(new_mem);
 }
@@ -614,12 +633,17 @@ INTERCEPTOR(char*, __strdup, const char *s) {
   GET_STACK_TRACE_MALLOC;
   void *new_mem = asan_malloc(length + 1, &stack);
   if (new_mem) {
+#if SANITIZER_AIX
+    internal_memcpy(new_mem, s, length + 1);
+#else
     REAL(memcpy)(new_mem, s, length + 1);
+#endif
   }
   return reinterpret_cast<char*>(new_mem);
 }
 #endif // ASAN_INTERCEPT___STRDUP
 
+#if SANITIZER_INTERCEPT_STRCPY
 INTERCEPTOR(char*, strncpy, char *to, const char *from, usize size) {
   void *ctx;
   ASAN_INTERCEPTOR_ENTER(ctx, strncpy);
@@ -632,6 +656,7 @@ INTERCEPTOR(char*, strncpy, char *to, const char *from, usize size) {
   }
   return REAL(strncpy)(to, from, size);
 }
+#endif
 
 template <typename Fn>
 static ALWAYS_INLINE auto StrtolImpl(void *ctx, Fn real, const char *nptr,
@@ -743,6 +768,14 @@ static void AtCxaAtexit(void *unused) {
 }
 #endif
 
+#if ASAN_INTERCEPT_EXIT
+INTERCEPTOR(void, exit, int status) {
+  AsanInitFromRtl();
+  StopInitOrderChecking();
+  REAL(exit)(status);
+}
+#endif
+
 #if ASAN_INTERCEPT___CXA_ATEXIT
 INTERCEPTOR(int, __cxa_atexit, void (*func)(void *), void *arg,
             void *dso_handle) {
@@ -804,10 +837,14 @@ void InitializeAsanInterceptors() {
   InitializeSignalInterceptors();
 
   // Intercept str* functions.
+#if SANITIZER_INTERCEPT_STRCAT
   ASAN_INTERCEPT_FUNC(strcat);
-  ASAN_INTERCEPT_FUNC(strcpy);
   ASAN_INTERCEPT_FUNC(strncat);
+#endif
+#if SANITIZER_INTERCEPT_STRCPY
+  ASAN_INTERCEPT_FUNC(strcpy);
   ASAN_INTERCEPT_FUNC(strncpy);
+#endif
   ASAN_INTERCEPT_FUNC(strdup);
 #  if ASAN_INTERCEPT___STRDUP
   ASAN_INTERCEPT_FUNC(__strdup);
@@ -827,7 +864,9 @@ void InitializeAsanInterceptors() {
 #  endif
 
   // Intecept jump-related functions.
+#if ASAN_INTERCEPT_LONGJMP
   ASAN_INTERCEPT_FUNC(longjmp);
+#endif
 
 #  if ASAN_INTERCEPT_SWAPCONTEXT
   ASAN_INTERCEPT_FUNC(swapcontext);
@@ -894,6 +933,10 @@ void InitializeAsanInterceptors() {
   ASAN_INTERCEPT_FUNC(atexit);
 #endif
 
+#if ASAN_INTERCEPT_EXIT
+  ASAN_INTERCEPT_FUNC(exit);
+#endif
+
 #if ASAN_INTERCEPT_PTHREAD_ATFORK
   ASAN_INTERCEPT_FUNC(pthread_atfork);
 #endif
diff --git a/compiler-rt/lib/asan/asan_interceptors.h b/compiler-rt/lib/asan/asan_interceptors.h
index 3e2386eaf8092..2ca6bd45b6604 100644
--- a/compiler-rt/lib/asan/asan_interceptors.h
+++ b/compiler-rt/lib/asan/asan_interceptors.h
@@ -31,10 +31,20 @@ void InitializePlatformInterceptors();
 // really defined to replace libc functions.
 #if !SANITIZER_FUCHSIA
 
+#if !SANITIZER_AIX
+# define ASAN_INTERCEPT_LONGJMP 1
+#else
+# define ASAN_INTERCEPT_LONGJMP 0
+#endif
+
 // Use macro to describe if specific function should be
 // intercepted on a given platform.
 #i...
[truncated]

@davidmrdavid
Copy link
Contributor

@jakeegan - this seems like a pretty big PR, close to 200 files changed. Would it make sense to split this into smaller PRs for ease of review?

Comment on lines +246 to +250
# Suppress -Watomic-alignment warnings by not treating them as errors
if (CMAKE_SYSTEM_NAME MATCHES "AIX")
list(APPEND SANITIZER_CFLAGS "-Wno-error=atomic-alignment")
endif()

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is ineffective for handling usage of compiler-rt/lib/sanitizer_common/sanitizer_atomic_clang.h from builds of files outside sanitizer_common.

@vitalybuka vitalybuka self-requested a review March 9, 2025 02:43
Comment on lines +283 to +284
#elif defined(__powerpc__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
const char* const kSymbolizerArch = "--default-arch=powerpc";
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is incorrect. __powerpc__ is also set when __powerpc64__ is set. This change prevents reaching the --default-arch=powerpc64 case.

Copy link
Collaborator

@vitalybuka vitalybuka left a comment

Choose a reason for hiding this comment

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

Please split into patches where each one contains just one type of fixes, with corresponding description.

Comment on lines +182 to +186
// On AIX, the address for the data in the object is the same with the runtime one.
// So, we don't need to sub the base address.
#if SANITIZER_AIX
*module_offset = address;
#else
Copy link
Collaborator

Choose a reason for hiding this comment

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

We know this is not true (even though it works this way sometimes).

@jakeegan jakeegan marked this pull request as draft March 18, 2025 13:46
@@ -38,11 +38,11 @@ int main(int argc, char *argv[]) {
inc2(array, -1); // BOOM
// CHECK: ERROR: AddressSanitizer: heap-buffer-overflow
// CHECK: READ of size 4 at 0x{{.*}}
// CHECK: #0 {{.*}} in inc2 {{.*}}asan-symbolize-sanity-test.cpp:[[@LINE+21]]
// CHECK: #1 {{.*}} in main {{.*}}asan-symbolize-sanity-test.cpp:[[@LINE-4]]
// CHECK: #0 {{.*}} in {{inc2|.inc2}} {{.*}}asan-symbolize-sanity-test.cpp:[[@LINE+21]]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we redo all of these cases using {{\.?}}?
Regardless, this is missing a \ before the ..

@@ -3,7 +3,10 @@
// Make sure ___asan_gen_* strings do not end up in the symbol table.

// RUN: %clang_asan %s -o %t.exe
// RUN: nm %t.exe | FileCheck %s
// RUN: nm %if target={{.*aix.*}} %{ -X32_64 %} %t.exe | FileCheck %s
Copy link
Collaborator

Choose a reason for hiding this comment

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

Change nm to %nm and set the LIT config to have it expand to nm -X32_64 on AIX.

@jakeegan jakeegan changed the title [compiler-rt] Implement address sanitizer on AIX (3/3) [compiler-rt] Implement address sanitizer on AIX Apr 3, 2025
@jakeegan jakeegan closed this Apr 29, 2025
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.

5 participants