Create a binary tool (
binutils)
Binutils is a collection of binary tools that contain the AS and LD we use.
First, we unzip the binutils source file we downloaded.
$CD $PRJROOT/build-tools $tar-XVJF binutils-2.10.1.tar.bz2 |
Then enter the Build-binutils directory configuration and compile binutils. (Should make sure so you have ' lex ' (or ' flex ') installed, or you can ' t pass the ' configure ', I used UBUNTU and it's not Installed beforehand) labels behind configure are necessary, or you can ' t pass ' make '
$CD build-binutils $.. /binutils-2.10.1/configure--target= $TARGET--prefix= $PREFIX |
The--target option is to point out that we are generating the Arm-linux tool,--prefix is the location where our executable files are installed.
There will be a lot of check, resulting in Makefile files.
With Makefile, we compile and install binutils, and the commands are simple.
Take a look at the generated files we $PREFIX/bin.
$ls $PREFIX/bin arm-linux-addr2line arm-linux-gasp arm-linux-objdump arm-linux-strings arm-linux-ar arm-linux-ld arm-linux-ranlib arm-linux-strip arm-linux-as arm-linux-nm arm-linux-readelf arm-linux-c++filt arm-linux-objcopy arm-linux-size |
Let's explain what the executable file generated above is for.
Add2line-Converts the address you are looking for to a file and line number and uses the debug information.
ar-generates, modifies, and unlocks an archive file
The assembler of the AS-GNU
C++filt-c++ and Java have an overloaded function, the use of overloaded functions will be compiled into the final compilation of the label, C++filt is to achieve this reverse transformation, according to the label to get the function name.
Gasp-gnu compiler preprocessor.
Connectors for Ld-gnu
nm-lists the symbol and corresponding address of the target file
objcopy-converts a file in a format to a target file in a different format
objdump-displays information about the target file
ranlib-generates an index for an archive file and stores the index in an archive file
readelf-displays information about target files in elf format
size-displays the size of each section of the target file and the size of the destination file
strings-prints a string that can be printed in the destination file, with a default length of 4
strip-Strip all symbolic information of the target file
Create the initial compiler (bootstrap GCC)
First enter the Build-tools directory, will download GCC source code decompression
$CD $PRJROOT/build-tools $tar-xvzf gcc-2.95.3.tar.gz |
Then go to the gcc-2.95.3 directory and patch up GCC.
$CD gcc-2.95.3 $patch-p1<. /gcc-patch/gcc-2.95.3.-2.patch $patch-p1<. /gcc-patch/gcc-2.95.3.-no-fixinc.patch $patch-p1<. /gcc-patch/gcc-2.95.3-returntype-fix.patch echo Timestamp > gcc/cstamp-h.in |
Before we compile and install GCC, we need to change a file $PREFIX/build-tools/gcc-2.95.3/gcc/config/arm/t-linux
Target_libgcc2-cflags =-fomit-frame-pointer-fpic
This line is changed to
Target_libgcc2-cflags =-fomit-frame-pointer-fpic-dinhibit_libc-d__gthr_posix_h
The next thing is to configure Boostrap GCC, followed by bootstrap GCC to compile the glibc library.
$CD.; CD BUILD-BOOT-GCC $.. /gcc-2.95.3/configure--target= $TARGET--prefix= $PREFIX/ >--without-headers--enable-languages=c--disable-threads (not needed when you modify the file mentioned above) |
The-target 、--prefix and configuration binutils in this command are the same,--without-headers means that no header file is required because it is a cross compilation tool and does not require a header file on this machine. -enable-languages=c means that our BOOT-GCC only supports the C language. --disable-threads is to remove the thread function, this function requires GLIBC support.
Then we compile and install BOOT-GCC
$make ALL-GCC $make INSTALL-GCC |
An error like ' ~~/arm.c:530:error:invalid Lvalue in assignment ' would occur if you are compile it on a 64-bit machine. The contant is:
(Arm_prog_mode =target_apcs_32?) PROG_MODE_PROG32:PROG_MODE_PROG26;)
Open file gcc-2.95.3/gcc/config/arm/arm.h and find the line:
#define Arm_prog_mode ((enum Attr_prog_mode) arm_prgmode)
Modify it as:
#define ARM_PROG_MODE (Arm_prgmode)
Let's see what's going on in $PREFIX/bin.
You'll find more ARM-LINUX-GCC, Arm-linux-unprotoize, CPP.