Bug#733632: mpv: FTBFS on mips/mipsel/powerpc/sparc: undefined reference to `__sync_add_and_fetch_8'

Aurelien Jarno aurel32 at debian.org
Mon Dec 30 14:22:38 UTC 2013


Package: mpv
Version: 0.3.0-1
Severity: serious
Tags: upstream patch
Justification: fails to build from source (but built successfully in the past)

mpv fails to build from source on mips/mipsel/powerpc/sparc with the
following error message:

| [243/243] linking -> build/mpv
| common/msg.c.10.o: In function `mp_msg_update_msglevels':
| /«PKGBUILDDIR»/build/../common/msg.c:243: undefined reference to `__sync_add_and_fetch_8'
| collect2: error: ld returned 1 exit status
| Waf: Leaving directory `/«PKGBUILDDIR»/build'
| Build failed

The problem is that the new version of mpv tries to uses 64-bit GCC
legacy atomic builtins [1], which are not all available on all
architectures.

The solution to this problem is to use the new GCC atomics, similar
to the C11 ones [2]. For that you need GCC 4.8, which is unfortunately
not the default on all architectures, and to link with libatomic. The
later library provides a fallback implementation if a given atomic bultin
is not available natively, which is usually the case for 64-bit atomics
on 32-bit platforms.

The patch below implements that and should fix the problem, though I
have only tested it on mips so far.

[1] http://gcc.gnu.org/onlinedocs/gcc/_005f_005fsync-Builtins.html
[2] http://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html

--- mpv-0.3.0/debian/control
+++ mpv-0.3.0/debian/control
@@ -45,7 +45,8 @@
  pkg-config,
  python,
  python-docutils,
- yasm
+ yasm,
+ gcc-4.8
 Standards-Version: 3.9.5
 Homepage: http://mpv.io/
 Vcs-Git: git://anonscm.debian.org/pkg-multimedia/mpv.git
--- mpv-0.3.0/debian/patches/04_gcc-atomic.diff
+++ mpv-0.3.0/debian/patches/04_gcc-atomic.diff
@@ -0,0 +1,21 @@
+--- mpv-0.3.0/compat/atomics.h
++++ mpv-0.3.0/compat/atomics.h
+@@ -20,4 +20,4 @@
+ // time. We only support a full memory barrier.
+ 
+ #define mp_memory_barrier()           __sync_synchronize()
+-#define mp_atomic_add_and_fetch(a, b) __sync_add_and_fetch(a, b)
++#define mp_atomic_add_and_fetch(a, b) __atomic_fetch_add(a, b, __ATOMIC_SEQ_CST)
+--- mpv-0.3.0/wscript
++++ mpv-0.3.0/wscript
+@@ -104,6 +104,10 @@ main_dependencies = [
+         'deps': [ 'pthreads' ],
+         'func': check_cc(lib='rt')
+     }, {
++        'name': 'libatomic',
++        'desc': 'linking with -latomic',
++        'func': check_cc(lib='atomic')
++    }, {
+         'name': '--iconv',
+         'desc': 'iconv',
+         'func': check_iconv,
--- mpv-0.3.0/debian/patches/series
+++ mpv-0.3.0/debian/patches/series
@@ -1,3 +1,4 @@
 01_desktop-path.patch
 02_fix-config-path.patch
 03_waf.patch
+04_gcc-atomic.diff
--- mpv-0.3.0/debian/rules
+++ mpv-0.3.0/debian/rules
@@ -1,5 +1,7 @@
 #!/usr/bin/make -f
 
+export CC=gcc-4.8
+
 %:
 	dh $@
 

-- System Information:
Debian Release: jessie/sid
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: mips (mips64)

Kernel: Linux 3.2.0-4-5kc-malta
Locale: LANG=fr_FR.UTF-8, LC_CTYPE=fr_FR.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash



More information about the pkg-multimedia-maintainers mailing list