Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
9fbf126
Escape Analysis init
apaznikov Oct 14, 2024
312d6bb
Updated GEP aliasing logic
apaznikov Oct 15, 2024
b4d7468
Fixed EA aliasing/GEP/GP logic
apaznikov Oct 18, 2024
11ce82d
Enabling Escape Analysis in TSan
apaznikov Oct 18, 2024
56b5364
Make Alias relation (partly) symmetrical. Refactoring
apaznikov Oct 23, 2024
ed8da00
Added escaping function arguments support
apaznikov Oct 24, 2024
5d97016
Passing value is neither escaping nor aliasing
apaznikov Oct 25, 2024
a837b65
Add mutual (recursive) aliases support
apaznikov Oct 28, 2024
40cb7f6
Make EA BB-wise, update TSan integration
apaznikov Oct 29, 2024
819b16c
Efforts for support of 'already escaped objects' (such as pointer arg…
apaznikov Oct 31, 2024
d432a4b
Considering external 'already escaped' objects, fix aliasing, refacto…
apaznikov Nov 4, 2024
7bbbe09
Fix bugs with external objects
apaznikov Nov 4, 2024
2ebed05
Add global_arrays.ll (ConstExprGEP) test, combine return.ll and simpl…
apaznikov Nov 6, 2024
ab460b0
Make getUnderlyingMayEscapeObjectsNew return the list of object (in p…
apaznikov Nov 6, 2024
28e1f2f
Move to more wide use of ValueTracking infrastructure in getUnderlyin…
apaznikov Nov 7, 2024
f7fe4ca
Migration to getUnderlyingMayEscObjectsNew
apaznikov Nov 8, 2024
2f95b0b
Added inttoptr/ptrtoint tests
apaznikov Nov 11, 2024
348eeb0
Minor refactoring (mostly compOutEscapeState)
apaznikov Nov 12, 2024
1945512
Added GlobalEscapeAnalysis pass infrastructure
apaznikov Nov 13, 2024
9ac70ee
Updated escape/no-escape with passing to calls or aliasing to ptr arg…
apaznikov Nov 15, 2024
4c86254
Starting work on propagation of argument escape info: add argument to…
apaznikov Nov 26, 2024
cefcd9e
Finished IPA EA, refactoring, tests
apaznikov Nov 27, 2024
020af62
Added recursive call conservative algorithm
apaznikov Nov 28, 2024
b155fe5
Fix std::optional<std::reference_wrapper<ArgumentEscapesMap>> ArgsEsc…
apaznikov Nov 29, 2024
bc3186e
Added recursive call conservative algorithm
apaznikov Nov 28, 2024
fbbe19e
Fix std::optional<std::reference_wrapper<ArgumentEscapesMap>> ArgsEsc…
apaznikov Nov 29, 2024
b342f09
Efforts on TSan and IPA EA integration
apaznikov Nov 29, 2024
178fd58
Add Global EA usage to TSan
apaznikov Dec 3, 2024
d0c40d7
Finished support of IPA EA & TSan, fixed bugs
apaznikov Dec 3, 2024
f862a25
Add support of function returning escaped value -- draft
apaznikov Dec 4, 2024
56855b2
Minor fixes for argument escape logic (DBG)
apaznikov Dec 5, 2024
2efb371
Add support of function returning escaped value -- draft 2
apaznikov Dec 5, 2024
2aa25f7
Add EscapeReasonTy
apaznikov Dec 5, 2024
6fbd3bd
Fix addEscapingObject logic for EscReason support
apaznikov Dec 5, 2024
dbc01a3
Fix logic with EscReasons, isEscapeForFunc, etc
apaznikov Dec 6, 2024
24ded0c
Fixed merging escape states, fixed printing, minor fixes, add tests w…
apaznikov Dec 9, 2024
de71362
Support of SCC in IPA - in progress
apaznikov Dec 9, 2024
a03d550
Many fixes for recursive functions, argument, aliasing processing and…
apaznikov Dec 11, 2024
460e60e
Refactoring and debug
apaznikov Dec 12, 2024
ce24c31
Fixed logic mainly with EscapeReason/Argument checks. Add support for…
apaznikov Dec 13, 2024
142270d
Merge branch 'tsan-with-ea-IPA-DBG-rec-calls-TMP' into tsan-with-ea-IPA
apaznikov Dec 13, 2024
781082f
Refactor to simplify and unify logic
apaznikov Dec 13, 2024
2772c1e
Refactor EscapeAnalysis API to improve readability and maintainability
apaznikov Dec 15, 2024
7962dcd
Add support of calls returning pointers (should lead escape)
apaznikov Dec 16, 2024
ed91d09
Use CaptureTracker first, and then EscapeAnalysis
apaznikov Dec 17, 2024
83ca510
Added EscapeReason statistics to TSan. Refactor escape analysis to tr…
apaznikov Dec 18, 2024
01b846c
Add support IPA return info
apaznikov Dec 19, 2024
3f11e06
Try traverse -- DEBUG
apaznikov Dec 19, 2024
87eef69
Argument escape tracking - DEBUG.
apaznikov Dec 20, 2024
408ec0d
Add top-down argument escape analysis (DEBUG)
apaznikov Dec 23, 2024
a69e19e
Add support for detecting functions passed to ObjC selectors
apaznikov Dec 26, 2024
3c7af95
Remove debug logs and enhance escape analysis logic, add test for top…
apaznikov Dec 26, 2024
1d44daa
Fix incorrect assertion in escape analysis.
apaznikov Dec 29, 2024
675f201
Efforts for new pointer escape logic: add UnderlObjInfo, updates in a…
apaznikov Jan 3, 2025
d2329e4
Refactor logic for treating escaping pointers: now pointers (if they …
apaznikov Jan 10, 2025
8eaf60e
Make isEscapedForBBInFuncTSan more optimistic
apaznikov Jan 10, 2025
e6ff26f
Use IPA version `isEscapedForBBIPA` in isEscapedForBBInFuncTSan
apaznikov Jan 10, 2025
b3a7a9a
Fixed IPA escape analysis logic
apaznikov Jan 13, 2025
d9a48f9
Added support of SCCs for TopDownIPA, fixed evalTopDownArgEscStatus (…
apaznikov Jan 14, 2025
006c2d3
Large update for memcpy/memset/memmove
apaznikov Jan 17, 2025
2690475
Enable interceptor toggling via `InterceptorEnabled` global variable …
apaznikov Jan 27, 2025
c946299
Introduce global InterceptorEnabled for interceptor control
apaznikov Feb 4, 2025
f7cfec5
Add intercepted call handling (strlen, strcmp, memchr)
apaznikov Feb 5, 2025
22a26b0
Fixed bug and cleanup debug output
apaznikov Feb 5, 2025
d76f5b0
Enable/disable in sanitizer_common_interceptors.inc
apaznikov Feb 6, 2025
ef66b29
Add __tsan_enable/__tsan_disalbe intrinsics
apaznikov Feb 24, 2025
16216da
Minor fixes
apaznikov Mar 24, 2025
10d6ed8
hunk cherry-pick from 8a2198773e: fix InterceptorEnabled visibility.
MorthimerMcMare Apr 27, 2025
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
6 changes: 6 additions & 0 deletions compiler-rt/include/sanitizer/tsan_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,12 @@ int SANITIZER_CDECL __tsan_get_report_unique_tid(void *report,
/// \returns An opaque pointer to the current report. Otherwise returns NULL.
void *SANITIZER_CDECL __tsan_get_current_report();

/////////////////////////////////////////////////////////////////////////////
// This code is for disabling/enabling instrumentation
// for specific code section
void SANITIZER_CDECL __tsan_enable();
void SANITIZER_CDECL __tsan_disable();

#ifdef __cplusplus
} // extern "C"
#endif
Expand Down
3 changes: 3 additions & 0 deletions compiler-rt/lib/sanitizer_common/sanitizer_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
#include "sanitizer_libc.h"
#include "sanitizer_placement_new.h"

extern "C" __attribute__((visibility("default")))
bool InterceptorEnabled = true;

namespace __sanitizer {

const char *SanitizerToolName = "SanitizerTool";
Expand Down
13 changes: 13 additions & 0 deletions compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
#include "sanitizer_symbolizer.h"
#include "sanitizer_tls_get_addr.h"

extern "C" bool InterceptorEnabled;

#if SANITIZER_INTERCEPTOR_HOOKS
#define CALL_WEAK_INTERCEPTOR_HOOK(f, ...) f(__VA_ARGS__);
#define DECLARE_WEAK_INTERCEPTOR_HOOK(f, ...) \
Expand Down Expand Up @@ -378,6 +380,9 @@ UNUSED static void DeleteInterceptorMetadata(void *addr) {

#if SANITIZER_INTERCEPT_STRLEN
INTERCEPTOR(SIZE_T, strlen, const char *s) {
if (!InterceptorEnabled)
return REAL(strlen)(s);

// Sometimes strlen is called prior to InitializeCommonInterceptors,
// in which case the REAL(strlen) typically used in
// COMMON_INTERCEPTOR_ENTER will fail. We use internal_strlen here
Expand Down Expand Up @@ -457,6 +462,10 @@ DECLARE_WEAK_INTERCEPTOR_HOOK(__sanitizer_weak_hook_strcmp, uptr called_pc,
const char *s1, const char *s2, int result)

INTERCEPTOR(int, strcmp, const char *s1, const char *s2) {
// Enabling escape analysis based optimization
if (!InterceptorEnabled)
return REAL(strcmp)(s1, s2);

void *ctx;
COMMON_INTERCEPTOR_ENTER(ctx, strcmp, s1, s2);
unsigned char c1, c2;
Expand Down Expand Up @@ -866,6 +875,10 @@ INTERCEPTOR(int, bcmp, const void *a1, const void *a2, uptr size) {

#if SANITIZER_INTERCEPT_MEMCHR
INTERCEPTOR(void*, memchr, const void *s, int c, SIZE_T n) {
// Enabling escape analysis based optimization
if (!InterceptorEnabled)
return REAL(memchr)(s, c, n);

if (COMMON_INTERCEPTOR_NOTHING_IS_INITIALIZED)
return internal_memchr(s, c, n);
void *ctx;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
#include "interception/interception.h"
#include "sanitizer_platform_interceptors.h"

extern "C" __attribute__((visibility("default")))
bool InterceptorEnabled;

// Platform-specific options.
#if SANITIZER_APPLE
#define PLATFORM_HAS_DIFFERENT_MEMCPY_AND_MEMMOVE 0
Expand All @@ -41,43 +44,49 @@
#endif // SANITIZER_APPLE

#ifndef COMMON_INTERCEPTOR_MEMSET_IMPL
#define COMMON_INTERCEPTOR_MEMSET_IMPL(ctx, dst, v, size) \
{ \
if (COMMON_INTERCEPTOR_NOTHING_IS_INITIALIZED) \
return internal_memset(dst, v, size); \
COMMON_INTERCEPTOR_ENTER(ctx, memset, dst, v, size); \
if (common_flags()->intercept_intrin) \
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, dst, size); \
return REAL(memset)(dst, v, size); \
#define COMMON_INTERCEPTOR_MEMSET_IMPL(ctx, dst, v, size) \
{ \
if (InterceptorEnabled) { \
if (COMMON_INTERCEPTOR_NOTHING_IS_INITIALIZED) \
return internal_memset(dst, v, size); \
COMMON_INTERCEPTOR_ENTER(ctx, memset, dst, v, size); \
if (common_flags()->intercept_intrin) \
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, dst, size); \
} \
return REAL(memset)(dst, v, size); \
}
#endif

#ifndef COMMON_INTERCEPTOR_MEMMOVE_IMPL
#define COMMON_INTERCEPTOR_MEMMOVE_IMPL(ctx, dst, src, size) \
{ \
if (COMMON_INTERCEPTOR_NOTHING_IS_INITIALIZED) \
return internal_memmove(dst, src, size); \
COMMON_INTERCEPTOR_ENTER(ctx, memmove, dst, src, size); \
if (common_flags()->intercept_intrin) { \
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, dst, size); \
COMMON_INTERCEPTOR_READ_RANGE(ctx, src, size); \
} \
return REAL(memmove)(dst, src, size); \
#define COMMON_INTERCEPTOR_MEMMOVE_IMPL(ctx, dst, src, size) \
{ \
if (InterceptorEnabled) { \
if (COMMON_INTERCEPTOR_NOTHING_IS_INITIALIZED) \
return internal_memmove(dst, src, size); \
COMMON_INTERCEPTOR_ENTER(ctx, memmove, dst, src, size); \
if (common_flags()->intercept_intrin) { \
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, dst, size); \
COMMON_INTERCEPTOR_READ_RANGE(ctx, src, size); \
} \
} \
return REAL(memmove)(dst, src, size); \
}
#endif

#ifndef COMMON_INTERCEPTOR_MEMCPY_IMPL
#define COMMON_INTERCEPTOR_MEMCPY_IMPL(ctx, dst, src, size) \
{ \
if (COMMON_INTERCEPTOR_NOTHING_IS_INITIALIZED) { \
return internal_memmove(dst, src, size); \
} \
COMMON_INTERCEPTOR_ENTER(ctx, memcpy, dst, src, size); \
if (common_flags()->intercept_intrin) { \
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, dst, size); \
COMMON_INTERCEPTOR_READ_RANGE(ctx, src, size); \
} \
return REAL(memcpy)(dst, src, size); \
#define COMMON_INTERCEPTOR_MEMCPY_IMPL(ctx, dst, src, size) \
{ \
if (InterceptorEnabled) { \
if (COMMON_INTERCEPTOR_NOTHING_IS_INITIALIZED) { \
return internal_memmove(dst, src, size); \
} \
COMMON_INTERCEPTOR_ENTER(ctx, memcpy, dst, src, size); \
if (common_flags()->intercept_intrin) { \
COMMON_INTERCEPTOR_WRITE_RANGE(ctx, dst, size); \
COMMON_INTERCEPTOR_READ_RANGE(ctx, src, size); \
} \
} \
return REAL(memcpy)(dst, src, size); \
}
#endif

Expand Down
4 changes: 4 additions & 0 deletions compiler-rt/lib/tsan/rtl/tsan_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,10 @@ SANITIZER_INTERFACE_ATTRIBUTE
void __tsan_go_atomic64_compare_exchange(ThreadState *thr, uptr cpc, uptr pc,
u8 *a);

// Functions for disabling/enabling instrumentation
// for specific code section
SANITIZER_INTERFACE_ATTRIBUTE void __tsan_disable();
SANITIZER_INTERFACE_ATTRIBUTE void __tsan_enable();
} // extern "C"

} // namespace __tsan
Expand Down
6 changes: 6 additions & 0 deletions compiler-rt/lib/tsan/rtl/tsan_interface.inc
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,9 @@ void __tsan_read_range_pc(void *addr, uptr size, void *pc) {
void __tsan_write_range_pc(void *addr, uptr size, void *pc) {
MemoryAccessRange(cur_thread(), STRIP_PAC_PC(pc), (uptr)addr, size, true);
}

///////////////////////////////////////////////////////////////////////////////
// This is for disabling/enabling TSan instrumentation
int GV;
SANITIZER_INTERFACE_ATTRIBUTE void __tsan_disable() { GV++; };
SANITIZER_INTERFACE_ATTRIBUTE void __tsan_enable() { GV++; };
2 changes: 2 additions & 0 deletions compiler-rt/lib/tsan/rtl/tsan_rtl.h
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,8 @@ bool OutputReport(ThreadState *thr, const ScopedReport &srep);
bool IsFiredSuppression(Context *ctx, ReportType type, StackTrace trace);
bool IsExpectedReport(uptr addr, uptr size);

//#define TSAN_DEBUG_OUTPUT 2

#if defined(TSAN_DEBUG_OUTPUT) && TSAN_DEBUG_OUTPUT >= 1
# define DPrintf Printf
#else
Expand Down
6 changes: 6 additions & 0 deletions compiler-rt/test/tsan/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ def get_required_attr(config, attr_name):
else:
extra_cflags = []

# Enable new Escape Analysis instead of default Capture Tracking
#escape_analysis_flag = ["-mllvm -tsan-use-escape-analysis"]
escape_analysis_flag = ["-mllvm -tsan-use-escape-analysis-global"]

tsan_incdir = config.test_source_root + "/../"
# Setup default compiler flags used with -fsanitize=thread option.
clang_tsan_cflags = (
Expand All @@ -55,9 +59,11 @@ def get_required_attr(config, attr_name):
+ config.debug_info_flags
+ extra_cflags
+ ["-I%s" % tsan_incdir]
+ escape_analysis_flag
)
clang_tsan_cxxflags = (
config.cxx_mode_flags + clang_tsan_cflags + ["-std=c++11"] + ["-I%s" % tsan_incdir]
+ escape_analysis_flag
)
# Add additional flags if we're using instrumented libc++.
# Instrumented libcxx currently not supported on Darwin.
Expand Down
1 change: 1 addition & 0 deletions llvm/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# Nested build directory.
#==============================================================================#
/build
/cmake-build*

#==============================================================================#
# Explicit files to ignore (only matches one).
Expand Down
Loading