From 58e0b240067194f8f7819ed78ee8ca09656970cf Mon Sep 17 00:00:00 2001 From: Piotr Tworek Date: Wed, 27 Oct 2021 13:26:49 +0200 Subject: [PATCH] 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 --- repos/base/src/lib/startup/_main.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/repos/base/src/lib/startup/_main.cc b/repos/base/src/lib/startup/_main.cc index 5d6780a17a..3e8657d0c0 100644 --- a/repos/base/src/lib/startup/_main.cc +++ b/repos/base/src/lib/startup/_main.cc @@ -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)()); }