Skip to content

Add relative rpath for runtime library discovery#3377

Closed
yulazariy wants to merge 3 commits intovalkey-io:unstablefrom
yulazariy:add-relative-rpath
Closed

Add relative rpath for runtime library discovery#3377
yulazariy wants to merge 3 commits intovalkey-io:unstablefrom
yulazariy:add-relative-rpath

Conversation

@yulazariy
Copy link
Copy Markdown
Contributor

Add relative rpath for runtime library discovery

Summary

This PR adds relative rpath entries to the build configuration, allowing Valkey binaries to discover shared
libraries in a relative lib directory at runtime.

Changes

• Added $ORIGIN/../lib rpath for Linux builds
• Added @loader_path/../lib rpath for macOS builds
• Maintains existing absolute rpath entries for backward compatibility

Motivation

Currently, Valkey binaries use absolute rpaths, which limits installation flexibility. With relative rpaths,
binaries can find libraries in a predictable location relative to their own path, enabling:
• Relocatable installations without modifying environment variables
• Self-contained directory structures (e.g., bin/ and lib/ siblings)
• Easier packaging and distribution

Testing

Verified on macOS that the rpath is correctly set using otool -l:
path @loader_path/../lib (offset 12)

Add $ORIGIN/../lib (Linux) and @loader_path/../lib (macOS) to the
rpath configuration. This allows binaries to find shared libraries
in a relative lib directory, enabling more flexible installation
layouts without requiring LD_LIBRARY_PATH or DYLD_LIBRARY_PATH.

This is particularly useful for relocatable installations where
binaries and libraries are installed in a self-contained directory
structure.

Signed-off-by: yulazariy <yulazari@amazon.com>
@yulazariy yulazariy force-pushed the add-relative-rpath branch from 5eb2989 to 4d33d40 Compare March 18, 2026 09:33
@ranshid ranshid moved this to Todo in Valkey 9.1 Mar 18, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.49%. Comparing base (ac5e44c) to head (2ac4c4c).
⚠️ Report is 10 commits behind head on unstable.

Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #3377      +/-   ##
============================================
- Coverage     74.53%   74.49%   -0.04%     
============================================
  Files           130      130              
  Lines         72731    72748      +17     
============================================
- Hits          54208    54197      -11     
- Misses        18523    18551      +28     

see 21 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

@sarthakaggarwal97 sarthakaggarwal97 left a comment

Choose a reason for hiding this comment

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

Seeing some errors in CI, might be worth looking into

lto1: fatal error: open debug.o failed: No such file or directory
compilation terminated.
lto-wrapper: fatal error: cc returned 1 exit status
compilation terminated.
/usr/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:692: valkey-server] Error 1
make[1]: *** Waiting for unfinished jobs....

@yulazariy
Copy link
Copy Markdown
Contributor Author

Seeing some errors in CI, might be worth looking into

lto1: fatal error: open debug.o failed: No such file or directory
compilation terminated.
lto-wrapper: fatal error: cc returned 1 exit status
compilation terminated.
/usr/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:692: valkey-server] Error 1
make[1]: *** Waiting for unfinished jobs....

Will take a look but not sure how it is related to the change as it only update the rpath.

Replace .make-prerequisites with .make-deps-built to eliminate race
condition where distclean runs in parallel with linking, causing LTO
errors when object files are deleted during link-time optimization.

Changes:
- Remove automatic distclean trigger from .make-prerequisites
- Add .make-deps-built marker file that only builds dependencies
- Use order-only prerequisites (|) to avoid unnecessary rebuilds
- Users must manually run 'make distclean' when build settings change

This fixes build failures like:
  lto1: fatal error: open debug.o failed: No such file or directory
  /usr/bin/ld: cannot find zipmap.o: No such file or directory

Signed-off-by: yulazariy <yulazari@amazon.com>
@yulazariy yulazariy force-pushed the add-relative-rpath branch from 94a2c07 to 86c33df Compare March 22, 2026 18:11
Replace .make-prerequisites with .make-deps-built to eliminate race
condition where distclean runs in parallel with linking, causing LTO
errors when object files are deleted during link-time optimization.

Also export MALLOC variable so unit tests can properly detect the
allocator and avoid trying to use jemalloc headers when MALLOC=libc.

Changes:
- Remove automatic distclean trigger from .make-prerequisites
- Add .make-deps-built marker file that only builds dependencies
- Use order-only prerequisites (|) to avoid unnecessary rebuilds
- Export MALLOC variable for sub-makes
- Update unit test Makefile to use .make-deps-built

This fixes build failures like:
  lto1: fatal error: open debug.o failed: No such file or directory
  /usr/bin/ld: cannot find zipmap.o: No such file or directory
  fatal error: 'jemalloc/jemalloc.h' file not found (on macOS)

Signed-off-by: yulazariy <yulazari@amazon.com>
@yulazariy yulazariy closed this Mar 25, 2026
@github-project-automation github-project-automation Bot moved this from Todo to Done in Valkey 9.1 Mar 25, 2026
@yulazariy
Copy link
Copy Markdown
Contributor Author

will be fixed in a different PR #3392

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

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants