Skip to content

ldso-cache: match glibc ldconfig directory and entry ordering - #2598

Merged
xnox merged 1 commit into
chainguard-dev:mainfrom
xnox:ldsocache-order
Oct 23, 2026
Merged

xnox merged 1 commit into
chainguard-dev:mainfrom
xnox:ldsocache-order

Conversation

@xnox

@xnox xnox commented Oct 23, 2026

Copy link
Copy Markdown
Member

Summary

  • Directory order: scan the ld.so.conf directories first, then the built-in /lib and /usr/lib, matching glibc's ldconfig (elf/ldconfig.c). Previously /lib was scanned first and /usr/lib was never added implicitly. Duplicate directories are dropped, keeping the first.
  • usrmerge: skip /lib entirely when it is a symlink, so libraries are not listed twice.
  • Entry order: use a stable sort and break _dl_cache_libcmp ties on flags (descending), mirroring compare() in glibc's elf/cache.c. ld.so uses the first matching entry, so the first directory that provides a library now reliably wins. Previously the unstable sort left this undefined.
  • ParseLDSOConf include bug: parsing returned right after the first include directive, silently dropping any directories listed after it. Included directories are now deduplicated too.

Testing

  • New TestLdsoLibDirs (split /lib, usrmerge, /lib in ld.so.conf under usrmerge, conf precedence).
  • New Test_LDSOCacheEntriesForDirs_DuplicatesKeepLibdirOrder.
  • New Test_ParseLDSOConf_LinesAfterInclude.
  • go test ./pkg/build/... ./internal/... passes.

🤖 Generated with Claude Code

Scan the ld.so.conf directories first, then the built-in /lib and
/usr/lib, as glibc's ldconfig does, dropping duplicate directories.
Skip /lib when it is a symlink (usrmerge) so libraries are not listed
twice.

Sort cache entries stably, breaking _dl_cache_libcmp ties on flags as
glibc's compare() does, so that the first directory providing a
library is the one ld.so picks.

Also fix ParseLDSOConf returning after the first include directive,
which silently dropped any directories listed after it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@xnox
xnox enabled auto-merge (squash) October 23, 2026 16:59
@xnox
xnox merged commit 42188bb into chainguard-dev:main Oct 23, 2026
12 checks passed
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