This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Properly handle .eh_frame in linker scripts
ClosedPublic

Authored by phosek on Mar 5 2017, 5:27 PM.

Details

Summary

Using .eh_frame input section pattern in linker script currently causes a crash; this is because .eh_frame input sections require special handling since they're all combined into a synthetic section rather than regular output section.

Diff Detail

Repository
rL LLVM

Event Timeline

phosek created this revision.Mar 5 2017, 5:27 PM
ruiu edited edge metadata.Mar 6 2017, 9:32 AM

SHF_MERGE sections are also handled in a special way because they are aggregated one synthetic section (which is done in combineMergableSections in Writer.cpp). Maybe we should do the same thing for .eh_frame? At least they need to be consistent.

phosek updated this revision to Diff 90783.Mar 6 2017, 7:27 PM

I tried to use the same handling as in case of combineMergableSections, let me know if this makes sense.

ruiu added inline comments.Mar 7 2017, 3:42 PM
ELF/SyntheticSections.cpp
507–508 ↗(On Diff #90783)

What is this for?

ELF/Writer.cpp
227 ↗(On Diff #90783)

EHFrame -> EhFrame since we have EhFrameSection.

935–938 ↗(On Diff #90783)

What is this?

phosek added inline comments.Mar 7 2017, 5:49 PM
ELF/SyntheticSections.cpp
507–508 ↗(On Diff #90783)

.eh_frame can have relocations, so we need to ensure that if the EhFrameSection gets GC'ed, .rel.eh_frame/.rela.eh_frame gets GC'ed as well.

ELF/Writer.cpp
935–938 ↗(On Diff #90783)

To process .eh_frame relocations.

ruiu added inline comments.Mar 7 2017, 5:56 PM
ELF/SyntheticSections.cpp
507–508 ↗(On Diff #90783)

But when the control reached Writer::run function, all garbage has already been gc'ed, no?

phosek added inline comments.Mar 7 2017, 6:02 PM
ELF/SyntheticSections.cpp
507–508 ↗(On Diff #90783)

Not necessarily, for example you can have /DISCARD/ : { *(.eh_frame) } in the linker script which only gets processed in LinkerScript::processCommands.

ruiu accepted this revision.Mar 7 2017, 6:05 PM

LGTM

ELF/SyntheticSections.cpp
507–508 ↗(On Diff #90783)

Ah, that's right.

Somewhat orthogonal, but can you avoid using std::move and just copy? I don't think we need memory here.

This revision is now accepted and ready to land.Mar 7 2017, 6:05 PM
phosek updated this revision to Diff 90980.Mar 7 2017, 8:53 PM
phosek marked 2 inline comments as done.

This patch causes crash, when creating PT_GNU_EH_FRAME segment in Writer<ELFT>::createPhdrs (OutSec is nullptr) in case .eh_frame section is discarded in linker script.

This revision was automatically updated to reflect the committed changes.