This is an archive of the discontinued LLVM Phabricator instance.

[LLD] Add terminator to .eh_frame sections
ClosedPublic

Authored by kettenis on Feb 24 2017, 5:30 AM.

Details

Summary

Currenlty ld.lld does not add a terminator (a CIE with its length field set to zero) to the .eh_frame sections it generates.
While the relevant standards (the AMD64 SysV ABI and the Linux LSB) are not explicit about this, such a terminator
is expected by some unwinder implementations and seems to be always emitted by ld.bfd. In addition to that, the
Linux LSB

https://refspecs.linuxfoundation.org/LSB_5.0.0/LSB-Core-generic/LSB-Core-generic/ehframechpt.html#EHFRAME

explicitly says that

The .eh_frame section shall contain 1 or more Call Frame Information (CFI) records.

Currently, if the .eh_frame sections of the input files only contain terminators, ld.lld emits a zero=sized .eh_frame section
which clearly doesn't meet that requirement.

The diff makes sure a terminator gets added to each .eh_frame section and adjusts all the relevant tests to account
for that. An additional test isn't needed as these adjustments mean that the existence of the terminator is tested for by
several tests already.

Diff Detail

Event Timeline

kettenis created this revision.Feb 24 2017, 5:30 AM
ruiu added inline comments.Feb 24 2017, 10:40 AM
tools/lld/ELF/OutputSections.cpp
413

This needs to be a bit more friendly for future software archaeologist. Please also mention that

  • .eh_frame can optionally end with an empty CIE which is a 4 byte zero,
  • adding a terminator is not required by the standard, but
  • we add that for the sake of compatibility with the GNU linker because they always add that (and some tools seem to depend on that).
kettenis updated this revision to Diff 89796.Feb 25 2017, 10:31 AM

Thanks for the review. This new version expands the comment to explain why we're adding the terminator.

ruiu accepted this revision.Feb 25 2017, 1:22 PM

LGTM. Thanks!

This revision is now accepted and ready to land.Feb 25 2017, 1:22 PM

Could you commit this for me?

This revision was automatically updated to reflect the committed changes.
emaste added a subscriber: emaste.Feb 27 2017, 12:57 PM

some unwinder implementations

Out of curiosity, do you have a link to a specific example?