dash.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Configure check for stat64 does not work on Apple silicon
@ 2021-05-16  8:47 Saagar Jha
  2021-05-26  5:49 ` shell: Call CHECK_DECL on stat64 Herbert Xu
  0 siblings, 1 reply; 3+ messages in thread
From: Saagar Jha @ 2021-05-16  8:47 UTC (permalink / raw)
  To: dash

Hi,

I’m working on getting dash building on macOS for Apple silicon. On this platform, stat64 is not available:

  CC       cd.o
cd.c:99:16: error: variable has incomplete type 'struct stat64'
        struct stat64 statb;
                      ^
cd.c:99:9: note: forward declaration of 'struct stat64'
        struct stat64 statb;
               ^
cd.c:135:7: error: implicit declaration of function 'stat64' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
                if (stat64(p, &statb) >= 0 && S_ISDIR(statb.st_mode)) {
                    ^
cd.c:135:7: note: did you mean 'stat'?
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/usr/include/sys/stat.h:386:9: note: 'stat' declared here
int     stat(const char *, struct stat *) __DARWIN_INODE64(stat);
        ^
2 errors generated.

(If you happen to have access to an Intel Mac, you can reproduce this by running configure as CC="xcrun clang -arch arm64" ./configure --build=arm64-apple-darwin --host=x86_64-apple-darwin.)

Even though stat64 is not in the public headers, AC_CHECK_FUNC will “find” it because the symbol exists at link time for the test, even though it is not meant to be used. What do you think would be the best way to fix this check on this platform? Would it be preferred to check if the headers contain a declaration of the function?

Thanks,
Saagar Jha


^ permalink raw reply	[flat|nested] 3+ messages in thread

* shell: Call CHECK_DECL on stat64
  2021-05-16  8:47 Configure check for stat64 does not work on Apple silicon Saagar Jha
@ 2021-05-26  5:49 ` Herbert Xu
  2021-05-27  8:43   ` Saagar Jha
  0 siblings, 1 reply; 3+ messages in thread
From: Herbert Xu @ 2021-05-26  5:49 UTC (permalink / raw)
  To: Saagar Jha; +Cc: dash

Saagar Jha <saagar@saagarjha.com> wrote:
>
> Even though stat64 is not in the public headers, AC_CHECK_FUNC will “find” it because the symbol exists at link time for the test, even though it is not meant to be used. What do you think would be the best way to fix this check on this platform? Would it be preferred to check if the headers contain a declaration of the function?

Yes we should check for a declaration.  Does this patch fix the
problem?

---8<---
On macOS it is possible to find stat64 at link-time but not at
compile-time.  To make the build process more robust we should
check for the header file as well as the library.

Reported-by: Saagar Jha <saagar@saagarjha.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

diff --git a/configure.ac b/configure.ac
index 44f2f95..466df4c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -140,11 +140,12 @@ if test "$ac_cv_func_signal" != yes; then
 fi
 
 dnl Check for stat64 (dietlibc/klibc).
-AC_CHECK_FUNC(stat64,, [
+AC_CHECK_DECL(stat64, AC_CHECK_FUNC(stat64))
+if test "$ac_cv_func_stat64" != yes; then
 	AC_DEFINE(fstat64, fstat, [64-bit operations are the same as 32-bit])
 	AC_DEFINE(lstat64, lstat, [64-bit operations are the same as 32-bit])
 	AC_DEFINE(stat64, stat, [64-bit operations are the same as 32-bit])
-])
+fi
 
 AC_CHECK_FUNC(glob64,, [
 	AC_DEFINE(glob64_t, glob_t, [64-bit operations are the same as 32-bit])
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: shell: Call CHECK_DECL on stat64
  2021-05-26  5:49 ` shell: Call CHECK_DECL on stat64 Herbert Xu
@ 2021-05-27  8:43   ` Saagar Jha
  0 siblings, 0 replies; 3+ messages in thread
From: Saagar Jha @ 2021-05-27  8:43 UTC (permalink / raw)
  To: Herbert Xu; +Cc: dash

I was able the compilation to succeed with the patch and the binary seemed to work in my basic tests, so it looks good from my side. Thanks for preparing this!

Regards,
Saagar

> On May 25, 2021, at 22:49, Herbert Xu <herbert@gondor.apana.org.au> wrote:
> 
> Saagar Jha <saagar@saagarjha.com> wrote:
>> 
>> Even though stat64 is not in the public headers, AC_CHECK_FUNC will “find” it because the symbol exists at link time for the test, even though it is not meant to be used. What do you think would be the best way to fix this check on this platform? Would it be preferred to check if the headers contain a declaration of the function?
> 
> Yes we should check for a declaration.  Does this patch fix the
> problem?
> 
> ---8<---
> On macOS it is possible to find stat64 at link-time but not at
> compile-time.  To make the build process more robust we should
> check for the header file as well as the library.
> 
> Reported-by: Saagar Jha <saagar@saagarjha.com>
> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
> 
> diff --git a/configure.ac b/configure.ac
> index 44f2f95..466df4c 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -140,11 +140,12 @@ if test "$ac_cv_func_signal" != yes; then
> fi
> 
> dnl Check for stat64 (dietlibc/klibc).
> -AC_CHECK_FUNC(stat64,, [
> +AC_CHECK_DECL(stat64, AC_CHECK_FUNC(stat64))
> +if test "$ac_cv_func_stat64" != yes; then
> 	AC_DEFINE(fstat64, fstat, [64-bit operations are the same as 32-bit])
> 	AC_DEFINE(lstat64, lstat, [64-bit operations are the same as 32-bit])
> 	AC_DEFINE(stat64, stat, [64-bit operations are the same as 32-bit])
> -])
> +fi
> 
> AC_CHECK_FUNC(glob64,, [
> 	AC_DEFINE(glob64_t, glob_t, [64-bit operations are the same as 32-bit])
> -- 
> Email: Herbert Xu <herbert@gondor.apana.org.au>
> Home Page: http://gondor.apana.org.au/~herbert/
> PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-05-27  8:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-16  8:47 Configure check for stat64 does not work on Apple silicon Saagar Jha
2021-05-26  5:49 ` shell: Call CHECK_DECL on stat64 Herbert Xu
2021-05-27  8:43   ` Saagar Jha

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).