Skip to content

feat(gotter)!: add DT_HASH fallback, relocation type guard, and hook_symbol - #2297

Open
gyuheon0h wants to merge 10 commits into
mainfrom
gyuheon0h/got-hook-utils
Open

feat(gotter)!: add DT_HASH fallback, relocation type guard, and hook_symbol#2297
gyuheon0h wants to merge 10 commits into
mainfrom
gyuheon0h/got-hook-utils

Conversation

@gyuheon0h

@gyuheon0h gyuheon0h commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Stacked above refactor(got-patching): extract shared GOT-patching primitives into libdd-got-hook
Stacked under feat(crashtracking): retrieve c assert message for linux when __assert_fail is dynamically loaded

PROF-15629

What does this PR do?

Adds three general improvements to libdd-got-hook for crash tracking (and beneficial to heap profiling):

  • DT_HASH (SysV) fallback: DynamicInfo::from_phdr no longer requires DT_GNU_HASH. Objects linked with --hash-style=sysvare now parsed by reading nchain from the SysV hash header. We jjust skipped these objects previously.
  • Relocation type guard: elf64_r_type + is_got_pointer_reloc now only patches GLOB_DAT and JUMP_SLOT relocations (pointer-sized GOT slots) on both x86_64 and aarch64. Non-pointer relocation types are now skipped, preventing potential corruption of adjacent code/data from writing 8 bytes into a 4-byte relocation field. Applied to both libdd-got-hook's patch_got_entries and libdd-profiling-heap-gotter's process_relocation. (this was a codex recommendation)
  • hook_symbol: Single-symbol convenience wrapper that combines dlsym + iterate_libraries + patch_got_entries into one call.

Motivation

What inspired you to submit this pull request?

Additional Notes

Gated on @scottgerring's approval

How to test the change?

Describe here in detail how the change can be validated.

gyuheon0h commented Jul 29, 2026

Copy link
Copy Markdown
Contributor Author

@datadog-prod-us1-3

datadog-prod-us1-3 Bot commented Jul 29, 2026

Copy link
Copy Markdown

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 76.34%
Overall Coverage: 75.15% (+0.01%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: e9568ee | Docs | Datadog PR Page | Give us feedback!

@dd-octo-sts

dd-octo-sts Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Artifact Size Benchmark Report

aarch64-alpine-linux-musl
Artifact Baseline Commit Change
/aarch64-alpine-linux-musl/lib/libdatadog_profiling.a 87.84 MB 87.84 MB 0% (0 B) 👌
/aarch64-alpine-linux-musl/lib/libdatadog_profiling.so 8.07 MB 8.07 MB 0% (0 B) 👌
aarch64-unknown-linux-gnu
Artifact Baseline Commit Change
/aarch64-unknown-linux-gnu/lib/libdatadog_profiling.so 10.88 MB 10.88 MB 0% (0 B) 👌
/aarch64-unknown-linux-gnu/lib/libdatadog_profiling.a 98.97 MB 98.97 MB 0% (0 B) 👌
libdatadog-x64-windows
Artifact Baseline Commit Change
/libdatadog-x64-windows/debug/dynamic/datadog_profiling_ffi.dll 26.21 MB 26.21 MB 0% (0 B) 👌
/libdatadog-x64-windows/debug/dynamic/datadog_profiling_ffi.lib 89.92 KB 89.92 KB 0% (0 B) 👌
/libdatadog-x64-windows/debug/dynamic/datadog_profiling_ffi.pdb 188.66 MB 188.66 MB 0% (0 B) 👌
/libdatadog-x64-windows/debug/static/datadog_profiling_ffi.lib 985.57 MB 985.57 MB 0% (0 B) 👌
/libdatadog-x64-windows/release/dynamic/datadog_profiling_ffi.dll 8.56 MB 8.56 MB 0% (0 B) 👌
/libdatadog-x64-windows/release/dynamic/datadog_profiling_ffi.lib 89.92 KB 89.92 KB 0% (0 B) 👌
/libdatadog-x64-windows/release/dynamic/datadog_profiling_ffi.pdb 25.22 MB 25.22 MB 0% (0 B) 👌
/libdatadog-x64-windows/release/static/datadog_profiling_ffi.lib 50.23 MB 50.23 MB 0% (0 B) 👌
libdatadog-x86-windows
Artifact Baseline Commit Change
/libdatadog-x86-windows/debug/dynamic/datadog_profiling_ffi.dll 22.84 MB 22.84 MB 0% (0 B) 👌
/libdatadog-x86-windows/debug/dynamic/datadog_profiling_ffi.lib 91.33 KB 91.33 KB 0% (0 B) 👌
/libdatadog-x86-windows/debug/dynamic/datadog_profiling_ffi.pdb 193.44 MB 193.44 MB -0% (-8.00 KB) 👌
/libdatadog-x86-windows/debug/static/datadog_profiling_ffi.lib 974.34 MB 974.34 MB 0% (0 B) 👌
/libdatadog-x86-windows/release/dynamic/datadog_profiling_ffi.dll 6.61 MB 6.61 MB 0% (0 B) 👌
/libdatadog-x86-windows/release/dynamic/datadog_profiling_ffi.lib 91.33 KB 91.33 KB 0% (0 B) 👌
/libdatadog-x86-windows/release/dynamic/datadog_profiling_ffi.pdb 27.12 MB 27.12 MB 0% (0 B) 👌
/libdatadog-x86-windows/release/static/datadog_profiling_ffi.lib 47.83 MB 47.83 MB 0% (0 B) 👌
x86_64-alpine-linux-musl
Artifact Baseline Commit Change
/x86_64-alpine-linux-musl/lib/libdatadog_profiling.a 78.21 MB 78.21 MB 0% (0 B) 👌
/x86_64-alpine-linux-musl/lib/libdatadog_profiling.so 9.00 MB 9.00 MB 0% (0 B) 👌
x86_64-unknown-linux-gnu
Artifact Baseline Commit Change
/x86_64-unknown-linux-gnu/lib/libdatadog_profiling.a 93.85 MB 93.85 MB 0% (0 B) 👌
/x86_64-unknown-linux-gnu/lib/libdatadog_profiling.so 10.97 MB 10.97 MB 0% (0 B) 👌

@pr-commenter

pr-commenter Bot commented Jul 29, 2026

Copy link
Copy Markdown

Benchmarks

Comparison

Benchmark execution time: 2026-08-05 21:23:31

Comparing candidate commit e9568ee in PR branch gyuheon0h/got-hook-utils with baseline commit 9ac89b9 in branch main.

Found 3 performance improvements and 0 performance regressions! Performance is the same for 137 metrics, 0 unstable metrics.

Explanation

This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

  • 🟩 = significantly better candidate vs. baseline
  • 🟥 = significantly worse candidate vs. baseline

We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

More details about the CI and significant changes

You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

CIs of the difference of means are often centered around 0%, because often changes are not that big:

---------------------------------(------|---^--------)-------------------------------->
                              -0.6%    0%  0.3%     +1.2%
                                 |          |        |
         lower bound of the CI --'          |        |
sample mean (center of the CI) -------------'        |
         upper bound of the CI ----------------------'

As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

----------------------------------------|---------|---(---------^---------)---------->
                                       0%        1%  1.3%      2.2%      3.1%
                                                  |   |         |         |
       significant impact threshold --------------'   |         |         |
                      lower bound of CI --------------'         |         |
       sample mean (center of the CI) --------------------------'         |
                      upper bound of CI ----------------------------------'

scenario:vec_map/get_hit/16

  • 🟩 execution_time [-19.985ns; -19.765ns] or [-9.071%; -8.972%]
  • 🟩 throughput [+7163115.463op/s; +7240514.613op/s] or [+9.863%; +9.969%]

scenario:vec_map/get_miss/64

  • 🟩 execution_time [-28.642ns; -28.531ns] or [-50.684%; -50.488%]

Benchmark execution time: 2026-08-05 21:32:48

Comparing candidate commit e9568ee in PR branch gyuheon0h/got-hook-utils with baseline commit 9ac89b9 in branch main.

Found 3 performance improvements and 11 performance regressions! Performance is the same for 154 metrics, 10 unstable metrics.

Explanation

This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

  • 🟩 = significantly better candidate vs. baseline
  • 🟥 = significantly worse candidate vs. baseline

We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

More details about the CI and significant changes

You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

CIs of the difference of means are often centered around 0%, because often changes are not that big:

---------------------------------(------|---^--------)-------------------------------->
                              -0.6%    0%  0.3%     +1.2%
                                 |          |        |
         lower bound of the CI --'          |        |
sample mean (center of the CI) -------------'        |
         upper bound of the CI ----------------------'

As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

----------------------------------------|---------|---(---------^---------)---------->
                                       0%        1%  1.3%      2.2%      3.1%
                                                  |   |         |         |
       significant impact threshold --------------'   |         |         |
                      lower bound of CI --------------'         |         |
       sample mean (center of the CI) --------------------------'         |
                      upper bound of CI ----------------------------------'

scenario:alloc_free/system/4096

  • 🟥 execution_time [+8.720ns; +8.906ns] or [+10.333%; +10.553%]

scenario:datadog_sample_span/resource_pattern_rule_not_matching/wall_time

  • 🟥 execution_time [+13.679ns; +13.751ns] or [+8.608%; +8.653%]

scenario:glob_matcher/ascii_wildcard_heavy_backtrack/wall_time

  • 🟥 execution_time [+1.713ns; +1.733ns] or [+4.190%; +4.239%]

scenario:glob_matcher/ascii_wildcard_question_match/wall_time

  • 🟩 execution_time [-21.374ns; -21.353ns] or [-36.702%; -36.666%]

scenario:glob_matcher/ascii_wildcard_star_match/wall_time

  • 🟩 execution_time [-21.374ns; -21.348ns] or [-36.686%; -36.642%]

scenario:glob_matcher/unicode_pattern_wildcard_match/wall_time

  • 🟥 execution_time [+14.531ns; +14.590ns] or [+11.760%; +11.807%]

scenario:no_profiler/short_circuit/4096

  • 🟩 execution_time [-13.683ns; -13.547ns] or [-13.269%; -13.137%]

scenario:profiler_attached/fast_path_noop/16

  • 🟥 execution_time [+12.056ns; +12.067ns] or [+83.314%; +83.388%]

scenario:profiler_attached/fast_path_noop/256

  • 🟥 execution_time [+12.056ns; +12.068ns] or [+83.313%; +83.393%]

scenario:profiler_attached/fast_path_noop/4096

  • 🟥 execution_time [+12.057ns; +12.065ns] or [+83.326%; +83.381%]

scenario:profiler_attached/fast_path_noop/64

  • 🟥 execution_time [+12.058ns; +12.070ns] or [+83.322%; +83.401%]

scenario:profiler_attached/fast_path_noop/65536

  • 🟥 execution_time [+12.057ns; +12.067ns] or [+83.325%; +83.394%]

scenario:profiler_attached/fast_path_system/4096

  • 🟥 execution_time [+10.651ns; +10.778ns] or [+11.279%; +11.413%]

scenario:profiler_attached/slow_path_system/4096

  • 🟥 execution_time [+6.986ns; +7.118ns] or [+4.730%; +4.820%]

Candidate

Omitted due to size.

Baseline

Omitted due to size.

@gyuheon0h
gyuheon0h force-pushed the gyuheon0h/got-hook-utils branch from 1c3157f to 5f00ce2 Compare July 29, 2026 16:57
@gyuheon0h
gyuheon0h force-pushed the gyuheon0h/extract-got-hook-crate branch from e9b992a to 18d4e84 Compare July 29, 2026 16:57
@gyuheon0h
gyuheon0h force-pushed the gyuheon0h/got-hook-utils branch from 1c3157f to 5f00ce2 Compare July 29, 2026 16:57
@gyuheon0h
gyuheon0h force-pushed the gyuheon0h/extract-got-hook-crate branch 2 times, most recently from 18d4e84 to 00baa22 Compare July 29, 2026 18:27
@gyuheon0h
gyuheon0h force-pushed the gyuheon0h/got-hook-utils branch from 5f00ce2 to 4618f83 Compare July 29, 2026 18:27
@gyuheon0h
gyuheon0h force-pushed the gyuheon0h/extract-got-hook-crate branch from 00baa22 to d4b9d82 Compare July 29, 2026 18:28
@gyuheon0h
gyuheon0h force-pushed the gyuheon0h/got-hook-utils branch from 4618f83 to 8713e2e Compare July 29, 2026 18:28
@gyuheon0h
gyuheon0h force-pushed the gyuheon0h/extract-got-hook-crate branch from d4b9d82 to 560d0a6 Compare July 29, 2026 19:01
@gyuheon0h
gyuheon0h force-pushed the gyuheon0h/got-hook-utils branch 2 times, most recently from 0f700c2 to 934d93c Compare July 29, 2026 19:22
@gyuheon0h
gyuheon0h force-pushed the gyuheon0h/extract-got-hook-crate branch from 560d0a6 to 45c074d Compare July 29, 2026 19:22
@gyuheon0h
gyuheon0h marked this pull request as ready for review July 29, 2026 19:46
@gyuheon0h
gyuheon0h requested review from a team as code owners July 29, 2026 19:46

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 934d93c530

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread libdd-gotter/src/elf.rs
Comment thread libdd-got-hook/src/elf.rs Outdated
Comment on lines +566 to +568
matches!(
r_type,
R_X86_64_GLOB_DAT | R_X86_64_JUMP_SLOT | R_AARCH64_GLOB_DAT | R_AARCH64_JUMP_SLOT

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Gate the relocation filter to supported architectures

On 64-bit Linux targets other than x86_64/aarch64, this crate still compiles and the GOT-patching APIs are active, but this shared predicate now admits only the x86_64/aarch64 relocation numbers. Architectures such as s390x, ppc64, or riscv64 use different GLOB_DAT/JUMP_SLOT values, so their import relocations are all skipped and installation can report success after resolving originals without actually patching any GOT entries. Either gate the Linux implementation to the supported architectures or add the architecture-specific constants.

Useful? React with 👍 / 👎.

Comment thread libdd-got-hook/src/elf.rs Outdated
@gyuheon0h
gyuheon0h marked this pull request as draft July 29, 2026 19:56
@gyuheon0h
gyuheon0h force-pushed the gyuheon0h/got-hook-utils branch from 934d93c to 5e08f80 Compare July 30, 2026 16:39
@gyuheon0h
gyuheon0h force-pushed the gyuheon0h/extract-got-hook-crate branch from 45c074d to 11a3920 Compare July 30, 2026 16:39
@gyuheon0h
gyuheon0h force-pushed the gyuheon0h/got-hook-utils branch from 5e08f80 to e2110f9 Compare July 30, 2026 17:38
@gyuheon0h
gyuheon0h marked this pull request as ready for review July 30, 2026 17:45
@gyuheon0h
gyuheon0h force-pushed the gyuheon0h/got-hook-utils branch from e2110f9 to cad573a Compare July 30, 2026 17:50
@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

🔒 Cargo Deny Results

No issues found!

📦 libdd-gotter - ✅ No issues

📦 libdd-profiling-heap-gotter - ✅ No issues


Updated: 2026-08-05 20:51:23 UTC | Commit: a4010a9 | dependency-check job results

@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

📚 Documentation Check Results

⚠️ 61 documentation warning(s) found

📦 libdd-gotter - 6 warning(s)

📦 libdd-profiling-heap-gotter - 55 warning(s)


Updated: 2026-08-05 20:49:45 UTC | Commit: a4010a9 | missing-docs job results

@gyuheon0h
gyuheon0h force-pushed the gyuheon0h/got-hook-utils branch from 8674202 to a4a6346 Compare August 4, 2026 13:23
gyuheon0h added a commit that referenced this pull request Aug 4, 2026
…ibdd-got-hook (#2282)

Stacked under [feat(got-hook): add DT_HASH fallback, relocation type
guard, and hook_symbol](#2297)

# What does this PR do?

Moves the ELF GOT-patching infrastructure out of
libdd-profiling-heap-gotter into a new shared crate libdd-got-hook, so
multiple crates can reuse the same machinery for runtime function
interposition.

This is a pure code move. I tried to have no behavioral changes here.

What moves to `libdd-got-hook`
- `DynamicInfo::from_phdr`: parse PT_DYNAMIC from a loaded ELF object
- `gnu_hash` / `gnu_hash_symbol_count` / `gnu_hash_lookup` /
`check_sym`: GNU hash table utilities
- `iterate_libraries`: this is a `dl_iterate_phdr` wrapper with
panic-safe trampoline
- `PageProtGuard` / `read_proc_maps` / `MapEntry`: RELRO-aware page
protection management
- `lookup_symbol` / `LookupResult`: used for resolving a symbol across
all loaded objects
- `elf64_r_sym`: relocation info helper
-  ELF types and constants

What stays in `libdd-profiling-heap-gotter`
- `SymbolOverrides`: multi-symbol registry
- `hooks.rs`: the actual `malloc`/`free`/`calloc`/`realloc` hook
functions
- lib.rs: `install_heap_overrides` / `update_heap_overrides` public API

# Motivation

What inspired you to submit this pull request?

# Additional Notes
Gated on @scottgerring's approval

# How to test the change?

Describe here in detail how the change can be validated.
Base automatically changed from gyuheon0h/extract-got-hook-crate to main August 4, 2026 14:11
@gyuheon0h
gyuheon0h requested a review from a team as a code owner August 4, 2026 14:11
…_symbol

- DT_HASH (sysv) fallback: from_phdr no longer requires DT_GNU_HASH.
  Objects linked with --hash-style=sysv are now parsed by reading
  nchain from the sysv hash header.
- elf64_r_type + is_got_pointer_reloc: only patch GLOB_DAT and
  JUMP_SLOT relocations. Skips non-pointer relocation types that would
  corrupt adjacent code/data if overwritten as 8-byte pointer slots.
- hook_symbol: single-symbol convenience wrapper that composes dlsym,
  iterate_libraries, and patch_got_entries into one call.
@gyuheon0h
gyuheon0h force-pushed the gyuheon0h/got-hook-utils branch from a4a6346 to 9d4d601 Compare August 4, 2026 14:12
@gyuheon0h gyuheon0h changed the title feat(got-hook): add DT_HASH fallback, relocation type guard, and hook_symbol feat(got-hook)!: add DT_HASH fallback, relocation type guard, and hook_symbol Aug 4, 2026
@gyuheon0h
gyuheon0h force-pushed the gyuheon0h/got-hook-utils branch from 9d4d601 to f19c984 Compare August 4, 2026 14:36
@gyuheon0h

Copy link
Copy Markdown
Contributor Author

@scottgerring

Also out of curiosity, did you see the older sysv hashing in the wild somewhere?

No. Unfortunately, its hard to see what customers are running for their elf hashing :( but as part of just making this library more robust, I thought it was worth to do haha

@gyuheon0h
gyuheon0h requested a review from scottgerring August 4, 2026 15:59
@gyuheon0h gyuheon0h changed the title feat(got-hook)!: add DT_HASH fallback, relocation type guard, and hook_symbol feat(gotter)!: add DT_HASH fallback, relocation type guard, and hook_symbol Aug 4, 2026
Comment thread libdd-gotter/src/elf.rs
Comment thread libdd-gotter/src/elf.rs
///
/// `hook_fn` must point to a function with the same calling convention
/// and signature as the symbol being hooked. The patching is permanent.
pub unsafe fn hook_symbol(symbol_name: &CStr, hook_fn: usize, orig_out: &mut usize) -> bool {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this function return errors if any?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It returns false for any failure (symbol not found, no GOT entries patched). The callers treat hooking as best-effort. If it fails, the feature degrades gracefully ( crash reports just show SIGABRT instead of the assert expression). We could change to Result if we want diagnostics, but none of the current callers would act on specific error variants. Happy to add it if you feel strongly. WDYT?

@gyuheon0h
gyuheon0h requested review from danielsn and yannham August 4, 2026 20:39
Comment thread libdd-gotter/src/elf.rs Outdated
Comment thread libdd-gotter/src/elf.rs Outdated
Comment thread libdd-gotter/src/elf.rs
(sym_count_fallback(symtab, strtab, sysv_hash), 0)
};

// SAFETY (applies to all `slice::from_raw_parts` calls below):

@gyuheon0h gyuheon0h Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These safety points come from from_raw_parts contract

@gyuheon0h
gyuheon0h force-pushed the gyuheon0h/got-hook-utils branch from 2d9bca3 to e9568ee Compare August 5, 2026 20:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants