This is an archive of the discontinued LLVM Phabricator instance.

[lld-macho] Force higher alignment for __thread_vars
ClosedPublic

Authored by BertalanD on Sep 24 2022, 12:49 PM.

Details

Reviewers
thakis
Group Reviewers
Restricted Project
Commits
rGd2f3d7bad26a: [lld-macho] Force higher alignment for __thread_vars
Summary

__thread_vars contains pointers to __tlv_bootstrap, which are fixed
up by dyld; however the section's alignment is not specified. This means
that the relocations might end up on odd addresses, which is not
representable by the soon to be added chained fixups.

This is arguably a bug in MC, but this behavior has been there since TLV
support was originally added.

This patch forces the __thread_vars sections to be aligned to the
target's pointer size size. This is done by ld64 as well.

Diff Detail

Event Timeline

BertalanD created this revision.Sep 24 2022, 12:49 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptSep 24 2022, 12:49 PM
BertalanD requested review of this revision.Sep 24 2022, 12:49 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 24 2022, 12:49 PM
thakis accepted this revision.Sep 24 2022, 2:01 PM
thakis added a subscriber: thakis.

LG (nice catch!), but should probably fix this in MC too eventually

This revision is now accepted and ready to land.Sep 24 2022, 2:01 PM
BertalanD added a comment.EditedSep 24 2022, 2:16 PM

thank you!

should probably fix this in MC too eventually

Sure. The fix is a single line change (+ some more for adjusting old tests). I'll submit it for review in a sec.

Oh, MC's layering is a bit confusing. Not sure where to put the setAlignment call.

We'll still need to have this workaround though if we want to be able to link old objects.

We'll still need to have this workaround though if we want to be able to link old objects.

Yes, we'll have to keep the linker-side workaround for quite a while (MC change needs to go to stable, be picked up by projects depending on LLVM like Swift and Rust, those need to be released, people need to adopt the new versions…and also, linking against binary frameworks is a thing on the platform anyways). But one day, maybe we can turn it into an error (or, first, a warning) :)

This revision was automatically updated to reflect the committed changes.