This is an archive of the discontinued LLVM Phabricator instance.

[lld/mac] Make sure __thread_ptrs is in front of __thread_bss
ClosedPublic

Authored by thakis on Jun 19 2021, 7:59 AM.

Details

Summary

The exact location doesn't matter, but it should be in front
of __thread_bss. We put it right in front of __thread_data
which is where ld64 seems to put it as well.

Fixes PR50769.

(As mentioned on the bug, there is probably a more structural
fix too, see comment 5. If we don't address this, it's likely
we'll run into this again with other synthetic sections. But
for now, let's fix the immediate breakage.)

Diff Detail

Event Timeline

thakis created this revision.Jun 19 2021, 7:59 AM
Herald added a reviewer: gkm. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript

The reason it's important that zerofill sections are at the end is because dyld does

bool ImageLoaderMachO::segHasTrailingZeroFill(unsigned int segIndex)
{
	return ( segWriteable(segIndex) && (segSize(segIndex) > segFileSize(segIndex)) );
}

to detect zerofill sections. It doesn't look at section flags but only on where and how large the section is (and then it maps with VM_PROT_ZF when needed).

thakis edited the summary of this revision. (Show Details)Jun 19 2021, 8:02 AM
int3 accepted this revision.Jun 19 2021, 9:42 AM

Thanks! I see why you were checking for the GOT in tlv-dylib.s now...

This revision is now accepted and ready to land.Jun 19 2021, 9:42 AM
This revision was landed with ongoing or failed builds.Jun 19 2021, 9:57 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptJun 19 2021, 9:57 AM