Skip to content

[asan] Implement address sanitizer on AIX: build configuration #139583

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 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions compiler-rt/cmake/Modules/AddCompilerRT.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,24 @@ 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 arch)
set(src_file "${CMAKE_CURRENT_SOURCE_DIR}/${file_name}")
get_compiler_rt_output_dir(${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>
Expand Down
13 changes: 13 additions & 0 deletions compiler-rt/lib/asan/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@ else()
PARENT_TARGET asan)
endif()

# On AIX, we only need the static libraries.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I understand that the overall usability (and what steps may be needed to use) the shared libraries is in question, but I am not sure that it means we should suppress them here in the build (as opposed to avoiding their usage in the Clang driver).

Copy link
Member Author

@jakeegan jakeegan May 26, 2025

Choose a reason for hiding this comment

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

I realized if I allow the shared libraries to be built, I get a cmake error because both shared and static libraries have the same name libclang_rt.asan.a. So this would take additional work to support building shared libraries that won't be used at the moment. I think it makes sense to not build them for now.

Copy link
Member

Choose a reason for hiding this comment

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

This is a general issue with the runtimes on AIX (C++, flang_rt, etc.). For now we've been doing exactly this and disallowing you to build both at the same time.

if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "AIX")
foreach(arch ${ASAN_SUPPORTED_ARCH})
if (COMPILER_RT_HAS_VERSION_SCRIPT)
if(WIN32)
Expand Down Expand Up @@ -382,10 +384,21 @@ else()
endif()
endif()
endforeach()
endif()
endif()

add_compiler_rt_resource_file(asan_ignorelist asan_ignorelist.txt asan)

# On AIX, static sanitizer libraries are not added to the DSO, so we need to put
# asan.link_with_main_exec.txt and asan_cxx.link_with_main_exec.txt to the build
# and install dir for use in resolving undefined sanitizer symbols at runtime.
if (${CMAKE_SYSTEM_NAME} MATCHES "AIX")
foreach(arch ${ASAN_SUPPORTED_ARCH})
add_compiler_rt_cfg(asan_symbols_${arch} asan.link_with_main_exec.txt asan ${arch})
add_compiler_rt_cfg(asan_cxx_symbols_${arch} asan_cxx.link_with_main_exec.txt asan ${arch})
endforeach()
endif()

add_subdirectory(scripts)

if(COMPILER_RT_INCLUDE_TESTS)
Expand Down
115 changes: 115 additions & 0 deletions compiler-rt/lib/asan/asan.link_with_main_exec.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#! .
Copy link
Collaborator

Choose a reason for hiding this comment

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

Myabe have name with aix in it if this is AIX specific file?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Would moving it to a AIX-specific subdirectory in the source tree address this? I think it should be okay to have the file named as-is in the install tree (since it would only be present for AIX).

Full disclosure: This file should ideally be automatically generated with the same set of symbols as what the shared library build would export. Currently, there is some issue with the visibility of symbols in the build.

__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
21 changes: 21 additions & 0 deletions compiler-rt/lib/asan/asan_cxx.link_with_main_exec.txt
Original file line number Diff line number Diff line change
@@ -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
Loading