-
Notifications
You must be signed in to change notification settings - Fork 0
Instrumentation
Instrumentation is applied on LLVM modules in src/compilerlib/instrumentation/.
| Pass | Entry point | Main inserted hooks |
|---|---|---|
| Allocation | wrapAllocCalls() |
__ct_malloc, __ct_free, __ct_new, __ct_delete, __ct_realloc, __ct_mmap, ... |
| Bounds | instrumentMemoryAccesses() |
__ct_check_bounds(base, ptr, size, site, is_write) |
| Trace | instrumentModule() |
__ct_trace_enter, typed exit hooks (void/i64/ptr/f64/unknown) |
| VTable | instrumentVirtualCalls() |
__ct_vtable_dump, __ct_vcall_trace
|
The allocation pass rewrites calls for C and C++ allocators/deallocators and several memory APIs. Highlights:
- tracks allocations with source-site strings,
- supports malloc/calloc/realloc/free,
- supports
new/deletevariants (including nothrow/destroying delete hooks), - supports
posix_memalign,aligned_alloc,mmap/munmap,sbrk/brkwrappers, - adds auto-free helper calls for unreachable allocations when enabled.
The bounds pass instruments:
- loads/stores,
- atomic memory ops,
-
llvm.mem*intrinsics.
Each check receives base pointer, accessed pointer, access size, site string, and write/read mode.
The trace pass:
- inserts
__ct_trace_enterat function entry, - inserts typed exit hooks based on return type,
- skips non-user/runtime functions via shared filtering helpers.
The vtable pass instruments indirect virtual-style calls when it can recover a this pointer pattern.
Depending on config:
-
dump_vtable: injects__ct_vtable_dump(this, site, static_type) -
trace_calls: injects__ct_vcall_trace(this, callee, site, static_type)
include/compilerlib/instrumentation/config.hpp:
-
shadow_enabled(defaultfalse) -
shadow_aggressive(defaultfalse) -
bounds_no_abort(defaultfalse) -
trace_enabled(defaulttrue) -
alloc_enabled(defaulttrue) -
bounds_enabled(defaulttrue) -
vtable_enabled(defaultfalse) -
vcall_trace_enabled(defaultfalse) -
vtable_diag_enabled(defaultfalse) -
autofree_enabled(defaultfalse) -
alloc_trace_enabled(defaulttrue) -
bounds_without_alloc(derived) -
optnone_enabled(defaultfalse)
If bounds is enabled while alloc is disabled, CoreTrace emits a warning because bounds checks rely on allocation metadata.
frontend/OptNoneAction can wrap frontend actions to force optnone/noinline on user functions.
This is controlled by --ct-optnone and can apply even without --instrument.
Start
Architecture
Instrumentation
Developer