What's the differences between arm-eabi-gcc and arm-elf-gcc?
Can they both compile the same source code for cortex-m3 arch?
arm-elf-gcc is the old toolchain supporting legacy floating-point accelerator (FPA) and the mixed-endian floating-point format.
arm-eabi-gcc is the newer geneartion of toolchain supporting VFP floating-point format.
I imagine they can compile the same source, but the later one is newer so that must be richer feature wise. What you want to hear depends on which OS / libraries you are compiling against. Toolchain, fundamental libraries and OS go arm in arm. They need to have same ABIs.
Related
I'm new in ARM development. Now I'm really confused about the cross tool chain of ARM. Here some problems that I encountered:
Are the developers of gcc and arm-linux-gcc the same? Or there are many different developers of arm-linux-gcc for different versions? If there are, what is the origin of all arm-linux-gcc compilers? Is there an official website for arm-linux-gcc?
Where to get official documentation of arm-linux-gcc? Now I can only get official documentation of gcc from the official GNU website, but I downloaded my arm-linux-gcc from GNUTOOLCHAIN and cannot find any documents. According to my experience, the options of gcc and arm-linux-gcc are not exactly same.
Finally, what are the differences between different prebuilt versions of arm-linux-gcc? I guess the only difference between them is the default options of the compiler, am I right? Can I use a prebuilt arm-linux-gcc for arm1176 to compile a program for a cortex-A8? If so, what compile options should I pay attention to?
Is there any authoritative book about such things?
Answers for your questions are below:
There are different compiler options for doing compilation for arm from different developers. The one I commonly use are Linaro and Code Sourcery. You can search these keywords on Google and find their website easily.
arm-linux-gcc should support all the flags and options of gcc, so all the generic stuff is same as compared to gcc. So you can use the gcc documentation on official GNU website. For something specific you can use the documentation of the specific compiler.
The prebuilt versions are the ones with default options for a particular platform, but they might also include some fixes or maybe hacks to run it on a particular platform. For example in case of RPi you cannot use the generic linaro toolchain and have to use a prebuilt one.
When you work with embedded devices, you usually need a cross-compiler which runs on a fast host machine (e.g., x86) and compiles for a slower target machine (e.g., ARM).
arm-linux-gcc is the cross-compiler for arm. It is normal gcc compiler, but compiled to run on a host machine and to generate target for an ARM machine.
The issue I am having is with some neon instructions which I believe are supported on the arm7 architecture. I am using the default compiler (Apple LLVM 5.0), it recognises other neon instructions although it does not like the half-float instruction.
Here is the code:
vcvt.f32.f16, q0, d1
This has compiled on gcc although the apple compiler does not like this instruction and gives the error: Instruction requires: half-float
Is there a compiler flag I can give to XCode? I can't find out how to enable the half float instructions googling around.
Thanks!
The half-float format is actually not supported on all ARM v7 implementations. See the ARM manual here. It's required by vfp4, so if your chip supports that, that's a good start. In general I would recommend using run-time detection and dispatching. To enable the instruction in general, you would need to use one of several floating point support options, in general "fp16" is the keyword, for example:
-mfpu=neon-fp16 if you are sure that your target supports it for neon. I couldn't find all of the examples for llvm either, but I think they are generally compatible with the GCC options, found in the GCC manual.
I am getting the following error while trying to compile some code for an ARM Cortex-M4
using
gcc -mcpu=cortex-m4 arm.c
`-mcpu=' is deprecated. Use `-mtune=' or '-march=' instead.
arm.c:1: error: bad value (cortex-m4) for -mtune= switch
I was following GCC 4.7.1 ARM options. Not sure whether I am missing some critical option. Any kickstart for using GCC for ARM will also be really helpful.
As starblue implied in a comment, that error is because you're using a native compiler built for compiling for x86 CPUs, rather than a cross-compiler for compiling to ARM.
GCC only supports a single general architecture type in any given compiler binary -- so, although the same copy of GCC can compile for both 32-bit and 64-bit x86 machines, you can't compile to both x86 and ARM with the same copy of GCC -- you need an ARM-specific GCC.
(As auselen suggests, getting a pre-built one will save you quite a lot of work, even if you're only using it as a starting point to get things set up. You need to have GCC, binutils, and a C library as a minimum, and those are all separate open-source projects that the pre-built versions have already done the work of combining. I'll recommend Sourcery CodeBench Lite since that's the one my company makes and I do think it's a fairly good one.)
As the error message says -mcpu is deprecated, and you should use the other options stated. However "deprectated" simply means that its use may not continue to be supported; it will still work.
ARM Cortex-M4 is ARM Architecture V7E-M, so you should use -march=armv7-m (the documentation does not specifically list armv7e-m, but that may have been added since the documentation was last updated. The E is essentially the difference between M3 and M4 - the DSP instructions, so the compiler will not generate code that takes advantage of these instructions. Using ARM's Cortex-M DSP library is probably the best way to use these instructions to benefit your application. If your part has an FPU, then other options will be needed enable code generation for that.
Like others already pointed out, you are using a compiler for your host machine, and you need a compiler for generating code for your target processor instead (a cross compiler). Like #Brooks suggested, you can use a pre-built toolchain, but if you want to roll out your own cross-compiler, libc and binutils, there is a nice tool called Crosstool-NG. It greatly simplifies the process of building a cross-compiler optimized to generate code for a specific processor, so you're not stuck with a generic prebuilt toolchain, which usually builds code for a family of compatible processors (e.g. you could tune the toolchain for generating ASM for your specific target, or floating point code for a hardware FPU which is specific to your processor, instead of using only software floating point routines, which are default to most pre-built toolchains).
Recently I've been playing around with cross compiling using GCC and discovered what seems to be a complicated area, tool-chains.
I don't quite understand this as I was under the impression GCC can create binary machine code for most of the common architectures, and all that else really matters is what libraries you link with and what type of executable is created.
Can GCC not do all these things itself? With a single build of GCC, all the appropriate libraries and the correct flags sent to GCC, could I produce a PE executable for a Windows x86 machine, then create an ELF executable for an embedded Linux MIPS device and finally an executable for an OSX PowerPC machine?
If not can someone explain how you would achieve this?
With a single build of GCC, all the
appropriate libraries and the correct
flags sent to GCC, could I produce a
PE executable for a Windows x86
machine, then create an ELF executable
for an embedded Linux MIPS device and
finally an executable for an OSX
PowerPC machine? If not can someone
explain how you would achieve this?
No. A single build of GCC produces object code for one target architecture. You would need a build targeting Intel x86, a build targeting MIPS, and a build targeting PowerPC. However, the compiler is not the only tool you need, despite the fact that you can build source code into an executable with a single invocation of GCC. Under the hood, it makes use of the assembler (as) and linker (ld) as well, and those need to be built for the target architecture and platform. Usually GCC uses the versions of these tools from the GNU binutils package, so you'd need to build that for the target platform too.
You can read more about building a cross-compiling toolchain here.
I don't quite understand this as I was
under the impression GCC can create
binary machine code for most of the
common architectures
This is true in the sense that the source code of GCC itself can be built into compilers that target various architectures, but you still require separate builds.
Regarding -march, this does not allow the same build of GCC to switch between platforms. Rather it's used to select the allowable instructions to use for the same family of processors. For example, some of the instructions supported by modern x86 processors weren't supported by the earliest x86 processors because they were introduced later on (such as extension instruction sets like MMX and SSE). When you pass -march, GCC enables all opcodes supported on that processor and its predecessors. To quote the GCC manual:
While picking a specific cpu-type will
schedule things appropriately for that
particular chip, the compiler will not
generate any code that does not run on
the i386 without the -march=cpu-type
option being used.
If you want to try cross-compiling, and don't want to build the toolchain yourself, I'd recommend looking at CodeSourcery. They have a GNU-based toolchain, and their free "Lite" version supports quite a few architectures. I've used it for Linux/ARM and Android/ARM.
Can a toolchain for any ARM processor be used to compile any operating system? What is the dependency of toolchain on OS?
My problem may sound trivial...I have no idea about toolchains for ARM.
Can a toolchain for any Arm processor be used to compile any
Operating system?
It depends on the target OS. If it has support for the ARM architecture (such as Linux) then only configuration and patches are missing, but generally yes.
What is the dependency of toolchain on
OS?
I'm only experienced in GCC, so I'd say binutils, glibc+kernel headers and then GCC. If you want threads, you'd need pthreads too.
See this article on how to bootstrap Linux on ARM. While it's rather old, the same process applies, with appropriate patches.
You might want to look at BuildRoot for building a toolchain to target Arm and other processors.
In general, no. The toolchain has compiler libraries that depend on the system libC libraries, and these come from the operating system (unless you're compiling for small "bare metal" systems without an operating system, in which case they come from somewhere else).
Thus, programs compiled with a given toolchain will only work on systems with a compatible libC. For instance, if you have a toolchain for ARM GlibC-based systems, it will work to compile programs for standard ARM Linux systems that use GlibC, but won't work on ARM uClinux systems that use uClibc, or on ARM bare-metal systems using Newlib.
There are some other minor dependencies as well (which I'm less familiar with), but that's the biggest one.
There are many cross platform compiler are available even many version of gcc also provides... to compile kernel for arm you need to get cross compiler and change the top level Makefile of kernel folder ex: ARCH = arm and CROSS_COMPILE = arm-linux-, the CROSS_COMPILE argument depends on where u kept the gcc-cross-platform tool...
Here ARCH stands for Architecture