Compilation error while cross compiling LLVM for ARM

Hi,

i am a newbie to llvm architecture. i have been trying to port llvm on ARM target. i am using the following configuration for cross compiling llvm.

…/llvm/configure --host=arm-linux --target=arm-linux --build=i686-linux --prefix=/opt/llvm-arm/ --enable-optimized --disable-debug
–disable-expensive-checks --disable-doxygen
–disable-threads --enable-targets=cbe,cpp,arm

using this configuration i am facing the following compilation error. pls help me how to resolve this error…

make[1]: Entering directory /home/prasanth/LLVM_ARM/llvm-target/obj-new/lib/System'* *llvm[1]: Compiling Alarm.cpp for Release build* *llvm[1]: Compiling Atomic.cpp for Release build* *llvm[1]: Compiling Disassembler.cpp for Release build* *llvm[1]: Compiling DynamicLibrary.cpp for Release build* *llvm[1]: Compiling Errno.cpp for Release build* *llvm[1]: Compiling Host.cpp for Release build* *llvm[1]: Compiling IncludeFile.cpp for Release build* *llvm[1]: Compiling Memory.cpp for Release build* <i>/home/prasanth/LLVM_ARM/llvm-target/llvm/lib/System/Memory.cpp: In static member function ‘static void llvm::sys::Memory::InvalidateInstructionCache(const void*, size_t)’:</i> */home/prasanth/LLVM_ARM/llvm-target/llvm/lib/System/Memory.cpp:67: error: ‘__clear_cache’ was not declared in this scope* <i>make[1]: *** [/home/prasanth/LLVM_ARM/llvm-target/obj-new/lib/System/Release/Memory.o] Error 1</i> *make[1]: Leaving directory /home/prasanth/LLVM_ARM/llvm-target/obj-new/lib/System’
make: *** [all] Error 1

i can able to compile by commenting the line in Memory.cpp but i am not sure whether it will affect anything while running llvm on target.
After cross-compilation i copied the binaries to target and i tried to compile and run a simple helloworld.c application. As clang requires a working gcc on target i used to “-ccc-clang-archs” options to skip the need for gcc on target. But still i am getting the following error.

# TMPDIR=/dtv/usb/sda …/bin/clang -ccc-clang-archs arm hello.c -v -I/dtv/usb/sda/LLVM/include
clang version 1.0 (https://llvm.org/svn/llvm-project/cfe/branches/release_26 exported)
Target: arm-unknown-linux-gnu
Thread model: posix
“/dtv/usb/sda/LLVM/llvm-2.6-arm/bin/…/libexec/clang-cc” -triple arm-unknown-linux-gnu -S -disable-free -main-file-name hello.c --relocation-mc
clang-cc version 1.0 based upon llvm 2.6 hosted on arm-unknown-linux-gnu
ignoring nonexistent directory “/usr/local/include”
ignoring nonexistent directory “/usr/include”
ignoring nonexistent directory “/System/Library/Frameworks”
ignoring nonexistent directory “/Library/Frameworks”
#include “…” search starts here:
#include <…> search starts here:
/dtv/usb/sda/LLVM/include
/dtv/usb/sda/LLVM/llvm-2.6-arm/lib/clang/1.0/include
End of search list.
clang-cc: /home/prasanth/LLVM_ARM/llvm-target/llvm-2.6/include/llvm/ADT/ilist.h:197: typename bidirectional_iterator<NodeTy, int>::reference ll.
0 clang-cc 0x00cd314c
Stack dump:
0. Program arguments: /dtv/usb/sda/LLVM/llvm-2.6-arm/bin/…/libexec/clang-cc -triple arm-unknown-linux-gnu -S -disable-free -main-file-nam
1. parser at end of file
2. Code generation
3. Running pass ‘ARM Instruction Selection’ on function ‘@main
clang: error: compiler command failed due to signal 6 (use -v to see invocation)

Prasanth J skrev:

Hi,

i am a newbie to llvm architecture. i have been trying to port llvm on
ARM target. i am using the following configuration for cross compiling
llvm.

../llvm/configure --host=arm-linux --target=arm-linux
--build=i686-linux --prefix=/opt/llvm-arm/ --enable-optimized
--disable-debug \
--disable-expensive-checks --disable-doxygen \
--disable-threads --enable-targets=cbe,cpp,arm

using this configuration i am facing the following compilation error.
pls help me how to resolve this error..

/make[1]: Entering directory
`/home/prasanth/LLVM_ARM/llvm-target/obj-new/lib/System'
llvm[1]: Compiling Alarm.cpp for Release build
llvm[1]: Compiling Atomic.cpp for Release build
llvm[1]: Compiling Disassembler.cpp for Release build
llvm[1]: Compiling DynamicLibrary.cpp for Release build
llvm[1]: Compiling Errno.cpp for Release build
llvm[1]: Compiling Host.cpp for Release build
llvm[1]: Compiling IncludeFile.cpp for Release build
llvm[1]: Compiling Memory.cpp for Release build
/home/prasanth/LLVM_ARM/llvm-target/llvm/lib/System/Memory.cpp: In
static member function ‘static void
llvm::sys::Memory::InvalidateInstructionCache(const void*, size_t)’:
/home/prasanth/LLVM_ARM/llvm-target/llvm/lib/System/Memory.cpp:67:
error: ‘__clear_cache’ was not declared in this scope
make[1]: ***
[/home/prasanth/LLVM_ARM/llvm-target/obj-new/lib/System/Release/Memory.o]
Error 1
make[1]: Leaving directory
`/home/prasanth/LLVM_ARM/llvm-target/obj-new/lib/System'
make: *** [all] Error 1//

/i can able to compile by commenting the line in Memory.cpp but i am
not sure whether it will affect anything while running llvm on target.
After cross-compilation i copied the binaries to target and i tried to
compile and run a simple helloworld.c application. As clang requires a
working gcc on target i used to "-ccc-clang-archs" options to skip the
need for gcc on target. But still i am getting the following error.

By commenting out that line will make your llvm version crash
sporadically since you would recreate llvm PR4960 if using the llvm JIT.
http://llvm.org/bugs/show_bug.cgi?id=4960

__clear_cache are needed to clear the instructioncache after jitting a
function and this gcc builtin are found in gcc 4.3.3 and later or
CodeSourcery's 2007Q3/2008Q1 compiler releases and later.

Try updating you cross compiler!

Cheers
Xerxes

Hi all,
with reference to the reply below, I downloaded toolchain from codesourcery (arm-2009q1-203-arm-none-linux-gnueabi) with gcc 4.3.3… when i compile llvm+clang with this toolchain i am getting the following error

make[4]: Entering directory /home/prasanth/LLVM_ARM/llvm-with-armgcc433/llvm-obj/tools/clang/tools/c-index-test' llvm[4]: Linking Release executable c-index-test (without symbols) /home/prasanth/arm-toolchain/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.3/../../../../arm-none-linux-gnueabi/bin/ld: /home/prasanth/LLVM_ARM/llvm-with-armgcc433/llvm-obj/Release/bin/c-index-test: hidden symbol __sync_val_compare_and_swap_4’ in /home/prasanth/arm-toolchain/bin/…/lib/gcc/arm-none-linux-gnueabi/4.3.3/libgcc.a(linux-atomic.o) is referenced by DSO
/home/prasanth/arm-toolchain/bin/…/lib/gcc/arm-none-linux-gnueabi/4.3.3/…/…/…/…/arm-none-linux-gnueabi/bin/ld: final link failed: Nonrepresentable section on output
collect2: ld returned 1 exit status
make[4]: *** [/home/prasanth/LLVM_ARM/llvm-with-armgcc433/llvm-obj/Release/bin/c-index-test] Error 1
make[4]: Leaving directory /home/prasanth/LLVM_ARM/llvm-with-armgcc433/llvm-obj/tools/clang/tools/c-index-test' make[3]: *** [all] Error 1 make[3]: Leaving directory /home/prasanth/LLVM_ARM/llvm-with-armgcc433/llvm-obj/tools/clang/tools’
make[2]: *** [all] Error 1
make[2]: Leaving directory /home/prasanth/LLVM_ARM/llvm-with-armgcc433/llvm-obj/tools/clang' make[1]: *** [clang/.makeall] Error 2 make[1]: Leaving directory /home/prasanth/LLVM_ARM/llvm-with-armgcc433/llvm-obj/tools’
make: *** [all] Error 1

can anyone please tell me why am i getting this error and how can i resolve this?

Thanks and Regards,
Prasanth J

Prasanth J wrote:

Hi all,
with reference to the reply below, I downloaded toolchain from
codesourcery (arm-2009q1-203-arm-none-linux-gnueabi) with gcc 4.3.3...
when i compile llvm+clang with this toolchain i am getting the
following error

make[4]: Entering directory
`/home/prasanth/LLVM_ARM/llvm-with-armgcc433/llvm-obj/tools/clang/tools/c-index-test'
llvm[4]: Linking Release executable c-index-test (without symbols)
/home/prasanth/arm-toolchain/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.3/../../../../arm-none-linux-gnueabi/bin/ld:
/home/prasanth/LLVM_ARM/llvm-with-armgcc433/llvm-obj/Release/bin/c-index-test:
hidden symbol `__sync_val_compare_and_swap_4' in
/home/prasanth/arm-toolchain/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.3/libgcc.a(linux-atomic.o)
is referenced by DSO
/home/prasanth/arm-toolchain/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.3/../../../../arm-none-linux-gnueabi/bin/ld:
final link failed: Nonrepresentable section on output
collect2: ld returned 1 exit status
make[4]: ***
[/home/prasanth/LLVM_ARM/llvm-with-armgcc433/llvm-obj/Release/bin/c-index-test]
Error 1
make[4]: Leaving directory
`/home/prasanth/LLVM_ARM/llvm-with-armgcc433/llvm-obj/tools/clang/tools/c-index-test'
make[3]: *** [all] Error 1
make[3]: Leaving directory
`/home/prasanth/LLVM_ARM/llvm-with-armgcc433/llvm-obj/tools/clang/tools'
make[2]: *** [all] Error 1
make[2]: Leaving directory
`/home/prasanth/LLVM_ARM/llvm-with-armgcc433/llvm-obj/tools/clang'
make[1]: *** [clang/.makeall] Error 2
make[1]: Leaving directory
`/home/prasanth/LLVM_ARM/llvm-with-armgcc433/llvm-obj/tools'
make: *** [all] Error 1

can anyone please tell me why am i getting this error and how can i
resolve this?

Thanks and Regards,
Prasanth J

You get this linking error because the code contains a gcc atomic
intrinsic calls using __sync_val_compare_and_swap . These are GCC
built-ins and have only been implemented on ARM using GCC 4.4.
http://gcc.gnu.org/onlinedocs/gcc-4.4.2/gcc/Atomic-Builtins.html
If you want to use GCC 4.3.3 then you have to implement the
__sync_val_compare_and_swap_4 function yourself.

Ubuntu Jaunty ARM toolchains have been patched to contains the atomic
intrinsics support in GCC 4.3.3

So to solve this issue do one of the following:
a) update your code sourcery cross compiler to arm-2009q3 that are using
GCC 4.4
b) use the Ubuntu gcc 4.3.3 provided toolchain (i use this when
compiling llvm natively on a arm machine without cross compilation)
c) implement the __sync_val_compare_and_swap_4 function and patch llvm
to enable compilation using older toolchains.

Cheers
Xerxes

Hi,

As you said i downloaded arm toolchain from codesourcery(2009q3 with gcc 4.4.1 version)… if i use this toolchain i am getting the following error…

make[2]: Entering directory /home/prasanth/LLVM_ARM/llvm-with-armgcc441/llvm-obj/lib/Analysis' llvm[2]: Compiling LoopPass.cpp for Release build if arm-none-linux-gnueabi-g++ -I/home/prasanth/LLVM_ARM/llvm-with-armgcc433/llvm/include -I/home/prasanth/LLVM_ARM/llvm-with-armgcc433/llvm/lib/Analysis -I/home/prasanth/LLVM_ARM/llvm-with-armgcc441/llvm-obj/include -I/home/prasanth/LLVM_ARM/llvm-with-armgcc441/llvm-obj/lib/Analysis -D_DEBUG -D_GNU_SOURCE -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -O2 -fomit-frame-pointer -fno-exceptions -fPIC -Woverloaded-virtual -pedantic -Wno-long-long -Wall -W -Wno-unused-parameter -Wwrite-strings -c -MMD -MP -MF "/home/prasanth/LLVM_ARM/llvm-with-armgcc441/llvm-obj/lib/Analysis/Release/LoopPass.d.tmp" -MT "/home/prasanth/LLVM_ARM/llvm-with-armgcc441/llvm-obj/lib/Analysis/Release/LoopPass.o" -MT "/home/prasanth/LLVM_ARM/llvm-with-armgcc441/llvm-obj/lib/Analysis/Release/LoopPass.d" /home/prasanth/LLVM_ARM/llvm-with-armgcc433/llvm/lib/Analysis/LoopPass.cpp -o /home/prasanth/LLVM_ARM/llvm-with-armgcc441/llvm-obj/lib/Analysis/Release/LoopPass.o ; \ then /bin/mv -f "/home/prasanth/LLVM_ARM/llvm-with-armgcc441/llvm-obj/lib/Analysis/Release/LoopPass.d.tmp" "/home/prasanth/LLVM_ARM/llvm-with-armgcc441/llvm-obj/lib/Analysis/Release/LoopPass.d"; else /bin/rm "/home/prasanth/LLVM_ARM/llvm-with-armgcc441/llvm-obj/lib/Analysis/Release/LoopPass.d.tmp"; exit 1; fi /home/prasanth/LLVM_ARM/llvm-with-armgcc433/llvm/lib/Analysis/LoopPass.cpp: In member function 'void llvm::LPPassManager::deleteLoopFromQueue(llvm::Loop*)': /home/prasanth/LLVM_ARM/llvm-with-armgcc433/llvm/lib/Analysis/LoopPass.cpp:100: internal compiler error: Segmentation fault Please submit a full bug report, with preprocessed source if appropriate. See <[https://support.codesourcery.com/GNUToolchain/](https://support.codesourcery.com/GNUToolchain/)> for instructions. /bin/rm: cannot remove /home/prasanth/LLVM_ARM/llvm-with-armgcc441/llvm-obj/lib/Analysis/Release/LoopPass.d.tmp’: No such file or directory
make[2]: *** [/home/prasanth/LLVM_ARM/llvm-with-armgcc441/llvm-obj/lib/Analysis/Release/LoopPass.o] Error 1
make[2]: Leaving directory /home/prasanth/LLVM_ARM/llvm-with-armgcc441/llvm-obj/lib/Analysis' make[1]: *** [Analysis/.makeall] Error 2 make[1]: Leaving directory /home/prasanth/LLVM_ARM/llvm-with-armgcc441/llvm-obj/lib’
make: *** [all] Error 1

please let me know how should i resolve this error…

Thanks and Regards,
Prasanth J

Prasanth J wrote:

Hi,

As you said i downloaded arm toolchain from codesourcery(2009q3 with
gcc 4.4.1 version).. if i use this toolchain i am getting the
following error..

make[2]: Entering directory
`/home/prasanth/LLVM_ARM/llvm-with-armgcc441/llvm-obj/lib/Analysis'
llvm[2]: Compiling LoopPass.cpp for Release build
if arm-none-linux-gnueabi-g++
-I/home/prasanth/LLVM_ARM/llvm-with-armgcc433/llvm/include
-I/home/prasanth/LLVM_ARM/llvm-with-armgcc433/llvm/lib/Analysis
-I/home/prasanth/LLVM_ARM/llvm-with-armgcc441/llvm-obj/include
-I/home/prasanth/LLVM_ARM/llvm-with-armgcc441/llvm-obj/lib/Analysis
-D_DEBUG -D_GNU_SOURCE -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS
-O2 -fomit-frame-pointer -fno-exceptions -fPIC -Woverloaded-virtual
-pedantic -Wno-long-long -Wall -W -Wno-unused-parameter
-Wwrite-strings -c -MMD -MP -MF
"/home/prasanth/LLVM_ARM/llvm-with-armgcc441/llvm-obj/lib/Analysis/Release/LoopPass.d.tmp"
-MT
"/home/prasanth/LLVM_ARM/llvm-with-armgcc441/llvm-obj/lib/Analysis/Release/LoopPass.o"
-MT
"/home/prasanth/LLVM_ARM/llvm-with-armgcc441/llvm-obj/lib/Analysis/Release/LoopPass.d"
/home/prasanth/LLVM_ARM/llvm-with-armgcc433/llvm/lib/Analysis/LoopPass.cpp
-o
/home/prasanth/LLVM_ARM/llvm-with-armgcc441/llvm-obj/lib/Analysis/Release/LoopPass.o
; \
            then /bin/mv -f
"/home/prasanth/LLVM_ARM/llvm-with-armgcc441/llvm-obj/lib/Analysis/Release/LoopPass.d.tmp"
"/home/prasanth/LLVM_ARM/llvm-with-armgcc441/llvm-obj/lib/Analysis/Release/LoopPass.d";
else /bin/rm
"/home/prasanth/LLVM_ARM/llvm-with-armgcc441/llvm-obj/lib/Analysis/Release/LoopPass.d.tmp";
exit 1; fi
/home/prasanth/LLVM_ARM/llvm-with-armgcc433/llvm/lib/Analysis/LoopPass.cpp:
In member function 'void
llvm::LPPassManager::deleteLoopFromQueue(llvm::Loop*)':
/home/prasanth/LLVM_ARM/llvm-with-armgcc433/llvm/lib/Analysis/LoopPass.cpp:100:
internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <https://support.codesourcery.com/GNUToolchain/> for instructions.
/bin/rm: cannot remove
`/home/prasanth/LLVM_ARM/llvm-with-armgcc441/llvm-obj/lib/Analysis/Release/LoopPass.d.tmp':
No such file or directory
make[2]: ***
[/home/prasanth/LLVM_ARM/llvm-with-armgcc441/llvm-obj/lib/Analysis/Release/LoopPass.o]
Error 1
make[2]: Leaving directory
`/home/prasanth/LLVM_ARM/llvm-with-armgcc441/llvm-obj/lib/Analysis'
make[1]: *** [Analysis/.makeall] Error 2
make[1]: Leaving directory
`/home/prasanth/LLVM_ARM/llvm-with-armgcc441/llvm-obj/lib'
make: *** [all] Error 1

please let me know how should i resolve this error...

Thanks and Regards,
Prasanth J

Make sure you are running a clean build.
If you are then follow the suggested instructions in the error message
and file a bugreport for your toolchain to codesourcery.

/home/prasanth/LLVM_ARM/llvm-with-armgcc433/llvm/lib/Analysis/LoopPass.cpp:100:
internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <https://support.codesourcery.com/GNUToolchain/> for instructions.

Cheers
Xerxes

Hi,

I can able to compile LLVM using armgcc_4.3.3 (codesourcery2009q1…)… but when i tried to run it on target it shows GCC 4.3.0 version not found. So i copied the runtime libraries (libc.so and libgcc_s.so) from the toolchain to the target and exported its path in LD_LIBRARY_PATH. But when i tried to run any llvm tools on target its crashing with Segmentation fault. What could be the problem for this.

My target kernel and rootfs are compiled with armgcc-4.2.1… so should i need to compile the kernel and rootfs with armgcc-4.3.3?

If i want to use arm-toolchain-4.2.1 , what should i do for clearing the instruction cache call in lib/System/Memory.cpp?

Thanks and Regards,
Prasanth J

Prasanth J wrote:

Hi,

I can able to compile LLVM using armgcc_4.3.3 (codesourcery2009q1..)..
but when i tried to run it on target it shows GCC 4.3.0 version not
found. So i copied the runtime libraries (libc.so and libgcc_s.so)
from the toolchain to the target and exported its path in
LD_LIBRARY_PATH. But when i tried to run any llvm tools on target its
crashing with Segmentation fault. What could be the problem for this.

Impossible to know without debugging. whats the backtrace when running
the program from inside the gnu debugger gdb?
and what tools did you run.

What command did you run that caused the crash?

What are the output from
llc -version
and
lli -version
?

My target kernel and rootfs are compiled with armgcc-4.2.1... so
should i need to compile the kernel and rootfs with armgcc-4.3.3?

Probably not needed.

If i want to use arm-toolchain-4.2.1 , what should i do for clearing
the instruction cache call in lib/System/Memory.cpp?

You have to implement it using inline assembler for GCC 4.2.1 and below
to work.
You can check the gcc sources to see how __clear_cache got implemeted in
gcc 4.3.3 or check the arm reference manual (ARM ARM):
http://www.arm.com/miscPDFs/14128.pdf

Cheers
Xerxes

Prasanth J wrote:

If i want to use arm-toolchain-4.2.1 , what should i do for clearing
the instruction cache call in lib/System/Memory.cpp?

You can also look how other projects have solved this problem in the past:
http://www.complang.tuwien.ac.at/viewcvs/cgi-bin/viewcvs.cgi/gforth/arch/arm/cacheflush-linux.c?rev=1.4
Here the clear cache are implemented using inline asm and a linux
systemcall to be usable with gcc 4.2.1.

Cheers
Xerxes

Prasanth J wrote:

Hi,

I can able to compile LLVM using armgcc_4.3.3 (codesourcery2009q1…)…
but when i tried to run it on target it shows GCC 4.3.0 version not
found. So i copied the runtime libraries (libc.so and libgcc_s.so)
from the toolchain to the target and exported its path in
LD_LIBRARY_PATH. But when i tried to run any llvm tools on target its
crashing with Segmentation fault. What could be the problem for this.

Impossible to know without debugging. whats the backtrace when running
the program from inside the gnu debugger gdb?
and what tools did you run.

What command did you run that caused the crash?

What are the output from
llc -version
and
lli -version
?

when i tried to run this command (lli -version)i got the following error

…/…/llvm-with-gcc433/bin/lli: /lib/libstdc++.so.6: version CXXABI_ARM_1.3.3' not found (required by ../../llvm-with-gcc433/bin/lli) ../../llvm-with-gcc433/bin/lli: /lib/libgcc_s.so.1: version GCC_4.3.0’ not found (required by …/…/llvm-with-gcc433/bin/lli)

so i exported the path to libstdc++ and libgcc_s in LD_LIBRARY_PATH. after exporting when i tried to run lli ( or any llvm tools) i am getting a crash saying Segmentation fault.

i could not post the backtrace as even running gdb creates a crash.