Dmitry V. Levin wrote:
> Is this __DEFINED_va_list macro the official way of detecting musl?

No, but in a world where the musl people don't want to provide an official
way [1][2] and the Alpine Linux people break their previously working way of
detecting musl [3], we (GNU) need to use our own heuristics to fulfil the
practical need of programs (especially test suites) to distinguish musl
systems from glibc systems.

> It looks very fragile to me.

Indeed, config.guess would be less fragile if we combined both heuristics.
Patch attached. It's a trade-off between code size and robustness.

Bruno

[1] https://wiki.musl-libc.org/faq.html
[2] https://lists.gnu.org/archive/html/bug-gnulib/2018-02/msg00079.html
[3] https://lists.gnu.org/archive/html/config-patches/2020-09/msg00002.html
>From 78ceae822bde047eea1db841a5feeba94f57fe7d Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Sun, 20 Sep 2020 13:17:12 +0200
Subject: [PATCH] * config.guess: Combine two heuristics to detect musl libc.

Reported by Dmitry V. Levin.
---
 ChangeLog    |  5 +++++
 config.guess | 10 +++++++++-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 834f4e5..63101b8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2020-09-20  Bruno Haible  <br...@clisp.org>
+
+	* config.guess: Combine two heuristics to detect musl libc.
+	Reported by Dmitry V. Levin.
+
 2020-09-19  Bruno Haible  <br...@clisp.org>
 
 	* config.guess: Don't use 'ldd --version' to determine the presence of
diff --git a/config.guess b/config.guess
index 8d70ec2..cd8a0a3 100755
--- a/config.guess
+++ b/config.guess
@@ -2,7 +2,7 @@
 # Attempt to guess a canonical system name.
 #   Copyright 1992-2020 Free Software Foundation, Inc.
 
-timestamp='2020-09-19'
+timestamp='2020-09-20'
 
 # This file is free software; you can redistribute it and/or modify it
 # under the terms of the GNU General Public License as published by
@@ -151,6 +151,7 @@ Linux|GNU|GNU/*)
 	LIBC=dietlibc
 	#else
 	#include <stdarg.h>
+	/* First heuristic to detect musl libc.  */
 	#ifdef __DEFINED_va_list
 	LIBC=musl
 	#else
@@ -159,6 +160,13 @@ Linux|GNU|GNU/*)
 	#endif
 	EOF
 	eval "`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^LIBC' | sed 's, ,,g'`"
+
+	# Second heuristic to detect musl libc.
+	if command -v ldd >/dev/null && \
+		ldd --version 2>&1 | grep -q ^musl
+	then
+	    LIBC=musl
+	fi
 	;;
 esac
 
-- 
2.7.4

Reply via email to