This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Move SHF_LINK_ORDER till OutputSection addresses are known
ClosedPublic

Authored by psmith on May 2 2020, 3:14 AM.

Details

Summary

Sections L with the SHF_LINK_ORDER flag must be ordered in the same relative order as the Sections they have a link to. When using a linker script an arbitrary expression may be used for the virtual address of the OutputSection. In some cases the virtual address does not monotonically increase as the OutputSection index increases, so if we base the ordering of the SHF_LINK_ORDER sections on the index then we can get the order wrong. We fix this by moving SHF_LINK_ORDER resolution till after we have created OutputSection virtual addresses.

This is a follow up patch from D78422 which moved the .ARM.exidx to a similar place.

Diff Detail

Event Timeline

psmith created this revision.May 2 2020, 3:14 AM
grimar accepted this revision.May 2 2020, 4:18 AM

This LGTM. Please wait for another approvement.

nit: the patch is missing content.

(I am on vacation until 12 of May).

lld/ELF/Writer.cpp
2135

nit: unrelated comment change.

lld/test/ELF/linkorder-script.s
12

nit: double space after .linkorder

24

nit: I'd probably just use nop for text*

This revision is now accepted and ready to land.May 2 2020, 4:18 AM
psmith updated this revision to Diff 261632.May 2 2020, 4:49 AM

Add context to diff

MaskRay accepted this revision.May 2 2020, 9:58 AM
MaskRay added inline comments.
lld/ELF/Writer.cpp
2131

Confirmed that gc-sections-linkorder-err.s (initially added in D67761) needs early-return here.

lld/test/ELF/linkorder-script.s
24

You can use nop for .text* and .byte for .linkorder*

Everything being one-byte makes it easier to recognize the section order.

Sections L with the SHF_LINK_ORDER flag must be ordered in the same relative order as the Sections they have a link to.

s/Sections L/Sections/

psmith added a comment.May 4 2020, 6:26 AM

Thanks for the comments. I've updated the patch prior to commit.

This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptMay 4 2020, 6:54 AM