Skip to content

Commit e91455b

Browse files
committed
Add general asan part
1 parent da16012 commit e91455b

8 files changed

+219
-4
lines changed

compiler-rt/cmake/Modules/AddCompilerRT.cmake

+17
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,23 @@ macro(add_compiler_rt_script name)
582582
DESTINATION ${COMPILER_RT_INSTALL_BINARY_DIR})
583583
endmacro(add_compiler_rt_script src name)
584584

585+
macro(add_compiler_rt_cfg target_name file_name component)
586+
set(src_file "${CMAKE_CURRENT_SOURCE_DIR}/${file_name}")
587+
get_compiler_rt_output_dir(${COMPILER_RT_DEFAULT_TARGET_ARCH} output_dir)
588+
set(dst_file "${output_dir}/${file_name}")
589+
add_custom_command(OUTPUT ${dst_file}
590+
DEPENDS ${src_file}
591+
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src_file} ${dst_file}
592+
COMMENT "Copying ${file_name}...")
593+
add_custom_target(${target_name} DEPENDS ${dst_file})
594+
install(FILES ${file_name}
595+
DESTINATION ${COMPILER_RT_INSTALL_LIBRARY_DIR}
596+
COMPONENT ${component})
597+
add_dependencies(${component} ${target_name})
598+
599+
set_target_properties(${target_name} PROPERTIES FOLDER "Compiler-RT Misc")
600+
endmacro()
601+
585602
# Builds custom version of libc++ and installs it in <prefix>.
586603
# Can be used to build sanitized versions of libc++ for running unit tests.
587604
# add_custom_libcxx(<name> <prefix>

compiler-rt/lib/asan/CMakeLists.txt

+11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Build for the AddressSanitizer runtime support library.
22

33
set(ASAN_SOURCES
4+
asan_aix.cpp
45
asan_allocator.cpp
56
asan_activation.cpp
67
asan_debugging.cpp
@@ -281,6 +282,8 @@ else()
281282
PARENT_TARGET asan)
282283
endif()
283284

285+
# On AIX, we only need the static libraries.
286+
if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "AIX")
284287
foreach(arch ${ASAN_SUPPORTED_ARCH})
285288
if (COMPILER_RT_HAS_VERSION_SCRIPT)
286289
if(WIN32)
@@ -382,10 +385,18 @@ else()
382385
endif()
383386
endif()
384387
endforeach()
388+
endif()
385389
endif()
386390

387391
add_compiler_rt_resource_file(asan_ignorelist asan_ignorelist.txt asan)
388392

393+
On AIX, we need to put asan.link_with_main_exec.txt and asan_cxx.link_with_main_exec.txt
394+
# to the build and install dir.
395+
if (${CMAKE_SYSTEM_NAME} MATCHES "AIX")
396+
add_compiler_rt_cfg(asan_symbols asan.link_with_main_exec.txt asan)
397+
add_compiler_rt_cfg(asan_cxx_symbols asan_cxx.link_with_main_exec.txt asan)
398+
endif()
399+
389400
add_subdirectory(scripts)
390401

391402
if(COMPILER_RT_INCLUDE_TESTS)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
#! .
2+
__asan_report_load_n
3+
__asan_loadN
4+
__asan_report_load1
5+
__asan_load1
6+
__asan_report_load2
7+
__asan_load2
8+
__asan_report_load4
9+
__asan_load4
10+
__asan_report_load8
11+
__asan_load8
12+
__asan_report_load16
13+
__asan_load16
14+
__asan_report_store_n
15+
__asan_storeN
16+
__asan_report_store1
17+
__asan_store1
18+
__asan_report_store2
19+
__asan_store2
20+
__asan_report_store4
21+
__asan_store4
22+
__asan_report_store8
23+
__asan_store8
24+
__asan_report_store16
25+
__asan_store16
26+
__asan_report_exp_load_n
27+
__asan_exp_loadN
28+
__asan_report_exp_load1
29+
__asan_exp_load1
30+
__asan_report_exp_load2
31+
__asan_exp_load2
32+
__asan_report_exp_load4
33+
__asan_exp_load4
34+
__asan_report_exp_load8
35+
__asan_exp_load8
36+
__asan_report_exp_load16
37+
__asan_exp_load16
38+
__asan_report_exp_store_n
39+
__asan_exp_storeN
40+
__asan_report_exp_store1
41+
__asan_exp_store1
42+
__asan_report_exp_store2
43+
__asan_exp_store2
44+
__asan_report_exp_store4
45+
__asan_exp_store4
46+
__asan_report_exp_store8
47+
__asan_exp_store8
48+
__asan_report_exp_store16
49+
__asan_exp_store16
50+
__asan_memmove
51+
__asan_memcpy
52+
__asan_memset
53+
__asan_handle_no_return
54+
__sanitizer_ptr_cmp
55+
__sanitizer_ptr_sub
56+
__asan_before_dynamic_init
57+
__asan_after_dynamic_init
58+
__asan_register_globals
59+
__asan_unregister_globals
60+
__asan_register_image_globals
61+
__asan_unregister_image_globals
62+
__asan_register_elf_globals
63+
__asan_unregister_elf_globals
64+
__asan_init
65+
__asan_version_mismatch_check_v8
66+
__asan_stack_malloc_0
67+
__asan_stack_malloc_1
68+
__asan_stack_malloc_2
69+
__asan_stack_malloc_3
70+
__asan_stack_malloc_4
71+
__asan_stack_malloc_5
72+
__asan_stack_malloc_6
73+
__asan_stack_malloc_7
74+
__asan_stack_malloc_8
75+
__asan_stack_malloc_9
76+
__asan_stack_malloc_10
77+
__asan_stack_malloc_always_0
78+
__asan_stack_malloc_always_1
79+
__asan_stack_malloc_always_2
80+
__asan_stack_malloc_always_3
81+
__asan_stack_malloc_always_4
82+
__asan_stack_malloc_always_5
83+
__asan_stack_malloc_always_6
84+
__asan_stack_malloc_always_7
85+
__asan_stack_malloc_always_8
86+
__asan_stack_malloc_always_9
87+
__asan_stack_malloc_always_10
88+
__asan_stack_free_0
89+
__asan_stack_free_1
90+
__asan_stack_free_2
91+
__asan_stack_free_3
92+
__asan_stack_free_4
93+
__asan_stack_free_5
94+
__asan_stack_free_6
95+
__asan_stack_free_7
96+
__asan_stack_free_8
97+
__asan_stack_free_9
98+
__asan_stack_free_10
99+
__asan_set_shadow_00
100+
__asan_set_shadow_01
101+
__asan_set_shadow_02
102+
__asan_set_shadow_03
103+
__asan_set_shadow_04
104+
__asan_set_shadow_05
105+
__asan_set_shadow_06
106+
__asan_set_shadow_07
107+
__asan_set_shadow_f1
108+
__asan_set_shadow_f2
109+
__asan_set_shadow_f3
110+
__asan_set_shadow_f5
111+
__asan_set_shadow_f8
112+
__asan_poison_stack_memory
113+
__asan_unpoison_stack_memory
114+
__asan_option_detect_stack_use_after_return
115+
__asan_shadow_memory_dynamic_address

compiler-rt/lib/asan/asan_aix.cpp

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//===-- asan_aix.cpp ------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This file is a part of AddressSanitizer, an address sanity checker.
10+
//
11+
// AIX-specific details.
12+
//===----------------------------------------------------------------------===//
13+
14+
#include "sanitizer_common/sanitizer_platform.h"
15+
16+
#if SANITIZER_AIX
17+
# include "asan_mapping.h"
18+
# include "sanitizer_common/sanitizer_internal_defs.h"
19+
20+
namespace __asan {
21+
22+
void AsanCheckIncompatibleRT() {}
23+
24+
void AsanCheckDynamicRTPrereqs() {}
25+
26+
void InitializePlatformExceptionHandlers() {}
27+
28+
void *AsanDoesNotSupportStaticLinkage() { return 0; }
29+
30+
void InitializePlatformInterceptors() {}
31+
void AsanApplyToGlobals(globals_op_fptr op, const void *needle) {}
32+
33+
uptr FindDynamicShadowStart() {
34+
UNREACHABLE("AIX does not use dynamic shadow offset!");
35+
return 0;
36+
}
37+
38+
void FlushUnneededASanShadowMemory(uptr p, uptr size) {
39+
ReleaseMemoryPagesToOS(MemToShadow(p), MemToShadow(p + size));
40+
}
41+
42+
} // namespace __asan
43+
44+
#endif // SANITIZER_AIX

compiler-rt/lib/asan/asan_allocator.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -797,8 +797,10 @@ struct Allocator {
797797
void ReportInvalidFree(void *ptr, u8 chunk_state, BufferedStackTrace *stack) {
798798
if (chunk_state == CHUNK_QUARANTINE)
799799
ReportDoubleFree((uptr)ptr, stack);
800-
else
801-
ReportFreeNotMalloced((uptr)ptr, stack);
800+
else {
801+
if (common_flags()->enable_unmalloced_free_check)
802+
ReportFreeNotMalloced((uptr)ptr, stack);
803+
}
802804
}
803805

804806
void CommitBack(AsanThreadLocalMallocStorage *ms, BufferedStackTrace *stack) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#! .
2+
_ZdaPv
3+
_ZdaPvRKSt9nothrow_t
4+
_ZdaPvSt11align_val_t
5+
_ZdaPvSt11align_val_tRKSt9nothrow_t
6+
_ZdaPvm
7+
_ZdaPvmSt11align_val_t
8+
_ZdlPv
9+
_ZdlPvRKSt9nothrow_t
10+
_ZdlPvSt11align_val_t
11+
_ZdlPvSt11align_val_tRKSt9nothrow_t
12+
_ZdlPvm
13+
_ZdlPvmSt11align_val_t
14+
_Znam
15+
_ZnamRKSt9nothrow_t
16+
_ZnamSt11align_val_t
17+
_ZnamSt11align_val_tRKSt9nothrow_t
18+
_Znwm
19+
_ZnwmRKSt9nothrow_t
20+
_ZnwmSt11align_val_t
21+
_ZnwmSt11align_val_tRKSt9nothrow_t

compiler-rt/lib/asan/asan_posix.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
#include "sanitizer_common/sanitizer_platform.h"
1515
#if SANITIZER_POSIX
1616

17+
// tid_t is also defined in AIX header /usr/include/sys/types.h which is
18+
// included by system pthread.h
19+
# define tid_t tid_t_temp
1720
# include <pthread.h>
21+
# undef tid_t
1822
# include <signal.h>
1923
# include <stdlib.h>
2024
# include <sys/resource.h>
@@ -173,7 +177,7 @@ static void AfterFork(bool fork_child) {
173177
}
174178

175179
void InstallAtForkHandler() {
176-
# if SANITIZER_SOLARIS || SANITIZER_NETBSD || SANITIZER_APPLE || \
180+
# if SANITIZER_SOLARIS || SANITIZER_NETBSD || SANITIZER_APPLE || SANITIZER_AIX || \
177181
(SANITIZER_LINUX && SANITIZER_SPARC)
178182
// While other Linux targets use clone in internal_fork which doesn't
179183
// trigger pthread_atfork handlers, Linux/sparc64 uses __fork, causing a

compiler-rt/lib/asan/scripts/asan_symbolize.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def is_valid_arch(s):
5959
"armv7s",
6060
"armv7k",
6161
"arm64",
62+
"powerpc",
6263
"powerpc64",
6364
"powerpc64le",
6465
"s390x",
@@ -449,7 +450,7 @@ def __init__(self, plugin_proxy=None, dsym_hint_producer=None):
449450
# E.g. in Chrome several binaries may share a single .dSYM.
450451
self.dsym_hint_producer = dsym_hint_producer
451452
self.system = os.uname()[0]
452-
if self.system not in ["Linux", "Darwin", "FreeBSD", "NetBSD", "SunOS"]:
453+
if self.system not in ["Linux", "Darwin", "FreeBSD", "NetBSD", "SunOS", "AIX"]:
453454
raise Exception("Unknown system")
454455
self.llvm_symbolizers = {}
455456
self.last_llvm_symbolizer = None

0 commit comments

Comments
 (0)