After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 756078 - [PATCH] build failure with musl libc due to use of __libc_free/__libc_malloc
[PATCH] build failure with musl libc due to use of __libc_free/__libc_malloc
Status: RESOLVED FIXED
Product: gdk-pixbuf
Classification: Platform
Component: general
git master
Other Linux
: Normal normal
: ---
Assigned To: gdk-pixbuf-maint
gdk-pixbuf-maint
Depends on:
Blocks:
 
 
Reported: 2015-10-05 11:26 UTC by ncopa
Modified: 2015-10-07 01:40 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
0001-Run-only-pixbuf-lowmem-test-on-GNU-libc.patch (1.23 KB, patch)
2015-10-06 07:14 UTC, ncopa
accepted-commit_now Details | Review

Description ncopa 2015-10-05 11:26:22 UTC
since 2.31.6 gdk-pixbuf no longer builds with musl libc:

pixbuf-lowmem.o: In function `record_bytes':
pixbuf-lowmem.c:(.text+0x20): undefined reference to `__libc_free'
pixbuf-lowmem.o: In function `malloc':
pixbuf-lowmem.c:(.text+0x9f): undefined reference to `__libc_malloc'
pixbuf-lowmem.o: In function `calloc':
pixbuf-lowmem.c:(.text+0xc1): undefined reference to `__libc_malloc'
pixbuf-lowmem.o: In function `realloc':
pixbuf-lowmem.c:(.text+0x1b8): undefined reference to `__libc_realloc'
pixbuf-lowmem.o: In function `free':
pixbuf-lowmem.c:(.text+0x13c): undefined reference to `__libc_free'
collect2: error: ld returned 1 exit status
Makefile:1149: recipe for target 'pixbuf-lowmem' failed
make[3]: *** [pixbuf-lowmem] Error 1
make[3]: Leaving directory '/home/ncopa/aports/main/gdk-pixbuf/src/gdk-pixbuf-2.31.7/tests'
Makefile:961: recipe for target 'all' failed
make[2]: *** [all] Error 2

A wild guess is that commit https://git.gnome.org/browse/gdk-pixbuf/commit/?id=b07c3bffffefb8573ad9ffcf926c07cb9f93d08b introduced it.
Comment 1 ncopa 2015-10-05 11:34:02 UTC
The tests/Makefile.am has this:

...
if OS_LINUX
noinst_PROGRAMS +=                      \
        pixbuf-lowmem                   \
        $(NULL)
endif
...


which wrongly assumes that all Linux is GNU libc. It should test for GNU libc instead of linux kernel.
Comment 2 ncopa 2015-10-05 12:50:06 UTC
One possible way to fix it:

diff --git a/configure.ac b/configure.ac
index 8cba622..1c65c71 100644
--- a/configure.ac
+++ b/configure.ac
@@ -136,6 +136,12 @@ case $host in
     ;;
 esac
 
+AC_EGREP_CPP(yes,
+[#ifdef __GLIBC__
+  yes
+#endif
+], is_gnu_libc=yes, is_gnu_libc=no)
+
 if test "$os_win32" = "yes"; then
   if test x$enable_static = xyes -o x$enable_static = x; then
     AC_MSG_WARN([Disabling static library build, must build as DLL on Windows.])
@@ -170,6 +176,7 @@ AM_CONDITIONAL(PLATFORM_WIN32, test "$platform_win32" = "yes")
 AM_CONDITIONAL(OS_WIN32, test "$os_win32" = "yes")
 AM_CONDITIONAL(OS_UNIX, test "$os_win32" != "yes")
 AM_CONDITIONAL(OS_LINUX, test "$os_linux" = "yes")
+AM_CONDITIONAL(PLATFORM_GNU_LIBC, test "$is_gnu_libc" = "yes")
 
 if test "$os_win32" = "yes"; then
   AC_CHECK_TOOL(WINDRES, windres, no)
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 1f09711..1a3288d 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -21,7 +21,7 @@ noinst_PROGRAMS +=                    \
        pixbuf-random                   \
        $(NULL)
 
-if OS_LINUX
+if PLATFORM_GNU_LIBC
 noinst_PROGRAMS +=                     \
        pixbuf-lowmem                   \
        $(NULL)
Comment 3 ncopa 2015-10-05 13:04:17 UTC
Other option is to test for the __libc_* malloc functions using AC_LINK_IFELSE:

diff --git a/configure.ac b/configure.ac
index 8cba622..71bfad7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -136,6 +136,15 @@ case $host in
     ;;
 esac
 
+AC_LINK_IFELSE([AC_LANG_SOURCE([[
+extern void *__libc_malloc (size_t size);
+extern void *__libc_realloc (void *mem, size_t size);
+extern void *__libc_free (void *mem);
+int main(void) {
+  return __libc_malloc(0) || __libc_realloc(0) || __libc_free(0);
+}
+]])],[have_glibc_malloc="yes"], [have_glibc_malloc="no"])
+
 if test "$os_win32" = "yes"; then
   if test x$enable_static = xyes -o x$enable_static = x; then
     AC_MSG_WARN([Disabling static library build, must build as DLL on Windows.])
@@ -170,6 +179,7 @@ AM_CONDITIONAL(PLATFORM_WIN32, test "$platform_win32" = "yes")
 AM_CONDITIONAL(OS_WIN32, test "$os_win32" = "yes")
 AM_CONDITIONAL(OS_UNIX, test "$os_win32" != "yes")
 AM_CONDITIONAL(OS_LINUX, test "$os_linux" = "yes")
+AM_CONDITIONAL(HAVE_GLIBC_MALLOC, test "$have_glibc_malloc" = "yes")
 
 if test "$os_win32" = "yes"; then
   AC_CHECK_TOOL(WINDRES, windres, no)
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 1f09711..9655e6a 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -21,7 +21,7 @@ noinst_PROGRAMS +=                    \
        pixbuf-random                   \
        $(NULL)
 
-if OS_LINUX
+if HAVE_GLIBC_MALLOC
 noinst_PROGRAMS +=                     \
        pixbuf-lowmem                   \
        $(NULL)
Comment 4 Matthias Clasen 2015-10-05 23:21:08 UTC
Im not thrilled to add configure nonsense to support building with alternative libc's. I'd rather take a patch that always builds the offending test case and use some existing glibc marker define to protect glibc specific parts. In this case, we should probably just skip the test
Comment 5 ncopa 2015-10-06 07:10:04 UTC
There are already configure nonsense to support building with alternative libc's (except that the current configure nonsense wrongly assumes that Linux is the only OS with GNU libc and that GNU libc is the only libc for Linux).

Here is a third option with configure nonense removed:

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 1f09711..2a0325a 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -19,13 +19,8 @@ LDADD = \
 noinst_PROGRAMS +=                     \
        pixbuf-read                     \
        pixbuf-random                   \
-       $(NULL)
-
-if OS_LINUX
-noinst_PROGRAMS +=                     \
        pixbuf-lowmem                   \
        $(NULL)
-endif
 
 test_programs =                        \
        animation                       \
diff --git a/tests/pixbuf-lowmem.c b/tests/pixbuf-lowmem.c
index ae71788..9e9571f 100644
--- a/tests/pixbuf-lowmem.c
+++ b/tests/pixbuf-lowmem.c
@@ -24,6 +24,7 @@
 #include <time.h>
 #include <string.h>
 
+#ifdef __GLIBC__
 #define PRETEND_MEM_SIZE (16 * 1024 * 1024)
 #define REMAINING_MEM_SIZE 100000
 
@@ -225,3 +226,10 @@ main (int argc, char **argv)
   
   return 0;
 }
+#else
+int
+main (int argc, char **argv)
+{
+       return 0;
+}
+#endif
Comment 6 ncopa 2015-10-06 07:14:30 UTC
Created attachment 312710 [details] [review]
0001-Run-only-pixbuf-lowmem-test-on-GNU-libc.patch

Patch that you can git am.
Comment 7 Matthias Clasen 2015-10-06 13:44:41 UTC
Review of attachment 312710 [details] [review]:

Thanks, thats what I had in mind. I'll pick this up for the next release