meson: sincos and sincosf always detected as existing, even if not
Steps to reproduce
NetBSD does not provide sincos nor sincosf. meson as used by gtk erronously detects it does.
When building gtk 4.6.6 on NetBSD, the build fails with:
ld: gsk/libgsk.a.p/gskrendernodeimpl.c.o: in function `project':
/scratch/x11/gtk4/work/gtk-4.6.6/output/../gsk/gskrendernodeimpl.c:838: undefined reference to `sincos'
ld: /scratch/x11/gtk4/work/gtk-4.6.6/output/../gsk/gskrendernodeimpl.c:838: undefined reference to `sincos'
ld: gsk/libgsk.a.p/gsktransform.c.o: in function `_sincos':
/scratch/x11/gtk4/work/gtk-4.6.6/output/../gsk/gsktransform.c:725: undefined reference to `sincosf'
ld: /scratch/x11/gtk4/work/gtk-4.6.6/output/../gsk/gsktransform.c:725: undefined reference to `sincosf'
Current behavior
Do not use sincos (and sincosf) on NetBSD.
Expected outcome
Build succeeds.
Version information
gtk 4.4.6 No relevant options for building.
Additional information
I looked in output/meson-logs/meson-log.txt to check what happens and found that it first checks for sincos() and fails:
Command line: gcc -L/usr/pkg/lib -L/usr/lib -L/usr/pkg/lib/ffmpeg5 -I/usr/pkg/include -I/usr/include/krb5 -I/usr/include -I/usr/pkg/include/glib-2.0 -I/usr/pkg/include/gio-unix-2.0 -I/usr/pkg/lib/glib-2.0/include -I/usr/pkg/include/freetype2 -I/usr/pkg/include/harfbuzz -I/usr/pkg/include/libdrm -I/usr/pkg/include/ffmpeg5 -I/usr/pkg/include/python3.10 /scratch/x11/gtk4/work/gtk-4.6.6/output/meson-private/tmpbkd1cny6/testfile.c -o /scratch/x11/gtk4/work/gtk-4.6.6/output/meson-private/tmpbkd1cny6/output.exe -O2 -g -fPIC -D_FORTIFY_SOURCE=2 -fstack-check -g -D_FILE_OFFSET_BITS=64 -O0 -std=gnu99 -Wl,--start-group -lm -Wl,-zrelro -Wl,-znow -Wl,-R/usr/pkg/lib -Wl,-R/usr/lib -lexecinfo -Wl,--end-group -Wl,-R/usr/pkg/lib/ffmpeg5
Code:
#define sincos meson_disable_define_of_sincos
#include <limits.h>
#undef sincos
#ifdef __cplusplus
extern "C"
#endif
char sincos (void);
#if defined __stub_sincos || defined __stub___sincos
fail fail fail this function is not going to work
#endif
int main(void) {
return sincos ();
}
Compiler stdout:
Compiler stderr:
/scratch/x11/gtk4/work/gtk-4.6.6/output/meson-private/tmpbkd1cny6/testfile.c:10:14: warning: conflicting types for built-in function 'sincos'; expected 'void(double, double *, double *)' [-Wbuiltin-declaration-mismatch]
10 | char sincos (void);
| ^~~~~~
/scratch/x11/gtk4/work/gtk-4.6.6/output/meson-private/tmpbkd1cny6/testfile.c:5:1: note: 'sincos' is declared in header '<math.h>'
4 | #include <limits.h>
+++ |+#include <math.h>
5 | #undef sincos
ld: /tmp//ccqPthr7.o: in function `main':
/scratch/x11/gtk4/work/gtk-4.6.6/output/meson-private/tmpbkd1cny6/testfile.c:17: undefined reference to `sincos'
However, then it tries to detect sincos again, this time in libm, but the test is completely different and succeeds:
Command line: gcc -L/usr/pkg/lib -L/usr/lib -L/usr/pkg/lib/ffmpeg5 -I/usr/pkg/include -I/usr/include/krb5 -I/usr/include -I/usr/pkg/include/glib-2.0 -I/usr/pkg/include/gio-unix-2.0 -I/usr/pkg/lib/glib-2.0/include -I/usr/pkg/include/freetype2 -I/usr/pkg/include/harfbuzz -I/usr/pkg/include/libdrm -I/usr/pkg/include/ffmpeg5 -I/usr/pkg/include/python3.10 /scratch/x11/gtk4/work/gtk-4.6.6/output/meson-private/tmppd6x0sw0/testfile.c -o /scratch/x11/gtk4/work/gtk-4.6.6/output/meson-private/tmppd6x0sw0/output.exe -O2 -g -fPIC -D_FORTIFY_SOURCE=2 -fstack-check -g -D_FILE_OFFSET_BITS=64 -O0 -std=gnu99 -Wl,--start-group -lm -Wl,-zrelro -Wl,-znow -Wl,-R/usr/pkg/lib -Wl,-R/usr/lib -lexecinfo -Wl,--end-group -Wl,-R/usr/pkg/lib/ffmpeg5
Code:
int main(void) {
/* With some toolchains (MSYS2/mingw for example) the compiler
* provides various builtins which are not really implemented and
* fall back to the stdlib where they aren't provided and fail at
* build/link time. In case the user provides a header, including
* the header didn't lead to the function being defined, and the
* function we are checking isn't a builtin itself we assume the
* builtin is not functional and we just error out. */
#if !1 && !defined(sincos) && !0
#error "No definition for __builtin_sincos found in the prefix"
#endif
#ifdef __has_builtin
#if !__has_builtin(__builtin_sincos)
#error "__builtin_sincos not found"
#endif
#elif ! defined(sincos)
__builtin_sincos;
#endif
return 0;
}
Compiler stdout:
Compiler stderr:
Checking for function "sincos" with dependency -lm: YES
This test is broken. In my environment, it reduces to (cc -E output):
# 1 "sincos.c"
int main(void) {
# 21 "sincos.c"
return 0;
}
I don't know enough about meson to fix this, can you please advise?
(The warning from the compiler in the first case looks like a bug in gcc on NetBSD, I'll track that elsewhere - it doesn't seem relevant here, since the code for the second test with libm is so completely weird.)