This is an archive of the discontinued LLVM Phabricator instance.

ELF: --gdb-index: Change findSection to return an InputSection.
ClosedPublic

Authored by pcc on May 14 2017, 4:37 PM.

Details

Summary

We should only ever expect this function to return a regular
InputSection; I would not expect a function definition to be in a
MergeInputSection or EhInputSection. We were previously crashing
in writeTo if this function returned a section that was not an
InputSection because we do not set OutSec for such sections.

This can happen in practice if a function is defined in an empty
section which shares its offset-in-file with a MergeInputSection,
as in the provided test case.

Diff Detail

Repository
rL LLVM

Event Timeline

pcc created this revision.May 14 2017, 4:37 PM
grimar edited edge metadata.May 15 2017, 3:16 AM

So findSection() approach does not seem to be clean itself and that is root of problem it seems.
We probably can land this one to stop crashing (and as a bonus it adds testcase which also seems useful to have),
but for solving general issue I just posted D33183 which removes findSection() need and not only
speedup things but also should fix issue this patch addresses either.

I am OK to land this for start too. Rui ?

ruiu edited edge metadata.May 15 2017, 10:24 AM

How did you create that object file? At least you want to leave a comment in the test about how you created it.

lld/ELF/SyntheticSections.cpp
1707 ↗(On Diff #98937)

Use dyn_cast instead of isa and cast.

pcc added a comment.May 15 2017, 10:42 AM

So findSection() approach does not seem to be clean itself and that is root of problem it seems.
We probably can land this one to stop crashing (and as a bonus it adds testcase which also seems useful to have),
but for solving general issue I just posted D33183 which removes findSection() need and not only
speedup things but also should fix issue this patch addresses either.

Agreed that we should fix the interface (thanks for working on that!), and that this is useful at least for the test case.

In D33176#755234, @ruiu wrote:

How did you create that object file? At least you want to leave a comment in the test about how you created it.

See lld/test/ELF/Inputs/gdb-index-empty.o.sh, but I'll convert this to a .s.

pcc updated this revision to Diff 99026.May 15 2017, 10:53 AM
pcc marked an inline comment as done.
  • Address review comments
ruiu accepted this revision.May 15 2017, 10:55 AM

LGTM. Let's land this first to fix the crash bug.

This revision is now accepted and ready to land.May 15 2017, 10:55 AM
This revision was automatically updated to reflect the committed changes.
grimar added inline comments.May 16 2017, 8:03 AM
lld/trunk/test/ELF/gdb-index-empty.s
15

I think this *.s can be significantly reduced.

Honestly I was fine with binary.
But if we have .s, I would expect to see much less code here.