This is an archive of the discontinued LLVM Phabricator instance.

[Driver] Default to -ftls-model=initial-exec on SerenityOS
AbandonedPublic

Authored by ADKaster on Jul 3 2023, 6:51 PM.

Details

Reviewers
None
Summary

Force Clang use the initial-exec TLS model instead of the default
local-exec when building code for Serenity.

This patch should be removed when the SerenityOS program loader
implements proper TLS support.

Depends on D154396

Diff Detail

Event Timeline

ADKaster created this revision.Jul 3 2023, 6:51 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 3 2023, 6:51 PM
ADKaster requested review of this revision.Jul 3 2023, 6:51 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 3 2023, 6:51 PM
jrtc27 added a subscriber: jrtc27.Jul 3 2023, 9:35 PM

This is pretty dodgy, I don't think it belongs upstream

ADKaster abandoned this revision.Jul 3 2023, 10:49 PM

This is pretty dodgy, I don't think it belongs upstream

Fair enough, the original patch had "probably don't upstream this" in the commit description. @BertalanD mentioned to me on discord that he had a WIP patch for proper TLS on x86_64 and aarch64 cooking already . I'll drop this one and by the time the series lands we'll most likely have the TLS support in serenity already (or we can add it to the default clang args we already use for setting --sysroot for Ports).

I don't think this belongs to the upstream, either. Note: musl's TLS implementation is very clean and may be a good reference.

https://maskray.me/blog/2021-02-14-all-about-thread-local-storage

glibc ld.so reserves some space in static TLS blocks and allows dlopen on such a shared object if its TLS size is small. There could be an obscure reason for using such an attribute: general dynamic and local dynamic TLS models are not async-signal-safe in glibc. However, other libc implementations may not reserve additional TLS space for dlopen'ed initial-exec shared objects, e.g. musl will error.

glibc's model makes it very error-prone, even if dlopen TLS is supported to some extent.

Hi MaskRay!

Your blog post (alongside the Drepper TLS doc) proved to be a very helpful resource for our implementation of the dynamic TLS interface. I currently have a SerenityOS PR open that implements __tls_get_addr and TLSDESC on top of our current TLS infrastructure which only supports static TLS blocks. (Long story short, our loader passes the initial TLS image to the kernel, which automagically copies it over and sets up the thread pointer whenever a new thread is created. We need to move it to the userspace if we want to have a dynamic thread vector and separately allocated TLS blocks). I'd love it if you'd take a look at the PR.