From f946a818294b3ee82c300a3bb0527799a1650ec9 Mon Sep 17 00:00:00 2001 From: "Ivan G." Date: Tue, 1 Jul 2025 12:39:36 +0100 Subject: [PATCH 1/6] Update E_Cross_Compilers.md --- 99_Appendices/E_Cross_Compilers.md | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/99_Appendices/E_Cross_Compilers.md b/99_Appendices/E_Cross_Compilers.md index a53173e..aa7b536 100644 --- a/99_Appendices/E_Cross_Compilers.md +++ b/99_Appendices/E_Cross_Compilers.md @@ -72,7 +72,7 @@ cd binutils_build From this temporary directory we can use the configure script to generate the build files, like so: ```bash -/path/to/binutils_src/configure --target=$TARGET --with-sysroot --disable-nls --disable-werror +/path/to/binutils_src/configure --prefix=$PREFIX --target=$TARGET --with-sysroot --disable-nls --disable-werror ``` At this point the configure script has generated a makefile for us with our requested options, now we can do the usual series of commands: @@ -99,6 +99,19 @@ For brevity we'll only explain the new flags: - `--enable-languages=c,c++`: select which language frontends to enable, these two are the default. We can disable c++ but if we plan to cross compile more things than our kernel this can be nice to have. - `--without-headers`: tells the compiler not to rely on any headers from the host and instead generate its own. +If it fails with the following error: + +``` +configure: error: Building GCC requires GMP 4.2+, MPFR 3.1.0+ and MPC 0.8.0+. +``` + +Just run the following script from the gcc _source directory_: + +```sh +./contrib/download_prerequisites +``` + +It will download the missing dependencies for us. Now is possible to relaunch the `configure` command. Once the script is finished we can run a few make targets to build the compiler and its support libraries. By default running `make`/`make all` is not recommended as this builds everything for a full userspace compiler. We don't need all that and it can take a lot of time. For a freestanding program like a kernel we only need the compiler and libgcc. ```bash @@ -154,7 +167,7 @@ Qemu is quite a large program, so it's recommended to make use of all cores when ## GDB -The steps for building GDB are similar to binutils and GCC. We'll create a temporary working directory and move into it. Gdb has a few extra dependencies we'll need (name can be different depending on the distribution used): +The steps for building GDB are similar to binutils and GCC. We'll create a temporary working directory and move into it. Gdb has a few extra dependencies we'll need (name can be different depending on the distribution used, the names below are for _Debian_ based distributions): * libncurses-dev * libsource-highlight-dev From 6af9d7d673cd42f157480ffbdff4001693f48874 Mon Sep 17 00:00:00 2001 From: "Ivan G." Date: Tue, 1 Jul 2025 13:08:00 +0100 Subject: [PATCH 2/6] Update E_Cross_Compilers.md --- 99_Appendices/E_Cross_Compilers.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/99_Appendices/E_Cross_Compilers.md b/99_Appendices/E_Cross_Compilers.md index aa7b536..c907254 100644 --- a/99_Appendices/E_Cross_Compilers.md +++ b/99_Appendices/E_Cross_Compilers.md @@ -147,7 +147,7 @@ Of course we can use any emulator we want, but in our example we rely on qemu. T As usual let's create a new folder called `build_qemu` and move into it. The configure command is: ```bash -/path/qemu_src/configure --prefix=$PREFIX --target-list=riscv64-softmmu --enable-gtk --enable-gtk-clipboard --enable-tools --enable-vhost-net +/path/qemu_src/configure --prefix=$PREFIX --target-list=riscv64-softmmu,x86_64-softmmu --enable-gtk --enable-gtk-clipboard --enable-tools --enable-vhost-net ``` where: From 345464f9ad1e062b87bd9307a3e6119a0ffe0e20 Mon Sep 17 00:00:00 2001 From: "Ivan G." Date: Tue, 1 Jul 2025 14:36:45 +0100 Subject: [PATCH 3/6] Update E_Cross_Compilers.md --- 99_Appendices/E_Cross_Compilers.md | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/99_Appendices/E_Cross_Compilers.md b/99_Appendices/E_Cross_Compilers.md index c907254..31acd98 100644 --- a/99_Appendices/E_Cross_Compilers.md +++ b/99_Appendices/E_Cross_Compilers.md @@ -88,7 +88,7 @@ That's it! Now all the binutils tools are installed in the `PREFIX` directory an The process for building GCC is very similar to binutils. Note that we need to have a version of binutils for our target triplet before trying to build GCC. These binaries must also be in the path, which we did before. Let's create a new folder for the build files (`build_gcc`) and move into it. -Now we can use the configure script like before: +Now we can use the configure: ```bash /path/to/gcc_sources/configure --target=$TARGET --prefix=$PREFIX --disable-nls --enable-languages=c,c++ --without-headers @@ -99,18 +99,6 @@ For brevity we'll only explain the new flags: - `--enable-languages=c,c++`: select which language frontends to enable, these two are the default. We can disable c++ but if we plan to cross compile more things than our kernel this can be nice to have. - `--without-headers`: tells the compiler not to rely on any headers from the host and instead generate its own. -If it fails with the following error: - -``` -configure: error: Building GCC requires GMP 4.2+, MPFR 3.1.0+ and MPC 0.8.0+. -``` - -Just run the following script from the gcc _source directory_: - -```sh -./contrib/download_prerequisites -``` - It will download the missing dependencies for us. Now is possible to relaunch the `configure` command. Once the script is finished we can run a few make targets to build the compiler and its support libraries. By default running `make`/`make all` is not recommended as this builds everything for a full userspace compiler. We don't need all that and it can take a lot of time. For a freestanding program like a kernel we only need the compiler and libgcc. From a07308c24b918802903945ce50f68420a7ff1ba2 Mon Sep 17 00:00:00 2001 From: "Ivan G." Date: Tue, 1 Jul 2025 15:12:43 +0100 Subject: [PATCH 4/6] Update E_Cross_Compilers.md --- 99_Appendices/E_Cross_Compilers.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/99_Appendices/E_Cross_Compilers.md b/99_Appendices/E_Cross_Compilers.md index 31acd98..7c271cd 100644 --- a/99_Appendices/E_Cross_Compilers.md +++ b/99_Appendices/E_Cross_Compilers.md @@ -130,7 +130,7 @@ Of course we can use any emulator we want, but in our example we rely on qemu. T * ninja-build * python3-sphinx * sphinx-rtd-theme -* If we want to use the gtk ui, we also need libgtk3-dev +* If we want to use the gtk ui, we also need libgtk-3-dev As usual let's create a new folder called `build_qemu` and move into it. The configure command is: From fb76b87429f61b50f3dde2f3ffc1644b39b2a95c Mon Sep 17 00:00:00 2001 From: "Ivan G." Date: Tue, 1 Jul 2025 15:43:38 +0100 Subject: [PATCH 5/6] Update E_Cross_Compilers.md --- 99_Appendices/E_Cross_Compilers.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/99_Appendices/E_Cross_Compilers.md b/99_Appendices/E_Cross_Compilers.md index 7c271cd..100582c 100644 --- a/99_Appendices/E_Cross_Compilers.md +++ b/99_Appendices/E_Cross_Compilers.md @@ -129,6 +129,8 @@ Of course we can use any emulator we want, but in our example we rely on qemu. T * ninja-build * python3-sphinx +* python3-pip +* python3-venv * sphinx-rtd-theme * If we want to use the gtk ui, we also need libgtk-3-dev From 7b737139eec35a9a4b32db949bcd7c4e62fdd4dc Mon Sep 17 00:00:00 2001 From: "Ivan G." Date: Fri, 4 Jul 2025 12:13:47 +0100 Subject: [PATCH 6/6] Update E_Cross_Compilers.md Changes requested. --- 99_Appendices/E_Cross_Compilers.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/99_Appendices/E_Cross_Compilers.md b/99_Appendices/E_Cross_Compilers.md index 100582c..e76e037 100644 --- a/99_Appendices/E_Cross_Compilers.md +++ b/99_Appendices/E_Cross_Compilers.md @@ -88,7 +88,7 @@ That's it! Now all the binutils tools are installed in the `PREFIX` directory an The process for building GCC is very similar to binutils. Note that we need to have a version of binutils for our target triplet before trying to build GCC. These binaries must also be in the path, which we did before. Let's create a new folder for the build files (`build_gcc`) and move into it. -Now we can use the configure: +Now we can use the configure command: ```bash /path/to/gcc_sources/configure --target=$TARGET --prefix=$PREFIX --disable-nls --enable-languages=c,c++ --without-headers @@ -99,7 +99,7 @@ For brevity we'll only explain the new flags: - `--enable-languages=c,c++`: select which language frontends to enable, these two are the default. We can disable c++ but if we plan to cross compile more things than our kernel this can be nice to have. - `--without-headers`: tells the compiler not to rely on any headers from the host and instead generate its own. -It will download the missing dependencies for us. Now is possible to relaunch the `configure` command. +It will download the missing dependencies for us. Now is possible to re-run the `configure` command. Once the script is finished we can run a few make targets to build the compiler and its support libraries. By default running `make`/`make all` is not recommended as this builds everything for a full userspace compiler. We don't need all that and it can take a lot of time. For a freestanding program like a kernel we only need the compiler and libgcc. ```bash