Skip to content

feat(gotter)!: add fn to hook symbol but exclude self - #2312

Open
gyuheon0h wants to merge 5 commits into
gyuheon0h/got-hook-utilsfrom
gyuheon0h/got-hook-exclude-self
Open

feat(gotter)!: add fn to hook symbol but exclude self#2312
gyuheon0h wants to merge 5 commits into
gyuheon0h/got-hook-utilsfrom
gyuheon0h/got-hook-exclude-self

Conversation

@gyuheon0h

@gyuheon0h gyuheon0h commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Stacked above feat(got-hook)!: add DT_HASH fallback, relocation type guard, and hook_symbol

PROF-15630

What does this PR do?

PHP needs to be able to hook libs and bins but skip its own exported fn.

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 Aug 4, 2026

Copy link
Copy Markdown
Contributor

📚 Documentation Check Results

⚠️ 6 documentation warning(s) found

📦 libdd-gotter - 6 warning(s)


Updated: 2026-08-05 20:49:41 UTC | Commit: 72de605 | missing-docs job results

@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

🔒 Cargo Deny Results

No issues found!

📦 libdd-gotter - ✅ No issues


Updated: 2026-08-05 20:51:50 UTC | Commit: 72de605 | dependency-check job results

@datadog-prod-us1-6

datadog-prod-us1-6 Bot commented Aug 4, 2026

Copy link
Copy Markdown

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 54.88%
Overall Coverage: 75.01% (-0.14%)

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

@gyuheon0h gyuheon0h changed the title feat(gotter): add fn to hook but exclude self feat(gotter): add fn to hook symbol but exclude self Aug 4, 2026
@gyuheon0h
gyuheon0h force-pushed the gyuheon0h/got-hook-exclude-self branch 2 times, most recently from 05b1bde to 92dd335 Compare August 4, 2026 14:12
@gyuheon0h
gyuheon0h force-pushed the gyuheon0h/got-hook-utils branch from a4a6346 to 9d4d601 Compare August 4, 2026 14:12
@pr-commenter

pr-commenter Bot commented Aug 4, 2026

Copy link
Copy Markdown

Benchmarks

Comparison

Benchmark execution time: 2026-08-05 21:22:38

Comparing candidate commit 520be6b in PR branch gyuheon0h/got-hook-exclude-self with baseline commit e9568ee in branch gyuheon0h/got-hook-utils.

Found 0 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:profiles_dictionary/profile_string_inserts/threads/1

  • 🟥 execution_time [+15.021µs; +16.707µs] or [+4.882%; +5.430%]
  • 🟥 throughput [-172145.936op/s; -154284.467op/s] or [-5.172%; -4.636%]

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

Comparing candidate commit 520be6b in PR branch gyuheon0h/got-hook-exclude-self with baseline commit e9568ee in branch gyuheon0h/got-hook-utils.

Found 6 performance improvements and 2 performance regressions! Performance is the same for 160 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:datadog_sample_span/multiple_rules_last_match/wall_time

  • 🟥 execution_time [+15.979ns; +16.089ns] or [+8.004%; +8.059%]

scenario:glob_matcher/ascii_wildcard_question_match/wall_time

  • 🟥 execution_time [+1.620ns; +1.636ns] or [+4.384%; +4.426%]

scenario:profiler_attached/fast_path_system/4096

  • 🟩 execution_time [-25.977ns; -25.844ns] or [-24.895%; -24.767%]

scenario:profiler_attached/slow_path_system/4096

  • 🟩 execution_time [-16.735ns; -16.558ns] or [-10.847%; -10.733%]

scenario:trace_buffer/2_senders/no_delay

  • 🟩 execution_time [-145.788µs; -131.234µs] or [-8.764%; -7.889%]
  • 🟩 throughput [+92925.677op/s; +103040.834op/s] or [+8.582%; +9.516%]

scenario:trace_buffer/4_senders/no_delay

  • 🟩 execution_time [-165.547µs; -153.848µs] or [-4.325%; -4.019%]
  • 🟩 throughput [+39470.512op/s; +42467.685op/s] or [+4.196%; +4.515%]

Candidate

Omitted due to size.

Baseline

Omitted due to size.

@gyuheon0h
gyuheon0h force-pushed the gyuheon0h/got-hook-utils branch from 9d4d601 to f19c984 Compare August 4, 2026 14:36
@gyuheon0h
gyuheon0h force-pushed the gyuheon0h/got-hook-exclude-self branch from 92dd335 to 0b9de90 Compare August 4, 2026 14:36
@gyuheon0h gyuheon0h changed the title feat(gotter): add fn to hook symbol but exclude self feat(gotter)!: add fn to hook symbol but exclude self Aug 4, 2026
@dd-octo-sts

dd-octo-sts Bot commented Aug 4, 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% (+8.00 KB) 👌
/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% (0 B) 👌
/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) 👌

@gyuheon0h
gyuheon0h marked this pull request as ready for review August 4, 2026 15:23
@gyuheon0h
gyuheon0h requested review from a team as code owners August 4, 2026 15:23

@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: 9e038403da

ℹ️ 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 Outdated

// Skip the hook's own library if requested.
if let Some(base) = skip_base {
if info.dlpi_addr as usize == base {

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 Handle non-PIE executables when skipping self

When hook_fn lives in a non-PIE main executable, dl_iterate_phdr reports the executable's dlpi_addr as 0 while dladdr(...).dli_fbase is the executable's load base, so this equality never matches and hook_symbol_excluding_self still patches the binary that contains the hook. In that context the hook's own executable can have its GOT entries redirected back to the hook, leading to recursion or crashes; please compare against the object's actual mapped range/PHDR base rather than dlpi_addr alone.

AGENTS.md reference: AGENTS.md:L70-L71

Useful? React with 👍 / 👎.

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.

Not sure if this is common enough to do. Php tracer's GOT patching doesn't seem to care for this. WDYT @realFlowControl

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Non-PIE executables are uncommon but still in use; we should handle this.

@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.

Got it. Im gonna be honest, I am not familiar with PIE, but I came to this commit: 520be6b off of reading https://one2bla.me/the-dark-arts/exploit-mitigations/position-independent-executables.html and some stack overflow blogs, with the help of my buddy claude.

Would appreciate special review over the above commit. Thanks :D

Comment thread libdd-gotter/src/elf.rs Outdated
Comment thread libdd-gotter/src/elf.rs Outdated
Comment thread libdd-gotter/src/elf.rs Outdated
@gyuheon0h
gyuheon0h marked this pull request as draft August 4, 2026 15:33
@gyuheon0h
gyuheon0h marked this pull request as ready for review August 4, 2026 15:53
@gyuheon0h
gyuheon0h force-pushed the gyuheon0h/got-hook-exclude-self branch 3 times, most recently from 72c1fe9 to 65852e6 Compare August 4, 2026 18:15
Comment thread libdd-gotter/src/elf.rs
@gyuheon0h
gyuheon0h force-pushed the gyuheon0h/got-hook-exclude-self branch from 74f89d5 to fd11980 Compare August 5, 2026 20:26
@gyuheon0h
gyuheon0h force-pushed the gyuheon0h/got-hook-utils branch from 2d9bca3 to e9568ee Compare August 5, 2026 20:47
@gyuheon0h
gyuheon0h force-pushed the gyuheon0h/got-hook-exclude-self branch from fd11980 to 520be6b Compare August 5, 2026 20:47
@gyuheon0h
gyuheon0h requested a review from scottgerring August 5, 2026 20:48
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.

2 participants