Is it possible to set up Clang for cross compiling for the ARM processor? The host will likely be on x86 ( AMD64 - Probably Ubuntu 12.04 ) and the target would be ARM ( Raspberry Pi as well as Pandaboard - will do separate compilations for each ), I may at some point also wish to cross compile for the PowerPC architecture? The program source is in C.
To cross-compile for Raspberry Pi running soft-float Linux distros add flags -ccc-host-triple arm-eabi -marm -mfpu=vfp -mcpu=arm1176jzf-s -mtune=arm1176jzf-s -mfloat-abi=softfp
To cross-compile for Raspberry Pi running hard-float Linux distros use the flags -ccc-host-triple arm-eabi -marm -mfpu=vfp -mcpu=arm1176jzf-s -mtune=arm1176jzf-s -mfloat-abi=hard
To cross-compile for Pandaboard use flags -ccc-host-triple arm-eabiv7 -mthumb -mfpu=neon-fp16 -mcpu=cortex-a9 -mtune=cortex-a9 -mfloat-abi=hard (assuming that your Pandaboard runs Ubuntu)
Note: more recent clang version use -target option instead of -ccc-host-triple
See EmbToolkit project. It gives ability to generate clang/llvm
or gcc based cross compiler toolchain.
Related
I have a program consisting of multiple C source files and I would like to execute it in qemu with a Cortex-M4/M7 CPU. I am using the following command to build the objects:
"arm-none-eabi-gcc" -c -mcpu=cortex-m4 -mthumb -fomit-frame-pointer -Wimplicit-fallthrough -O3 -Wall -Wshadow -Wcast-qual -Wno-long-long -Wno-unknown-pragmas
The linker creates a library:
arm-none-eabi-ar cru lib *.o
And the main is then linked to an executable:
"arm-none-eabi-gcc" -mthumb -specs=rdimon.specs main.o lib.a -lstdc++ -lm -L./lib/arm_none-eabi_gcc/ -o run_main
Now running this binary gives me:
qemu-arm -cpu cortex-m4 run_main
qemu: uncaught target signal 4 (Illegal instruction) - core dumped
Illegal instruction
It all works well when using Cortex-A9 as CPU, but the M-Models are troubling me. What am I doing wrong?
ARM Cortex-M MCUs always require custom linker script and startup code. Flash and RAM addresses are not standardized across vendors, and the interrupt vector table is device specific.
The linker command line should also specify the core via "-mcpu=cortex-m4" in order to link to the correct libraries (multilib).
I'm looking for a GNU toolchain:
target platform is aarch64 bare metal (cortex-a53/armv8-a)
host Mac OSX
Or by other words I need a bunch of aarch64-none-elf-* files
Any advise where could I get these tools?
Thanks
You don't need the -none- version of the toolchain anymore on aarch64. You can simply use aarch64-linux-gnu-gcc for instance, with the right parameters (no standard libs or headers):
aarch64-linux-gnu-gcc -march=armv8-a -nostdinc -fno-builtin -c -o main.o main.c
Following the instructions given here, I’ve downloaded the latest version of OpenSSL (openssl-1.0.1e.tar.gz) from here and installed it on Ubuntu v12.10 (32-bit).
I have a C project in Eclipse CDT (v1.2.0.201212170456) that statically links to the following two .a files:
home/usr/local/ssl/lib/libcrypto.a
home/usr/local/ssl/lib/ libssl.a
However when I build my project I get these errors:
/home/tashimaya/Applications/CodeSourcery/bin/../lib/gcc/arm-none-linux-gnueabi/4.4.1/../../../../arm-none-linux-gnueabi/bin/ld: skipping incompatible /usr/local/ssl/lib/libssl.a when searching for -lssl
/home/tashimaya/Applications/CodeSourcery/bin/../lib/gcc/arm-none-linux-gnueabi/4.4.1/../../../../arm-none-linux-gnueabi/bin/ld: cannot find –lssl
My toolchain is CodeSourcery (Sourcery G++ Lite 2010q1-202) and is for 32-bit OS.
What am I doing wrong?
Compiler command line I'm using:
arm-none-linux-gnueabi-gcc -I"/path to my/include" -O0 -g3 -Wall -c -fmessage-length=0 -v -MMD -MP -MF"main.d" -MT"main.d" -o "main.o" "../main.c"
You have installed OpenSSL on an Ubuntu 32-bit machine (assuming x86), but are trying to link it to an ARM binary:
/home/tashimaya/Applications/CodeSourcery/bin/../lib/gcc/arm-none-linux-gnueabi: your ARM toolchain
/usr/local/ssl/lib/libssl.a: a 32-bit x86 version of OpenSSL
You will have to cross-compile OpenSSL for ARM using your ARM toolchain (i.e.: arm-none-linux-gnueabi-gcc), then you will be able to link it to an ARM binary.
It says that /usr/local/ssl/lib/libssl.a is not in the size expected. Try file on it to check if you compiled it in 32 or 64 bit version. And check how you are compiling your own program too. If both matches linker (ld) will link it fine.
If you compile your program into 64 bit and link it with libssl.a in 32 bit, this will not work
example:
file a.out
/* kind ofoutput */ a.out: Mach-O 64-bit executable x86_64
http://unixhelp.ed.ac.uk/CGI/man-cgi?file
I need to port a few Intel based Linux applications to the ARM platform. Can anybody tell me
what are the best cross compiling tools for this project?
Thanks.
On the Ubuntu Linux host you may use just a default ARM toolchain:
sudo apt-get install gcc-arm-linux-gnueabi
To build your linux applications you just have to use the same tools,
but prefixed with:
arm-linux-gnueabi-
For example, to build a simple helloworld.c:
arm-linux-gnueabi-gcc -o helloworld helloworld.c
You can also set some ARM-related flags to optimize your build or to specify your target platform. Here some examples of important ARM GCC flags, depending on the target ARM CPU:
ARM 11: -mtune=arm1136j-s -mfpu=vfp -mfp=vfp -march=armv6 -mfloat-abi=softfp
Cortex A8: -mtune=cortex-a8 -mfpu=neon -mfloat-abi=softfp -Wl,--fix-cortex-a8
Cortex A9: -mtune=cortex-a9 -mfpu=neon -mfloat-abi=softfp
Note, that your target ARM CPU may require another options, for example if it doesn't support NEON instructions. GCC compilers from CodeSourcery may also need another options set - just read the docs from CodeSourcery for a particular GCC version.
I am trying to compile a plugin for Stata (a statistical programming language) that is written in C. Its author was able to compile it on other machines using the following commands on a 32-bit PC Windows (using Cygwin):
gcc -shared -mno-cygwin stplugin.c strgroup.c -O3 -funroll-loops -o strgroup.PC.Windows.plugin
He was also able to compile it on 64-bit Unix with:
gcc -shared -fPIC -DSYSTEM=OPUNIX stplugin.c strgroup.c -O3 -funroll-loops -o "strgroup.PC (64-bit x86-64).Unix.plugin"
And Macintosh OS X with:
gcc -bundle -arch i386 -arch x86_64 -arch ppc -DSYSTEM=APPLEMAC stplugin.c strgroup.c -O3 -funroll-loops -o "strgroup.Macintosh.MacOSX.plugin"
I am trying to compile it on 64-bit Windows 7 machine using Cygwin 1.7.9-1 and gcc v4.5.3. The mno-cygwin flag is giving me trouble, but I am not able to figure out how to use a mingw-targeted cross-compiler.
The -mno-cygwin option is no longer supported.
Install either of the mingw-*, mingw64-i686-* or mingw64-x86_64-* toolchain (category Devel in the Cygwin package manager) to get a proper cross-compiler.