Repository navigation
Conversation
Codecov Report
@@ Coverage Diff @@
## master #10674 +/- ##
==========================================
+ Coverage 58.31% 66.54% +8.23%
==========================================
Files 203 203
Lines 44048 44098 +50
Branches 9770 9781 +11
==========================================
+ Hits 25685 29344 +3659
+ Misses 16071 12420 -3651
- Partials 2292 2334 +42
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
eli-schwartz
left a comment
There was a problem hiding this comment.
In addition to the CI failures that indicate this logic is flawed, there are a couple of typos.
|
This is tricky to get right. I made a test using autotools: configure.acAC_INIT([testcheck], [1.0])
AM_INIT_AUTOMAKE([foreign])
AC_CHECK_LIB(m, sincos)
AC_CHECK_FUNC(alloca)
AC_PROG_CC
AC_CONFIG_FILES([Makefile])
AC_OUTPUTMakefile.ambin_PROGRAMS=testcheckmain.cint main()
{
return 0;
}Running autoreconf -fiv
./configureYelds the following output: Here's the relevant log: |
|
To know if a built-in may not be inlined, I guess we can test for __has_builtin (func) && __has_builtin (__builtin_func)Then, to know if func is provided by the target libc, we may use the -u symbol command-line option:
|
dc4514c to
ffbb1a4
Compare
ffbb1a4 to
378d220
Compare
|
All this seems much to complicated to me. What we want to know is:
I don't see why there is any need to fiddle with builtins here. |
|
Yeah, see also:
Now that compilers have |
|
@lazka could you let us know more about the non-functioning builtins in mingw GCC? |
that's all I know: https://github.com/mesonbuild/meson/pull/7116/files#r424014885 edit: I'm happy to forward any specific questions though |
|
Anyway consider compiling a math library using sincos(), sqrt() etc. on netBSD. If the architecture has machine instruction for sincos, we don't actually care that the netBSD libc doesn't implement sincos(), because GCC uses the machine instruction anyway. So yes, I'd say the function should be reported as available. Avoiding that could hurt performance considerably. Anyway, the fix is for compilers to implement a |
But if the compiler doesn't use a library function, then compiling a trivial test program using sincos(x) will succeed, no? Why do we need to fiddle with builtins? |
Unfortunately no, it will fail with GCC (not so sure about CLang) A build system writes a simple test program to check for availability of a function. It doesn't know how it should call the function though, because it doesn't have any knowledge of the argument list (signature). Thus the function is prototyped in a generic way: /* generic prototype */
char func();
int main()
{
return func();
}If that compiles and links, the function is available. Now consider what happens when It can also be tested on Linux:
Another example is: /* remove me to compile */
char __builtin_trap();
int main()
{
__builtin_trap();
return 0;
}Finally, another issue that might get in the way is explained in https://gcc.gnu.org/pipermail/gcc/2022-August/239262.html That is quite complicated and I'm not an expert in compilers (at all!), so if anybody has some idea to make that work I'd be very happy :) |
|
I would be quite ok if the check determines that sincos is not available on netbsd. |
|
I would say the 'generic prototype' is part of the problem here. Maybe something like this would work better: |
|
Here's something very intersting: in clang, #if __has_builtin (sincos)
#error "sincos is a builtin"
#else
#error "sincos is NOT a builtin"
#endif
int main ()
{
return 0;
}Here's the outcome of compilation: The same happens for |
|
IMO the behavior of clang makes more sense. Also, |
A builtin function may resolve to a function call, but it's not mandatory
for a libc implementation to provide such function. When testing for the
presence of a builtin function, also check if linking succeeds or not.
Fixes #10641