Skip to content

Atomic builtins for older toolchains

ricardopadilha edited this page Nov 4, 2014 · 1 revision

If you are getting error messsages like undefined reference to __sync_sub_and_fetch_4 while compiling for the DroboFS or DroboShare, it means the code is trying to use atomic builtins, which are not supported by GCC < 4.3.

Although it is possible to use alternative toolchains, the easiest way to work around this limitation is to create a small static library containing the missing functionality.

Assuming you have a cross-compiling VM, set the CC environment variable to the toolchain's GCC, and execute inside the VM:

cd ~/build
mkdir gcc-atomic
cd gcc-atomic
wget -O linux-atomic.c ";a=blob_plain;f=libgcc/config/arm/linux-atomic.c;hb=master"
libtool --tag=CC --mode=compile $CC -g -Os -MT linux-atomic.lo -MD -MP -MF linux-atomic.Tpo -c -o linux-atomic.lo linux-atomic.c
libtool --tag=CC --mode=link $CC -g -Os -o linux-atomic.lo

Then redefine your environment like this:

LDFLAGS="$LDFLAGS -L~/build/gcc-atomic"
LIBS="$LIBS -llinux-atomic"

Adapted from: