summaryrefslogtreecommitdiff
path: root/Fosdem2024/contents.md
blob: 4c8b74e1cb2a96f1dc45100463d8652b3d821d64 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
---
title: RISC-V Bootstrapping in Guix and Live-Bootstrap
subtitle: Status report for 2023, and what's coming up next

license: CC-BY-SA
author: Ekaitz Zárraga
links-as-notes: true
lang: spanish
polyglossia-lang:
    name: english
how-to: pandoc -f markdown+smart -t beamer contents.md -o beamer.pdf --pdf-engine=xelatex --template=template.tex
convert-img: inkscape IN.svg --export-filename OUT.png --export-type=png --export-background-opacity=0.0 # NOT NEEDED!
header-includes:
    - \usepackage{multicol}
    - \newcommand{\hideFromPandoc}[1]{#1}
    - \hideFromPandoc{
        \let\Begin\begin
        \let\End\end
      }
...

## Before we start

If you want details and don't mind reading large text walls full of
nitty-gritty details, you can leave this talk and read [all the blogposts I did
on the process](https://ekaitz.elenq.tech/tag/bootstrapping-gcc-in-risc-v.html)

**You can still stay here and smile, too.**

## Who I am

- Telecommunication engineer (EEE equivalent)
- Freelance engineer/programmer at [ElenQ.Tech](https://elenq.tech)
- Guix user and contributor
- You might remember me from my talk last year:
  *"Bringing RISC-V to Guix's bootstrap"*



## Context

- In 2021 [NlNet][nlnet-grant-i] funded me to do some bootstrapping work: I
  backported RISC-V support to GCC 4.6.4 from 7.5, and to our TinyCC-Boot from
  upstream TinyCC. These were fundamental points in our bootstrap chain.
- I explained that in [FOSDEM 2023][fosdem-2023].

[nlnet-grant-i]: https://nlnet.nl/project/GNUMes-RISCV/index.html
[fosdem-2023]: https://archive.fosdem.org/2023/schedule/event/guixriscv/

\hfill ![\ ](img/nlnet.svg){height=25px}\
\hfill ![\ ](img/NGIAssure.svg){height=15px}


## Intro

- The work wasn't finished so I asked for a [second grant to
  NlNet][nlnet-grant-ii].
- I was tired of the previous effort and I needed help. I decided to bring more
  people to the project:
    - **Andrius Štikonas**: Involved in `live-bootstrap`, `stage-0` and the
      related projects. Has the context awareness I lack.
    - **Janneke**: `Mes` maintainer and author, `TinyCC-boot` maintainer and
      `guix` contributor. All these projects are structural to the
      bootstrapping process.
    - More people
- My goal was to pay people for their good work, using the success of my
  previous effort as a lever to get funded.

[nlnet-grant-ii]: https://nlnet.nl/project/GNUMes-RISCV-bootstrap/

\hfill ![\ ](img/nlnet.svg){height=25px}\
\hfill ![\ ](img/NGIAssure.svg){height=15px}


# In pictures

## Bootstrapping process - Before

\Begin{multicols}{2}

- Colors represent RISC-V support:
    - **\textcolor{red}{RED}**: no RISC-V support
    - **\textcolor{orange}{ORANGE}**: some RISC-V support
    - **\textcolor{green}{GREEN}**: full RISC-V support
- **TinyCC-boot** and **GCC (old)** are **\textcolor{red}{RED}**.
\vfill

\columnbreak

![\ ](img/Bootstrapping_simple.svg)

\End{multicols}

## Bootstrapping process - After the Backport (2022)

\Begin{multicols}{2}

- **Arrows** are still **\textcolor{red}{RED}**
- At that time I didn't know **TinyCC** was **\textcolor{orange}{ORANGE}**,
  that was discovered later
- **GCC (old)** was actually **\textcolor{green}{GREEN}ER** than I thought
\vfill

\columnbreak

![\ ](img/Bootstrapping_with_backport.svg)

\End{multicols}

## Bootstrapping process - Now

\Begin{multicols}{2}
- **TinyCC-Boot** is **\textcolor{green}{GREEN}** now
- The **\textcolor{green}{GREEN}** rectangle is included in `Guix` and
  `live-bootstrap`
- **GCC (old)** is **\textcolor{green}{GREEN}** now: Tested in Debian in real
  RISC-V hardware.
\vfill

\columnbreak

![\ ](img/Bootstrapping_now.svg)

\End{multicols}

## Bootstrapping process - Future

\Begin{multicols}{2}
- **\textcolor{red}{->} TinyCC** requires changes in MesLibC
- **\textcolor{red}{->} GCC (old)**:
    - requires `make`
    - TinyCC claims to be able to build GCC 4, but we didn't test that (i386
      bootstrap uses GCC 2.95 in between).
- **\textcolor{red}{->} GCC** should *just work*
- A powerful `libc` is needed, built with TinyCC, which doesn't support
  Extended Assembly.
\vfill

\columnbreak

![\ ](img/Bootstrapping_now.svg)

\End{multicols}


# Questions?

## 

<!-- EXTRA -->

# Limitations of the backport

## TinyCC

- I only tested the backend, in an emulated environment, using a using TinyCC
  as a cross-compiler
- I tested on **GLibC**, but in the bootstrapping process it uses **MesLibC**,
  a minimal **LibC**, part of Mes.
- **TinyCC-Boot** is in fact compiled several times (up to 6) with different
  features (using conditional compilation via macro definitions like `-D...`).
    - In a cross compiled environment this is not possible to test
- I didn't test the TinyCC **RISC-V assembler**, which happened to be
  unimplemented (yeah... LOL), and it's needed for the **LibC**.

## TinyCC

![TinyCC-Boot bootstrapping process](img/tcc-boot.svg)

## GCC

- I tested it as a Cross-Compiler, so only the backend was tested. Again, no
  bootstrap[^gcc-bootstrap].
- It never compiled itself
- I didn't work on the C++ support

[^gcc-bootstrap]: GCC has a bootstrap process that checks if the compiler works
    correctly. First, it's compiled with your compiler of choice. Then, the
    resulting binary is used to compile the GCC codebase again. The result of
    that compiles GCC again. Then the binaries are compared, to make sure they
    are identical. This can't be done in a cross-compiled environment, for
    obvious reasons.

# The work

## TinyCC-Boot

We focused on this, and let the other projects be carried by this effort.

- Andrius and I spent many nights debugging crazy things in here.
- TinyCC's codebase is hard to read
- Many errors we got were not reproducible using a TinyCC compiled with GCC, so
  we needed to build it from MesCC, which is very slow
- MesCC doesn't provide very helpful debug symbols
- We learned many things as we went

> I wouldn't have the energy to make this without Andrius.

## TinyCC-Boot - Crazy things

1. Body is never executed:

    ``` c
    if ( x < 8 ) {
        // body
    }
    ```
2. `A << 20 >> 20`
3. `__global_pointer$ is not a valid symbol`
4. Assembler uses a weird syntax and doesn't support Extended Assembly
5. `cannot cast from/to void`
6. And segfaults, segfaults everywhere!

[Read more about them here](https://ekaitz.elenq.tech/bootstrapGcc8.html)

## TinyCC-Boot - Results

We finally managed to bootstrap TinyCC-Boot.

- Andrius included the [build recipe in `live-bootstrap`](https://github.com/fosslinux/live-bootstrap/blob/master/steps/tcc-0.9.26/pass1.kaem)
- I did the [`guix` recipe](https://issues.guix.gnu.org/68222)

## GNU Mes

The problems we found in **TinyCC-Boot** made us improve Mes in several ways:

- **MesCC**, the C compiler, had some limitations that were unnoticed in the i386
  bootstrap that appeared in RISC-V: faulty `switch-case`s, wrong `struct`
  initializations, some integer weirdness...
- **MesLibC**, had to be split for our TinyCC as it doesn't support Extended
  Assembly, and it also needed some extra tweaks: `char` signedness, `va_args`
  support, build script support for the changes...

> Having Janneke with us made the process very smooth.


## GCC

- We compiled GCC with itself in a Debian machine in real RISC-V hardware
- Including C++ support
- [Only needed a few commits!](https://github.com/ekaitz-zarraga/gcc/compare/working-compiler...riscv)
- Guix recipe is pending, as we need to fix other steps to be able to add this:
  `make`, a proper `libc`, TinyCC...


# Last words

## Last words

- People is important: I felt alone, and I didn't know how to continue. If I
  had to spend another year working alone I would've just rejected the project.
  **Bringing people gave me energy, knowledge and emotional support**

- Money is important: thanks to NlNet I had the chance to pay people for their
  work and buy some hardware. Covering people's basic needs is fundamental.
  **Getting paid makes people independent, so they can focus on what they are
  good at instead of struggling to survive**

## So

- Thanks, Andrius and Janneke
- Thanks, NlNet
- And...

# Thank you

## Contact and take part

- Email me: <ekaitz@elenq.tech>
- Relevant IRC channels: `#bootstrappable`, `#guix`, `#guix-risc-v`