This is an archive of the discontinued LLVM Phabricator instance.

[LLD] Fix padding of .eh_frame when in executable segment
ClosedPublic

Authored by andrewng on Sep 5 2017, 3:33 AM.

Details

Summary

The default padding for an executable segment is the target trap
instruction which for x86_64 is 0xCC. However, the .eh_frame section
requires the padding to be zero. The code that writes the .eh_frame
section assumes that its segment is zero initialized and does not
explicitly write the zero padding. This does not work when the .eh_frame
section is in the executable segment (for example when using
-no-rosegment).

This patch changes the .eh_frame writing code to explicitly write the
zero padding.

Diff Detail

Repository
rL LLVM

Event Timeline

andrewng created this revision.Sep 5 2017, 3:33 AM

A similar fix was required for the string table, see https://reviews.llvm.org/D36267.

ruiu added inline comments.Sep 5 2017, 11:14 AM
ELF/SyntheticSections.cpp
525 ↗(On Diff #113815)

I think you can simplify the code by adding this piece of code here.

constexpr size_t Wordsize = sizeof(typename ELFT::uint);

// Zero-clear trailing padding if exists.
memset(Buf + D.size(), 0, Wordsize - D.size() % Wordsize);
andrewng updated this revision to Diff 113975.Sep 6 2017, 3:08 AM

Updated based on suggestion. I still think that keeping the common "AlignSize" is better and safer.

ruiu edited edge metadata.Sep 6 2017, 11:08 AM

LGTM

ELF/SyntheticSections.cpp
526 ↗(On Diff #113975)

I'd name this Aligned as AlignSize sounds like a verb (and AlignedSize is too long).

This revision was automatically updated to reflect the committed changes.