2012-06-20 18:18:43 +08:00
|
|
|
# Build system for the common Sanitizer runtime support library components.
|
|
|
|
# These components are shared between AddressSanitizer and ThreadSanitizer.
|
|
|
|
|
[sanitizer] Move termination functions in their own file
Summary:
As suggested by kcc@ in http://reviews.llvm.org/D20084#441418, move the CheckFailed and Die functions, and their associated callback functionalities in their own separate file.
I expended the build rules to include a new rule that would not include those termination functions, so that another project can define their own.
The tests check-{a,t,m,ub,l,e,df}san are all passing.
Reviewers: llvm-commits, kcc
Subscribers: kubabrecka
Differential Revision: http://reviews.llvm.org/D20742
llvm-svn: 271055
2016-05-28 05:57:17 +08:00
|
|
|
set(SANITIZER_SOURCES_NOTERMINATION
|
2012-06-20 18:18:43 +08:00
|
|
|
sanitizer_allocator.cc
|
|
|
|
sanitizer_common.cc
|
2014-02-28 18:48:13 +08:00
|
|
|
sanitizer_deadlock_detector1.cc
|
2014-03-04 20:52:20 +08:00
|
|
|
sanitizer_deadlock_detector2.cc
|
2017-07-06 08:50:57 +08:00
|
|
|
sanitizer_errno.cc
|
2017-07-22 09:46:40 +08:00
|
|
|
sanitizer_file.cc
|
2012-07-10 17:17:06 +08:00
|
|
|
sanitizer_flags.cc
|
2015-01-15 23:13:43 +08:00
|
|
|
sanitizer_flag_parser.cc
|
2017-08-02 06:22:25 +08:00
|
|
|
sanitizer_fuchsia.cc
|
2012-06-20 18:18:43 +08:00
|
|
|
sanitizer_libc.cc
|
2013-10-03 21:37:17 +08:00
|
|
|
sanitizer_libignore.cc
|
2012-06-20 18:18:43 +08:00
|
|
|
sanitizer_linux.cc
|
2016-04-16 06:11:10 +08:00
|
|
|
sanitizer_linux_s390.cc
|
2012-06-20 18:18:43 +08:00
|
|
|
sanitizer_mac.cc
|
2014-05-21 17:02:13 +08:00
|
|
|
sanitizer_persistent_allocator.cc
|
2013-09-06 22:20:01 +08:00
|
|
|
sanitizer_platform_limits_linux.cc
|
2013-02-19 17:19:16 +08:00
|
|
|
sanitizer_platform_limits_posix.cc
|
2012-06-20 18:18:43 +08:00
|
|
|
sanitizer_posix.cc
|
|
|
|
sanitizer_printf.cc
|
2014-08-06 18:16:52 +08:00
|
|
|
sanitizer_procmaps_common.cc
|
|
|
|
sanitizer_procmaps_freebsd.cc
|
2013-12-25 16:01:16 +08:00
|
|
|
sanitizer_procmaps_linux.cc
|
|
|
|
sanitizer_procmaps_mac.cc
|
2012-09-11 18:50:32 +08:00
|
|
|
sanitizer_stackdepot.cc
|
2012-08-28 22:11:57 +08:00
|
|
|
sanitizer_stacktrace.cc
|
2014-11-06 06:44:36 +08:00
|
|
|
sanitizer_stacktrace_printer.cc
|
2017-02-14 05:03:15 +08:00
|
|
|
sanitizer_stoptheworld_mac.cc
|
2013-06-26 23:37:14 +08:00
|
|
|
sanitizer_suppressions.cc
|
2013-10-26 07:03:29 +08:00
|
|
|
sanitizer_symbolizer.cc
|
2014-01-16 21:48:15 +08:00
|
|
|
sanitizer_symbolizer_libbacktrace.cc
|
2015-03-12 18:53:18 +08:00
|
|
|
sanitizer_symbolizer_mac.cc
|
2012-08-14 21:00:32 +08:00
|
|
|
sanitizer_symbolizer_win.cc
|
2014-01-29 17:29:16 +08:00
|
|
|
sanitizer_tls_get_addr.cc
|
2013-03-14 21:54:30 +08:00
|
|
|
sanitizer_thread_registry.cc
|
2013-06-11 16:13:36 +08:00
|
|
|
sanitizer_win.cc)
|
2012-06-20 18:18:43 +08:00
|
|
|
|
[sanitizer][esan] Add internal_sigaction_syscall
Summary:
Adds a version of sigaction that uses a raw system call, to avoid circular
dependencies and support calling sigaction prior to setting up
interceptors. The new sigaction relies on an assembly sigreturn routine
for its restorer, which is Linux x86_64-only for now.
Uses the new sigaction to initialize the working set tool's shadow fault
handler prior to libc interceptor being set up. This is required to
support instrumentation invoked during interceptor setup, which happens
with an instrumented tcmalloc or other allocator compiled with esan.
Adds a test that emulates an instrumented allocator.
Reviewers: aizatsky
Subscribers: vitalybuka, tberghammer, zhaoqin, danalbert, kcc, srhines, eugenis, llvm-commits, kubabrecka
Differential Revision: http://reviews.llvm.org/D21083
llvm-svn: 272676
2016-06-14 23:15:38 +08:00
|
|
|
if(UNIX AND NOT APPLE)
|
|
|
|
list(APPEND SANITIZER_SOURCES_NOTERMINATION
|
|
|
|
sanitizer_linux_x86_64.S)
|
2016-10-06 17:58:11 +08:00
|
|
|
list(APPEND SANITIZER_SOURCES_NOTERMINATION
|
|
|
|
sanitizer_linux_mips64.S)
|
[sanitizer][esan] Add internal_sigaction_syscall
Summary:
Adds a version of sigaction that uses a raw system call, to avoid circular
dependencies and support calling sigaction prior to setting up
interceptors. The new sigaction relies on an assembly sigreturn routine
for its restorer, which is Linux x86_64-only for now.
Uses the new sigaction to initialize the working set tool's shadow fault
handler prior to libc interceptor being set up. This is required to
support instrumentation invoked during interceptor setup, which happens
with an instrumented tcmalloc or other allocator compiled with esan.
Adds a test that emulates an instrumented allocator.
Reviewers: aizatsky
Subscribers: vitalybuka, tberghammer, zhaoqin, danalbert, kcc, srhines, eugenis, llvm-commits, kubabrecka
Differential Revision: http://reviews.llvm.org/D21083
llvm-svn: 272676
2016-06-14 23:15:38 +08:00
|
|
|
endif()
|
|
|
|
|
[sanitizer] Move termination functions in their own file
Summary:
As suggested by kcc@ in http://reviews.llvm.org/D20084#441418, move the CheckFailed and Die functions, and their associated callback functionalities in their own separate file.
I expended the build rules to include a new rule that would not include those termination functions, so that another project can define their own.
The tests check-{a,t,m,ub,l,e,df}san are all passing.
Reviewers: llvm-commits, kcc
Subscribers: kubabrecka
Differential Revision: http://reviews.llvm.org/D20742
llvm-svn: 271055
2016-05-28 05:57:17 +08:00
|
|
|
set(SANITIZER_SOURCES
|
|
|
|
${SANITIZER_SOURCES_NOTERMINATION} sanitizer_termination.cc)
|
|
|
|
|
2015-07-24 06:05:20 +08:00
|
|
|
# Libc functions stubs. These sources should be linked instead of
|
|
|
|
# SANITIZER_LIBCDEP_SOURCES when sanitizer_common library must not depend on
|
|
|
|
# libc.
|
|
|
|
set(SANITIZER_NOLIBC_SOURCES
|
|
|
|
sanitizer_common_nolibc.cc)
|
|
|
|
|
2013-05-18 00:17:19 +08:00
|
|
|
set(SANITIZER_LIBCDEP_SOURCES
|
|
|
|
sanitizer_common_libcdep.cc
|
2017-01-12 09:37:35 +08:00
|
|
|
sancov_flags.cc
|
|
|
|
sanitizer_coverage_libcdep_new.cc
|
[sancov] Define delimiters for sanitizer coverage's binary section on Windows.
On Windows, the symbols "___stop___sancov_guards" and "___start___sancov_guards"
are not defined automatically. So, we need to take a different approach.
We define 3 sections: ".SCOV$A", ".SCOV$M" and ".SCOV$Z".
Section ".SCOV$A" will only hold a variable ___start___sancov_guard.
Section ".SCOV$M" will hold the main data.
Section ".SCOV$Z" will only hold a variable ___stop___sancov_guards.
When linking, they will be merged sorted by the characters after the $, so we
can use the pointers of the variables ___[start|stop]___sancov_guard to know the
actual range of addresses of that section.
___[start|stop]___sancov_guard should be defined only once per module. On
Windows, we have 2 different cases:
+ When considering a shared runtime:
All the modules, main executable and dlls, are linked to an auxiliary static
library dynamic_runtime_thunk.lib. Because of that, we include the delimiters
in `SancovDynamicRuntimeThunk`.
+ When considering a static runtime:
The main executable in linked to the static runtime library.
All the dlls are linked to an auxiliary static library dll_thunk.
Because of that, we include the delimiter to both `SancovDllThunk` and
`SANITIZER_LIBCDEP_SOURCES` (which is included in the static runtime lib).
Differential Revision: https://reviews.llvm.org/D28435
llvm-svn: 293959
2017-02-03 07:02:15 +08:00
|
|
|
sanitizer_coverage_win_sections.cc
|
2013-05-20 23:57:44 +08:00
|
|
|
sanitizer_linux_libcdep.cc
|
2017-07-13 07:29:21 +08:00
|
|
|
sanitizer_mac_libcdep.cc
|
2013-05-21 18:27:07 +08:00
|
|
|
sanitizer_posix_libcdep.cc
|
2013-11-07 14:33:06 +08:00
|
|
|
sanitizer_stacktrace_libcdep.cc
|
2013-05-21 19:38:39 +08:00
|
|
|
sanitizer_stoptheworld_linux_libcdep.cc
|
2013-10-26 07:03:29 +08:00
|
|
|
sanitizer_symbolizer_libcdep.cc
|
2014-09-01 21:07:50 +08:00
|
|
|
sanitizer_symbolizer_posix_libcdep.cc
|
2015-06-25 04:13:44 +08:00
|
|
|
sanitizer_unwind_linux_libcdep.cc)
|
2013-05-18 00:17:19 +08:00
|
|
|
|
2012-12-21 22:04:52 +08:00
|
|
|
# Explicitly list all sanitizer_common headers. Not all of these are
|
|
|
|
# included in sanitizer_common source files, but we need to depend on
|
|
|
|
# headers when building our custom unit tests.
|
|
|
|
set(SANITIZER_HEADERS
|
2014-03-05 21:55:32 +08:00
|
|
|
sanitizer_addrhashmap.h
|
2012-12-21 22:04:52 +08:00
|
|
|
sanitizer_allocator.h
|
2016-07-21 06:06:41 +08:00
|
|
|
sanitizer_allocator_bytemap.h
|
|
|
|
sanitizer_allocator_combined.h
|
2014-07-08 01:39:31 +08:00
|
|
|
sanitizer_allocator_interface.h
|
2013-05-29 17:15:39 +08:00
|
|
|
sanitizer_allocator_internal.h
|
2016-07-21 06:06:41 +08:00
|
|
|
sanitizer_allocator_local_cache.h
|
|
|
|
sanitizer_allocator_primary32.h
|
|
|
|
sanitizer_allocator_primary64.h
|
|
|
|
sanitizer_allocator_secondary.h
|
|
|
|
sanitizer_allocator_size_class_map.h
|
|
|
|
sanitizer_allocator_stats.h
|
2013-11-22 16:55:33 +08:00
|
|
|
sanitizer_atomic.h
|
2012-12-21 22:04:52 +08:00
|
|
|
sanitizer_atomic_clang.h
|
|
|
|
sanitizer_atomic_msvc.h
|
2014-02-12 15:05:24 +08:00
|
|
|
sanitizer_bitvector.h
|
2014-02-12 19:28:09 +08:00
|
|
|
sanitizer_bvgraph.h
|
2012-12-21 22:04:52 +08:00
|
|
|
sanitizer_common.h
|
2013-01-18 21:01:18 +08:00
|
|
|
sanitizer_common_interceptors.inc
|
2013-06-20 17:19:28 +08:00
|
|
|
sanitizer_common_interceptors_ioctl.inc
|
2014-01-21 21:01:20 +08:00
|
|
|
sanitizer_common_interceptors_format.inc
|
2013-04-11 22:37:04 +08:00
|
|
|
sanitizer_common_syscalls.inc
|
2014-02-13 15:44:51 +08:00
|
|
|
sanitizer_deadlock_detector.h
|
2014-02-28 18:48:13 +08:00
|
|
|
sanitizer_deadlock_detector_interface.h
|
2017-07-06 08:50:57 +08:00
|
|
|
sanitizer_errno.h
|
|
|
|
sanitizer_errno_codes.h
|
2017-07-22 09:46:40 +08:00
|
|
|
sanitizer_file.h
|
2015-01-15 23:13:43 +08:00
|
|
|
sanitizer_flag_parser.h
|
2012-12-21 22:04:52 +08:00
|
|
|
sanitizer_flags.h
|
2015-01-06 10:44:05 +08:00
|
|
|
sanitizer_flags.inc
|
2017-08-02 06:22:25 +08:00
|
|
|
sanitizer_fuchsia.h
|
2015-02-19 23:15:33 +08:00
|
|
|
sanitizer_interface_internal.h
|
2012-12-21 22:04:52 +08:00
|
|
|
sanitizer_internal_defs.h
|
2013-01-14 16:23:34 +08:00
|
|
|
sanitizer_lfstack.h
|
2012-12-21 22:04:52 +08:00
|
|
|
sanitizer_libc.h
|
2013-10-03 21:37:17 +08:00
|
|
|
sanitizer_libignore.h
|
2013-02-27 19:22:40 +08:00
|
|
|
sanitizer_linux.h
|
2012-12-21 22:04:52 +08:00
|
|
|
sanitizer_list.h
|
2014-02-03 23:45:03 +08:00
|
|
|
sanitizer_mac.h
|
2012-12-21 22:04:52 +08:00
|
|
|
sanitizer_mutex.h
|
2014-05-21 17:02:13 +08:00
|
|
|
sanitizer_persistent_allocator.h
|
2012-12-21 22:04:52 +08:00
|
|
|
sanitizer_placement_new.h
|
2013-11-22 16:55:33 +08:00
|
|
|
sanitizer_platform.h
|
2012-12-21 22:04:52 +08:00
|
|
|
sanitizer_platform_interceptors.h
|
2013-11-22 16:55:33 +08:00
|
|
|
sanitizer_platform_limits_posix.h
|
2015-04-09 01:08:24 +08:00
|
|
|
sanitizer_posix.h
|
2012-12-21 22:04:52 +08:00
|
|
|
sanitizer_procmaps.h
|
2013-01-11 16:07:43 +08:00
|
|
|
sanitizer_quarantine.h
|
2012-12-21 22:04:52 +08:00
|
|
|
sanitizer_report_decorator.h
|
|
|
|
sanitizer_stackdepot.h
|
2014-05-21 17:02:13 +08:00
|
|
|
sanitizer_stackdepotbase.h
|
2012-12-21 22:04:52 +08:00
|
|
|
sanitizer_stacktrace.h
|
2014-11-06 06:44:36 +08:00
|
|
|
sanitizer_stacktrace_printer.h
|
2013-11-22 16:55:33 +08:00
|
|
|
sanitizer_stoptheworld.h
|
|
|
|
sanitizer_suppressions.h
|
2012-12-21 22:04:52 +08:00
|
|
|
sanitizer_symbolizer.h
|
2015-03-03 05:15:09 +08:00
|
|
|
sanitizer_symbolizer_internal.h
|
2014-01-16 21:48:15 +08:00
|
|
|
sanitizer_symbolizer_libbacktrace.h
|
2015-03-12 18:53:18 +08:00
|
|
|
sanitizer_symbolizer_mac.h
|
2013-11-22 16:55:33 +08:00
|
|
|
sanitizer_syscall_generic.inc
|
|
|
|
sanitizer_syscall_linux_x86_64.inc
|
2015-08-21 22:50:36 +08:00
|
|
|
sanitizer_syscall_linux_aarch64.inc
|
2017-02-03 07:01:51 +08:00
|
|
|
sanitizer_thread_registry.h
|
|
|
|
sanitizer_win.h)
|
2012-12-21 22:04:52 +08:00
|
|
|
|
[sanitizer] Split dll_thunks into different sanitizers.
When the sanitizer is implemented as a static library and is included in the
main executable, we need an auxiliary static library dll_thunk that will be
linked to the dlls that have instrumentation, so they can refer to the runtime
in the main executable. Basically, it uses interception to get a pointer the
function in the main executable and override its function with that pointer.
Before this diff, all of the implementation for dll_thunks was included in asan.
In this diff I split it into different sanitizers, so we can use other
sanitizers regardless of whether we include asan or not.
All the sanitizers include a file sanitizer_win_dll_thunk.cc that register
functions to be intercepted in the binary section: DLLTH
When the dll including dll_thunk is initialized, it will execute
__dll_thunk_init() implemented in: sanitizer_common/sanitizer_win_dll_thunk.cc,
which will consider all the CB registered in the section DLLTH. So, all the
functions registered will be intercepted, and redirected to the implementation
in the main executable.
All the files "sanitizer_win_dll_thunk.cc" are independent, so we don't need to
include a specific list of sanitizers. Now, we compile: asan_win_dll_thunk.cc
ubsan_win_dll_thunk.cc, sanitizer_coverage_win_dll_thunk.cc and
sanitizer_win_dll_thunk.cc, to generate asan_dll_thunk, because we include asan,
ubsan and sanitizer coverage in the address sanitizer library.
Differential Revision: https://reviews.llvm.org/D29154
llvm-svn: 293951
2017-02-03 07:01:28 +08:00
|
|
|
include_directories(..)
|
|
|
|
|
2014-01-28 17:28:57 +08:00
|
|
|
set(SANITIZER_COMMON_DEFINITIONS)
|
|
|
|
|
2015-04-09 16:06:49 +08:00
|
|
|
include(CheckIncludeFile)
|
|
|
|
append_have_file_definition(rpc/xdr.h HAVE_RPC_XDR_H SANITIZER_COMMON_DEFINITIONS)
|
|
|
|
append_have_file_definition(tirpc/rpc/xdr.h HAVE_TIRPC_RPC_XDR_H SANITIZER_COMMON_DEFINITIONS)
|
|
|
|
|
2014-02-18 15:52:40 +08:00
|
|
|
set(SANITIZER_CFLAGS ${SANITIZER_COMMON_CFLAGS})
|
2016-03-05 18:01:04 +08:00
|
|
|
append_rtti_flag(OFF SANITIZER_CFLAGS)
|
2012-06-25 16:40:10 +08:00
|
|
|
|
2015-04-28 07:49:39 +08:00
|
|
|
append_list_if(SANITIZER_LIMIT_FRAME_SIZE -Wframe-larger-than=570
|
2015-01-03 12:29:12 +08:00
|
|
|
SANITIZER_CFLAGS)
|
|
|
|
append_list_if(COMPILER_RT_HAS_WGLOBAL_CONSTRUCTORS_FLAG -Wglobal-constructors
|
|
|
|
SANITIZER_CFLAGS)
|
2013-09-11 17:57:15 +08:00
|
|
|
|
[sanitizer][esan] Add internal_sigaction_syscall
Summary:
Adds a version of sigaction that uses a raw system call, to avoid circular
dependencies and support calling sigaction prior to setting up
interceptors. The new sigaction relies on an assembly sigreturn routine
for its restorer, which is Linux x86_64-only for now.
Uses the new sigaction to initialize the working set tool's shadow fault
handler prior to libc interceptor being set up. This is required to
support instrumentation invoked during interceptor setup, which happens
with an instrumented tcmalloc or other allocator compiled with esan.
Adds a test that emulates an instrumented allocator.
Reviewers: aizatsky
Subscribers: vitalybuka, tberghammer, zhaoqin, danalbert, kcc, srhines, eugenis, llvm-commits, kubabrecka
Differential Revision: http://reviews.llvm.org/D21083
llvm-svn: 272676
2016-06-14 23:15:38 +08:00
|
|
|
if (LLVM_ENABLE_PEDANTIC AND UNIX AND NOT APPLE)
|
|
|
|
# With -pedantic, our .S files raise warnings about empty macro arguments
|
|
|
|
# from __USER_LABEL_PREFIX__ being an empty arg to GLUE(). Unfortunately,
|
|
|
|
# there is no simple way to test for an empty define, nor to disable just
|
|
|
|
# that warning or to disable -pedantic. There is also no simple way to
|
|
|
|
# remove -pedantic from just this file (we'd have to remove from
|
|
|
|
# CMAKE_C*_FLAGS and re-add as a source property to all the non-.S files).
|
|
|
|
set_source_files_properties(sanitizer_linux_x86_64.S
|
|
|
|
PROPERTIES COMPILE_FLAGS "-w")
|
2016-10-06 17:58:11 +08:00
|
|
|
set_source_files_properties(sanitizer_linux_mips64.S
|
|
|
|
PROPERTIES COMPILE_FLAGS "-w")
|
[sanitizer][esan] Add internal_sigaction_syscall
Summary:
Adds a version of sigaction that uses a raw system call, to avoid circular
dependencies and support calling sigaction prior to setting up
interceptors. The new sigaction relies on an assembly sigreturn routine
for its restorer, which is Linux x86_64-only for now.
Uses the new sigaction to initialize the working set tool's shadow fault
handler prior to libc interceptor being set up. This is required to
support instrumentation invoked during interceptor setup, which happens
with an instrumented tcmalloc or other allocator compiled with esan.
Adds a test that emulates an instrumented allocator.
Reviewers: aizatsky
Subscribers: vitalybuka, tberghammer, zhaoqin, danalbert, kcc, srhines, eugenis, llvm-commits, kubabrecka
Differential Revision: http://reviews.llvm.org/D21083
llvm-svn: 272676
2016-06-14 23:15:38 +08:00
|
|
|
endif ()
|
|
|
|
|
2012-08-10 22:45:52 +08:00
|
|
|
if(APPLE)
|
2015-08-28 06:23:27 +08:00
|
|
|
set(OS_OPTION OS ${SANITIZER_COMMON_SUPPORTED_OS})
|
2012-06-20 18:18:43 +08:00
|
|
|
endif()
|
2012-08-10 22:45:52 +08:00
|
|
|
|
2015-08-28 06:23:27 +08:00
|
|
|
add_compiler_rt_object_libraries(RTSanitizerCommon
|
|
|
|
${OS_OPTION}
|
|
|
|
ARCHS ${SANITIZER_COMMON_SUPPORTED_ARCH}
|
|
|
|
SOURCES ${SANITIZER_SOURCES}
|
|
|
|
CFLAGS ${SANITIZER_CFLAGS}
|
|
|
|
DEFS ${SANITIZER_COMMON_DEFINITIONS})
|
[sanitizer] Move termination functions in their own file
Summary:
As suggested by kcc@ in http://reviews.llvm.org/D20084#441418, move the CheckFailed and Die functions, and their associated callback functionalities in their own separate file.
I expended the build rules to include a new rule that would not include those termination functions, so that another project can define their own.
The tests check-{a,t,m,ub,l,e,df}san are all passing.
Reviewers: llvm-commits, kcc
Subscribers: kubabrecka
Differential Revision: http://reviews.llvm.org/D20742
llvm-svn: 271055
2016-05-28 05:57:17 +08:00
|
|
|
add_compiler_rt_object_libraries(RTSanitizerCommonNoTermination
|
|
|
|
${OS_OPTION}
|
|
|
|
ARCHS ${SANITIZER_COMMON_SUPPORTED_ARCH}
|
|
|
|
SOURCES ${SANITIZER_SOURCES_NOTERMINATION}
|
|
|
|
CFLAGS ${SANITIZER_CFLAGS}
|
|
|
|
DEFS ${SANITIZER_COMMON_DEFINITIONS})
|
2015-08-28 06:23:27 +08:00
|
|
|
add_compiler_rt_object_libraries(RTSanitizerCommonNoLibc
|
|
|
|
${OS_OPTION}
|
|
|
|
ARCHS ${SANITIZER_COMMON_SUPPORTED_ARCH}
|
|
|
|
SOURCES ${SANITIZER_NOLIBC_SOURCES}
|
|
|
|
CFLAGS ${SANITIZER_CFLAGS}
|
|
|
|
DEFS ${SANITIZER_COMMON_DEFINITIONS})
|
|
|
|
add_compiler_rt_object_libraries(RTSanitizerCommonLibc
|
|
|
|
${OS_OPTION}
|
|
|
|
ARCHS ${SANITIZER_COMMON_SUPPORTED_ARCH}
|
|
|
|
SOURCES ${SANITIZER_LIBCDEP_SOURCES}
|
|
|
|
CFLAGS ${SANITIZER_CFLAGS}
|
|
|
|
DEFS ${SANITIZER_COMMON_DEFINITIONS})
|
|
|
|
|
2017-02-09 04:43:39 +08:00
|
|
|
if(WIN32)
|
[sanitizer] Use interception to access to strong definitions in the executable.
In Windows, when sanitizers are implemented as a shared library (DLL), users can
redefine and export a new definition for weak functions, in the main executable,
for example:
extern "C" __declspec(dllexport)
void __sanitizer_cov_trace_pc_guard(u32* guard) {
// Different implementation provided by the client.
}
However, other dlls, will continue using the default implementation imported
from the sanitizer dll. This is different in linux, where all the shared
libraries will consider the strong definition.
With the implementation in this diff, when the dll is initialized, it will check
if the main executable exports the definition for some weak function (for
example __sanitizer_cov_trace_pc_guard). If it finds that function, then it will
override the function in the dll with that pointer. So, all the dlls with
instrumentation that import __sanitizer_cov_trace_pc_guard__dll() from asan dll,
will be using the function provided by the main executable.
In other words, when the main executable exports a strong definition for a weak
function, we ensure all the dlls use that implementation instead of the default
weak implementation.
The behavior is similar to linux. Now, every user that want to override a weak
function, only has to define and export it. The same for Linux and Windows, and
it will work fine. So, there is no difference on the user's side.
All the sanitizers will include a file sanitizer_win_weak_interception.cc that
register sanitizer's weak functions to be intercepted in the binary section WEAK
When the sanitizer dll is initialized, it will execute weak_intercept_init()
which will consider all the CB registered in the section WEAK. So, for all the
weak functions registered, we will check if a strong definition is provided in
the main executable.
All the files sanitizer_win_weak_interception.cc are independent, so we do not
need to include a specific list of sanitizers.
Now, we include [asan|ubsan|sanitizer_coverage]_win_weak_interception.cc and
sanitizer_win_weak_interception.cc in asan dll, so when it is initialized, it
will consider all the weak functions from asan, ubsan and sanitizer coverage.
After this diff, sanitizer coverage is fixed for MD on Windows. In particular
libFuzzer can provide custom implementation for all sanitizer coverage's weak
functions, and they will be considered by asan dll.
Differential Revision: https://reviews.llvm.org/D29168
llvm-svn: 293958
2017-02-03 07:02:11 +08:00
|
|
|
add_compiler_rt_object_libraries(SanitizerCommonWeakInterception
|
|
|
|
${SANITIZER_COMMON_SUPPORTED_OS}
|
|
|
|
ARCHS ${SANITIZER_COMMON_SUPPORTED_ARCH}
|
|
|
|
SOURCES sanitizer_win_weak_interception.cc
|
|
|
|
CFLAGS ${SANITIZER_CFLAGS} -DSANITIZER_DYNAMIC
|
|
|
|
DEFS ${SANITIZER_COMMON_DEFINITIONS})
|
|
|
|
add_compiler_rt_object_libraries(SancovWeakInterception
|
|
|
|
${SANITIZER_COMMON_SUPPORTED_OS}
|
|
|
|
ARCHS ${SANITIZER_COMMON_SUPPORTED_ARCH}
|
|
|
|
SOURCES sanitizer_coverage_win_weak_interception.cc
|
|
|
|
CFLAGS ${SANITIZER_CFLAGS} -DSANITIZER_DYNAMIC
|
|
|
|
DEFS ${SANITIZER_COMMON_DEFINITIONS})
|
|
|
|
|
[sanitizer] Split dll_thunks into different sanitizers.
When the sanitizer is implemented as a static library and is included in the
main executable, we need an auxiliary static library dll_thunk that will be
linked to the dlls that have instrumentation, so they can refer to the runtime
in the main executable. Basically, it uses interception to get a pointer the
function in the main executable and override its function with that pointer.
Before this diff, all of the implementation for dll_thunks was included in asan.
In this diff I split it into different sanitizers, so we can use other
sanitizers regardless of whether we include asan or not.
All the sanitizers include a file sanitizer_win_dll_thunk.cc that register
functions to be intercepted in the binary section: DLLTH
When the dll including dll_thunk is initialized, it will execute
__dll_thunk_init() implemented in: sanitizer_common/sanitizer_win_dll_thunk.cc,
which will consider all the CB registered in the section DLLTH. So, all the
functions registered will be intercepted, and redirected to the implementation
in the main executable.
All the files "sanitizer_win_dll_thunk.cc" are independent, so we don't need to
include a specific list of sanitizers. Now, we compile: asan_win_dll_thunk.cc
ubsan_win_dll_thunk.cc, sanitizer_coverage_win_dll_thunk.cc and
sanitizer_win_dll_thunk.cc, to generate asan_dll_thunk, because we include asan,
ubsan and sanitizer coverage in the address sanitizer library.
Differential Revision: https://reviews.llvm.org/D29154
llvm-svn: 293951
2017-02-03 07:01:28 +08:00
|
|
|
add_compiler_rt_object_libraries(SanitizerCommonDllThunk
|
|
|
|
${SANITIZER_COMMON_SUPPORTED_OS}
|
|
|
|
ARCHS ${SANITIZER_COMMON_SUPPORTED_ARCH}
|
|
|
|
SOURCES sanitizer_win_dll_thunk.cc
|
|
|
|
CFLAGS ${SANITIZER_CFLAGS} -DSANITIZER_DLL_THUNK
|
|
|
|
DEFS ${SANITIZER_COMMON_DEFINITIONS})
|
|
|
|
add_compiler_rt_object_libraries(SancovDllThunk
|
|
|
|
${SANITIZER_COMMON_SUPPORTED_OS}
|
|
|
|
ARCHS ${SANITIZER_COMMON_SUPPORTED_ARCH}
|
|
|
|
SOURCES sanitizer_coverage_win_dll_thunk.cc
|
[sancov] Define delimiters for sanitizer coverage's binary section on Windows.
On Windows, the symbols "___stop___sancov_guards" and "___start___sancov_guards"
are not defined automatically. So, we need to take a different approach.
We define 3 sections: ".SCOV$A", ".SCOV$M" and ".SCOV$Z".
Section ".SCOV$A" will only hold a variable ___start___sancov_guard.
Section ".SCOV$M" will hold the main data.
Section ".SCOV$Z" will only hold a variable ___stop___sancov_guards.
When linking, they will be merged sorted by the characters after the $, so we
can use the pointers of the variables ___[start|stop]___sancov_guard to know the
actual range of addresses of that section.
___[start|stop]___sancov_guard should be defined only once per module. On
Windows, we have 2 different cases:
+ When considering a shared runtime:
All the modules, main executable and dlls, are linked to an auxiliary static
library dynamic_runtime_thunk.lib. Because of that, we include the delimiters
in `SancovDynamicRuntimeThunk`.
+ When considering a static runtime:
The main executable in linked to the static runtime library.
All the dlls are linked to an auxiliary static library dll_thunk.
Because of that, we include the delimiter to both `SancovDllThunk` and
`SANITIZER_LIBCDEP_SOURCES` (which is included in the static runtime lib).
Differential Revision: https://reviews.llvm.org/D28435
llvm-svn: 293959
2017-02-03 07:02:15 +08:00
|
|
|
sanitizer_coverage_win_sections.cc
|
[sanitizer] Split dll_thunks into different sanitizers.
When the sanitizer is implemented as a static library and is included in the
main executable, we need an auxiliary static library dll_thunk that will be
linked to the dlls that have instrumentation, so they can refer to the runtime
in the main executable. Basically, it uses interception to get a pointer the
function in the main executable and override its function with that pointer.
Before this diff, all of the implementation for dll_thunks was included in asan.
In this diff I split it into different sanitizers, so we can use other
sanitizers regardless of whether we include asan or not.
All the sanitizers include a file sanitizer_win_dll_thunk.cc that register
functions to be intercepted in the binary section: DLLTH
When the dll including dll_thunk is initialized, it will execute
__dll_thunk_init() implemented in: sanitizer_common/sanitizer_win_dll_thunk.cc,
which will consider all the CB registered in the section DLLTH. So, all the
functions registered will be intercepted, and redirected to the implementation
in the main executable.
All the files "sanitizer_win_dll_thunk.cc" are independent, so we don't need to
include a specific list of sanitizers. Now, we compile: asan_win_dll_thunk.cc
ubsan_win_dll_thunk.cc, sanitizer_coverage_win_dll_thunk.cc and
sanitizer_win_dll_thunk.cc, to generate asan_dll_thunk, because we include asan,
ubsan and sanitizer coverage in the address sanitizer library.
Differential Revision: https://reviews.llvm.org/D29154
llvm-svn: 293951
2017-02-03 07:01:28 +08:00
|
|
|
CFLAGS ${SANITIZER_CFLAGS} -DSANITIZER_DLL_THUNK
|
|
|
|
DEFS ${SANITIZER_COMMON_DEFINITIONS})
|
[sanitizer] Add dynamic_runtime_thunk for different sanitizers.
In Windows, when the sanitizer is implemented as a shared library (DLL), we need
an auxiliary static library dynamic_runtime_thunk that will be linked to the
main executable and dlls.
In the sanitizer DLL, we are exposing weak functions with WIN_WEAK_EXPORT_DEF(),
which exports the default implementation with __dll suffix. For example: for
sanitizer coverage, the default implementation of __sanitizer_cov_trace_cmp is
exported as: __sanitizer_cov_trace_cmp__dll.
In the dynamic_runtime_thunk static library, we include weak aliases to the
imported implementation from the dll, using the macro WIN_WEAK_IMPORT_DEF().
By default, all users's programs that include calls to weak functions like
__sanitizer_cov_trace_cmp, will be redirected to the implementation in the dll,
when linking to dynamic_runtime_thunk.
After this diff, we are able to compile code with sanitizer coverage
instrumentation on Windows. When the instrumented object files are linked with
clang-rt_asan_dynamic_runtime_thunk-arch.lib all the weak symbols will be
resolved to the implementation imported from asan dll.
All the files sanitizer_dynamic_runtime_thunk.cc are independent, so we do not
need to include a specific list of sanitizers.
Now, we compile: [asan|ubsan|sanitizer_coverage]_win_dynamic_runtime_thunk.cc
and sanitizer_win_dynamic_runtime_thunk.cc to generate
asan_dynamic_runtime_thunk.lib, because we include asan, ubsan and sanitizer
coverage in the address sanitizer library.
Differential Revision: https://reviews.llvm.org/D29158
llvm-svn: 293953
2017-02-03 07:01:41 +08:00
|
|
|
|
|
|
|
set(DYNAMIC_RUNTIME_THUNK_CFLAGS "-DSANITIZER_DYNAMIC_RUNTIME_THUNK")
|
|
|
|
if(MSVC)
|
|
|
|
list(APPEND DYNAMIC_RUNTIME_THUNK_CFLAGS "-Zl")
|
|
|
|
elseif(CMAKE_C_COMPILER_ID MATCHES Clang)
|
|
|
|
list(APPEND DYNAMIC_RUNTIME_THUNK_CFLAGS "-nodefaultlibs")
|
|
|
|
endif()
|
|
|
|
add_compiler_rt_object_libraries(SanitizerCommonDynamicRuntimeThunk
|
|
|
|
${SANITIZER_COMMON_SUPPORTED_OS}
|
|
|
|
ARCHS ${SANITIZER_COMMON_SUPPORTED_ARCH}
|
|
|
|
SOURCES sanitizer_win_dynamic_runtime_thunk.cc
|
|
|
|
CFLAGS ${SANITIZER_CFLAGS} ${DYNAMIC_RUNTIME_THUNK_CFLAGS}
|
|
|
|
DEFS ${SANITIZER_COMMON_DEFINITIONS})
|
|
|
|
add_compiler_rt_object_libraries(SancovDynamicRuntimeThunk
|
|
|
|
${SANITIZER_COMMON_SUPPORTED_OS}
|
|
|
|
ARCHS ${SANITIZER_COMMON_SUPPORTED_ARCH}
|
|
|
|
SOURCES sanitizer_coverage_win_dynamic_runtime_thunk.cc
|
[sancov] Define delimiters for sanitizer coverage's binary section on Windows.
On Windows, the symbols "___stop___sancov_guards" and "___start___sancov_guards"
are not defined automatically. So, we need to take a different approach.
We define 3 sections: ".SCOV$A", ".SCOV$M" and ".SCOV$Z".
Section ".SCOV$A" will only hold a variable ___start___sancov_guard.
Section ".SCOV$M" will hold the main data.
Section ".SCOV$Z" will only hold a variable ___stop___sancov_guards.
When linking, they will be merged sorted by the characters after the $, so we
can use the pointers of the variables ___[start|stop]___sancov_guard to know the
actual range of addresses of that section.
___[start|stop]___sancov_guard should be defined only once per module. On
Windows, we have 2 different cases:
+ When considering a shared runtime:
All the modules, main executable and dlls, are linked to an auxiliary static
library dynamic_runtime_thunk.lib. Because of that, we include the delimiters
in `SancovDynamicRuntimeThunk`.
+ When considering a static runtime:
The main executable in linked to the static runtime library.
All the dlls are linked to an auxiliary static library dll_thunk.
Because of that, we include the delimiter to both `SancovDllThunk` and
`SANITIZER_LIBCDEP_SOURCES` (which is included in the static runtime lib).
Differential Revision: https://reviews.llvm.org/D28435
llvm-svn: 293959
2017-02-03 07:02:15 +08:00
|
|
|
sanitizer_coverage_win_sections.cc
|
[sanitizer] Add dynamic_runtime_thunk for different sanitizers.
In Windows, when the sanitizer is implemented as a shared library (DLL), we need
an auxiliary static library dynamic_runtime_thunk that will be linked to the
main executable and dlls.
In the sanitizer DLL, we are exposing weak functions with WIN_WEAK_EXPORT_DEF(),
which exports the default implementation with __dll suffix. For example: for
sanitizer coverage, the default implementation of __sanitizer_cov_trace_cmp is
exported as: __sanitizer_cov_trace_cmp__dll.
In the dynamic_runtime_thunk static library, we include weak aliases to the
imported implementation from the dll, using the macro WIN_WEAK_IMPORT_DEF().
By default, all users's programs that include calls to weak functions like
__sanitizer_cov_trace_cmp, will be redirected to the implementation in the dll,
when linking to dynamic_runtime_thunk.
After this diff, we are able to compile code with sanitizer coverage
instrumentation on Windows. When the instrumented object files are linked with
clang-rt_asan_dynamic_runtime_thunk-arch.lib all the weak symbols will be
resolved to the implementation imported from asan dll.
All the files sanitizer_dynamic_runtime_thunk.cc are independent, so we do not
need to include a specific list of sanitizers.
Now, we compile: [asan|ubsan|sanitizer_coverage]_win_dynamic_runtime_thunk.cc
and sanitizer_win_dynamic_runtime_thunk.cc to generate
asan_dynamic_runtime_thunk.lib, because we include asan, ubsan and sanitizer
coverage in the address sanitizer library.
Differential Revision: https://reviews.llvm.org/D29158
llvm-svn: 293953
2017-02-03 07:01:41 +08:00
|
|
|
CFLAGS ${SANITIZER_CFLAGS} ${DYNAMIC_RUNTIME_THUNK_CFLAGS}
|
|
|
|
DEFS ${SANITIZER_COMMON_DEFINITIONS})
|
[sanitizer] Split dll_thunks into different sanitizers.
When the sanitizer is implemented as a static library and is included in the
main executable, we need an auxiliary static library dll_thunk that will be
linked to the dlls that have instrumentation, so they can refer to the runtime
in the main executable. Basically, it uses interception to get a pointer the
function in the main executable and override its function with that pointer.
Before this diff, all of the implementation for dll_thunks was included in asan.
In this diff I split it into different sanitizers, so we can use other
sanitizers regardless of whether we include asan or not.
All the sanitizers include a file sanitizer_win_dll_thunk.cc that register
functions to be intercepted in the binary section: DLLTH
When the dll including dll_thunk is initialized, it will execute
__dll_thunk_init() implemented in: sanitizer_common/sanitizer_win_dll_thunk.cc,
which will consider all the CB registered in the section DLLTH. So, all the
functions registered will be intercepted, and redirected to the implementation
in the main executable.
All the files "sanitizer_win_dll_thunk.cc" are independent, so we don't need to
include a specific list of sanitizers. Now, we compile: asan_win_dll_thunk.cc
ubsan_win_dll_thunk.cc, sanitizer_coverage_win_dll_thunk.cc and
sanitizer_win_dll_thunk.cc, to generate asan_dll_thunk, because we include asan,
ubsan and sanitizer coverage in the address sanitizer library.
Differential Revision: https://reviews.llvm.org/D29154
llvm-svn: 293951
2017-02-03 07:01:28 +08:00
|
|
|
endif()
|
|
|
|
|
2012-09-11 18:50:32 +08:00
|
|
|
# Unit tests for common sanitizer runtime.
|
2014-02-19 19:18:47 +08:00
|
|
|
if(COMPILER_RT_INCLUDE_TESTS)
|
2012-09-11 18:50:32 +08:00
|
|
|
add_subdirectory(tests)
|
|
|
|
endif()
|