littlekernel / lk

LK embedded kernel
MIT License
3.11k stars 613 forks source link

[top] use incomplete array declarations for constructor symbols #323

Closed pcc closed 2 years ago

pcc commented 2 years ago

Clang will omit the initial comparison in this while loop on the assumption that two different variables will not have the same address, which will lead to a crash if the kernel has no constructors.

It will, however, retain the comparison for incomplete arrays because they may have zero size (and therefore may alias with another variable). Therefore, change the declarations of the start/end symbols for the constructor list to incomplete arrays.

travisg commented 2 years ago

Thanks! I really need to add proper support for clang in the build system as well, since a lot of projects downstream use it.