VILLASframework / node

Connecting real-time power grid simulation equipment
https://fein-aachen.org/projects/villas-node/
Apache License 2.0
10 stars 5 forks source link

static logger initialization and subsequent static initializations using logging.get is undefined behavior #799

Closed n-eiling closed 1 month ago

n-eiling commented 1 month ago

We initialize villas::logging as a static member in log.cpp. At the same time several other objects are created as static objects. Some of them (e.g., MemoryManager, DirectedGraph, HostRamAllocator) use the static object to create their own logging instances, i.e., villas::logging.get(). The initialization order of these objects is undefined and thus what we are doing is undefined behavior. If I activate link time optimization (-lto) I get segmentation faults because the initialization order is different.

I would suggest to move the initialization of these objects to an explicit initialization function, where we can make the initialization order explicit and call this function for example from a library constructor or via a single static initialization.

I only researched this briefly so I may have misunderstood some of this.

n-eiling commented 1 month ago

Nitpick: This would not have happened if we were using static macro loggers :P