Skip to content

MUSL can not compiles OpenZFS 2.3.2 because of S_IFMT #17293

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

Closed
jlsalvador opened this issue May 2, 2025 · 9 comments · Fixed by #17294
Closed

MUSL can not compiles OpenZFS 2.3.2 because of S_IFMT #17293

jlsalvador opened this issue May 2, 2025 · 9 comments · Fixed by #17294
Labels
Type: Defect Incorrect behavior (e.g. crash, hang)

Comments

@jlsalvador
Copy link
Contributor

jlsalvador commented May 2, 2025

Hello!

It's me again; that's means that a compiler does not compiles OpenZFS anymore. This time is MUSL compiling a test cmd from the commit 6503f8c (that was added to the zfs-2.3.2 branch. zfs-2.3.1 works correctly for GLIBC, MUSL, and UCLIBC).

Ps: UCLIBC is broken for another reason, I have no idea yet why.

System information

Type Version/Name
Distribution Name buildroot
Distribution Version master
Kernel Version 6.12.9
Architecture aarch64
OpenZFS Version 2.3.2

Describe the problem you're observing

I saw that the test cmd (tests/zfs-tests/cmd/statx.c) includes some definitions safeguards, but it does not includes S_IFMT. From my view point there are two alternatives:

  • Add the #ifndef S_IFMT as the others.
  • #include <stat.h>.

Can someone propose a better solution?

Describe how to reproduce the problem

Try to compile openzfs-2.3.2 with musl.

Include any warning/errors/backtraces from the system logs

[...]
  CC       cmd/zfs_ids_to_path.o                                                                                                                          
  CC       cmd/zhack-zhack.o                                                                                                                              
  CC       cmd/ztest-ztest.o                                                                                                                              
  CC       cmd/zgenhostid.o
  CC       tests/zfs-tests/cmd/getversion.o
  CC       tests/zfs-tests/cmd/user_ns_exec.o
  CC       tests/zfs-tests/cmd/renameat2.o
  CC       tests/zfs-tests/cmd/xattrtest.o
  CC       tests/zfs-tests/cmd/statx.o 
tests/zfs-tests/cmd/statx.c: In function 'main':
tests/zfs-tests/cmd/statx.c:254:61: error: 'S_IFMT' undeclared (first use in this function)
  254 |                         printf("type: %u\n", stx.stx_mode & S_IFMT);
      |                                                             ^~~~~~
tests/zfs-tests/cmd/statx.c:254:61: note: each undeclared identifier is reported only once for each function it appears in
make[4]: *** [Makefile:8949: tests/zfs-tests/cmd/statx.o] Error 1
make[4]: *** Waiting for unfinished jobs....
make[3]: *** [Makefile:12621: all-recursive] Error 1
make[2]: *** [Makefile:4779: all] Error 2
make[1]: *** [package/pkg-generic.mk:273: /tmp/tmp.QADMx4LtMA/TestZfsMusl/build/zfs-2.3.2/.stamp_built] Error 2
make: *** [Makefile:23: _all] Error 2
make: Leaving directory '/tmp/tmp.QADMx4LtMA/TestZfsMusl'
E
======================================================================
ERROR: test_run (tests.package.test_zfs.TestZfsMusl.test_run)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/data/support/testing/infra/basetest.py", line 74, in setUp
    self.b.build()
  File "/data/support/testing/infra/builder.py", line 105, in build
    raise SystemError("Build failed")
SystemError: Build failed

----------------------------------------------------------------------
Ran 1 test in 599.316s

FAILED (errors=1)
@jlsalvador jlsalvador added the Type: Defect Incorrect behavior (e.g. crash, hang) label May 2, 2025
@jlsalvador
Copy link
Contributor Author

jlsalvador commented May 2, 2025

My PR propose:

0001-fix-musl-S_IFMT.patch:

diff --git a/tests/zfs-tests/cmd/statx.c b/tests/zfs-tests/cmd/statx.c
index 89939f6ef..0abb26d83 100644
--- a/tests/zfs-tests/cmd/statx.c
+++ b/tests/zfs-tests/cmd/statx.c
@@ -109,6 +109,9 @@ _statx(int fd, const char *path, int flags, unsigned int mask, void *stx)
 #ifndef STATX_DIOALIGN
 #define    STATX_DIOALIGN  (1<<13)
 #endif
+#ifndef S_IFMT
+#define S_IFMT 0170000
+#endif
 
 typedef struct {
    int64_t     tv_sec;

I verified that this patch fix the MUSL compilation.

Thoughts?

@robn
Copy link
Member

robn commented May 2, 2025

Better way might be to define _XOPEN_SOURCE before including sys/stat.h. Can you give it a try?

(afaict, S_IFMT is from Single Unix, and then POSIX 2008).

@jlsalvador
Copy link
Contributor Author

jlsalvador commented May 2, 2025

Better way might be to define _XOPEN_SOURCE before including sys/stat.h. Can you give it a try?

(afaict, S_IFMT is from Single Unix, and then POSIX 2008).

Hello @robn , I can not find any _XOPEN_SOURCE in the openzfs current code. Can you comment here an example?

GLIBC definition for S_IFMT: https://git.savannah.gnu.org/cgit/gnulib.git/tree/lib/sys_stat.in.h#n197 *(https://git.savannah.gnu.org/cgit/gnulib.git/plain/lib/sys_stat.in.h)
MUSL definition for S_IFMT: https://git.musl-libc.org/cgit/musl/tree/include/sys/stat.h#n36
UCLIBC definition for S_IFMT: https://github.com/kraj/uclibc-ng/blob/master/include/sys/stat.h#L109

@robn
Copy link
Member

robn commented May 2, 2025

No I mean:

diff --git tests/zfs-tests/cmd/statx.c tests/zfs-tests/cmd/statx.c
index 89939f6efb..2917ea3997 100644
--- tests/zfs-tests/cmd/statx.c
+++ tests/zfs-tests/cmd/statx.c
@@ -22,6 +22,7 @@
  * IN THE SOFTWARE.
  */
 
+#define _XOPEN_SOURCE
 #include <stdint.h>
 #include <stdio.h>
 #include <string.h>

@jlsalvador
Copy link
Contributor Author

No I mean:

diff --git tests/zfs-tests/cmd/statx.c tests/zfs-tests/cmd/statx.c
index 89939f6efb..2917ea3997 100644
--- tests/zfs-tests/cmd/statx.c
+++ tests/zfs-tests/cmd/statx.c
@@ -22,6 +22,7 @@

  • IN THE SOFTWARE.
    */

+#define _XOPEN_SOURCE
#include <stdint.h>
#include <stdio.h>
#include <string.h>

Same error:

[...]
  CC       cmd/zgenhostid.o
  CC       tests/zfs-tests/cmd/getversion.o
  CC       tests/zfs-tests/cmd/user_ns_exec.o
  CC       tests/zfs-tests/cmd/renameat2.o
  CC       tests/zfs-tests/cmd/statx.o
  CC       tests/zfs-tests/cmd/xattrtest.o
tests/zfs-tests/cmd/statx.c: In function 'main':
tests/zfs-tests/cmd/statx.c:255:61: error: 'S_IFMT' undeclared (first use in this function)
  255 |                         printf("type: %u\n", stx.stx_mode & S_IFMT);
      |                                                             ^~~~~~
tests/zfs-tests/cmd/statx.c:255:61: note: each undeclared identifier is reported only once for each function it appears in
make[4]: *** [Makefile:8949: tests/zfs-tests/cmd/statx.o] Error 1
make[4]: *** Waiting for unfinished jobs....
make[3]: *** [Makefile:12621: all-recursive] Error 1
make[2]: *** [Makefile:4779: all] Error 2
make[1]: *** [package/pkg-generic.mk:273: /tmp/tmp.MIdt64jdn4/TestZfsMusl/build/zfs-2.3.2/.stamp_built] Error 2
make: *** [Makefile:23: _all] Error 2
make: Leaving directory '/tmp/tmp.MIdt64jdn4/TestZfsMusl'
E
======================================================================
ERROR: test_run (tests.package.test_zfs.TestZfsMusl.test_run)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/data/support/testing/infra/basetest.py", line 74, in setUp
    self.b.build()
  File "/data/support/testing/infra/builder.py", line 105, in build
    raise SystemError("Build failed")
SystemError: Build failed

----------------------------------------------------------------------
Ran 1 test in 469.661s

FAILED (errors=1)

@jlsalvador
Copy link
Contributor Author

jlsalvador commented May 2, 2025

No I mean:
diff --git tests/zfs-tests/cmd/statx.c tests/zfs-tests/cmd/statx.c
index 89939f6efb..2917ea3997 100644
--- tests/zfs-tests/cmd/statx.c
+++ tests/zfs-tests/cmd/statx.c
@@ -22,6 +22,7 @@

  • IN THE SOFTWARE.
    */

+#define _XOPEN_SOURCE
#include <stdint.h>
#include <stdio.h>
#include <string.h>

Same error:

[...]
  CC       cmd/zgenhostid.o
  CC       tests/zfs-tests/cmd/getversion.o
  CC       tests/zfs-tests/cmd/user_ns_exec.o
  CC       tests/zfs-tests/cmd/renameat2.o
  CC       tests/zfs-tests/cmd/statx.o
  CC       tests/zfs-tests/cmd/xattrtest.o
tests/zfs-tests/cmd/statx.c: In function 'main':
tests/zfs-tests/cmd/statx.c:255:61: error: 'S_IFMT' undeclared (first use in this function)
  255 |                         printf("type: %u\n", stx.stx_mode & S_IFMT);
      |                                                             ^~~~~~
tests/zfs-tests/cmd/statx.c:255:61: note: each undeclared identifier is reported only once for each function it appears in
make[4]: *** [Makefile:8949: tests/zfs-tests/cmd/statx.o] Error 1
make[4]: *** Waiting for unfinished jobs....
make[3]: *** [Makefile:12621: all-recursive] Error 1
make[2]: *** [Makefile:4779: all] Error 2
make[1]: *** [package/pkg-generic.mk:273: /tmp/tmp.MIdt64jdn4/TestZfsMusl/build/zfs-2.3.2/.stamp_built] Error 2
make: *** [Makefile:23: _all] Error 2
make: Leaving directory '/tmp/tmp.MIdt64jdn4/TestZfsMusl'
E
======================================================================
ERROR: test_run (tests.package.test_zfs.TestZfsMusl.test_run)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/data/support/testing/infra/basetest.py", line 74, in setUp
    self.b.build()
  File "/data/support/testing/infra/builder.py", line 105, in build
    raise SystemError("Build failed")
SystemError: Build failed

----------------------------------------------------------------------
Ran 1 test in 469.661s

FAILED (errors=1)

For the next patch, I got this another error (redefined statx with different arg types):

diff --git a/tests/zfs-tests/cmd/statx.c b/tests/zfs-tests/cmd/statx.c
index 89939f6ef..7235d8569 100644
--- a/tests/zfs-tests/cmd/statx.c
+++ b/tests/zfs-tests/cmd/statx.c
@@ -22,11 +22,13 @@
  * IN THE SOFTWARE.
  */
 
+#define _XOPEN_SOURCE
 #include <stdint.h>
 #include <stdio.h>
 #include <string.h>
 #include <errno.h>
 #include <fcntl.h>
+#include <sys/stat.h>
 #include <sys/syscall.h>
 #include <unistd.h>
  CC       cmd/ztest-ztest.o
  CC       cmd/zgenhostid.o
  CC       tests/zfs-tests/cmd/getversion.o
  CC       tests/zfs-tests/cmd/user_ns_exec.o
  CC       tests/zfs-tests/cmd/xattrtest.o
  CC       tests/zfs-tests/cmd/statx.o
  CC       tests/zfs-tests/cmd/renameat2.o
tests/zfs-tests/cmd/statx.c:60:1: error: conflicting types for 'statx'; have 'int(int,  const char *, int,  unsigned int,  void *)'
   60 | statx(int, const char *, int, unsigned int, void *)
      | ^~~~~
In file included from ./lib/libspl/include/os/linux/sys/stat.h:30,
                 from tests/zfs-tests/cmd/statx.c:31:
/tmp/tmp.2sKpJg3OuM/TestZfsMusl/host/aarch64-buildroot-linux-musl/sysroot/usr/include/sys/stat.h:153:5: note: previous declaration of 'statx' with type 'int(int,  const char * restrict,  int,  unsigned int,  struct statx * restrict)'
  153 | int statx(int, const char *__restrict, int, unsigned, struct statx *__restrict);
      |     ^~~~~
  CC       tests/zfs-tests/cmd/zed_fd_spill-zedlet.o
  CC       tests/zfs-tests/cmd/idmap_util.o
make[4]: *** [Makefile:8949: tests/zfs-tests/cmd/statx.o] Error 1
make[4]: *** Waiting for unfinished jobs....
make[3]: *** [Makefile:12621: all-recursive] Error 1
make[2]: *** [Makefile:4779: all] Error 2
make[1]: *** [package/pkg-generic.mk:273: /tmp/tmp.2sKpJg3OuM/TestZfsMusl/build/zfs-2.3.2/.stamp_built] Error 2
make: *** [Makefile:23: _all] Error 2
make: Leaving directory '/tmp/tmp.2sKpJg3OuM/TestZfsMusl'
E
======================================================================
ERROR: test_run (tests.package.test_zfs.TestZfsMusl.test_run)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/data/support/testing/infra/basetest.py", line 74, in setUp
    self.b.build()
  File "/data/support/testing/infra/builder.py", line 105, in build
    raise SystemError("Build failed")
SystemError: Build failed

----------------------------------------------------------------------
Ran 1 test in 471.068s

FAILED (errors=1)

@robn
Copy link
Member

robn commented May 2, 2025

Yeah, your patch is the way to do it then. We can't include sys/stat.h directly because it obscures some of things we're trying to test, which means we have to declare the things we need if we can't get them any other way.

Would you like me to do a PR for this, or would you prefer to?

@jlsalvador
Copy link
Contributor Author

Yeah, your patch is the way to do it then. We can't include sys/stat.h directly because it obscures some of things we're trying to test, which means we have to declare the things we need if we can't get them any other way.

Would you like me to do a PR for this, or would you prefer to?

Done at #17294
Please feel free to include yourself in the PR as a reviewer, co-author, or however you prefer.

@robn
Copy link
Member

robn commented May 2, 2025

Nice, thank you for that :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Defect Incorrect behavior (e.g. crash, hang)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants