mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 14:27:49 +00:00
Add and link article about cross compiling binutils
This commit is contained in:
@@ -172,6 +172,8 @@ Idx Name Size VMA LMA File off Algn
|
|||||||
1 .text 0000000b 0000000000100020 0000000000100020 000000a0 2**4
|
1 .text 0000000b 0000000000100020 0000000000100020 000000a0 2**4
|
||||||
CONTENTS, ALLOC, LOAD, READONLY, CODE
|
CONTENTS, ALLOC, LOAD, READONLY, CODE
|
||||||
```
|
```
|
||||||
|
_Note_: The `ld` and `objdump` commands are platform specific. If you're not working on x86_64 architecture, you will need to [cross compile binutils]. Then use `x86_64-elf-ld` and `x86_64-elf-objdump` instead of `ld` and `objdump`.
|
||||||
|
[cross compile binutils]: {{ site.url }}/rust-os/cross-compile-binutils.html
|
||||||
|
|
||||||
## Creating the ISO
|
## Creating the ISO
|
||||||
The last step is to create a bootable ISO image with GRUB. We need to create the following directory structure and copy the `kernel.bin` to the right place:
|
The last step is to create a bootable ISO image with GRUB. We need to create the following directory structure and copy the `kernel.bin` to the right place:
|
||||||
@@ -283,6 +285,7 @@ Some comments (see the [Makefile tutorial] if you don't know `make`):
|
|||||||
- the `$(wildcard src/arch/$(arch)/*.asm)` chooses all assembly files in the src/arch/$(arch)` directory, so you don't have to update the Makefile when you add a file
|
- the `$(wildcard src/arch/$(arch)/*.asm)` chooses all assembly files in the src/arch/$(arch)` directory, so you don't have to update the Makefile when you add a file
|
||||||
- the `patsubst` operation for `assembly_object_files` just translates `src/arch/$(arch)/XYZ.asm` to `build/arch/$(arch)/XYZ.o`
|
- the `patsubst` operation for `assembly_object_files` just translates `src/arch/$(arch)/XYZ.asm` to `build/arch/$(arch)/XYZ.o`
|
||||||
- the `$<` and `$@` in the assembly target are [automatic variables]
|
- the `$<` and `$@` in the assembly target are [automatic variables]
|
||||||
|
- if you're using [cross-compiled binutils][cross compile binutils] just replace `ld` with `x86_64-elf-ld`
|
||||||
|
|
||||||
[automatic variables]: https://www.gnu.org/software/make/manual/html_node/Automatic-Variables.html
|
[automatic variables]: https://www.gnu.org/software/make/manual/html_node/Automatic-Variables.html
|
||||||
|
|
||||||
|
|||||||
47
rust-os/cross-compile-binutils.md
Normal file
47
rust-os/cross-compile-binutils.md
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
---
|
||||||
|
layout: page
|
||||||
|
title: Cross Compile Binutils
|
||||||
|
category: "rust-os"
|
||||||
|
---
|
||||||
|
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.
|
||||||
|
[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 `binutils-2.X` where `X` is for example `25.1`. Now can create and switch to a new folder for building (recommended):
|
||||||
|
[download]: ftp://sourceware.org/pub/binutils/snapshots
|
||||||
|
|
||||||
|
```bash
|
||||||
|
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):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
../binutils-2.X/configure --target=x86_64-elf --prefix="$HOME/opt/cross" \
|
||||||
|
--disable-nls --disable-werror \
|
||||||
|
--disable-gdb --disable-libdecnumber --disable-readline --disable-sim
|
||||||
|
```
|
||||||
|
- The `target` argument specifies the the x86_64 target architecture.
|
||||||
|
- The `prefix` argument selects the installation directory, you can change it if you like. But be careful that you do not overwrite your system's binutils.
|
||||||
|
- The `disable-nls` flag disables native language support (so you'll get the same english error messages). It also reduces build dependencies.
|
||||||
|
- The `disable-werror` turns 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):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
make
|
||||||
|
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:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
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.
|
||||||
Reference in New Issue
Block a user