This is an archive of the discontinued LLVM Phabricator instance.

Put the header in the first PT_LOAD even if that PT_LOAD has a LMAExpr
ClosedPublic

Authored by espindola on Jan 25 2018, 11:12 AM.

Details

Reviewers
ruiu
grimar
Summary

This should fix

https://bugs.llvm.org/show_bug.cgi?id=36017

The root problem is that we were creating a PT_LOAD just for the header. That was technically valid, but inconvenient: we should not be making the ELF discontinuous.

The solution is to allow a section with LMAExpr to be added to a PT_LOAD if that PT_LOAD doesn't already have a LMAExpr.

Diff Detail

Event Timeline

espindola created this revision.Jan 25 2018, 11:12 AM
emaste added inline comments.Jan 25 2018, 11:20 AM
test/ELF/linkerscript/merge-header-load.s
11–12

This is true only for the case where we set LMA (right?)

In normal use w/o a linker script (or without setting LMA) the PT_PHDR is just included in the first PT_LOAD.

ruiu added inline comments.Jan 25 2018, 11:50 AM
ELF/Writer.h
47

Can you add a comment?

Added comment.

ruiu accepted this revision.Jan 25 2018, 12:49 PM

LGTM

ELF/Writer.h
50

I would remove A because it looks like it's A in A, B, C, .... and it's true even if two or more sections has a LMA.

This revision is now accepted and ready to land.Jan 25 2018, 12:49 PM
emaste added inline comments.Jan 26 2018, 6:33 AM
ELF/Writer.h
50

I think 'a section has LMA' is grammatically fine even if two or more sections have an LMA, but I see how it could be unclear; what about explicit 'AnySectionHasLMA'?