Skip to content

Commit bd6798d

Browse files
authored
Merge pull request llvm-mirror#1 from scchan/merge_20170612
Merge 20170612
2 parents fb18901 + 1e52223 commit bd6798d

File tree

465 files changed

+7477
-4907
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

465 files changed

+7477
-4907
lines changed

CMakeLists.txt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ mark_as_advanced(COMPILER_RT_BUILD_SANITIZERS)
3131
option(COMPILER_RT_BUILD_XRAY "Build xray" ON)
3232
mark_as_advanced(COMPILER_RT_BUILD_XRAY)
3333

34+
set(COMPILER_RT_BAREMETAL_BUILD OFF CACHE BOOLEAN
35+
"Build for a bare-metal target.")
36+
3437
if (COMPILER_RT_STANDALONE_BUILD)
3538
load_llvm_config()
3639

@@ -239,14 +242,24 @@ set(COMPILER_RT_LIBCXX_PATH ${LLVM_MAIN_SRC_DIR}/projects/libcxx)
239242
if(EXISTS ${COMPILER_RT_LIBCXX_PATH}/)
240243
set(COMPILER_RT_HAS_LIBCXX_SOURCES TRUE)
241244
else()
242-
set(COMPILER_RT_HAS_LIBCXX_SOURCES FALSE)
245+
set(COMPILER_RT_LIBCXX_PATH ${LLVM_MAIN_SRC_DIR}/../libcxx)
246+
if(EXISTS ${COMPILER_RT_LIBCXX_PATH}/)
247+
set(COMPILER_RT_HAS_LIBCXX_SOURCES TRUE)
248+
else()
249+
set(COMPILER_RT_HAS_LIBCXX_SOURCES FALSE)
250+
endif()
243251
endif()
244252

245253
set(COMPILER_RT_LLD_PATH ${LLVM_MAIN_SRC_DIR}/tools/lld)
246254
if(EXISTS ${COMPILER_RT_LLD_PATH}/ AND LLVM_TOOL_LLD_BUILD)
247255
set(COMPILER_RT_HAS_LLD TRUE)
248256
else()
249-
set(COMPILER_RT_HAS_LLD FALSE)
257+
set(COMPILER_RT_LLD_PATH ${LLVM_MAIN_SRC_DIR}/../lld)
258+
if(EXISTS ${COMPILER_RT_LLD_PATH}/ AND LLVM_TOOL_LLD_BUILD)
259+
set(COMPILER_RT_HAS_LLD TRUE)
260+
else()
261+
set(COMPILER_RT_HAS_LLD FALSE)
262+
endif()
250263
endif()
251264
pythonize_bool(COMPILER_RT_HAS_LLD)
252265

cmake/Modules/AddCompilerRT.cmake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,14 @@ function(add_compiler_rt_runtime name type)
210210
set_target_properties(${libname} PROPERTIES IMPORT_PREFIX "")
211211
set_target_properties(${libname} PROPERTIES IMPORT_SUFFIX ".lib")
212212
endif()
213+
if(APPLE)
214+
# Ad-hoc sign the dylibs
215+
add_custom_command(TARGET ${libname}
216+
POST_BUILD
217+
COMMAND codesign --sign - $<TARGET_FILE:${libname}>
218+
WORKING_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR}
219+
)
220+
endif()
213221
endif()
214222
install(TARGETS ${libname}
215223
ARCHIVE DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR}

cmake/base-config-ix.cmake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ else()
6363
set(COMPILER_RT_TEST_COMPILER_ID GNU)
6464
endif()
6565

66-
string(TOLOWER ${CMAKE_SYSTEM_NAME} COMPILER_RT_OS_DIR)
66+
if(NOT DEFINED COMPILER_RT_OS_DIR)
67+
string(TOLOWER ${CMAKE_SYSTEM_NAME} COMPILER_RT_OS_DIR)
68+
endif()
6769
set(COMPILER_RT_LIBRARY_OUTPUT_DIR
6870
${COMPILER_RT_OUTPUT_DIR}/lib/${COMPILER_RT_OS_DIR})
6971
set(COMPILER_RT_LIBRARY_INSTALL_DIR

cmake/builtin-config-ix.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ int foo(int x, int y) {
2424

2525

2626
set(ARM64 aarch64)
27-
set(ARM32 arm armhf armv6m)
27+
set(ARM32 arm armhf armv6m armv7m armv7em armv7 armv7s armv7k)
2828
set(X86 i386 i686)
2929
set(X86_64 x86_64)
3030
set(MIPS32 mips mipsel)

cmake/config-ix.cmake

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,12 @@ set(ALL_SANITIZER_COMMON_SUPPORTED_ARCH ${X86} ${X86_64} ${PPC64}
164164
set(ALL_ASAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64}
165165
${MIPS32} ${MIPS64} ${PPC64} ${S390X})
166166
set(ALL_DFSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64})
167-
set(ALL_LSAN_SUPPORTED_ARCH ${X86} ${X86_64} ${MIPS64} ${ARM64})
167+
168+
if(APPLE)
169+
set(ALL_LSAN_SUPPORTED_ARCH ${X86} ${X86_64} ${MIPS64} ${ARM64})
170+
else()
171+
set(ALL_LSAN_SUPPORTED_ARCH ${X86} ${X86_64} ${MIPS64} ${ARM64} ${ARM32})
172+
endif()
168173
set(ALL_MSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64} ${PPC64})
169174
set(ALL_PROFILE_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${PPC64}
170175
${MIPS32} ${MIPS64} ${S390X})
@@ -471,19 +476,12 @@ else()
471476
endif()
472477

473478
if (COMPILER_RT_HAS_SANITIZER_COMMON AND LSAN_SUPPORTED_ARCH AND
474-
OS_NAME MATCHES "Linux|FreeBSD")
479+
OS_NAME MATCHES "Darwin|Linux|FreeBSD")
475480
set(COMPILER_RT_HAS_LSAN TRUE)
476481
else()
477482
set(COMPILER_RT_HAS_LSAN FALSE)
478483
endif()
479484

480-
if(APPLE)
481-
option(COMPILER_RT_ENABLE_LSAN_OSX "Enable building LSan for OS X - Experimental" Off)
482-
if(COMPILER_RT_ENABLE_LSAN_OSX)
483-
set(COMPILER_RT_HAS_LSAN TRUE)
484-
endif()
485-
endif()
486-
487485
if (COMPILER_RT_HAS_SANITIZER_COMMON AND MSAN_SUPPORTED_ARCH AND
488486
OS_NAME MATCHES "Linux")
489487
set(COMPILER_RT_HAS_MSAN TRUE)

include/CMakeLists.txt

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
1-
set(SANITIZER_HEADERS
2-
sanitizer/allocator_interface.h
3-
sanitizer/asan_interface.h
4-
sanitizer/common_interface_defs.h
5-
sanitizer/coverage_interface.h
6-
sanitizer/dfsan_interface.h
7-
sanitizer/esan_interface.h
8-
sanitizer/linux_syscall_hooks.h
9-
sanitizer/lsan_interface.h
10-
sanitizer/msan_interface.h
11-
sanitizer/tsan_interface.h
12-
sanitizer/tsan_interface_atomic.h)
1+
if (COMPILER_RT_BUILD_SANITIZERS)
2+
set(SANITIZER_HEADERS
3+
sanitizer/allocator_interface.h
4+
sanitizer/asan_interface.h
5+
sanitizer/common_interface_defs.h
6+
sanitizer/coverage_interface.h
7+
sanitizer/dfsan_interface.h
8+
sanitizer/esan_interface.h
9+
sanitizer/linux_syscall_hooks.h
10+
sanitizer/lsan_interface.h
11+
sanitizer/msan_interface.h
12+
sanitizer/tsan_interface.h
13+
sanitizer/tsan_interface_atomic.h)
14+
endif(COMPILER_RT_BUILD_SANITIZERS)
1315

14-
set(XRAY_HEADERS
15-
xray/xray_interface.h
16-
xray/xray_log_interface.h)
16+
if (COMPILER_RT_BUILD_XRAY)
17+
set(XRAY_HEADERS
18+
xray/xray_interface.h
19+
xray/xray_log_interface.h)
20+
endif(COMPILER_RT_BUILD_XRAY)
1721

1822
set(COMPILER_RT_HEADERS
1923
${SANITIZER_HEADERS}

include/sanitizer/coverage_interface.h

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -19,51 +19,13 @@
1919
extern "C" {
2020
#endif
2121

22-
// Initialize coverage.
23-
void __sanitizer_cov_init();
2422
// Record and dump coverage info.
2523
void __sanitizer_cov_dump();
2624

2725
// Dump collected coverage info. Sorts pcs by module into individual
2826
// .sancov files.
2927
void __sanitizer_dump_coverage(const uintptr_t *pcs, uintptr_t len);
3028

31-
// Open <name>.sancov.packed in the coverage directory and return the file
32-
// descriptor. Returns -1 on failure, or if coverage dumping is disabled.
33-
// This is intended for use by sandboxing code.
34-
intptr_t __sanitizer_maybe_open_cov_file(const char *name);
35-
// Get the number of unique covered blocks (or edges).
36-
// This can be useful for coverage-directed in-process fuzzers.
37-
uintptr_t __sanitizer_get_total_unique_coverage();
38-
// Get the number of unique indirect caller-callee pairs.
39-
uintptr_t __sanitizer_get_total_unique_caller_callee_pairs();
40-
41-
// Reset the basic-block (edge) coverage to the initial state.
42-
// Useful for in-process fuzzing to start collecting coverage from scratch.
43-
// Experimental, will likely not work for multi-threaded process.
44-
void __sanitizer_reset_coverage();
45-
// Set *data to the array of covered PCs and return the size of that array.
46-
// Some of the entries in *data will be zero.
47-
uintptr_t __sanitizer_get_coverage_guards(uintptr_t **data);
48-
49-
// The coverage instrumentation may optionally provide imprecise counters.
50-
// Rather than exposing the counter values to the user we instead map
51-
// the counters to a bitset.
52-
// Every counter is associated with 8 bits in the bitset.
53-
// We define 8 value ranges: 1, 2, 3, 4-7, 8-15, 16-31, 32-127, 128+
54-
// The i-th bit is set to 1 if the counter value is in the i-th range.
55-
// This counter-based coverage implementation is *not* thread-safe.
56-
57-
// Returns the number of registered coverage counters.
58-
uintptr_t __sanitizer_get_number_of_counters();
59-
// Updates the counter 'bitset', clears the counters and returns the number of
60-
// new bits in 'bitset'.
61-
// If 'bitset' is nullptr, only clears the counters.
62-
// Otherwise 'bitset' should be at least
63-
// __sanitizer_get_number_of_counters bytes long and 8-aligned.
64-
uintptr_t
65-
__sanitizer_update_counter_bitset_and_clear_counters(uint8_t *bitset);
66-
6729
#ifdef __cplusplus
6830
} // extern "C"
6931
#endif

include/sanitizer/tsan_interface.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ const unsigned __tsan_mutex_recursive_unlock = 1 << 7;
6868
void __tsan_mutex_create(void *addr, unsigned flags);
6969

7070
// Annotate destruction of a mutex.
71-
// Supported flags: none.
71+
// Supported flags:
72+
// - __tsan_mutex_linker_init
7273
void __tsan_mutex_destroy(void *addr, unsigned flags);
7374

7475
// Annotate start of lock operation.
@@ -114,6 +115,22 @@ void __tsan_mutex_post_signal(void *addr, unsigned flags);
114115
void __tsan_mutex_pre_divert(void *addr, unsigned flags);
115116
void __tsan_mutex_post_divert(void *addr, unsigned flags);
116117

118+
// External race detection API.
119+
// Can be used by non-instrumented libraries to detect when their objects are
120+
// being used in an unsafe manner.
121+
// - __tsan_external_read/__tsan_external_write annotates the logical reads
122+
// and writes of the object at the specified address. 'caller_pc' should
123+
// be the PC of the library user, which the library can obtain with e.g.
124+
// `__builtin_return_address(0)`.
125+
// - __tsan_external_register_tag registers a 'tag' with the specified name,
126+
// which is later used in read/write annotations to denote the object type
127+
// - __tsan_external_assign_tag can optionally mark a heap object with a tag
128+
void *__tsan_external_register_tag(const char *object_type);
129+
void __tsan_external_register_header(void *tag, const char *header);
130+
void __tsan_external_assign_tag(void *addr, void *tag);
131+
void __tsan_external_read(void *addr, void *caller_pc, void *tag);
132+
void __tsan_external_write(void *addr, void *caller_pc, void *tag);
133+
117134
#ifdef __cplusplus
118135
} // extern "C"
119136
#endif

include/xray/xray_interface.h

Lines changed: 67 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===-- xray_interface.h ----------------------------------------*- C++ -*-===//
1+
//===- xray_interface.h -----------------------------------------*- C++ -*-===//
22
//
33
// The LLVM Compiler Infrastructure
44
//
@@ -11,72 +11,100 @@
1111
//
1212
// APIs for controlling XRay functionality explicitly.
1313
//===----------------------------------------------------------------------===//
14+
1415
#ifndef XRAY_XRAY_INTERFACE_H
1516
#define XRAY_XRAY_INTERFACE_H
1617

18+
#include <cstddef>
1719
#include <cstdint>
1820

1921
extern "C" {
2022

21-
// Synchronize this with AsmPrinter::SledKind in LLVM.
23+
/// Synchronize this with AsmPrinter::SledKind in LLVM.
2224
enum XRayEntryType {
2325
ENTRY = 0,
2426
EXIT = 1,
2527
TAIL = 2,
2628
LOG_ARGS_ENTRY = 3,
29+
CUSTOM_EVENT = 4,
2730
};
2831

29-
// Provide a function to invoke for when instrumentation points are hit. This is
30-
// a user-visible control surface that overrides the default implementation. The
31-
// function provided should take the following arguments:
32-
//
33-
// - function id: an identifier that indicates the id of a function; this id
34-
// is generated by xray; the mapping between the function id
35-
// and the actual function pointer is available through
36-
// __xray_table.
37-
// - entry type: identifies what kind of instrumentation point was encountered
38-
// (function entry, function exit, etc.). See the enum
39-
// XRayEntryType for more details.
40-
//
41-
// The user handler must handle correctly spurious calls after this handler is
42-
// removed or replaced with another handler, because it would be too costly for
43-
// XRay runtime to avoid spurious calls.
44-
// To prevent circular calling, the handler function itself and all its
45-
// direct&indirect callees must not be instrumented with XRay, which can be
46-
// achieved by marking them all with: __attribute__((xray_never_instrument))
47-
//
48-
// Returns 1 on success, 0 on error.
32+
/// Provide a function to invoke for when instrumentation points are hit. This
33+
/// is a user-visible control surface that overrides the default implementation.
34+
/// The function provided should take the following arguments:
35+
///
36+
/// - function id: an identifier that indicates the id of a function; this id
37+
/// is generated by xray; the mapping between the function id
38+
/// and the actual function pointer is available through
39+
/// __xray_table.
40+
/// - entry type: identifies what kind of instrumentation point was
41+
/// encountered (function entry, function exit, etc.). See the
42+
/// enum XRayEntryType for more details.
43+
///
44+
/// The user handler must handle correctly spurious calls after this handler is
45+
/// removed or replaced with another handler, because it would be too costly for
46+
/// XRay runtime to avoid spurious calls.
47+
/// To prevent circular calling, the handler function itself and all its
48+
/// direct&indirect callees must not be instrumented with XRay, which can be
49+
/// achieved by marking them all with: __attribute__((xray_never_instrument))
50+
///
51+
/// Returns 1 on success, 0 on error.
4952
extern int __xray_set_handler(void (*entry)(int32_t, XRayEntryType));
5053

51-
// This removes whatever the currently provided handler is. Returns 1 on
52-
// success, 0 on error.
54+
/// This removes whatever the currently provided handler is. Returns 1 on
55+
/// success, 0 on error.
5356
extern int __xray_remove_handler();
5457

58+
/// Use XRay to log the first argument of each (instrumented) function call.
59+
/// When this function exits, all threads will have observed the effect and
60+
/// start logging their subsequent affected function calls (if patched).
61+
///
62+
/// Returns 1 on success, 0 on error.
63+
extern int __xray_set_handler_arg1(void (*)(int32_t, XRayEntryType, uint64_t));
64+
65+
/// Disables the XRay handler used to log first arguments of function calls.
66+
/// Returns 1 on success, 0 on error.
67+
extern int __xray_remove_handler_arg1();
68+
69+
/// Provide a function to invoke when XRay encounters a custom event.
70+
extern int __xray_set_customevent_handler(void (*entry)(void*, std::size_t));
71+
72+
/// This removes whatever the currently provided custom event handler is.
73+
/// Returns 1 on success, 0 on error.
74+
extern int __xray_remove_customevent_handler();
75+
5576
enum XRayPatchingStatus {
5677
NOT_INITIALIZED = 0,
5778
SUCCESS = 1,
5879
ONGOING = 2,
5980
FAILED = 3,
6081
};
6182

62-
// This tells XRay to patch the instrumentation points. See XRayPatchingStatus
63-
// for possible result values.
83+
/// This tells XRay to patch the instrumentation points. See XRayPatchingStatus
84+
/// for possible result values.
6485
extern XRayPatchingStatus __xray_patch();
6586

66-
// Reverses the effect of __xray_patch(). See XRayPatchingStatus for possible
67-
// result values.
87+
/// Reverses the effect of __xray_patch(). See XRayPatchingStatus for possible
88+
/// result values.
6889
extern XRayPatchingStatus __xray_unpatch();
6990

70-
// Use XRay to log the first argument of each (instrumented) function call.
71-
// When this function exits, all threads will have observed the effect and
72-
// start logging their subsequent affected function calls (if patched).
73-
//
74-
// Returns 1 on success, 0 on error.
75-
extern int __xray_set_handler_arg1(void (*)(int32_t, XRayEntryType, uint64_t));
91+
/// This patches a specific function id. See XRayPatchingStatus for possible
92+
/// result values.
93+
extern XRayPatchingStatus __xray_patch_function(int32_t FuncId);
7694

77-
// Disables the XRay handler used to log first arguments of function calls.
78-
// Returns 1 on success, 0 on error.
79-
extern int __xray_remove_handler_arg1();
80-
}
95+
/// This unpatches a specific function id. See XRayPatchingStatus for possible
96+
/// result values.
97+
extern XRayPatchingStatus __xray_unpatch_function(int32_t FuncId);
98+
99+
/// This function returns the address of the function provided a valid function
100+
/// id. We return 0 if we encounter any error, even if 0 may be a valid function
101+
/// address.
102+
extern uintptr_t __xray_function_address(int32_t FuncId);
103+
104+
/// This function returns the maximum valid function id. Returns 0 if we
105+
/// encounter errors (when there are no instrumented functions, etc.).
106+
extern size_t __xray_max_function_id();
107+
108+
} // end extern "C"
81109

82-
#endif
110+
#endif // XRAY_XRAY_INTERFACE_H

0 commit comments

Comments
 (0)