- 论坛徽章:
- 0
|
Building ARM ELF EABI--Step by StepSomeone ask why not download binaries from
CodeSourcery instead of compile it. The answer is that, yes,
apparently, the lite edition toolchain is lack of functionality and
lack of sufficient libraries support. Besides, compiling from
scratch can also help us for understanding the whole structure of
compiler system.
My workstation is equipped with Ubuntu and
before our work, following packages should be installed(those
packages are x86 architecture):
mpfr, make, gmp, texinfo,
texlive
Now,
first of all, download source package from CodeSourcery server,
here is the website,
http://www.codesourcery.com/gnu_toolchains/arm/portal/package3381/public/arm-none-eabi/arm-2008q3-39-arm-none-eabi.src.tar.bz2
And then, unpack it to
/home/embedded/arm-2008q3-39-arm-none-eabi/ and unpack following
tarball. Updating PATH variable is also needed,
tar -jxvf
/home/embedded/arm-2008q3-39-arm-none-eabi/binutils-2008q3-39.tar.bz2
tar
-jxvf
/home/embedded/arm-2008q3-39-arm-none-eabi/gcc-2008q3-39.tar.bz2
tar
-jxvf
/home/embedded/arm-2008q3-39-arm-none-eabi/newlib-2008q3-39.tar.bz2
export
$PATH=/home/embedded/armelf/install/bin/:$PATH
Now cd into binutils-stable and build it. Here
are the configure scripts,
./configure
--build=i686-pc-linux-gnu --target=arm-none-eabi
--prefix=/home/embedded/armelf/install/ --host=i686-pc-linux-gnu
--disable-nls
--with-sysroot=/home/embedded/armelf/install/arm-none-eabi
--enable-poison-system-directories
make
make
install
Next,
build bootstrap GCC,
../source/gcc-4.3/configure
--build=i686-pc-linux-gnu --host=i686-pc-linux-gnu
--target=arm-none-eabi --enable-threads --disable-libmudflap
--disable-libssp --disable-libstdcxx-pch --with-gnu-as
--with-gnu-ld --enable-languages=c,c++ --disable-shared
--with-newlib --prefix=/home/embedded/armelf/install/
--disable-shared --disable-threads --disable-libssp
--disable-libgomp --without-headers --with-newlib
--disable-decimal-float --disable-libffi --enable-languages=c
--with-sysroot=/home/embedded/armelf/install/arm-none-eabi
--disable-libgomp --enable-poison-system-directories
--with-build-time-tools=/home/embedded/armelf/install/arm-none-eabi/bin/
--with-cpu=arm7tdmi
make
make
install
Newlib,
./configure
--build=i686-pc-linux-gnu --target=arm-none-eabi
--prefix=/home/embedded/armelf/install/ --host=i686-pc-linux-gnu
--enable-newlib-io-long-long --disable-newlib-supplied-syscalls
--disable-libgloss --disable-newlib-supplied-syscalls
--disable-nls
make
make
install
and GCC Final,
../source/gcc-4.3/configure
--build=i686-pc-linux-gnu --host=i686-pc-linux-gnu
--target=arm-none-eabi --enable-threads --disable-libmudflap
--disable-libssp --disable-libstdcxx-pch --with-gnu-as
--with-gnu-ld --enable-languages=c,c++ --disable-shared
--with-newlib --prefix=/home/embedded/armelf/install/
--disable-libgomp --enable-poison-system-directories
--with-build-time-tools=/home/embedded/armelf/install/arm-none-eabi/bin/
--with-headers=/home/embedded/armelf/install/arm-none-eabi/include/
--with-libs="/home/embedded/armelf/install/arm-none-eabi/lib/"
--with-cpu=arm7tdmi
make
make
install
Please pay attention to option "with-cpu" (where
I mark those as red color). If you want to change the target
architecture, you just change "arm7tdmi". The compiler will
consider this option as default when you doesn't specify "-mcpu"
using arm-gcc.
Quite simple, isn't it? Now let's try some
examples and see the results.
#include
int main(int argc,char** argv)
{
double
a=1.33,b=2.44;
double
c;
c=sin(a)+cos(b);
return
0;
}
arm-none-eabi-gcc ./test.c -o test -lm
file ./test
./test: ELF 32-bit LSB executable, ARM, version 1 (SYSV),
statically linked, not stripped
arm-none-eabi-readelf -h ./test #Display header section
ELF Header:
Magic: 7f 45 4c 46 01 01 01 00
00 00 00 00 00 00 00 00
Class:
ELF32
Data:
2's complement, little endian
Version:
1 (current)
OS/ABI:
UNIX -
System V
ABI
Version:
0
Type:
EXEC (Executable file)
Machine:
ARM
Version:
0x1
Entry point
address:
0x8018
Start of program
headers:
52 (bytes into file)
Start of section
headers:
64780 (bytes into file)
Flags:
0x5000002, has entry point, Version5
EABI
Size of this
header:
52 (bytes)
Size of program
headers:
32 (bytes)
Number of program
headers:
2
Size of section
headers:
40 (bytes)
Number of section
headers:
25
Section header string table index: 22
arm-none-eabi-readelf -A ./test #Display architecture specific
information
Attribute Section: aeabi
File Attributes
Tag_CPU_name: "ARM7TDMI"
Tag_CPU_arch: v4T
Tag_ARM_ISA_use: Yes
Tag_ABI_PCS_wchar_t: 4
Tag_ABI_FP_denormal: Needed
Tag_ABI_FP_exceptions: Needed
Tag_ABI_FP_number_model: IEEE 754
Tag_ABI_align8_needed: Yes
Tag_ABI_align8_preserved: Yes, except leaf SP
Tag_ABI_enum_size: small
The simplest way to investigate program ABI is
that, ARM-GCC without EABI support will show "GNU EABI" instead of
"Version5 EABI" in "Flags" option when you using arm-readelf.
And once more, ARM-ELF-EABI is not used for
compiling binaries running on top of Linux. You can see the warning
information like "No Entry Point" when you compile it. When you
want to rich the libary set, "prefix" option in configure stage
should be
/home/embedded/armelf/install/arm-none-eabi
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/90973/showart_1861425.html |
|