Skip to content

Fix: Exclude RTLD_DEEPBIND for Alpine Linux (musl-based systems)#1707

Merged
ranshid merged 1 commit intovalkey-io:unstablefrom
roshkhatri:issue-1705
Feb 11, 2025
Merged

Fix: Exclude RTLD_DEEPBIND for Alpine Linux (musl-based systems)#1707
ranshid merged 1 commit intovalkey-io:unstablefrom
roshkhatri:issue-1705

Conversation

@roshkhatri
Copy link
Member

Fixes #1705
Problem
Alpine Linux uses musl libc, which does not support RTLD_DEEPBIND. This causes compilation errors when building on Alpine:

module.c: In function 'moduleLoad':
module.c:12295:21: error: 'RTLD_DEEPBIND' undeclared (first use in this function)
12295 |     dlopen_flags |= RTLD_DEEPBIND;
      |                     ^~~~~~~~~~~~~
module.c:12295:21: note: each undeclared identifier is reported only once for each function it appears in
    CC expire.o
make[1]: *** [Makefile:538: module.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make[1]: Leaving directory '/usr/src/valkey/src'
make: *** [Makefile:6: all] Error 2

Currently, RTLD_DEEPBIND is conditionally included for Linux and FreeBSD, but this assumption does not account for musl-based systems like Alpine.

Solution
Modify the preprocessor condition to ensure RTLD_DEEPBIND is only included when:

  1. The system is Linux (glibc-based) or FreeBSD
  2. Address Sanitizer (ASAN) is not enabled
  3. glibc is used (defined(__GLIBC__) ensures musl-based systems like Alpine are excluded
  4. <dlfcn.h> is available (__has_include(<dlfcn.h>) provides an additional safety check

New Condition:

#if (defined(__linux__) || defined(__FreeBSD__)) && !defined(__SANITIZE_ADDRESS__) && defined(__GLIBC__) && __has_include(<dlfcn.h>)

@codecov
Copy link

codecov bot commented Feb 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 71.12%. Comparing base (b8c471e) to head (3a0a691).
Report is 1 commits behind head on unstable.

Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #1707      +/-   ##
============================================
+ Coverage     71.11%   71.12%   +0.01%     
============================================
  Files           123      123              
  Lines         65535    65535              
============================================
+ Hits          46605    46613       +8     
+ Misses        18930    18922       -8     
Files with missing lines Coverage Δ
src/module.c 9.61% <ø> (ø)

... and 12 files with indirect coverage changes

@ranshid ranshid merged commit 86469ab into valkey-io:unstable Feb 11, 2025
50 checks passed

int dlopen_flags = RTLD_NOW | RTLD_LOCAL;
#if (defined(__linux__) || defined(__FreeBSD__)) && !defined(__SANITIZE_ADDRESS__)
#if (defined(__linux__) || defined(__FreeBSD__)) && !defined(__SANITIZE_ADDRESS__) && defined(__GLIBC__) && __has_include(<dlfcn.h>)
Copy link
Contributor

@zuiderkwast zuiderkwast Feb 11, 2025

Choose a reason for hiding this comment

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

FreeBSD doesn't have GLIBC. I think this change disables DEEPBIND on FreeBSD.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should just check __GLIBC__ instead of __linux__? The libc implementation is what defines dlopen.

Suggested change
#if (defined(__linux__) || defined(__FreeBSD__)) && !defined(__SANITIZE_ADDRESS__) && defined(__GLIBC__) && __has_include(<dlfcn.h>)
#if (defined(__GLIBC__) || defined(__FreeBSD__)) && !defined(__SANITIZE_ADDRESS__) && __has_include(<dlfcn.h>)

zuiderkwast added a commit that referenced this pull request Feb 11, 2025
Fixes the failure trying to use dlopen with DEEPBIND with ASAN when
compiling with Clang:

==90510==You are trying to dlopen a
/home/runner/work/valkey/valkey/tests/modules/keyspecs.so shared library
with RTLD_DEEPBIND flag which is incompatible with sanitizer runtime
(see google/sanitizers#611 for details). If
you want to run
/home/runner/work/valkey/valkey/tests/modules/keyspecs.so library under
sanitizers please remove RTLD_DEEPBIND from dlopen flags.


https://github.com/valkey-io/valkey/actions/runs/13261241213/job/37018133361

The previous check only covers GCC.

Additionally, don't require GLIBC when FreeBSD is used. FreeBSD has it's
own libc which supports DEEPBIND according to its docs.

Follow-up of #1703, #1707

Signed-off-by: Viktor Söderqvist <[email protected]>
xbasel pushed a commit to xbasel/valkey that referenced this pull request Mar 27, 2025
…key-io#1707)

Fixes valkey-io#1705 
**Problem**
Alpine Linux uses `musl libc`, which does not support `RTLD_DEEPBIND`.
This causes compilation errors when building on Alpine:
```
module.c: In function 'moduleLoad':
module.c:12295:21: error: 'RTLD_DEEPBIND' undeclared (first use in this function)
12295 |     dlopen_flags |= RTLD_DEEPBIND;
      |                     ^~~~~~~~~~~~~
module.c:12295:21: note: each undeclared identifier is reported only once for each function it appears in
    CC expire.o
make[1]: *** [Makefile:538: module.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make[1]: Leaving directory '/usr/src/valkey/src'
make: *** [Makefile:6: all] Error 2
```

Currently, `RTLD_DEEPBIND` is conditionally included for `Linux` and
`FreeBSD`, but this assumption does not account for `musl-based` systems
like `Alpine`.

**Solution**
Modify the preprocessor condition to ensure `RTLD_DEEPBIND` is only
included when:

1. The system is Linux (glibc-based) or FreeBSD
2. Address Sanitizer (ASAN) is not enabled
3. `glibc` is used `(defined(__GLIBC__)` ensures `musl-based` systems
like Alpine are excluded
4. `<dlfcn.h>` is available `(__has_include(<dlfcn.h>)` provides an
additional safety check

New Condition:
```
#if (defined(__linux__) || defined(__FreeBSD__)) && !defined(__SANITIZE_ADDRESS__) && defined(__GLIBC__) && __has_include(<dlfcn.h>)
```

Signed-off-by: Roshan Khatri <[email protected]>
xbasel pushed a commit to xbasel/valkey that referenced this pull request Mar 27, 2025
Fixes the failure trying to use dlopen with DEEPBIND with ASAN when
compiling with Clang:

==90510==You are trying to dlopen a
/home/runner/work/valkey/valkey/tests/modules/keyspecs.so shared library
with RTLD_DEEPBIND flag which is incompatible with sanitizer runtime
(see google/sanitizers#611 for details). If
you want to run
/home/runner/work/valkey/valkey/tests/modules/keyspecs.so library under
sanitizers please remove RTLD_DEEPBIND from dlopen flags.


https://github.com/valkey-io/valkey/actions/runs/13261241213/job/37018133361

The previous check only covers GCC.

Additionally, don't require GLIBC when FreeBSD is used. FreeBSD has it's
own libc which supports DEEPBIND according to its docs.

Follow-up of valkey-io#1703, valkey-io#1707

Signed-off-by: Viktor Söderqvist <[email protected]>
xbasel pushed a commit to xbasel/valkey that referenced this pull request Mar 27, 2025
…key-io#1707)

Fixes valkey-io#1705 
**Problem**
Alpine Linux uses `musl libc`, which does not support `RTLD_DEEPBIND`.
This causes compilation errors when building on Alpine:
```
module.c: In function 'moduleLoad':
module.c:12295:21: error: 'RTLD_DEEPBIND' undeclared (first use in this function)
12295 |     dlopen_flags |= RTLD_DEEPBIND;
      |                     ^~~~~~~~~~~~~
module.c:12295:21: note: each undeclared identifier is reported only once for each function it appears in
    CC expire.o
make[1]: *** [Makefile:538: module.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make[1]: Leaving directory '/usr/src/valkey/src'
make: *** [Makefile:6: all] Error 2
```

Currently, `RTLD_DEEPBIND` is conditionally included for `Linux` and
`FreeBSD`, but this assumption does not account for `musl-based` systems
like `Alpine`.

**Solution**
Modify the preprocessor condition to ensure `RTLD_DEEPBIND` is only
included when:

1. The system is Linux (glibc-based) or FreeBSD
2. Address Sanitizer (ASAN) is not enabled
3. `glibc` is used `(defined(__GLIBC__)` ensures `musl-based` systems
like Alpine are excluded
4. `<dlfcn.h>` is available `(__has_include(<dlfcn.h>)` provides an
additional safety check

New Condition:
```
#if (defined(__linux__) || defined(__FreeBSD__)) && !defined(__SANITIZE_ADDRESS__) && defined(__GLIBC__) && __has_include(<dlfcn.h>)
```

Signed-off-by: Roshan Khatri <[email protected]>
xbasel pushed a commit to xbasel/valkey that referenced this pull request Mar 27, 2025
Fixes the failure trying to use dlopen with DEEPBIND with ASAN when
compiling with Clang:

==90510==You are trying to dlopen a
/home/runner/work/valkey/valkey/tests/modules/keyspecs.so shared library
with RTLD_DEEPBIND flag which is incompatible with sanitizer runtime
(see google/sanitizers#611 for details). If
you want to run
/home/runner/work/valkey/valkey/tests/modules/keyspecs.so library under
sanitizers please remove RTLD_DEEPBIND from dlopen flags.


https://github.com/valkey-io/valkey/actions/runs/13261241213/job/37018133361

The previous check only covers GCC.

Additionally, don't require GLIBC when FreeBSD is used. FreeBSD has it's
own libc which supports DEEPBIND according to its docs.

Follow-up of valkey-io#1703, valkey-io#1707

Signed-off-by: Viktor Söderqvist <[email protected]>
murphyjacob4 pushed a commit to enjoy-binbin/valkey that referenced this pull request Apr 13, 2025
…key-io#1707)

Fixes valkey-io#1705 
**Problem**
Alpine Linux uses `musl libc`, which does not support `RTLD_DEEPBIND`.
This causes compilation errors when building on Alpine:
```
module.c: In function 'moduleLoad':
module.c:12295:21: error: 'RTLD_DEEPBIND' undeclared (first use in this function)
12295 |     dlopen_flags |= RTLD_DEEPBIND;
      |                     ^~~~~~~~~~~~~
module.c:12295:21: note: each undeclared identifier is reported only once for each function it appears in
    CC expire.o
make[1]: *** [Makefile:538: module.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make[1]: Leaving directory '/usr/src/valkey/src'
make: *** [Makefile:6: all] Error 2
```

Currently, `RTLD_DEEPBIND` is conditionally included for `Linux` and
`FreeBSD`, but this assumption does not account for `musl-based` systems
like `Alpine`.

**Solution**
Modify the preprocessor condition to ensure `RTLD_DEEPBIND` is only
included when:

1. The system is Linux (glibc-based) or FreeBSD
2. Address Sanitizer (ASAN) is not enabled
3. `glibc` is used `(defined(__GLIBC__)` ensures `musl-based` systems
like Alpine are excluded
4. `<dlfcn.h>` is available `(__has_include(<dlfcn.h>)` provides an
additional safety check

New Condition:
```
#if (defined(__linux__) || defined(__FreeBSD__)) && !defined(__SANITIZE_ADDRESS__) && defined(__GLIBC__) && __has_include(<dlfcn.h>)
```

Signed-off-by: Roshan Khatri <[email protected]>
murphyjacob4 pushed a commit to enjoy-binbin/valkey that referenced this pull request Apr 13, 2025
Fixes the failure trying to use dlopen with DEEPBIND with ASAN when
compiling with Clang:

==90510==You are trying to dlopen a
/home/runner/work/valkey/valkey/tests/modules/keyspecs.so shared library
with RTLD_DEEPBIND flag which is incompatible with sanitizer runtime
(see google/sanitizers#611 for details). If
you want to run
/home/runner/work/valkey/valkey/tests/modules/keyspecs.so library under
sanitizers please remove RTLD_DEEPBIND from dlopen flags.


https://github.com/valkey-io/valkey/actions/runs/13261241213/job/37018133361

The previous check only covers GCC.

Additionally, don't require GLIBC when FreeBSD is used. FreeBSD has it's
own libc which supports DEEPBIND according to its docs.

Follow-up of valkey-io#1703, valkey-io#1707

Signed-off-by: Viktor Söderqvist <[email protected]>
@roshkhatri roshkhatri deleted the issue-1705 branch November 11, 2025 20:32
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.

Build fails on for Alpine Linux due to RTLD_DEEPBIND flag

4 participants