build failure on ARM linux

I’m seeing this new build failure, starting some time yesterday on ARM:

make[3]: Entering directory /home/nlewycky/llvm/tools/llvmc/driver' llvm[3]: Linking Debug executable llvmc g++ -DLLVMC_BUILTIN_PLUGIN_1=Base -DLLVMC_BUILTIN_PLUGIN_2=Clang -I/home/nlewycky/llvm/include -I/home/nlewycky/llvm/tools/llvmc/driver -D_DEBUG -D_GNU_SOURCE -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -g -fPIC -Woverloaded-virtual -pedantic -Wno-long-long -Wall -W -Wno-unused-parameter -Wwrite-strings -lCompilerDriver -g -Wl,-R -Wl,/home/nlewycky/llvm/Debug/bin -Wl,-export-dynamic -L/home/nlewycky/llvm/Debug/lib -L/home/nlewycky/llvm/Debug/lib -o /home/nlewycky/llvm/Debug/bin/llvmc /home/nlewycky/llvm/tools/llvmc/driver/Debug/Main.o -lplugin_llvmc_Base -lplugin_llvmc_Clang \ -lpthread -ldl -lm /usr/bin/ld: /home/nlewycky/llvm/Debug/bin/llvmc: hidden symbol __sync_val_compare_and_swap_4’ in /usr/lib/gcc/arm-linux-gnueabi/4.3.3/libgcc.a(linux-atomic.o) is referenced by DSO
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: ld returned 1 exit status
make[3]: *** [/home/nlewycky/llvm/Debug/bin/llvmc] Error 1

This is with LLVM being built by the system compiler (GCC 4.3.3-10 Debian). I’m not sure what to make of this. Would it be due to the atomics used for mutexes?

Nick

Nick Lewycky wrote:

I'm seeing this new build failure, starting some time yesterday on ARM:

make[3]: Entering directory `/home/nlewycky/llvm/tools/llvmc/driver'
llvm[3]: Linking Debug executable llvmc
g++ -DLLVMC_BUILTIN_PLUGIN_1=Base -DLLVMC_BUILTIN_PLUGIN_2=Clang -I/home/nlewycky/llvm/include -I/home/nlewycky/llvm/tools/llvmc/driver -D_DEBUG -D_GNU_SOURCE -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -g -fPIC -Woverloaded-virtual -pedantic -Wno-long-long -Wall -W -Wno-unused-parameter -Wwrite-strings -lCompilerDriver -g -Wl,-R -Wl,/home/nlewycky/llvm/Debug/bin -Wl,-export-dynamic -L/home/nlewycky/llvm/Debug/lib -L/home/nlewycky/llvm/Debug/lib -o /home/nlewycky/llvm/Debug/bin/llvmc /home/nlewycky/llvm/tools/llvmc/driver/Debug/Main.o -lplugin_llvmc_Base -lplugin_llvmc_Clang \
           -lpthread -ldl -lm
/usr/bin/ld: /home/nlewycky/llvm/Debug/bin/llvmc: hidden symbol `__sync_val_compare_and_swap_4' in /usr/lib/gcc/arm-linux-gnueabi/4.3.3/libgcc.a(linux-atomic.o) is referenced by DSO
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: ld returned 1 exit status
make[3]: *** [/home/nlewycky/llvm/Debug/bin/llvmc] Error 1

This is with LLVM being built by the system compiler (GCC 4.3.3-10
Debian). I'm not sure what to make of this. Would it be due to the
atomics used for mutexes?

Yes. It's just a matter of defining __sync_val_compare_and_swap_4:

http://gcc.gnu.org/svn/gcc/trunk/gcc/config/arm/linux-atomic.c

Andrew.

I’m getting a different failure in llvmc link on Leopard mac builds (Debug and Release):

llvm[1]: Linking Release executable llvmc (without symbols)
g++ -DLLVMC_BUILTIN_PLUGIN_1=Base -DLLVMC_BUILTIN_PLUGIN_2=Clang -I/Users/john/work/projects/comp/llvm-work/exp/build/llvm-check/include -I/Users/john/work/projects/comp/llvm-work/exp/build/llvm-check/tools/llvmc/driver -I/Users/john/work/projects/comp/llvm-work/llvm/include -I/Users/john/work/projects/comp/llvm-work/llvm/tools/llvmc/driver -D_DEBUG -D_GNU_SOURCE -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -O3 -fno-common -Woverloaded-virtual -m32 -pedantic -Wno-long-long -Wall -W -Wno-unused-parameter -Wwrite-strings -lCompilerDriver -O3 -L/Users/john/work/projects/comp/llvm-work/exp/build/llvm-check/Release/lib -L/Users/john/work/projects/comp/llvm-work/exp/build/llvm-check/Release/lib -o /Users/john/work/projects/comp/llvm-work/exp/build/llvm-check/Release/bin/llvmc /Users/john/work/projects/comp/llvm-work/exp/build/llvm-check/tools/llvmc/driver/Release/Main.o -lplugin_llvmc_Base -lplugin_llvmc_Clang
-lpthread -lffi -lm
Undefined symbols:
“llvmc::ForceLinkageClang()”, referenced from:
llvmc::ForceLinkage() in Main.o
_main in Main.o
“llvmc::ForceLinkageBase()”, referenced from:
llvmc::ForceLinkage() in Main.o
_main in Main.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make[1]: *** [/Users/john/work/projects/comp/llvm-work/exp/build/llvm-check/Release/bin/llvmc] Error 1
make: *** [all] Error 1

2009/6/30 Andrew Haley <aph@redhat.com>

Nick Lewycky wrote:

I’m seeing this new build failure, starting some time yesterday on ARM:

make[3]: Entering directory /home/nlewycky/llvm/tools/llvmc/driver' llvm[3]: Linking Debug executable llvmc g++ -DLLVMC_BUILTIN_PLUGIN_1=Base -DLLVMC_BUILTIN_PLUGIN_2=Clang -I/home/nlewycky/llvm/include -I/home/nlewycky/llvm/tools/llvmc/driver -D_DEBUG -D_GNU_SOURCE -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -g -fPIC -Woverloaded-virtual -pedantic -Wno-long-long -Wall -W -Wno-unused-parameter -Wwrite-strings -lCompilerDriver -g -Wl,-R -Wl,/home/nlewycky/llvm/Debug/bin -Wl,-export-dynamic -L/home/nlewycky/llvm/Debug/lib -L/home/nlewycky/llvm/Debug/lib -o /home/nlewycky/llvm/Debug/bin/llvmc /home/nlewycky/llvm/tools/llvmc/driver/Debug/Main.o -lplugin_llvmc_Base -lplugin_llvmc_Clang \ -lpthread -ldl -lm /usr/bin/ld: /home/nlewycky/llvm/Debug/bin/llvmc: hidden symbol __sync_val_compare_and_swap_4’ in /usr/lib/gcc/arm-linux-gnueabi/4.3.3/libgcc.a(linux-atomic.o) is referenced by DSO
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: ld returned 1 exit status
make[3]: *** [/home/nlewycky/llvm/Debug/bin/llvmc] Error 1

This is with LLVM being built by the system compiler (GCC 4.3.3-10
Debian). I’m not sure what to make of this. Would it be due to the
atomics used for mutexes?

Yes. It’s just a matter of defining __sync_val_compare_and_swap_4:

http://gcc.gnu.org/svn/gcc/trunk/gcc/config/arm/linux-atomic.c

The program is supposed to define it? LLVM doesn’t directly call __sync_val_compare_and_swap_4, so either the system headers #define something else to it or gcc lowers another call to that. In either case, why is it declared HIDDEN?

Nick

Nick Lewycky wrote:

2009/6/30 Andrew Haley <aph@redhat.com <mailto:aph@redhat.com>>

    Nick Lewycky wrote:
    > I'm seeing this new build failure, starting some time yesterday on
    ARM:

    Yes. It's just a matter of defining __sync_val_compare_and_swap_4:

    http://gcc.gnu.org/svn/gcc/trunk/gcc/config/arm/linux-atomic.c

The program is supposed to define it? LLVM doesn't directly call
__sync_val_compare_and_swap_4, so either the system headers #define
something else to it or gcc lowers another call to that.

gcc lowers atomic operations to that. It's part of libgcc now.

In either case, why is it declared HIDDEN?

I'm not sure.

Andrew.

llvm/lib/System/Atomic.cpp contains the call to __sync_val_compare_and_swap that lowers to the missing __sync_val_compare_and_swap_4 GCC intrinsic.

The same file contains several other __sync_* calls and all these has to be implemented if we want to be able to compile llvm on linux/ARM with GCC versions below < 4.4

xerxes@labbserver:~/llvm$ grep _sync lib/*/*
lib/System/Atomic.cpp: __sync_synchronize();
lib/System/Atomic.cpp: return __sync_val_compare_and_swap(ptr, old_value, new_value);
lib/System/Atomic.cpp: return __sync_add_and_fetch(ptr, 1);
lib/System/Atomic.cpp: return __sync_sub_and_fetch(ptr, 1);
lib/System/Atomic.cpp: return __sync_add_and_fetch(ptr, val);

Cheers
Xerxes

Andrew Haley skrev:

Andrew Haley wrote:

Nick Lewycky wrote:

2009/6/30 Andrew Haley <aph@redhat.com <mailto:aph@redhat.com>>

    Nick Lewycky wrote:
    > I'm seeing this new build failure, starting some time yesterday on
    ARM:

    Yes. It's just a matter of defining __sync_val_compare_and_swap_4:

    http://gcc.gnu.org/svn/gcc/trunk/gcc/config/arm/linux-atomic.c

The program is supposed to define it? LLVM doesn't directly call
__sync_val_compare_and_swap_4, so either the system headers #define
something else to it or gcc lowers another call to that.

gcc lowers atomic operations to that. It's part of libgcc now.

In either case, why is it declared HIDDEN?

I'm not sure.

This is a known bug in gcc: see 40133 – exception propagation support not enabled in libstdc++ 4.4 on {armeabi,hppa}-linux

We're trying to get it fixed.

Andrew.

Why is his configure not catching this? It tests for the linkability of these functions on the target arch, and should be detecting their absence if that is actually the case.

--Owen

Den 2009-07-01 17:43, Owen Anderson skrev:

Why is his configure not catching this? It tests for the linkability of these functions on the target arch, and should be detecting their absence if that is actually the case.

--Owen

After some testing today i can assure that __sync_val_compare_and_swap do exists and are implemented on the ARM/Linux system with gcc 4.3.3, configure should have no problem finding the implementations.

I have written a small to test the __sync_val_compare_and_swap implementation and to demonstrate one corner-case where the __sync_val_compare_and_swap are simply not linked into a shared library when using g++ to do the linking, it also outputs the same error like the broken llvm compilation.
My testcase for ARM can be downloaded here: http://labb.zafena.se/llvm-test/atomic_hidden_symbol_testcase.tar.gz

Output from the testcase when run on native ARM hardware, Ubuntu Jaunty on a sheeva plug, with gcc 4.3.3 :
xerxes@debian:~/test/atomic_hidden_symbol_testcase$ ./compileandtest.sh
fails using g++ to create the shared library
/usr/bin/ld: my_atomic_main: hidden symbol `__sync_val_compare_and_swap_4' in /usr/lib/gcc/arm-linux-gnueabi/4.3.3/libgcc.a(linux-atomic.o) is referenced by DSO
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: ld returned 1 exit status
./compileandtest.sh: line 6: ./my_atomic_main: No such file or directory

works using gcc to create the shared library
start of test
before b = CAFEBABE
testing __sync_val_compare_and_swap
after b = C0FFEE11 c = CAFEBABE __sync_val_compare_and_swap works!

So to compare with the failed compile of llvm:
Something fishy went wrong during the linking of libCompileDriver.so since that shared library got __sync_val_compare_and_swap_4 left unreferenced like a .o file.
Unfortunally I have not been able to do a sucessfull linking of llvm's libCompileDriver.so with gcc like what i did to solve my testcase, the symbols are still not linked in.

Should libCompileDriver be compiled and linked as a .so ? it are the only library in the llvm suite that gets linked to a shared library...

llvm/lib/System/Atomic.cpp contains the call to
__sync_val_compare_and_swap that lowers to the missing
__sync_val_compare_and_swap_4 GCC intrinsic.

The same file contains several other __sync_* calls and all these has
to be implemented if we want to be able to compile llvm on linux/ARM
with GCC versions below < 4.4

I got this one wrong: GCC 4.3.3 should be OK to compile llvm on ARM/Linux since it do have the __sync_* call implementation,

Like Andrew have pointed out what we are observing are probably the GCC bug that makes ARM fail to link in __sync_* when creating shared librarys.

Cheers
Xerxes

Andrew Haley wrote:

Andrew Haley wrote:

Nick Lewycky wrote:

2009/6/30 Andrew Haley <aph@redhat.com <mailto:aph@redhat.com>>

    Nick Lewycky wrote:
    > I'm seeing this new build failure, starting some time yesterday on
    ARM:

    Yes. It's just a matter of defining __sync_val_compare_and_swap_4:

    http://gcc.gnu.org/svn/gcc/trunk/gcc/config/arm/linux-atomic.c

The program is supposed to define it? LLVM doesn't directly call
__sync_val_compare_and_swap_4, so either the system headers #define
something else to it or gcc lowers another call to that.

gcc lowers atomic operations to that. It's part of libgcc now.

In either case, why is it declared HIDDEN?

I'm not sure.

This is a known bug in gcc: see 40133 – exception propagation support not enabled in libstdc++ 4.4 on {armeabi,hppa}-linux

We're trying to get it fixed.

Thanks for the reference! I've added myself to the cc.

Nick