Skip to content

[libLLVM] Function scoped statics cause segfaults when main thread exits during compilation #132452

Open
@patrick-rivos

Description

@patrick-rivos

Reproducer: https://github.com/patrick-rivos/llvm-function-scoped-statics

https://reviews.llvm.org/D129120 (and many other commits) removed uses of ManagedStatic and replaced the uses with a function-scoped static. This introduced subtle issues for multithreaded programs that dlopen libLLVM (eg. users of the jit).

Since static objects are destructed in reverse order of registration (alongside atexit handlers), multithreaded programs can encounter a situation where the main thread calls exit() and starts executing function-scoped static destructors. This can result in failed assertions or segfaults when compiling as the function-scoped static objects have been pulled out from under libLLVM.

Moving function-scoped statics back to ManagedStatic would fix this issue. Not sure if there are complexities with that approach.

Some relevant commits: ede6003 c4ccf60 ebbbd93

cc @nhaehnle

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions