This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Update .relr.dyn once in the absence of SECTIONS commands
AbandonedPublic

Authored by MaskRay on Jan 16 2022, 1:32 PM.

Details

Summary

If an output section does not have internal . = ALIGN(x);, the spacing among
its input sections remain unchanged after script->assignAddresses is called
for the first time.

r_offset is inputSec->getOutputSection().addr + inputSec->outSecOff + offsetInSec
If we delay inputSec->getOutputSection().addr addition to writeTo,
updateAllocSize can be called only once.

Conservatively use !hasSectionsCommand to mean .relr.dyn only needs one update.

With this change, the problem described by D67164 is very difficult to trigger.
I cannot figure out a case to get the ".relr.dyn needs ... padding word(s)"
diagnostic, but keep it just in case.

My --threads=8 chrome link is 1% faster.

Diff Detail

Event Timeline

MaskRay created this revision.Jan 16 2022, 1:32 PM
MaskRay requested review of this revision.Jan 16 2022, 1:32 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 16 2022, 1:32 PM

Will have to have a think to see if I can spot any problems.

If an output section does not have internal . = ALIGN(x);, the spacing among its input sections remain unchanged after script->assignAddresses is called for the first time.

Are you referring to an individual InputSection or an InputSectionDescription as one might have in a LinkerScript? In the presence of thunks you can have situations like:
// First call to assignAddresses, for brevity the first column is outSecOff. The second section has been overaligned to a cache-line size boundary which isn't unheard of at -O3.

0x0 section1 align 4 size 4
// 12 bytes padding
0x10 section2 align 16 size 4

// Case add a single range extension thunk in the middle, no change in overall size

0x0 section1 align 4 size 4
0x4 thunk align 4 size 8
// 4 bytes padding
0x10 section2 align 16 size 4

// Case add two range extension thunks in the middle, cross an alignment boundary.

0x0 section1 align 4 size 4
0x4 thunk align 4 size 8
0xc thunk align 4 size 8
// 12 bytes padding
0x20 section2 align 16 size 4

It is true that we won't see a range extension thunk in the middle of a .relr.dyn section, so this may not be important. It would certainly be true that the input sections in executable output sections might change address due to range-extension thunks. This is not hugely likely in AArch64 though as it would need > 128 MiB of code to trigger.

MaskRay added a comment.EditedJan 17 2022, 4:12 PM

You are right. target->needsThunks targets cannot use this optimization, either. InputSectionDescription spacing is not fixed in the presence of thunks.

Now this optimization seems unworthy because of the complexity to finalizeAddressDependentContent.


If !script->hasSectionsCommand and there is no symbol assignment (the majority of x86 programs), script->assignAddresses can be called only once.
But adding the condition make need to complicate finalizeAddressDependentContent (D117528).

MaskRay abandoned this revision.Feb 1 2022, 10:41 AM