This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Set SHF_INFO_LINK for .rel[a].plt and .rel[a].dyn
ClosedPublic

Authored by MaskRay on Oct 20 2020, 2:48 PM.

Details

Summary

The ELF spec says

If the sh_flags field for this section header includes the attribute SHF_INFO_LINK, then this member represents a section header table index.

Set SHF_INFO_LINK so that binary manipulation tools know that sh_info is
a section header table index instead of (the number of local symbols in the case of SHT_SYMTAB/SHT_DYNSYM).
We have already added SHF_INFO_LINK for --emit-relocs retained SHT_REL[A].

For example, we can teach llvm-objcopy to preserve the section index of the sh_info referenced section if
SHF_INFO_LINK is set. (GNU objcopy recognizes .rel[a].plt and updates
sh_info even if SHF_INFO_LINK is not set).

Diff Detail

Event Timeline

MaskRay created this revision.Oct 20 2020, 2:48 PM
MaskRay requested review of this revision.Oct 20 2020, 2:48 PM
MaskRay edited the summary of this revision. (Show Details)Oct 20 2020, 2:53 PM
grimar accepted this revision.Oct 21 2020, 5:53 AM

Looks reasonable. Probably worth waiting to see if others have objections.

This revision is now accepted and ready to land.Oct 21 2020, 5:53 AM

@psmith Does this also look good to you? (It is to be consistent with GNU ld and LLD's own --emit-relocs SHT_REL[A])

LGTM too. Apologies for the delay. This looks like it is consistent with the ELF specification.

This revision was automatically updated to reflect the committed changes.