Opened 3 years ago

Closed 2 years ago

#62853 closed defect (fixed)

dash @0.5.11.3: error: variable has incomplete type 'struct stat64'

Reported by: ryandesign (Ryan Carsten Schmidt) Owned by: Mathias.Laurin+macports@…
Priority: Normal Milestone:
Component: ports Version: 2.6.4
Keywords: bigsur arm64 Cc: saagarjha (Saagar Jha), ryandesign (Ryan Carsten Schmidt)
Port: dash

Description

dash doesn't build on our Apple Silicon Big Sur build machine:

https://build.macports.org/builders/ports-11_arm64-builder/builds/19940/steps/install-port/logs/stdio

exec.c:336:16: error: variable has incomplete type 'struct stat64'
        struct stat64 statb;
                      ^
exec.c:336:9: note: forward declaration of 'struct stat64'
        struct stat64 statb;
               ^
exec.c:346:11: error: implicit declaration of function 'stat64' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
                        while (stat64(name, &statb) < 0) {
                               ^
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)) {
                    ^
exec.c:346:11: note: did you mean 'stat'?

Also, silent build rules should be disabled.

Change History (14)

comment:1 Changed 3 years ago by saagarjha (Saagar Jha)

I don't have easy access to an Apple silicon machine at the moment, but it looks like the headers differ between Intel (which I tested on) and ARM here. I'll see if I can get upstream to build; if not perhaps we might need to carry a patch until they fix themselves.

comment:2 Changed 3 years ago by ryandesign (Ryan Carsten Schmidt)

The build log from macOS 11 x86_64 shows:

https://build.macports.org/builders/ports-11_x86_64-builder/builds/29994/steps/install-port/logs/stdio

cd.c:135:7: warning: 'stat64' is deprecated: first deprecated in macOS 10.6 [-Wdeprecated-declarations]
                if (stat64(p, &statb) >= 0 && S_ISDIR(statb.st_mode)) {
                    ^
/Library/Developer/CommandLineTools/SDKs/MacOSX11.3.sdk/usr/include/sys/stat.h:427:9: note: 'stat64' has been explicitly marked deprecated here
int     stat64(const char *, struct stat64 *) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_5, __MAC_10_6, __IPHONE_NA, __IPHONE_NA);
        ^
expand.c:1330:7: warning: 'lstat64' is deprecated: first deprecated in macOS 10.6 [-Wdeprecated-declarations]
                if (lstat64(expdir, &statb) >= 0)
                    ^
/Library/Developer/CommandLineTools/SDKs/MacOSX11.3.sdk/usr/include/sys/stat.h:426:9: note: 'lstat64' has been explicitly marked deprecated here
int     lstat64(const char *, struct stat64 *) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_5, __MAC_10_6, __IPHONE_NA, __IPHONE_NA);
        ^

Looks like Apple took the Apple Silicon transition as an opportunity to remove these long-deprecated types.

Here's another project fixing this problem:

https://github.com/stenzek/duckstation/commit/152ccd591722369aaad2785083fb2ab789effbbe

Looks like one should just use stat instead of stat64 on Mac OS X 10.6 or later.

comment:3 Changed 3 years ago by kencu (Ken)

maybe just a simple #define fix?

comment:4 Changed 3 years ago by saagarjha (Saagar Jha)

It would probably just be easier and better to fix the code properly, to be honest.

comment:5 Changed 3 years ago by saagarjha (Saagar Jha)

Actually, dash has a check for stat64:

dnl Check for stat64 (dietlibc/klibc).
AC_CHECK_FUNC(stat64,, [
	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])
])

This check is succeeding on arm64, as per the build logs:

checking for stat64... yes

Should it?

comment:6 Changed 3 years ago by ryandesign (Ryan Carsten Schmidt)

Huh. I don't know. Maybe they didn't remove stat64 after all. But then I don't know why it can't find it on arm64. The config.h is identical between runs on x86_64 and arm64.

comment:7 in reply to:  4 Changed 3 years ago by kencu (Ken)

Replying to saagarjha:

It would probably just be easier and better to fix the code properly, to be honest.

Oh, certainly, if that falls into your available time, a proper real code fix is alwys preferred.

Version 0, edited 3 years ago by kencu (Ken) (next)

comment:8 Changed 3 years ago by saagarjha (Saagar Jha)

The TL;DR is that the configure check (AC_CHECK_FUNC) doesn't actually look at the headers to see if stat64 is available, it forward declares it with a bogus signature and then tries to link it. On Apple silicon this succeeds because the symbols still exists even though the headers don't define it. I'm not an autoconf expert, but maybe we should be using a check that only looks at the headers?

comment:9 Changed 3 years ago by saagarjha (Saagar Jha)

#61784 seems related.

Last edited 3 years ago by ryandesign (Ryan Carsten Schmidt) (previous) (diff)

comment:10 Changed 3 years ago by ryandesign (Ryan Carsten Schmidt)

Yes, it does. There as here, I would recommend reporting the problem to the developers of the software so that they can fix it properly.

comment:11 Changed 3 years ago by saagarjha (Saagar Jha)

I reported the issue upstream yesterday, but their mailing list archives seem slow to update to unfortunately I don't have a link to it yet. I'm probably going to suggest this patch to them (if anyone has an actual Apple silicon Mac to test this on, that would be much appreciated):

$ git diff
diff --git a/configure.ac b/configure.ac
index 44f2f95..fbe7284 100644
--- a/configure.ac
+++ b/configure.ac
@@ -140,7 +140,7 @@ if test "$ac_cv_func_signal" != yes; then
 fi

 dnl Check for stat64 (dietlibc/klibc).
-AC_CHECK_FUNC(stat64,, [
+AC_CHECK_DECL(stat64,, [
        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])

I'm not sure what upstream's release schedule is; perhaps we should carry this until they cut a new version.

comment:12 Changed 3 years ago by ryandesign (Ryan Carsten Schmidt)

Same problem reported about gnudatalanguage in #62938.

comment:13 Changed 2 years ago by ryandesign (Ryan Carsten Schmidt)

Cc: ryandesign added

comment:14 Changed 2 years ago by ryandesign (Ryan Carsten Schmidt)

Resolution: fixed
Status: assignedclosed

In f6e3fa2ff301be85a0eb0e8ab310322a342fc3bf/macports-ports (master):

dash: Fix detection of stat64 on arm64

Closes: #62853

Note: See TracTickets for help on using tickets.