base: Ignore empty constructors array.

This does not affect default Genode builds as far as I can tell. There
is always at least one global static CTOR which seems to be coming from
one of the GCC runtime libs bundled in the toolchain. The problem became
visible for me only after I've replated GCC runtime with LLVM based
one. In such setup I often see binaries that do not have any static ctors.
Such binaries end up crashing Genode ld.lib.so.

Make sure the code does handle empty constructors array.

Fixes #4422
This commit is contained in:
Piotr Tworek 2021-10-27 13:26:49 +02:00 committed by Norman Feske
parent 05e4993d2e
commit 58e0b24006

View File

@ -61,6 +61,11 @@ namespace Genode {
*/
void call_global_static_constructors()
{
/* Don't do anything if there are no constructors to call */
addr_t const ctors_size = (addr_t)&_ctors_end - (addr_t)&_ctors_start;
if (ctors_size == 0)
return;
void (**func)();
for (func = &_ctors_end; func != &_ctors_start; (*--func)());
}