With musl-1.2.3: I get the following macros defined (from
$builddir/meson-config.h):

  #define WITH_LSTAT 1
  #define WITH_LSTAT64 1
  #define WITH_LSTAT_DECL 1
  #define WITH_STAT 1
  #define WITH_STAT64 1
  #define WITH_STAT_DECL 1
  #define WITH___LXSTAT 1
  #define WITH___LXSTAT64 1
  #define WITH___XSTAT 1
  #define WITH___XSTAT64 1

which in turn means the virmockstathelpers.c ends up defining:

  MOCK_STAT64
  MOCK_LSTAT64

But with  musl-1.2.4 everything changes and the set of defined
macros gets simplified to:

  #define WITH_LSTAT 1
  #define WITH_LSTAT_DECL 1
  #define WITH_STAT 1
  #define WITH_STAT_DECL 1
  #define WITH___LXSTAT 1
  #define WITH___XSTAT 1

which results in no MOCK_* macros defined in
virmockstathelpers.c, i.e. no stat() mocking, nada. The reason
for this simplification are thess musl commits [1][2] which removed all
64 bit aliases. And that's not what our logic for deciding what
flavor of stat() to mock counted with.

Nevertheless, we do build with Alpine Linux in our CI, so how
come we don't see this problem there? Well, simply because Alpine
Linux maintainers decided to revert the commits [3][4]. But on
distributions that use vanilla musl, this problem can be seen
easily.

1: 
https://git.musl-libc.org/cgit/musl/commit/?id=246f1c811448f37a44b41cd8df8d0ef9736d95f4
2: 
https://git.musl-libc.org/cgit/musl/commit/?id=25e6fee27f4a293728dd15b659170e7b9c7db9bc
3: 
https://git.alpinelinux.org/aports/commit/main/musl?id=6a5563fbb45b3d9d60678d7bbf60dbb312a2d481
4: 
https://git.alpinelinux.org/aports/commit/main/musl?id=a089bd852f8983623fa85e0f5755a3e25bf53c72

Resolves: https://bugs.gentoo.org/906167
Signed-off-by: Michal Privoznik <mpriv...@redhat.com>
---
 tests/virmockstathelpers.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/tests/virmockstathelpers.c b/tests/virmockstathelpers.c
index 5b1f3b08a7..a02ee04503 100644
--- a/tests/virmockstathelpers.c
+++ b/tests/virmockstathelpers.c
@@ -64,6 +64,10 @@
  * building on Apple Silicon (aarch64) those functions are missing
  * from the header altogether and should not be mocked.
  *
+ * Starting from 1.2.4, the musl library dropped 64-bit aliases, i.e. there's
+ * no stat64() only stat(). BTW: while musl implements __xstat(), it's never
+ * declared. And even the implementation is but a direct call to stat().
+ *
  * With all this in mind the list of functions we have to mock will depend
  * on several factors
  *
@@ -82,7 +86,9 @@
 #if !defined(__APPLE__)
 # if !defined(WITH___XSTAT_DECL)
 #  if defined(WITH_STAT)
-#   if !defined(WITH___XSTAT) && !defined(WITH_STAT64)
+#   if (!defined(WITH___XSTAT) && !defined(WITH_STAT64)) || \
+    (defined(WITH_STAT) && defined(WITH_STAT_DECL) && !defined(WITH_STAT64) && 
\
+     !defined(WITH___XSTAT64)) /* glibc || musl */
 #    define MOCK_STAT
 #   endif
 #  endif
@@ -99,7 +105,9 @@
 # endif /* WITH___XSTAT_DECL */
 # if !defined(WITH___LXSTAT_DECL)
 #  if defined(WITH_LSTAT)
-#   if !defined(WITH___LXSTAT) && !defined(WITH_LSTAT64)
+#   if (!defined(WITH___LXSTAT) && !defined(WITH_LSTAT64)) || \
+    (defined(WITH_LSTAT) && defined(WITH_LSTAT_DECL) && !defined(WITH_LSTAT64) 
\
+     && !defined(WITH___LXSTAT64)) /* glibc || musl */
 #    define MOCK_LSTAT
 #   endif
 #  endif
-- 
2.39.3

Reply via email to