Cross Compile Binutils
The [GNU Binutils] are a collection of various binary tools such as
readelf. These tools are platform-specific, so you need to compile them again if your host system and target system are different. In our case, we need
objdump for the x86_64 architecture.
[GNU Binutils]: https://www.gnu.org/software/binutils/
🔗 Building Setup
First, you need to download a current binutils version from [here][download] (the latest one is near the bottom). After extracting, you should have a folder named
X is for example
25.1. Now can create and switch to a new folder for building (recommended):
mkdir build-binutils cd build-binutils
We execute binutils's
configure and pass a lot of arguments to it (replace the
X with the version number):
../binutils-2.X/configure --target=x86_64-elf --prefix="$HOME/opt/cross" \ --disable-nls --disable-werror \ --disable-gdb --disable-libdecnumber --disable-readline --disable-sim
targetargument specifies the the x86_64 target architecture.
prefixargument selects the installation directory, you can change it if you like. But be careful that you do not overwrite your system's binutils.
disable-nlsflag disables native language support (so you'll get the same english error messages). It also reduces build dependencies.
disable-werrorturns all warnings into errors.
- The last line disables features we don't need to reduce compile time.
🔗 Building it
Now we can build and install it to the location supplied as
prefix (it will take a while):
make make install
Now you should have multiple
x86_64-elf-XXX files in
🔗 Adding it to the PATH
To use the tools from the command line easily, you should add the
bin folder to your PATH:
If you add this line to your e.g.
x86_64-elf-XXX commands are always available.