Skip to content

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

@n-eiling

Description

@n-eiling

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions