aboutsummaryrefslogtreecommitdiff
path: root/libs/kstd/include
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@ost.ch>2026-09-17 14:17:22 +0200
committerFelix Morgner <felix.morgner@ost.ch>2026-09-17 14:17:22 +0200
commit5bad38935238da045d9fd467eae9dfd958deea34 (patch)
tree497435b4b21c59644fa705ac5b7df66c10c8f90b /libs/kstd/include
parentbc31452b02c938ab522ace77f3da99f70c087f3b (diff)
downloadkernel-develop.tar.xz
kernel-develop.zip
build/x86_64: add missing -ffreestanding flagHEADdevelop
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 'libs/kstd/include')
0 files changed, 0 insertions, 0 deletions