-
Notifications
You must be signed in to change notification settings - Fork 7.8k
On riscv64, only require libatomic if actually needed #11790
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
clang and newer gcc releases support byte-sized atomic accesses on riscv64 through inline builtins. In both cases the hard dependency on libatomic added by GH-11321 isn't useful. Stop using AC_CHECK_LIB() which is too naive to notice that libatomic isn't needed. Instead, PHP_CHECK_FUNC() will retry the check with -latomic if required.
PR against the PHP-8.1 branch as the problem didn't appear earlier. It would be nice to have this merged in 8.2 and master. This has been tested on OpenBSD/riscv64, using clang (libatomic not needed) and gcc-8.4.0 (libatomic needed). The patch is currently used by the OpenBSD ports tree. |
Your solution makes sense to me in that case, but let's see what other people think. |
LGTM, builds fine on my starfive with GCC 12! |
Hello, thanks @jcourreges for finding this. Sure, we can add this to PHP-8.1 and above. Otherwise, the With
Probably these won't interfere with anything out there, but just in case let's try something like this first and then use the case $host_alias in
riscv64*)
AC_SEARCH_LIBS([__atomic_exchange_1],[atomic],[],
[AC_MSG_ERROR([Problem with enabling atomic. Please check config.log for details.])]
)
;;
esac |
Quoting the documentation for AC_SEARCH_LIBS() in autoconf-2.69:
PHP_ADD_LIBRARY() also modified LIBS before the change I'm proposing, and PHP_CHECK_FUNC() will also call PHP_ADD_LIBRARY() under the hood (if needed). That's desired I think, else I don't see how -latomic would end up into the linker flags. Also, another reason for using it was consistency with the rest of the surrounding checks. |
@jcourreges from what I've tested, AC_SEARCH_LIBS doesn't prepend the atomic to the LIBS if the program with function compiles in the first run without a library. If the compilation fails without linking library then it tries linking it and if that works, it prepends it to the LIBS. for ac_lib in '' $2
do
if test -z "$ac_lib"; then
ac_res="none required"
else
ac_res=-l$ac_lib
LIBS="-l$ac_lib $5 $ac_func_search_save_LIBS"
fi
AC_LINK_IFELSE([], [AS_VAR_SET([ac_Search], [$ac_res])])
AS_VAR_SET_IF([ac_Search], [break])
done I've tested it very quickly though. There were otherwise some bugs in the past with this macro, but were very specific to the way the program needed to be compiled together. This one should most likely work ok. Regarding consistency, this I believe is more consistent. It's in the Autoconf itself. PHP macro defines two more constants otherwise. Well, your call. P.S.: Plus what is also important, the compilation vs. running in case of cross-compilation. |
Hi.
Correct, we do agree on this. So both alternatives (PHP_CHECK_FUNC() and AC_SEARCH_LIBS()) behave similarly regarding to LIBS.
I find it strange that you find using AC_SEARCH_LIBS() more consistent, when it isn't used anywhere else in configure.ac. The other checks use PHP_CHECK_FUNC(). My gut feeling is that the PHP developers implemented interfaces like PHP_CHECK_FUNC() for valid reasons.
Not my call: I'm not a PHP developer and I've seldom contributed to this repo in the past. So you folks get to choose what's best in the end.
I may be misunderstanding, but PHP_CHECK_FUNC_LIB() doesn't blindly assume that it should link with the candidate library in cross-compilation mode. PHP_CHECK_FUNC_LIB() is only used if the AC_CHECK_LIB() call in PHP_CHECK_FUNC() failed to find the function. So if the function is found with no additional library, the check succeeds (rightfully so) whether or not cross-compilation is done. Looking at this code further...
In native compilation, an additional AC_RUN_IFELSE() on a dummy program is performed, which further validates that the candidate library is usable. In cross-compilation mode, no program is run, it is assumed that the library can be used. This looks ok to me. Does this address your concerns? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, sure it addresses my concerns. Thanks for explanations @jcourreges
Your call, since it fixes a bug you're having directly. Otherwise, now there also won't be error thrown in case the check fails. But since this is very limited and specific case all good then. My look on these PHP macros is a bit different though - they do too much for too many cases and they were written for very old Autoconf versions when Autoconf macro sets were more limited. But all good. Don't mind it. This will work completely fine. Ready for PHP-8.1 and above then.
Hi, thank you @petk for the approval.
That deserves an explanation indeed. The function we're checking for is an implementation detail. Erroring out would break ./configure for compilers that don't implement those builtins; even in situations where I'm not used to the PHP development process and CONTRIBUTING.md doesn't mention this: does "RM" in "Waiting on RM" stand for "Release Management" or something? Do I need to do anything else to get those changes in an upcoming PHP release? Thank you for your support so far on this PR. |
Merged to PHP-8.1+ Yes, the |
clang and newer gcc releases support byte-sized atomic accesses on riscv64 through inline builtins. In both cases the hard dependency on libatomic added by GH-11321 isn't useful.
Stop using AC_CHECK_LIB() which is too naive to notice that libatomic isn't needed. Instead, PHP_CHECK_FUNC() will retry the check with -latomic if required.