Writing an OS in Rust Philipp Oppermann's blog

Cross Compile Binutils

The GNU Binutils are a collection of various binary tools such as ld, as, objdump, or 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 ld and objdump for the x86_64 architecture.

🔗 Building Setup

First, you need to download a current binutils version from here (the latest one is near the bottom). After extracting, you should have a folder named binutils-2.X where X is for example 25.1. Now can create and switch to a new folder for building (recommended):

mkdir build-binutils
cd build-binutils

🔗 Configuration

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

🔗 Building it

Now we can build and install it to the location supplied as prefix (it will take a while):

make install

Now you should have multiple x86_64-elf-XXX files in $HOME/opt/cross/bin.

🔗 Adding it to the PATH

To use the tools from the command line easily, you should add the bin folder to your PATH:

export PATH="$HOME/opt/cross/bin:$PATH"

If you add this line to your e.g. .bashrc, the x86_64-elf-XXX commands are always available.