Skip to content

static initializer-based registration mechanism not portable #4139

@llvmbot

Description

@llvmbot
Bugzilla Link 3767
Version unspecified
OS All
Reporter LLVM Bugzilla Contributor
CC @asl

Extended Description

Throughout the code, LLVM uses statically initialized variables with the expectation that they will run before main. One example is registering the possible backends, and the other is registering command line flags.

Quoth the Standard: It is implementation-defined whether or not the dynamic initialization (8.5, 9.4, 12.1, 12.6.1) of an object of namespace scope is done before the first statement of main. If the initialization is deferred to some point in time after the first statement of main, it shall occur before the first use of any function or object defined in the same translation unit as the object to be initialized.

This mean that a static initializer need not execute until another function in the TU is called. This comes up in MSVC++ and Windows.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions