This is an archive of the discontinued LLVM Phabricator instance.

Fix line table resolution near the end of a section
ClosedPublic

Authored by labath on Aug 2 2019, 5:13 AM.

Details

Summary

lld r367537 changed the way the linker organizes sections and segments.
This exposed an lldb bug and caused some tests to fail.

In all of the failing tests the root cause was the same -- when we were
trying to resolve the last address in the line_table section, we failed
because it pointed past the end of the section.

This is similar to the problem encountered in D32022, where we had a
problem with unwinding of functions near the end of the section/module.
In that patch, we added a flag which allowed these end addresses to
resolve to the section, but we only did so for load address computations
(SectionLoadList). line table uses file addresses, and so we are not
able to take advantage of that here.

This patch adds an equivalent flag to the SectionList class, and changes
the line table resolving code to use it for end-of-sequence entries (as
those are the only ones that can validly point outside of a section).

I also revert the linker flags which were added to the failing tests to
restore previous behavior, and add a unit test to exercise the new API
more directly.

Diff Detail

Repository
rL LLVM

Event Timeline

labath created this revision.Aug 2 2019, 5:13 AM
clayborg requested changes to this revision.Aug 2 2019, 3:47 PM

I vote to not add any API calls with allow_section_end and just take care of this in source/Symbol/LineTable.cpp. All of my inline comments will reflect this notion.

include/lldb/Core/Module.h
683–684 ↗(On Diff #213020)

revert

include/lldb/Core/Section.h
74–80 ↗(On Diff #213020)

revert

133–137 ↗(On Diff #213020)

revert

source/Core/Module.cpp
426–440 ↗(On Diff #213020)

revert

source/Core/Section.cpp
270–276 ↗(On Diff #213020)

revert

590–603 ↗(On Diff #213020)

revert

source/Symbol/LineTable.cpp
247–249 ↗(On Diff #213020)

Take care of backing up the entry address if this is the last entry so we don't need any of the other API changes:

lldb::addr_t file_addr = entry.file_addr - (entry.is_terminal_entry ? 1 : 0);
if (module_sp && module_sp->ResolveFileAddress(file_addr, line_entry.range.GetBaseAddress())) {
  if (entry.is_terminal_entry) 
    line_entry.range.GetBaseAddress().Slide(1);
This revision now requires changes to proceed.Aug 2 2019, 3:48 PM
labath updated this revision to Diff 213342.Aug 5 2019, 6:12 AM
  • redo the patch to keep the logic inside the line table code. I've been

considering whether to do that my self. On one hand, this functionality seems
like it could be useful in other places, but OTOH, the bool argument api is not
really nice. I guess we can keep it this way until we come up with a better way
to do that.

I've kept the module unit test as it seems useful regardless of the fact that
I'm not changing that code.

clayborg accepted this revision.Aug 5 2019, 7:04 AM
This revision is now accepted and ready to land.Aug 5 2019, 7:04 AM
This revision was automatically updated to reflect the committed changes.
labath marked an inline comment as done.
Herald added a project: Restricted Project. · View Herald TranscriptAug 5 2019, 11:51 PM

(I eventually decided to skip the test, as without the extra flag, the same functionality can be exercised in a much more conventional way with "image lookup -a")