Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 3 additions & 2 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,22 @@ deny.toml @DataDog/libdatadog
docker-bake.hcl @DataDog/apm-common-components-core
docs @DataDog/libdatadog
examples @DataDog/libdatadog
libdd-agent-client @DataDog/apm-common-components-core
libdd-alloc/ @DataDog/libdatadog-profiling
libdd-capabilities*/ @DataDog/apm-common-components-core
libdd-common*/ @DataDog/libdatadog
libdd-crashtracker*/ @DataDog/libdatadog-profiling
libdd-data-pipeline*/ @DataDog/libdatadog-apm
libdd-ddsketch*/ @DataDog/libdatadog-apm @DataDog/apm-common-components-core
libdd-dogstatsd-client @DataDog/apm-common-components-core
libdd-profiling-heap-*/ @DataDog/libdatadog-profiling
libdd-gotter/ @DataDog/libdatadog @DataDog/libdatadog-profiling
libdd-http-client @DataDog/apm-common-components-core
libdd-agent-client @DataDog/apm-common-components-core
libdd-library-config*/ @DataDog/apm-sdk-capabilities-rust
libdd-log*/ @DataDog/apm-common-components-core
libdd-otel-thread-ctx/ @DataDog/apm-common-components-core
libdd-otel-thread-ctx-ffi/ @DataDog/apm-common-components-core
libdd-profiling*/ @DataDog/libdatadog-profiling
libdd-profiling-heap-*/ @DataDog/libdatadog-profiling
libdd-sampling/ @DataDog/apm-common-components-core
libdd-shared-runtime*/ @DataDog/apm-common-components-core
libdd-telemetry*/ @DataDog/apm-common-components-core
Expand Down
12 changes: 10 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ members = [
"libdd-alloc",
"libdd-profiling-heap-sampler",
"libdd-profiling-heap-allocator",
"libdd-gotter",
"libdd-profiling-heap-gotter",
"libdd-profiling-heap-gotter-ffi",
"libdd-crashtracker",
Expand Down
2 changes: 1 addition & 1 deletion LICENSE-3rdparty.csv
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ js-sys,https://github.com/rustwasm/wasm-bindgen/tree/master/crates/js-sys,MIT OR
kernel32-sys,https://github.com/retep998/winapi-rs,MIT,Peter Atashian <retep998@gmail.com>
kv-log-macro,https://github.com/yoshuawuyts/kv-log-macro,MIT OR Apache-2.0,Yoshua Wuyts <yoshuawuyts@gmail.com>
lazy_static,https://github.com/rust-lang-nursery/lazy-static.rs,MIT OR Apache-2.0,Marvin Löbel <loebel.marvin@gmail.com>
libc,https://github.com/rust-lang/libc,MIT OR Apache-2.0,The Rust Project Developers
libc,https://github.com/rust-lang/libc,MIT OR Apache-2.0,The libc Authors
libdd-libunwind-sys,https://github.com/DataDog/libdatadog/tree/main/libdd-libunwind-sys,Apache-2.0,The libdd-libunwind-sys Authors
libloading,https://github.com/nagisa/rust_libloading,ISC,Simonas Kazlauskas <libloading@kazlauskas.me>
libredox,https://gitlab.redox-os.org/redox-os/libredox,MIT,4lDO2 <4lDO2@protonmail.com>
Expand Down
18 changes: 18 additions & 0 deletions libdd-gotter/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2025-Present Datadog, Inc. https://www.datadoghq.com/
Comment thread
gyuheon0h marked this conversation as resolved.
# SPDX-License-Identifier: Apache-2.0

[package]
name = "libdd-gotter"
version = "0.1.0"
description = "ELF GOT-patching primitives for runtime function interposition on 64-bit Linux."
homepage = "https://github.com/DataDog/libdatadog/tree/main/libdd-gotter"
repository = "https://github.com/DataDog/libdatadog/tree/main/libdd-gotter"
edition.workspace = true
rust-version.workspace = true
license.workspace = true
Comment thread
gyuheon0h marked this conversation as resolved.

[lib]
bench = false

[dependencies]
libc.workspace = true
41 changes: 41 additions & 0 deletions libdd-gotter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# libdd-gotter

> [!WARNING]
> This library does runtime function interposition by patching the Global Offset Table (GOT) of loaded ELF objects. This is a substantial intervention in a running process — it modifies function pointers that the dynamic linker has already resolved, affecting all code that calls through those GOT entries. Incorrect use can cause crashes, infinite recursion, heap corruption, or silent data loss. Understand the ELF dynamic linking model before using this crate.

## What it does

When a shared library calls an external function like `malloc`, it jumps through a pointer in its **Global Offset Table** -- a writable table that the dynamic linker fills at load time. This crate walks every loaded ELF object via `dl_iterate_phdr`, parses its `PT_DYNAMIC` segment, and rewrites GOT entries so calls are redirected to a hook function. The original function address is resolved and returned so the hook can forward to it.
Comment thread
gyuheon0h marked this conversation as resolved.

## Usage

### Single-symbol hook (crashtracker intercepting `__assert_fail`)

```rust
use libdd_got_hook::hook_symbol;

static ORIG_FN: AtomicUsize = AtomicUsize::new(0);

unsafe extern "C" fn my_hook(/* same signature as target */) {
Comment thread
gyuheon0h marked this conversation as resolved.
// ... do work ...
// forward to original via ORIG_FN
}

let mut orig_addr: usize = 0;
unsafe {
hook_symbol(c"__assert_fail", my_hook as *const () as usize, &mut orig_addr);
}
// Release pairs with the Acquire load in my_hook, ensuring the GOT
// patches from hook_symbol are visible before the hook reads orig_addr.
ORIG_FN.store(orig_addr, Ordering::Release);
Comment thread
gyuheon0h marked this conversation as resolved.
```

### Multi-symbol registry (heap profiling hooking malloc/free/calloc/realloc)

See [`libdd-profiling-heap-gotter`](../libdd-profiling-heap-gotter) which builds a `SymbolOverrides` registry on top of the primitives exported by this crate.

## Support
This library can be used on ARM64 and AMD64 Linux in processes using glibc or musl runtimes.
Only symbols that have been dynamically linked can be intercept.
For instance, if you want to intercept the `malloc` of your C runtime,
you _cannot_ do so if the application has been statically linked against musl.
Loading
Loading