Skip to content

Fix the GNU IFUNC error in alpine (non-glibc) environment#2133

Merged
zuiderkwast merged 2 commits intovalkey-io:unstablefrom
zhulipeng:ifunc_alpine
May 25, 2025
Merged

Fix the GNU IFUNC error in alpine (non-glibc) environment#2133
zuiderkwast merged 2 commits intovalkey-io:unstablefrom
zhulipeng:ifunc_alpine

Conversation

@zhulipeng zhulipeng changed the title Fix the GUN IFUNC error in alpine environment Fix the GNU IFUNC error in alpine environment. May 24, 2025
---------

Signed-off-by: Lipeng Zhu <[email protected]>
Co-authored-by: Guo Wangyang <[email protected]>
@codecov
Copy link

codecov bot commented May 24, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 71.23%. Comparing base (053bf9e) to head (0d32ab5).
Report is 3 commits behind head on unstable.

Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #2133      +/-   ##
============================================
+ Coverage     71.18%   71.23%   +0.04%     
============================================
  Files           122      122              
  Lines         66046    66046              
============================================
+ Hits          47013    47046      +33     
+ Misses        19033    19000      -33     

see 14 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.

@zhulipeng zhulipeng added the run-extra-tests Run extra tests on this PR (Runs all tests from daily except valgrind and RESP) label May 24, 2025
Copy link
Contributor

@Fusl Fusl left a comment

Choose a reason for hiding this comment

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

Should change the name of the temp file from foo to something more descriptive and exclude it from .gitignore or use an actual temporary file in /tmp using a random file suffix if we can do that logic in Makefiles.

#define ATTRIBUTE_TARGET_AVX512
#endif

#if defined(__linux__) && (defined(__GNUC__) && (__GNUC__ > 4) || defined(__clang__) && (__clang_major__) > 5)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't we just add defined(__GLIBC__) to this check? Like we did here:

One more thing: Does ifunc require linux or just glibc? It's possible to run freebsd with glibc. There's a debian variant with this combo.

Copy link
Member Author

Choose a reason for hiding this comment

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

The ifunc feature requires ELF. Even though BSD systems have glibc, I'm not sure if there are any gaps between the loader and runtime linker compared to Linux.

---------

Signed-off-by: Lipeng Zhu <[email protected]>
Co-authored-by: Guo Wangyang <[email protected]>
Copy link
Contributor

@zuiderkwast zuiderkwast left a comment

Choose a reason for hiding this comment

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

Lgtm. If we have linux and glibc, we should be safe. We have cmake and make parallel builds so it's better to do it in the c file only.

@zuiderkwast zuiderkwast changed the title Fix the GNU IFUNC error in alpine environment. Fix the GNU IFUNC error in alpine (non-glibc) environment May 25, 2025
@zuiderkwast zuiderkwast merged commit 9dd5a02 into valkey-io:unstable May 25, 2025
60 checks passed
Copy link

@r-devulap r-devulap left a comment

Choose a reason for hiding this comment

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

Might be an overkill, but if we want a more robust approach, we could add a check to Makefile, something along the lines:

# In your Makefile

# Use a temporary file to test if 'ifunc' is supported
IFUNC_TEST := \
'#include <stdio.h>\n'\
'__attribute__((ifunc("resolve_func"))) int foo();\n'\
'int real_foo() { return 42; }\n'\
'int (*resolve_func(void))(void) { return real_foo; }\n'\
'int main() { return foo(); }\n'

check_ifunc_support:
	echo -e $(IFUNC_TEST) > test_ifunc.c && \
	$(CC) $(CFLAGS) test_ifunc.c -o test_ifunc 2>/dev/null && \
	echo "IFUNC_SUPPORTED = 1" > ifunc.mk || \
	echo "IFUNC_SUPPORTED = 0" > ifunc.mk
	rm -f test_ifunc.c test_ifunc

-include ifunc.mk

# Now you can use $(IFUNC_SUPPORTED) in your Makefile
ifeq ($(IFUNC_SUPPORTED),1)
  $(info IFUNC is supported)
else
  $(info IFUNC is NOT supported)
endif

@Fusl
Copy link
Contributor

Fusl commented May 29, 2025

The first version of this PR already had a very similar approach:

72effba#diff-3e2513390df543315686d7c85bd901ca9256268970032298815d2f893a9f0685R153-R166

To simplify things we decided not to add a compiler check step but use one of the existing flags instead.

@r-devulap
Copy link

Ah, apologies. I missed that commit :)

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

Labels

run-extra-tests Run extra tests on this PR (Runs all tests from daily except valgrind and RESP)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants