crates/intercept-preload/README.md
This crate provides a dynamic library for Unix systems that can be used with Bear for intercepting system calls via the LD_PRELOAD mechanism (or DYLD_INSERT_LIBRARIES on macOS).
libexec is designed to work with the Bear compilation database generator. It intercepts system calls like execve to track command execution during builds.
The library is split into a C shim (src/c/shim.c) and Rust implementation (src/implementation.rs). This separation exists because:
execl family)dlsym(RTLD_NEXT, ...)) avoids recursive interception issues| Platform | Mechanism | Symbol visibility |
|---|---|---|
| Linux, FreeBSD, OpenBSD, NetBSD, DragonFly BSD | LD_PRELOAD | ELF version scripts |
| macOS | DYLD_INSERT_LIBRARIES | -exported_symbols_list |
On unsupported platforms (e.g. Windows), the build displays a warning and skips library generation.
exec family calls, posix_spawn, popen, and systemexec callsTo build libexec in debug mode:
cargo build -p intercept-preload
For the release version:
cargo build -p intercept-preload --release
The resulting shared library will be in target/debug/libexec.so (or .dylib on macOS) and target/release/libexec.so respectively.