Skip to content

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

Open
gyuheon0h wants to merge 2 commits into
gyuheon0h/extract-got-hook-cratefrom
gyuheon0h/got-hook-utils
Open

feat(got-hook): add DT_HASH fallback, relocation type guard, and hook_symbol#2297
gyuheon0h wants to merge 2 commits 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 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.

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-gotter - 6 warning(s)

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


Updated: 2026-07-31 19:08:02 UTC | Commit: 2632792 | 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-gotter - ✅ No issues

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


Updated: 2026-07-31 19:10:03 UTC | Commit: 2632792 | 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: 68.49%
Overall Coverage: 74.90% (-0.01%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 788f2de | 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.33 MB 87.33 MB 0% (0 B) 👌
/aarch64-alpine-linux-musl/lib/libdatadog_profiling.so 8.01 MB 8.01 MB 0% (0 B) 👌
aarch64-unknown-linux-gnu
Artifact Baseline Commit Change
/aarch64-unknown-linux-gnu/lib/libdatadog_profiling.so 10.78 MB 10.78 MB 0% (0 B) 👌
/aarch64-unknown-linux-gnu/lib/libdatadog_profiling.a 98.59 MB 98.59 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% (+8.00 KB) 👌
/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-31 19:39:03

Comparing candidate commit 788f2de in PR branch gyuheon0h/got-hook-utils with baseline commit 31e53ca in branch gyuheon0h/extract-got-hook-crate.

Found 2 performance improvements and 2 performance regressions! Performance is the same for 138 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:msgpack_decoder::v05/high_sharing/2000

  • 🟩 execution_time [-95.826µs; -94.914µs] or [-5.806%; -5.750%]
  • 🟩 throughput [+73948.212op/s; +74664.468op/s] or [+6.103%; +6.162%]

scenario:profiles_dictionary/profile_string_inserts/threads/1

  • 🟥 execution_time [+16.553µs; +20.035µs] or [+5.480%; +6.633%]
  • 🟥 throughput [-211616.603op/s; -175394.257op/s] or [-6.242%; -5.174%]

Benchmark execution time: 2026-07-31 19:54:29

Comparing candidate commit 788f2de in PR branch gyuheon0h/got-hook-utils with baseline commit 31e53ca in branch gyuheon0h/extract-got-hook-crate.

Found 1 performance improvements and 9 performance regressions! Performance is the same for 167 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/sampled_system_fast_path/16

  • 🟥 execution_time [+6.605ns; +6.692ns] or [+25.433%; +25.769%]

scenario:alloc_free/sampled_system_fast_path/256

  • 🟥 execution_time [+11.900ns; +12.036ns] or [+46.078%; +46.604%]

scenario:alloc_free/sampled_system_fast_path/4096

  • 🟩 execution_time [-8.497ns; -8.336ns] or [-8.191%; -8.037%]

scenario:alloc_free/sampled_system_fast_path/64

  • 🟥 execution_time [+6.737ns; +6.865ns] or [+26.100%; +26.596%]

scenario:alloc_free/sampled_system_slow_path/16

  • 🟥 execution_time [+8.859ns; +8.946ns] or [+10.284%; +10.386%]

scenario:alloc_free/sampled_system_slow_path/4096

  • 🟥 execution_time [+7.192ns; +7.279ns] or [+5.035%; +5.096%]

scenario:alloc_free/sampled_system_slow_path/64

  • 🟥 execution_time [+8.800ns; +8.911ns] or [+10.218%; +10.347%]

scenario:alloc_free/system/256

  • 🟥 execution_time [+7.103ns; +7.134ns] or [+49.608%; +49.820%]

scenario:alloc_free/system/4096

  • 🟥 execution_time [+11.018ns; +11.204ns] or [+13.338%; +13.563%]

scenario:receiver_entry_point/report/2644

  • 🟥 execution_time [+151.325µs; +160.463µs] or [+4.158%; +4.409%]

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

@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: e2110f9534

ℹ️ 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-profiling-heap-gotter/src/elf.rs
@gyuheon0h
gyuheon0h force-pushed the gyuheon0h/got-hook-utils branch 2 times, most recently from 6264ccb to d224c5d Compare July 30, 2026 18:58
@gyuheon0h
gyuheon0h requested a review from yannham July 30, 2026 19:11
Comment thread libdd-gotter/src/elf.rs Outdated
Comment thread libdd-gotter/src/elf.rs
Comment thread libdd-gotter/src/elf.rs Outdated
Comment thread libdd-gotter/src/elf.rs Outdated
Comment thread libdd-gotter/src/elf.rs
Comment thread libdd-gotter/src/elf.rs Outdated
Comment thread libdd-gotter/src/elf.rs Outdated
if !is_got_pointer_reloc(elf64_r_type(reloc.r_info)) {
continue;
}
let sym_idx = elf64_r_sym(reloc.r_info) as u32;

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.

Isn't this already a u32?

Suggested change
let sym_idx = elf64_r_sym(reloc.r_info) as u32;
let sym_idx = elf64_r_sym(reloc.r_info);

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.

Nope, Elf64_Xword is u64

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.

The elf64_r_sym returns u64 and sym_name takes u32 because symbol indices are 32-bit values in practice.

So the as u32 cast is always lossless so perhaps we could just have elf64_r_sym return u32 directly since the result is always 32 bits

Comment thread libdd-gotter/src/elf.rs
let sym_idx = elf64_r_sym(reloc.r_info) as u32;
if let Some(cstr) = dyn_info.sym_name(sym_idx) {
if cstr.to_bytes() == symbol_name {
let addr = reloc.r_offset as usize + dyn_info.base_address();

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.

Nit: avoid as conversion. If we're on x64, I think there should be a direct From instance?

Suggested change
let addr = reloc.r_offset as usize + dyn_info.base_address();
let addr = usize::from(reloc.r_offset) + dyn_info.base_address();

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.

😢

error[E0277]: the trait bound `usize: From<u64>` is not satisfied
   --> libdd-gotter/src/elf.rs:816:28
    |
816 |                 let addr = usize::from(reloc.r_offset) + dyn_info.base_address();
    |                            ^^^^^ the trait `From<u64>` is not implemented for `usize`
    ```

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.

Agreed. Its a 🦶 🔫 that unchecked casts are easier than checked.

Comment thread libdd-gotter/src/elf.rs
/// parses it with a valid sym_count calculated from DT_HASH nchain.
#[test]
#[cfg_attr(miri, ignore)]
fn test_sysv_hash_library_parsed_correctly() {

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.

I wonder if it's reasonable to recompile a shared library each time just for a test. Would that be possible to pre-compile it instead as an asset and include it in the repo? Or maybe as an additional target of the crate and try to find it at test time using environment variable? Though maybe on a very small lib it's fast enough, but...

Comment thread libdd-gotter/src/elf.rs
#[cfg_attr(miri, ignore)]
fn test_dynamic_info_parses_loaded_library() {
let mut found = false;
iterate_libraries(|info, _| {

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.

On all those tests that use iterate_libraries, do you rely on libc being loaded at least for them to not be flaky?

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.

Yes. iterate_libraries always returns at least the main executable (which has PT_DYNAMIC on dynamically linked binaries), so the iteration itself isn't flaky. But a couple of things here:

  • test_dynamic_info_parses_loaded_library needs at least one object with PT_DYNAMIC + valid strtab/symtab/hash. The main executable could theoretically be statically linked with no dynamic section, making from_phdr return None for everything.
  • test_all_loaded_libraries_have_valid_sym_count is the same as abov
  • test_can_lookup_known_symbol needs malloc (or whatever symbol) to exist in a dynamically loaded library.

On our test runners, all of these seem to be okay, which seems to me like as long as our test runner images don't change, these should never be flaky.

But if you want these to be defensive, test_iterate_libraries_finds_loaded_objects could be the only hard assertion ( checks count > 0), and the others could skip gracefully if no library parses.

WDYT?

@gyuheon0h
gyuheon0h force-pushed the gyuheon0h/got-hook-utils branch from d224c5d to a752f7f Compare July 31, 2026 17:45
@gyuheon0h
gyuheon0h force-pushed the gyuheon0h/extract-got-hook-crate branch from aea0f42 to 66e5b36 Compare July 31, 2026 17:50
@gyuheon0h
gyuheon0h force-pushed the gyuheon0h/got-hook-utils branch from a752f7f to 5e2abd9 Compare July 31, 2026 17:50
…_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 5e2abd9 to 788f2de Compare July 31, 2026 19:06
@gyuheon0h
gyuheon0h force-pushed the gyuheon0h/extract-got-hook-crate branch from 66e5b36 to 31e53ca Compare July 31, 2026 19:06
Comment thread libdd-gotter/src/elf.rs
/// `info` must point to a valid `dl_phdr_info` from `dl_iterate_phdr`.
pub unsafe fn from_phdr(info: &dl_phdr_info) -> Option<Self> {
let phdrs = core::slice::from_raw_parts(info.dlpi_phdr, info.dlpi_phnum as usize);
let phdrs = slice::from_raw_parts(info.dlpi_phdr, info.dlpi_phnum as usize);

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.

I know Rust doesn't require unsafe blocks inside unsafe functions, but I consider that a design flaw. Consider putting the actually unsafe parts inside blocks with safety comments to make it easier to audit

Comment thread libdd-gotter/src/elf.rs
// Can't estimate; allow any index and rely on strtab
// bounds checking in sym_name to catch bad accesses.
u32::MAX
(sym_count_fallback(symtab, strtab, sysv_hash), 0)

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.

nice :)

Comment thread libdd-gotter/src/elf.rs
/// Narrow or PC-relative types (`R_X86_64_PC32`, `R_AARCH64_TLSDESC`, etc.)
/// are excluded since they have different widths and addend semantics
pub fn is_got_pointer_reloc(r_type: u32) -> bool {
// x86_64

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.

Should these be cfg guarded by platform?

Comment thread libdd-gotter/src/elf.rs
let sym_idx = elf64_r_sym(reloc.r_info) as u32;
if let Some(cstr) = dyn_info.sym_name(sym_idx) {
if cstr.to_bytes() == symbol_name {
let addr = reloc.r_offset as usize + dyn_info.base_address();

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.

Agreed. Its a 🦶 🔫 that unchecked casts are easier than checked.

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.

3 participants