This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Allow SHF_LINK_ORDER and non-SHF_LINK_ORDER to be mixed
ClosedPublic

Authored by MaskRay on Mar 28 2020, 11:34 PM.

Details

Summary

Currently, error: incompatible section flags for .rodata is reported
when we mix SHF_LINK_ORDER and non-SHF_LINK_ORDER sections in an output section.

This is overconstrained. This patch allows mixed flags with the
requirement that SHF_LINK_ORDER sections must be contiguous. Mixing
flags is used by Linux aarch64 (https://github.com/ClangBuiltLinux/linux/issues/953)

.init.data : { ... KEEP(*(__patchable_function_entries)) ... }

When the integrated assembler is enabled, clang's -fpatchable-function-entry=N[,M]
implementation sets the SHF_LINK_ORDER flag (D72215) to fix a number of
garbage collection issues.

Strictly speaking, the ELF specification does not require contiguous
SHF_LINK_ORDER sections but for many current uses of SHF_LINK_ORDER like
.ARM.exidx/__patchable_function_entries there has been a requirement for
the sections to be contiguous on top of the requirements of the ELF
specification.

This patch also imposes one restriction: SHF_LINK_ORDER sections cannot
be separated by a symbol assignment or a BYTE command. Not allowing BYTE is a natural
extension that a non-SHF_LINK_ORDER cannot be a separator.
Symbol assignments can delimiter the contents of SHF_LINK_ORDER sections.
Allowing SHF_LINK_ORDER sections cross symbol assignments (e.g. start_/stop_) can make things hard to explain.

Diff Detail

Event Timeline

MaskRay created this revision.Mar 28 2020, 11:34 PM
psmith accepted this revision.Mar 30 2020, 8:48 AM

I agree that there is no reason not to support the mixing of SHF_LINK_ORDER and non SHF_LINK_ORDER in the same OutputSection. Arm's proprietary linker will handle .ARM.exidx that way, I believe that a separate OutputSection is used in GNU ld and LLD as it simplifies the generation of Linker Generated Symbols that the library uses to find the tables.

Strictly speaking I don't think that there is anything in the ELF spec that requires that SHF_LINK_ORDER sections be contiguous.

This flag adds special ordering requirements for link editors. The requirements apply if the sh_link field of this section's header references another section (the linked-to section). If this section is combined with other sections in the output file, it must appear in the same relative order with respect to those sections, as the linked-to section appears with respect to sections the linked-to section is combined with.

In all current uses of SHF_LINK_ORDER like .ARM.exidx there has been a requirement for the sections to be contiguous on top of the requirements of the ELF specification so I'm happy to keep the diagnostic.

This revision is now accepted and ready to land.Mar 30 2020, 8:48 AM
MaskRay updated this revision to Diff 253621.Mar 30 2020, 9:47 AM
MaskRay edited the summary of this revision. (Show Details)

Incorporate some wording changes suggested by Peter

MaskRay updated this revision to Diff 253624.Mar 30 2020, 9:57 AM
MaskRay edited the summary of this revision. (Show Details)

Improve test.
Mention -fpatchable-function-entry= sets SHF_LINK_ORDER only if integrated assembler is enabled

MaskRay edited the summary of this revision. (Show Details)Mar 30 2020, 10:01 AM
This revision was automatically updated to reflect the committed changes.