Skip to content

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

Draft
gyuheon0h wants to merge 1 commit into
gyuheon0h/extract-got-hook-cratefrom
gyuheon0h/got-hook-utils
Draft

feat(got-hook): add DT_HASH fallback, relocation type guard, and hook_symbol#2297
gyuheon0h wants to merge 1 commit into
gyuheon0h/extract-got-hook-cratefrom
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

What does this PR do?

Adds three improvements to libdd-got-hook needed 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

Anything else we should know when reviewing?

How to test the change?

Describe here in detail how the change can be validated.

Copy link
Copy Markdown
Contributor Author

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@github-actions

github-actions Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

📚 Documentation Check Results

⚠️ 59 documentation warning(s) found

📦 libdd-got-hook - 6 warning(s)

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


Updated: 2026-07-29 19:24:24 UTC | Commit: 54a9982 | missing-docs job results

@github-actions

github-actions Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

🔒 Cargo Deny Results

No issues found!

📦 libdd-got-hook - ✅ No issues

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


Updated: 2026-07-29 19:26:26 UTC | Commit: 54a9982 | dependency-check job results

@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: 56.72%
Overall Coverage: 74.90% (-0.02%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 934d93c | 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.so 8.01 MB 8.01 MB 0% (0 B) 👌
/aarch64-alpine-linux-musl/lib/libdatadog_profiling.a 87.33 MB 87.33 MB 0% (0 B) 👌
aarch64-unknown-linux-gnu
Artifact Baseline Commit Change
/aarch64-unknown-linux-gnu/lib/libdatadog_profiling.a 98.59 MB 98.59 MB 0% (0 B) 👌
/aarch64-unknown-linux-gnu/lib/libdatadog_profiling.so 10.78 MB 10.78 MB 0% (0 B) 👌
libdatadog-x64-windows
Artifact Baseline Commit Change
/libdatadog-x64-windows/debug/dynamic/datadog_profiling_ffi.dll 26.08 MB 26.08 MB 0% (0 B) 👌
/libdatadog-x64-windows/debug/dynamic/datadog_profiling_ffi.lib 89.60 KB 89.60 KB 0% (0 B) 👌
/libdatadog-x64-windows/debug/dynamic/datadog_profiling_ffi.pdb 188.23 MB 188.23 MB 0% (0 B) 👌
/libdatadog-x64-windows/debug/static/datadog_profiling_ffi.lib 980.23 MB 980.23 MB 0% (0 B) 👌
/libdatadog-x64-windows/release/dynamic/datadog_profiling_ffi.dll 8.48 MB 8.48 MB 0% (0 B) 👌
/libdatadog-x64-windows/release/dynamic/datadog_profiling_ffi.lib 89.60 KB 89.60 KB 0% (0 B) 👌
/libdatadog-x64-windows/release/dynamic/datadog_profiling_ffi.pdb 25.08 MB 25.08 MB 0% (0 B) 👌
/libdatadog-x64-windows/release/static/datadog_profiling_ffi.lib 49.90 MB 49.90 MB 0% (0 B) 👌
libdatadog-x86-windows
Artifact Baseline Commit Change
/libdatadog-x86-windows/debug/dynamic/datadog_profiling_ffi.dll 22.65 MB 22.65 MB 0% (0 B) 👌
/libdatadog-x86-windows/debug/dynamic/datadog_profiling_ffi.lib 91.00 KB 91.00 KB 0% (0 B) 👌
/libdatadog-x86-windows/debug/dynamic/datadog_profiling_ffi.pdb 192.71 MB 192.72 MB +0% (+8.00 KB) 👌
/libdatadog-x86-windows/debug/static/datadog_profiling_ffi.lib 971.14 MB 971.14 MB 0% (0 B) 👌
/libdatadog-x86-windows/release/dynamic/datadog_profiling_ffi.dll 6.55 MB 6.55 MB 0% (0 B) 👌
/libdatadog-x86-windows/release/dynamic/datadog_profiling_ffi.lib 91.00 KB 91.00 KB 0% (0 B) 👌
/libdatadog-x86-windows/release/dynamic/datadog_profiling_ffi.pdb 26.94 MB 26.94 MB 0% (0 B) 👌
/libdatadog-x86-windows/release/static/datadog_profiling_ffi.lib 47.50 MB 47.50 MB 0% (0 B) 👌
x86_64-alpine-linux-musl
Artifact Baseline Commit Change
/x86_64-alpine-linux-musl/lib/libdatadog_profiling.a 77.82 MB 77.82 MB 0% (0 B) 👌
/x86_64-alpine-linux-musl/lib/libdatadog_profiling.so 8.93 MB 8.93 MB 0% (0 B) 👌
x86_64-unknown-linux-gnu
Artifact Baseline Commit Change
/x86_64-unknown-linux-gnu/lib/libdatadog_profiling.a 93.38 MB 93.38 MB 0% (0 B) 👌
/x86_64-unknown-linux-gnu/lib/libdatadog_profiling.so 10.87 MB 10.87 MB 0% (0 B) 👌

@pr-commenter

pr-commenter Bot commented Jul 29, 2026

Copy link
Copy Markdown

Benchmarks

Comparison

Benchmark execution time: 2026-07-29 19:53:48

Comparing candidate commit 934d93c in PR branch gyuheon0h/got-hook-utils with baseline commit 45c074d in branch gyuheon0h/extract-got-hook-crate.

Found 1 performance improvements and 2 performance regressions! Performance is the same for 139 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:profile_add_sample_timestamped_x1000

  • 🟩 execution_time [-172.362µs; -169.761µs] or [-4.117%; -4.055%]

scenario:vec_map/insert/8

  • 🟥 execution_time [+12.846ns; +14.225ns] or [+5.796%; +6.419%]
  • 🟥 throughput [-2166546.914op/s; -1965984.155op/s] or [-6.001%; -5.446%]

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 from 8713e2e to 0f700c2 Compare July 29, 2026 19:01
…_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 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-got-hook/src/elf.rs
Comment on lines +160 to +161
} else {
(sym_count_fallback(symtab, strtab, sysv_hash), 0)

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 Add a SysV lookup path for DT_HASH-only providers

When this new branch admits a DSO that only has DT_HASH, the resulting DynamicInfo still has no usable GNU hash, but lookup_symbol resolves definitions only through gnu_hash_lookup. If the real allocator or hook target is provided by a SysV-hash-only DSO, lookup_symbol returns None, SymbolOverrides::apply_overrides leaves the ref slot at 0, and the install path skips patching that symbol even though the object is now considered parseable. Add a SysV hash lookup or a bounded dynsym scan using nchain for this branch.

Useful? React with 👍 / 👎.

Comment thread libdd-got-hook/src/elf.rs
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
Comment on lines +624 to +630
let real = libc::dlsym(libc::RTLD_DEFAULT, symbol_name.as_ptr());
if real.is_null() {
return false;
}
let real_addr = real as usize;
if real_addr == hook_fn {
return false;

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 Resolve past the hook for same-name interposers

If the replacement function is exported under the same symbol_name being hooked (a common preload/interposer pattern for crash-tracking wrappers), dlsym(RTLD_DEFAULT, ...) can resolve this library's hook first; the equality check below then returns false and no GOT entries are patched. Use a lookup that excludes hook_fn (as SymbolOverrides already does) or an RTLD_NEXT-style resolution so same-name wrappers can still install.

Useful? React with 👍 / 👎.

@gyuheon0h
gyuheon0h marked this pull request as draft July 29, 2026 19:56
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.

1 participant