This is an archive of the discontinued LLVM Phabricator instance.

[libc] Linux threads - Setup TLS area of a new thread and cleanup at exit.
ClosedPublic

Authored by sivachandra on Jul 12 2022, 12:59 AM.

Diff Detail

Event Timeline

sivachandra created this revision.Jul 12 2022, 12:59 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJul 12 2022, 12:59 AM
sivachandra requested review of this revision.Jul 12 2022, 12:59 AM

Fix typos in aarch64 loader.

lntue added inline comments.Jul 12 2022, 5:30 PM
libc/config/linux/app.h
83

Why is this uintptr_t but not size_t?

sivachandra added inline comments.Jul 12 2022, 11:25 PM
libc/config/linux/app.h
83

This size value actually comes from the ELF TLS image description. In ELF64 it is a 64-bit value, and in ELF32 it is a 32-bit value. So, capturing it as a uintptr_t value will capture it without any potential mix ups.

lntue added inline comments.Jul 13 2022, 2:37 AM
libc/config/linux/app.h
83

In the implementation below, all the size computations were done with size_t, and then get converted to uintptr_t of TLSDescriptor. Shall we add a static assertion to make sure that it won't silently overflow, i.e. sizeof(size_t) <= sizeof(uintptr_t)? At least they are the same for most of our platforms of interest anyway.

overall LGTM, with a few stylish nits

libc/config/linux/app.h
18

Nit: If you're adjusting the comment below to talk about a TLS image instead of just a TLS, you should do it here too.

libc/src/__support/threads/linux/thread.cpp
112–113

Nit: delete this line.

sivachandra marked 2 inline comments as done.

Address comments.

libc/config/linux/app.h
83

Good catch. I fixed it now to use uintptr_t everywhere.

lntue accepted this revision.Jul 13 2022, 10:50 AM
This revision is now accepted and ready to land.Jul 13 2022, 10:50 AM