This is an archive of the discontinued LLVM Phabricator instance.

[lld] Fix elf::unlinkAsync detached thread
ClosedPublic

Authored by vitalybuka on Feb 14 2019, 11:40 AM.

Details

Summary

So this patch just make sure that the thread is at least stated
before we return from main.

If we just detach then the thread may be actually be stated just after
the process returned from main and it's calling atexit handers. Then the thread may try to create own function static variable and it will
add new at exit handlers confusing libc.

GLIBC before 2.27 had race in that case which corrupted atexit handlers
list. Support for this use-case for other implementation is also unclear,
so we can try just avoid that.

PR40162

Diff Detail

Repository
rL LLVM

Event Timeline

vitalybuka created this revision.Feb 14 2019, 11:40 AM
ruiu added inline comments.Feb 14 2019, 12:40 PM
lld/ELF/Filesystem.cpp
62 ↗(On Diff #186885)

Flip the condition and return early.

63 ↗(On Diff #186885)

Please leave a comment why we are waiting for a thread startup.

command and early return

moved comment

vitalybuka marked 2 inline comments as done.Feb 14 2019, 12:53 PM
Harbormaster completed remote builds in B28153: Diff 186901.
ruiu added inline comments.Feb 14 2019, 1:55 PM
lld/ELF/Filesystem.cpp
77 ↗(On Diff #186901)

I don't know if I understand this comment correctly. Why don't you simply mention that there is a race condition in glibc 2.27 and earlier that crashes an entire process if the main thread calls exit(2) while other thread is starting up.

nit: please insert a blank line before a multi-line comment.

simplify comments

vitalybuka marked an inline comment as done.Feb 14 2019, 2:40 PM
ruiu accepted this revision.Feb 14 2019, 2:56 PM

LGTM

This revision is now accepted and ready to land.Feb 14 2019, 2:56 PM
This revision was automatically updated to reflect the committed changes.