This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Support input section description .rel[a].dyn in /DISCARD/
ClosedPublic

Authored by MaskRay on Nov 25 2019, 2:00 PM.

Diff Detail

Event Timeline

MaskRay created this revision.Nov 25 2019, 2:00 PM
MaskRay added a comment.EditedNov 25 2019, 2:07 PM

A gvisor developer reported that .rela.dyn cannot be discarded. I find that supporting .rela.dyn does not even need extra code, so let's do it. We can support .relr.dyn as well, but it may need more work, so I don't include it in this patch.

// SyntheticSections.cpp
    addSize(config->useAndroidRelrTags ? DT_ANDROID_RELRSZ : DT_RELRSZ,
            part.relrDyn->getParent());  // If .relr.dyn is allowed to be discarded, part.relrDyn->getParent() will be null and part.relrDyn->getParent()->size will dereference a null pointer.

Note, there is a difference lld and GNU ld. To suppress .rela.dyn with GNU ld, /DISCARD/ : { *(.rela.data) } should be used instead. I feel that the lld way is more consistent. Sections such as .dynsym, .dynstr and .dynamic are synthesized sections, and they are discarded with an input section description *(.dynsym). It is inconsistent for *(.rela.dyn) not to discard .rela.dyn in GNU ld. It may be unimplemented, though.

ruiu accepted this revision.Nov 25 2019, 9:05 PM

LGTM

This revision is now accepted and ready to land.Nov 25 2019, 9:05 PM
This revision was automatically updated to reflect the committed changes.