Skip to content

attribute((init_priority(N))) is not codegen'ed properly #11852

@asl

Description

@asl
Bugzilla Link 11480
Resolution FIXED
Resolved on Sep 09, 2015 11:53
Version unspecified
OS All
CC @noloader,@kaomoneus

Extended Description

Right now attribute((init_array(N))) in clang defines the "local" order of initialization of statics in the same TU. However, gcc's behavior for init_array(N) is same as for constructor(N) - global priority wrt all TUs.

The solution seems to be easy - instead of emission of the single global initialization function, emit one for each priority and rely on the priorities in the LLVM's global_ctor / global_dtor section. There, if the target supports the ctor / dtor priorities, then everything will be emitted in the appropriate order. Otherwise (e.g. on Darwin, which does not support the priorities), we'll emit everything into the single section with the proper priority order.

Does this sound reasonable?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillaclang:codegenIR generation bugs: mangling, exceptions, etc.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions