diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2026-09-17 14:17:22 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2026-09-17 14:17:22 +0200 |
| commit | 5bad38935238da045d9fd467eae9dfd958deea34 (patch) | |
| tree | 497435b4b21c59644fa705ac5b7df66c10c8f90b /kernel/devices/src/storage/RAMDisk | |
| parent | bc31452b02c938ab522ace77f3da99f70c087f3b (diff) | |
| download | kernel-5bad38935238da045d9fd467eae9dfd958deea34.tar.xz kernel-5bad38935238da045d9fd467eae9dfd958deea34.zip | |
Enable the '-ffreestanding' flag in the x86_64 toolchain file to inform
the compiler about the fact that it cannot rely on the presence of a
standard library implementation, thereby suppressing some optimizations
designed for regular user applications.
GCC supports a number of clever optimizations, some of which rely on the
presence of a standard library. One of them is
"-ftree-loop-distribute-patterns". This optimization performs detection
of certain loop patterns, replacing them with library calls when
applicable. This is problematic for cases in which we implement the
standard library functionality. Consider, a schematic, `memset``:
```c++
void memset(void * d, int v, size_t n)
{
for(auto i = 0uz; i < n: ++i)
{
d[i] = static_cast<std::byte>(v);
}
}
```
GCC recognizes this loop, and similar versions of it, as an
implementation of `memset`. In a hosted implementation, this is an
important optimization, since a standard library may be able to provide
a specifically optimized version of `memset``. So the compiler replaces
this `memset` loop with a call to `memset`, since it is not aware of the
fact we are currently implementing `memset`. Interestingly, tail
recursion optimization eliminates the call, transforming it into a jump
to the start of `memset`. This leads to execution getting stuck inside
`memset` with no way of exiting and no stack usage increase, thus
causing an infinite lockup.
While we could suppress the specific optimization, it is more effective
to tell the compiler "why" it can emit a call to memset in those cases.
Diffstat (limited to 'kernel/devices/src/storage/RAMDisk')
0 files changed, 0 insertions, 0 deletions
