This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Fix fetching source line, when file has multiple "AX" sections
ClosedPublic

Authored by evgeny777 on Oct 28 2016, 6:03 AM.

Details

Summary

Very often object file would have multiple .text.* sections instead of one. This happens if you have comdat groups (use C++ templates) or compile C/C++ source
using -ffunction-sections compiler argument. In this case LLVM DWARF parser needs help fetching source line from .debug_line section, because it is not possible
to distinguish input section given its address (in ELF object file all sections have zero VA).

This patch implements DWARF parser LoadedObjectInfo interface to return fake VA for each section, which is equal to section file offset.

Diff Detail

Event Timeline

evgeny777 updated this revision to Diff 76181.Oct 28 2016, 6:03 AM
evgeny777 retitled this revision from to [ELF] Fix fetching source line, when file has multiple "AX" sections.
evgeny777 updated this object.
evgeny777 added reviewers: ruiu, rafael.
evgeny777 set the repository for this revision to rL LLVM.
evgeny777 added a project: lld.
evgeny777 added subscribers: grimar, ikudrin, llvm-commits.
rafael added inline comments.Oct 28 2016, 7:08 AM
ELF/InputFiles.cpp
52

Section names don't need to be unique. You need to used the section index.

For an easy example use -fno-unique-section-names.

evgeny777 added inline comments.Oct 28 2016, 7:20 AM
ELF/InputFiles.cpp
52

Unfortunately SectionRef doesn't allow getting it. Probably makes sense to propose patch to ELFObjectFile.h first and get Offset directly from SectionRef

ruiu added inline comments.Oct 28 2016, 2:55 PM
ELF/InputFiles.cpp
45

Enclose this file-local class definition in an anonymous namespace.

56–60
for (...)
  if (<flip the condition>)
    OffsetMap.insert(...);
evgeny777 updated this revision to Diff 76381.Oct 31 2016, 4:19 AM
evgeny777 removed rL LLVM as the repository for this revision.

Addressed review comments

ruiu accepted this revision.Oct 31 2016, 10:27 AM
ruiu edited edge metadata.

LGTM

ELF/InputFiles.cpp
48–49

Both functions are small, so I'd inline them here.

56–57

You can use auto or just return static_cast<const ELFSectionRef &>(Sec)->getOffset();.

This revision is now accepted and ready to land.Oct 31 2016, 10:27 AM
This revision was automatically updated to reflect the committed changes.