简体   繁体   中英

Crosscompile program for LLVM for ARMv6 on Ubuntu 32bit i686

I'm near to frustration ;-). Since more than a week I try to crosscompile on my ubunutu 12.04 box i686 Linux machine for a ARMv6 machine (arm1176jzf-s - known as Raspberry Pi) an own developed program with LLVM 3.4.2. After days I was able to compile and link successfully. But as I've tried to execute my code on the Raspberry Pi I only received a memory access error. It has turned out that a segmentation fault is raised. I have analyzed it with gdb. Please refer please to the enclosed picture.

用gdb分析ARM上的可执行文件 .

Basically I have done the following:

I build the C and C++ files: @echo 'Compiling' $(1).$(2); cd $(BIN); $(4) -c $(COMPILE_FLAGS) ../$(3)/$(1).$(2) -o $(1).o $(LLVM_CONFIG_COMPILE); cd .. 
I llvm-linked it: cd $(BIN); $(LINK) -o tl.bc $(1)
Then I called the system compiler: cd $(BIN); $(LLC)  $(LINKER_FLAGS) -filetype=obj tl.thumb.opt.bc -o tl.thumb.opt.o 
 And I called the linker, i.e. the arm-linux-gnueabihf-g++: $(LD) -o bin/tl bin/tl.thumb.opt.o $(LINK_OPTION) $(THREAD_LIB_DIR) $(call INFLATE_config)
`test -f bin/tl` && echo 'Make was successful. Find Turbo Lisp in folder' $(BIN)

Take a look at my console output for my make file:

Building Turbo Lisp 0.01 for machine i686 with operating system GNU/Linux

COMPILE_FLAGS used:

-fno-strict-aliasing -emit-llvm -mfloat-abi=hard -mcpu=arm1176jzf-s -mfpu=vfpv3-d16    -mthumb -target arm-unknown-linux-gnueabihf -I/usr/include/arm-linux-gnueabihf/c++/4.6 -I/usr/include/arm-linux-gnueabihf/c++/4.6/arm-linux-gnueabihf -I/usr/lib/gcc/arm-linux-gnueabihf/4.6/include -I/usr/local/lib/LLVM_ARM/BOOST -ccc-gcc-name arm-linux-gnueabihf-gcc

Compiling precedence.cpp
Compiling util.cpp
Compiling ast.cpp
Compiling abstractParser.cpp
Compiling metaparser.cpp
Compiling parserLisp.cpp
Compiling parserToy.cpp
Compiling preconfiguredLanguages.cpp
Compiling handler.cpp
Compiling helper.cpp
Compiling lexer.cpp
Compiling config_reader.cpp
Compiling tl.cpp
Compiling external_functions.c
Compiling error_util.cpp

Building binary code from:

tl.o preconfiguredLanguages.o handler.o external_functions.o abstractParser.o parserLisp.o parserToy.o metaparser.o ast.o helper.o util.o error_util.o config_reader.o lexer.o precedence.o

Linking...

cd bin; <myhome>/projects/llvm-3.4.2.src/buildARMCompileX86/Release+Asserts/bin/llvm-link -o tl.bc tl.o preconfiguredLanguages.o handler.o external_functions.o abstractParser.o parserLisp.o parserToy.o metaparser.o ast.o helper.o util.o error_util.o config_reader.o lexer.o precedence.o

Optimizing...

cd bin; <myhome>/projects/llvm-3.4.2.src/buildARMCompileX86/Release+Asserts/bin/opt tl.bc -o tl.thumb.opt.bc -float-abi=hard -std-compile-opts 

System compiling...

cd bin; <myhome>/projects/llvm-3.4.2.src/buildARMCompileX86/Release+Asserts/bin/llc   -float-abi=hard -march=arm -mtriple=arm-unknown-linux-gnueabihf -filetype=obj tl.thumb.opt.bc -o tl.thumb.opt.o

...And finally linking to native...

arm-linux-gnueabihf-g++ -o bin/tl bin/tl.thumb.opt.o -v -L/usr/lib/arm-linux-gnueabihf -L/usr/local/lib/LLVM_ARM/BOOST -L/usr/local/lib/LLVM_ARM -L/usr/lib/arm-linux-gnueabihf -L/usr/local/lib/LLVM_ARM/BOOST -L/usr/local/lib/LLVM_ARM -lz -lpthread -lrt -ldl -lm -lLLVMInterpreter -lLLVMMCJIT -lLLVMJIT -lLLVMRuntimeDyld -lLLVMExecutionEngine -lLLVMARMDisassembler -lLLVMARMCodeGen -lLLVMSelectionDAG -lLLVMAsmPrinter -lLLVMCodeGen -lLLVMObjCARCOpts -lLLVMScalarOpts -lLLVMInstCombine -lLLVMTransformUtils -lLLVMipa -lLLVMAnalysis -lLLVMARMAsmParser -lLLVMMCParser -lLLVMARMDesc -lLLVMARMInfo -lLLVMTarget -lLLVMCore -lLLVMARMAsmPrinter -lLLVMMC -lLLVMObject -lLLVMSupport -lpthread -ldl

`test -f bin/tl` && echo 'Make was successful. Find Turbo Lisp in folder' bin
Make was successful. Find Turbo Lisp in folder bin

It would be very nice, if anybody knowing much more about compiling for ARM could share his knowledge with me and direct me to the point I made so wrong.

Eventually, I did it!

Maybe many of you are more interested in gcc than in LLVM and clang. But I think the issue here is more generally , than specific to LLVM. After I tried to compile LLVM and clang for ARM I ran another gdb session. It has turned out that glibc has different versions on my raspberry (2.13) and on my ubuntu (2.15). So I copied the libc from my ARM to my ubuntu system, but this didn't worked. I received messages from my gdb like "invalid machine instruction". This has caused me to check a bit more thoroughly the configure.log file of the clang build.

And, yes, the gcc cross compiler of ubuntu is simply compiled for an ARMv7 architecture, but the Raspberry is of ARMv6 (with ARM11 chip set). So, the next point was to build my own gcc toolchain. First I tried to build my binutils, which allegedly was successful. Then I was heading to compile gcc linaro. And this has cost me days. At the end I hadn't achieved this mission. Either some include files were missing or linker issues have stopped me.

But I had the brilliant idea to make some more research, especially with keywords for the rasperry pi. And this has then pushed me back on track as I found crosstool-ng. What a great tool! You only need to configure in a kind of a menu which platform you like to address and then this tool downloads all your required files for a complete toolchain and installs it. Great! As I made this hurdle, it was pretty easy to build LLVM and clang. The only point everybody needs to manage is to upgrade the Raspberry Pi, ie upgrade libc and libstdc++ by apt-get with the "testing" stage.

Feel free to ignore it or just check it out if you have also troubles to build up a correct gcc toolchain: Tutorial to setup crosstool-ng for RPi

Would like to comment but can't due to low "reputaion"...

Since you are "near to frustration" I would suggest trying gcc instead of LLVM because then it's likely easier to get help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM