[Gc] Compilation issue against musl

Brendan Heading <[email protected]> Wed, 29 Jul 2015 00:31:56 +0100
Newsgroups gmane.comp.programming.garbage-collection.boehmgc
Message-ID <CA+BsyQ5dn5xiV+71JndfrSs+MnJXcfUtg=VO9P8YXQH73m4vmQ@mail.gmail.com>
Hi guys,

There's a minor compilation issue when building bdwgc against musl. The
problem is observed on version 7.4.2. The compilation error is as follows :

=================

In file included from os_dep.c:44:0:
/home/peko/autobuild/instance-2/output/host/usr/arm-buildroot-linux-musleabihf/sysroot/usr/include/asm/sigcontext.h:9:8:
error: redefinition of 'struct sigcontext'
 struct sigcontext {
        ^
In file included from
/home/peko/autobuild/instance-2/output/host/usr/arm-buildroot-linux-musleabihf/sysroot/usr/include/signal.h:243:0,
                 from ./include/private/../gc_pthread_redirects.h:42,
                 from ./include/private/../gc.h:1443,
                 from ./include/private/gc_priv.h:46,
                 from os_dep.c:17:
/home/peko/autobuild/instance-2/output/host/usr/arm-buildroot-linux-musleabihf/sysroot/usr/include/bits/signal.h:11:16:
note: originally defined here
 typedef struct sigcontext

=================

The root cause is in the following excerpt from os_dep.c

=================

#   if 2 <= __GLIBC__

#     if 2 == __GLIBC__ && 0 == __GLIBC_MINOR__

        /* glibc 2.1 no longer has sigcontext.h.  But signal.h          */

        /* has the right declaration for glibc 2.1.                     */

#       include <sigcontext.h>

#     endif /* 0 == __GLIBC_MINOR__ */

#   else /* __GLIBC__ < 2 */

      /* libc5 doesn't have <sigcontext.h>: go directly with the kernel   */

      /* one.  Check LINUX_VERSION_CODE to see which we should reference. */

#     include <asm/sigcontext.h>

#   endif /* __GLIBC__ < 2 */

=================

The logic here is intended to provide two special cases; one for
__GLIBC__ version 2.0, the other is a fall through case intended to be
reached if __GLIBC__ version is <2. However this fall through is also
reached if __GLIBC__ is undefined as is the case in musl. If the
__GLIBC__ version is 2.1 or greater no special action is taken.

musl, as a matter of policy, will never provide a macro to detect its
presence. Instead I propose that the above logic be wrapped in an
#ifdef __GLIBC__. I've tested that this allows the build to work on
musl, and should also work on uclibc and other C libraries.

I've attached a patch - I'm more than happy to update it if you feel
there is a better approach.

regards

Brendan

_______________________________________________
bdwgc mailing list
[email protected]
https://lists.opendylan.org/mailman/listinfo/bdwgc
0001-bdwgc-does-not-compile-under-the-musl-C-library.patch (text/x-patch, 2.1 KB)
From bcdc82c4c696222c8fdd5f319fc8521aa1e07a04 Mon Sep 17 00:00:00 2001
From: Brendan Heading <[email protected]>
Date: Wed, 29 Jul 2015 00:29:49 +0100
Subject: [PATCH 1/1] bdwgc does not compile under the musl C library

This is because musl does not define __GLIBC__. Some logic in os_deps.c
designed to detect and handle old versions of glibc only makes sense
if glibc is in use; this patch therefore checks to ensure __GLIBC__
is defined first.

Signed-off-by: Brendan Heading <[email protected]>
---
 os_dep.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/os_dep.c b/os_dep.c
index 08c501d..a9a3386 100644
--- a/os_dep.c
+++ b/os_dep.c
@@ -32,17 +32,19 @@
     /* prototypes, so we have to include the top-level sigcontext.h to    */
     /* make sure the former gets defined to be the latter if appropriate. */
 #   include <features.h>
-#   if 2 <= __GLIBC__
-#     if 2 == __GLIBC__ && 0 == __GLIBC_MINOR__
-        /* glibc 2.1 no longer has sigcontext.h.  But signal.h          */
-        /* has the right declaration for glibc 2.1.                     */
-#       include <sigcontext.h>
-#     endif /* 0 == __GLIBC_MINOR__ */
-#   else /* __GLIBC__ < 2 */
-      /* libc5 doesn't have <sigcontext.h>: go directly with the kernel   */
-      /* one.  Check LINUX_VERSION_CODE to see which we should reference. */
-#     include <asm/sigcontext.h>
-#   endif /* __GLIBC__ < 2 */
+#   ifdef __GLIBC__
+#     if 2 <= __GLIBC__
+#       if 2 == __GLIBC__ && 0 == __GLIBC_MINOR__
+          /* glibc 2.1 no longer has sigcontext.h.  But signal.h          */
+          /* has the right declaration for glibc 2.1.                     */
+#         include <sigcontext.h>
+#       endif /* 0 == __GLIBC_MINOR__ */
+#     else /* __GLIBC__ < 2 */
+        /* libc5 doesn't have <sigcontext.h>: go directly with the kernel   */
+        /* one.  Check LINUX_VERSION_CODE to see which we should reference. */
+#       include <asm/sigcontext.h>
+#     endif /* __GLIBC__ < 2 */
+#   endif /* __GLIBC__ */
 # endif
 #endif /* LINUX && !POWERPC */
 
-- 
2.4.3