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
0.36.0 incorrectly detects posix_memalign on MSYS2 (native MINGW64 and MINGW32 targets/shells/environs) #1083
Comments
I'll give that a try. I was half-expecting it to be an optimization thing tbh. Let's see if my instincts are any good... |
This is unrelated to #1053. What's happening is that somehow the libc you're using is defining You will need to check which libc is being used for linking, which gcc is being used, and why your compiler decides that this is available in your environment. The exact same check is done by Autotools. |
Confirmed not a dup. I'm completely lost now, other than to confirm the version I'm using:
And the fact that #1066 does not fix it like @nirbheek said:
|
I think in this case, meson is not doing its job properly. It was asked to confirm the presence of a specific function, and it failed. It then went looking for a similarly-named builtin, found that, and then declared that the original function was present. This feels wrong, but I'm no expert (not in meson, and not really in autotools). Why bother with the fallback? |
Meson might be doing something wrong, but till the questions I asked are answered, we can't know. |
To clarify, However, in the case of builtins this does not work because for those If the libc exports Hence, we require more investigation before we can know what the appropriate solution is. |
MSYS2 uses GCC 6.2.0 obtained from ftp.gnu.org/gnu/gcc, with the patches you can see at https://github.com/Alexpux/MINGW-packages/tree/master/mingw-w64-gcc.
And yeah,
These are part of the standard toolchain packages for this platform, and it's a fresh install (not that this is the cause of anything, I hope). The headers are built from the following sources: https://github.com/Alexpux/MINGW-packages/tree/master/mingw-w64-headers-git on top of https://sourceforge.net/p/mingw-w64/mingw-w64/ci/master/tree/. As for the libc:
Sorry, I don't know enough to help you diagnose that. |
So now what's left to check is why the mingw gcc provided by msys2 is exporting For instance, the compiler might be inlining a valid implementation and the bug might just be that MinGW neglects to add a proper header definition to use it in your application. Or, it might be replacing it with an equivalent invocation, or it's substituting a broken implementation, etc. You will also want to try with |
It's correctly detected as absent by the MSYS2 autoconf 2.69-3 (pkgbuild) that would have been used for the earlier graphene builds. ## Tests for @nirbheek ##
AC_CHECK_FUNC([aligned_alloc])
AC_CHECK_FUNC([posix_memalign])
AC_CHECK_FUNC([memalign]) checking for aligned_alloc... no
checking for posix_memalign... no
checking for memalign... no Here's the shell code that gets written into # [...]
# ac_fn_c_try_link LINENO
# -----------------------
# Try to link conftest.$ac_ext, and return whether this succeeded.
ac_fn_c_try_link ()
{
as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
rm -f conftest.$ac_objext conftest$ac_exeext
if { { ac_try="$ac_link"
case "(($ac_try" in
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
*) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
$as_echo "$ac_try_echo"; } >&5
(eval "$ac_link") 2>conftest.err
ac_status=$?
if test -s conftest.err; then
grep -v '^ *+' conftest.err >conftest.er1
cat conftest.er1 >&5
mv -f conftest.er1 conftest.err
fi
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; } && {
test -z "$ac_c_werror_flag" ||
test ! -s conftest.err
} && test -s conftest$ac_exeext && {
test "$cross_compiling" = yes ||
test -x conftest$ac_exeext
}; then :
ac_retval=0
else
$as_echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
ac_retval=1
fi
# Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information
# created by the PGI compiler (conftest_ipa8_conftest.oo), as it would
# interfere with the next link command; also delete a directory that is
# left behind by Apple's compiler. We do this before executing the actions.
rm -rf conftest.dSYM conftest_ipa8_conftest.oo
eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
as_fn_set_status $ac_retval
} # ac_fn_c_try_link
# [...]
# ac_fn_c_check_func LINENO FUNC VAR
# ----------------------------------
# Tests whether FUNC exists, setting the cache variable VAR accordingly
ac_fn_c_check_func ()
{
as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
$as_echo_n "checking for $2... " >&6; }
if eval \${$3+:} false; then :
$as_echo_n "(cached) " >&6
else
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
/* Define $2 to an innocuous variant, in case <limits.h> declares $2.
For example, HP-UX 11i <limits.h> declares gettimeofday. */
#define $2 innocuous_$2
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $2 (); below.
Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
<limits.h> exists even on freestanding compilers. */
#ifdef __STDC__
# include <limits.h>
#else
# include <assert.h>
#endif
#undef $2
/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char $2 ();
/* The GNU C library defines this for functions which it implements
to always fail with ENOSYS. Some functions are actually named
something starting with __ and the normal name is an alias. */
#if defined __stub_$2 || defined __stub___$2
choke me
#endif
int
main ()
{
return $2 ();
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
eval "$3=yes"
else
eval "$3=no"
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
fi
eval ac_res=\$$3
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
$as_echo "$ac_res" >&6; }
eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
} # ac_fn_c_check_func
# [...]
## Tests for @nirbheek ##
ac_fn_c_check_func "$LINENO" "aligned_alloc" "ac_cv_func_aligned_alloc"
if test "x$ac_cv_func_aligned_alloc" = xyes; then :
fi
ac_fn_c_check_func "$LINENO" "posix_memalign" "ac_cv_func_posix_memalign"
if test "x$ac_cv_func_posix_memalign" = xyes; then :
fi
ac_fn_c_check_func "$LINENO" "memalign" "ac_cv_func_memalign"
if test "x$ac_cv_func_memalign" = xyes; then :
fi |
As recommended by @nirbheek, only search for a single aligned memory allocation function: ebassi#86 (comment) The cascade of tests means we can exclude the ones for which MSYS2's native mingw-w64 builtins and headers conspire to provide meson with a dud test. Although it is still not clear that meson is doing the right thing in this case (mesonbuild/meson#1083), we can work around the failed build in graphene by excluding certain POSIXy cases on Windows. Closes ebassi#76, leaving ebassi#88 unsolved.
Does #1150 fix this for you? |
We were checking for builtins explicitly like this because the ordinary checks don't work for builtins at all. We do exactly the same check as Autoconf and it doesn't work with Autoconf either (Autoconf is broken!) So now we check for it in two ways: if there's no #include in prefix, we check if `__builtin_symbol` exists (has_function allows checking for functions without providing includes). If there's a #include, we check if `symbol` exists. The old method was causing problems with some buggy toolchains such as MSYS2 which define some builtins in the C library but don't expose them via headers which meant that `__builtin_symbol` would be found even though `symbol` is not available. Doing this allows people to always get the correct answer as long as they specify the includes that are required to find a function while also not forcing people to always specify includes to find a function which is cumbersome. Closes #1083
Closes: ebassi#76 This commit makes the existing flat set of macro tests into a big if-else block, and selects only one aligned alloc function. If no such function is available, meson now terminates with an error and the build will fail. This is as recommended by @nirbheek, who suggests that meson should only search for a single aligned memory allocation function during configuration of graphene. Ref: ebassi#86 (comment) On MSYS2, a buggy mismatch between in the native mingw-w64 builtins and headers causes meson < 0.37.0 to report that the function exists because the underlying builtin exists. Cascading the tests like this works around breaking configuration on the MSYS2 platform for meson<0.37 by excluding certain POSIX-only cases on Windows. Ref: mesonbuild/meson#1083
Closes: ebassi#76 This commit makes the existing flat set of macro tests into a big if-else block, and selects only one aligned alloc function. If no such function is available, meson now terminates with an error and the build will fail. This is as recommended by @nirbheek, who suggests that meson should only search for a single aligned memory allocation function during configuration of graphene. Ref: ebassi#86 (comment) On MSYS2, a buggy mismatch between the native mingw-w64 builtins and the standard headers causes meson < 0.37.0 to report that the function exists because the underlying builtin exists. Cascading the tests like this works around breaking configuration on the MSYS2 platform for meson<0.37 by excluding certain POSIX-only cases on Windows. Ref: mesonbuild/meson#1083
Still the same with 0.41.1. I've proposed a patch in MSYS2 for now: https://github.com/Alexpux/MINGW-packages/pull/2698 including stpcpy which fails the same way. |
This bug is fundamentally unfixable in Meson without a blacklist since this is an MSYS2 toolchain bug. The libc is defining these symbols as available as built-ins ( The actual fix would be in MSYS2's libc. It should not export builtin symbols that it does not support. |
The other option is for GCC to start supporting |
OK, thanks for the additional info. I don't have any experience with the msys2 toolchain internals, so the downstream patch will have to do for now. |
Reporting on @ebassi's behalf, since they're busy. This is affecting downstream at ebassi/graphene#76.
Meson incorrectly detects the presence of
posix_memalign()
with the following in the project'smeson.build
:The output in
meson-logs/meson-log.txt
seems to indicate that it's settling on__builtin_posix_memalign
compiling, and using that as a substitute for the real thing. But I have never used meson before, so I don't really understand this.The function is not defined in any header the MINGW64 and MINGW32 builds should be using.
The text was updated successfully, but these errors were encountered: