Skip to content

fix: promote loader symbols to global scope before loading embedded.so (glibc)#524

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 2 commits intomainfrom
r1viollet/fix/loader-rtld-global-glibc
Mar 25, 2026
Merged

fix: promote loader symbols to global scope before loading embedded.so (glibc)#524
gh-worker-dd-mergequeue-cf854d[bot] merged 2 commits intomainfrom
r1viollet/fix/loader-rtld-global-glibc

Conversation

@r1viollet
Copy link
Copy Markdown
Collaborator

@r1viollet r1viollet commented Mar 25, 2026

What does this PR do?

When libdd_profiling.so is dlopen'd with RTLD_GLOBAL, glibc defers symbol promotion until after dlopen returns. The inner dlopen of the embedded .so therefore cannot resolve ddprof_lib_state from the loader, causing it to fail silently.

Fix: in the loader constructor, use RTLD_NOLOAD | RTLD_GLOBAL to re-open the loader itself and upgrade its binding to global before loading the embedded library. The soname is passed via DDPROF_LOADER_SONAME from CMake to avoid hardcoding.

Note: dlopen with RTLD_GLOBAL is not supported on musl — musl rejects initial-exec TLS cross-library relocations for dlopen'd libraries. The test is skipped on musl and LD_PRELOAD is documented as the alternative.

Add loader_rtld_global_test to verify the fix on glibc. Document the dlopen usage and musl limitation in Troubleshooting.md.

Motivation

see following issue

Additional Notes

We considered several approaches including removing the static tls approach.

How to test the change?

A test was added for the dlopen use case.

I will add a test in ddprof-build that handles:

  • musl compilation
  • run on glibc with dlopen

@r1viollet r1viollet requested a review from nsavoire as a code owner March 25, 2026 08:41
@r1viollet r1viollet marked this pull request as draft March 25, 2026 08:49
@pr-commenter
Copy link
Copy Markdown

pr-commenter bot commented Mar 25, 2026

Benchmark results for collatz

Parameters

Baseline Candidate
config baseline candidate
profiler-version ddprof 0.24.0+bf23f795.103772975 ddprof 0.24.0+9a0ff499.104347914

Summary

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

See unchanged results
scenario Δ mean execution_time
scenario:ddprof -S bench-collatz --preset cpu_only collatz_runner.sh same

@pr-commenter
Copy link
Copy Markdown

pr-commenter bot commented Mar 25, 2026

Benchmark results for BadBoggleSolver_run

Parameters

Baseline Candidate
config baseline candidate
profiler-version ddprof 0.24.0+bf23f795.103772975 ddprof 0.24.0+9a0ff499.104347914

Summary

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

See unchanged results
scenario Δ mean execution_time
scenario:ddprof -S bench-bad-boggle-solver BadBoggleSolver_run work 1000 same

@r1viollet r1viollet marked this pull request as ready for review March 25, 2026 10:11
…so (glibc)

When libdd_profiling.so is dlopen'd with RTLD_GLOBAL, glibc defers symbol
promotion until after dlopen returns. The inner dlopen of the embedded .so
therefore cannot resolve ddprof_lib_state from the loader, causing it to
fail silently.

Fix: in the loader constructor, use RTLD_NOLOAD | RTLD_GLOBAL to re-open
the loader itself and upgrade its binding to global before loading the
embedded library. The soname is passed via DDPROF_LOADER_SONAME from CMake
(defined when USE_LOADER is enabled). Guarded by #ifdef so the call is
omitted in builds where USE_LOADER is not enabled.

Note: dlopen with RTLD_GLOBAL is not supported on musl — musl rejects
initial-exec TLS cross-library relocations for dlopen'd libraries. The
test is skipped on musl and LD_PRELOAD is documented as the alternative.

Add loader_rtld_global_test to verify the fix on glibc. Document the
dlopen usage and musl limitation in Troubleshooting.md.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@r1viollet r1viollet force-pushed the r1viollet/fix/loader-rtld-global-glibc branch from d80168d to d8c67b6 Compare March 25, 2026 10:49
- Clean up documentation
- Remove the test which was moved to ddprof-build
@r1viollet
Copy link
Copy Markdown
Collaborator Author

/merge

@gh-worker-devflow-routing-ef8351
Copy link
Copy Markdown

gh-worker-devflow-routing-ef8351 bot commented Mar 25, 2026

View all feedbacks in Devflow UI.

2026-03-25 15:06:37 UTC ℹ️ Start processing command /merge


2026-03-25 15:06:42 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in main is approximately 22m (p90).


2026-03-25 15:20:57 UTC ℹ️ MergeQueue: This merge request was merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants