Skip to content

Instantly share code, notes, and snippets.

@mmcloughlin
Created March 9, 2021 00:53
Show Gist options
  • Select an option

  • Save mmcloughlin/0e4d8212ce78cb47180d5e58b01c5809 to your computer and use it in GitHub Desktop.

Select an option

Save mmcloughlin/0e4d8212ce78cb47180d5e58b01c5809 to your computer and use it in GitHub Desktop.
Notes on function call interception.

Function Interception

Techniques

How to wrap a system call (libc function) in Linux demonstrates LD_PRELOAD and ld --wrap techniques.

Interception for Profiling

Generic Library Interception for Improved Performance Measurement and Insight describes creation of wrappers for arbitrary C/C++ libraries in Score-P. See the library_wrapper_generator source code, which uses Clang under the hood.

tau_wrap implements the same thing for the Tau profiling system, though it seems a lot more "hacky" and relies on PDT rather than Clang. The tau_gen_wrapper script uses tau_wrap under the hood.

Non-intrusive Performance Analysis of Parallel Hardware Accelerated Applications on Hybrid Architectures uses function call interception to monitor CUDA and OpenCL applications.

VampirTrace provided this functionality but has since been discontinued in favor of Score-P. The implementation is vtlibwrapgen based on the CTool parser (unmaintained).

Code Generation

Google Sandboxed API uses a libtooling-based tool to autogenerate function wrappers (see clang_generator).

Clang Tutorial: Finding Declarations is a first pass at what we want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment