This is an archive of the discontinued LLVM Phabricator instance.

[llvm-debuginfo-analyzer] Fix memory leak reported by sanitizers.
ClosedPublic

Authored by CarlosAlbertoEnciso on Nov 1 2022, 6:16 AM.

Details

Summary

After landing the 08-elf-reader patch the sanitizer reported
memory leak issues. The test causing the issue was disabled

https://reviews.llvm.org/rGd81725d2bc016b58cb9327910f7892a2d4ac53c1

The command line used in the test case is:

llvm-debuginfo-analyzer --attribute=level
                        --print=instructions
                        pr-incorrect-instructions-dwarf-clang.o

When dealing with logical instruction lines associated with
an artificial logical scope, skip the process of finding
their enclosing scope. Just add them to the scope.

Create logical debug lines only if the command line specifies:

--print=lines or --print=elements or --print=all

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptNov 1 2022, 6:16 AM
CarlosAlbertoEnciso requested review of this revision.Nov 1 2022, 6:16 AM
CarlosAlbertoEnciso edited the summary of this revision. (Show Details)Nov 1 2022, 6:30 AM
jryans accepted this revision.Nov 1 2022, 7:35 AM

Thanks, this looks reasonable to me! 🙂

Were you able to reproduce the failure locally?

This revision is now accepted and ready to land.Nov 1 2022, 7:35 AM

Thanks, this looks reasonable to me! 🙂

Were you able to reproduce the failure locally?

First of all, thanks very much for the review.

Building with sanitizers require extra setup and stages.
It was relatively fast to have a very basic memory tracking (new/delete) to find the places where the memory was allocated and reproduce the failure locally.

Log from @vitalybuka:

==1211325==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 1440 byte(s) in 12 object(s) allocated from:
    #0 0x560d26e1e8cd in operator new(unsigned long) /b/sanitizer-x86_64-linux-fast/build/llvm-project/compiler-rt/lib/asan/asan_new_delete.cpp:95:3
    #1 0x560d275ff029 in llvm::logicalview::LVBinaryReader::createInstructions(llvm::logicalview::LVScope*, unsigned long, std::__1::pair<unsigned long, unsigned long> const&) /b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/lib/DebugInfo/LogicalView/Readers/LVBinaryReader.cpp:424:31
    #2 0x560d27603fa6 in llvm::logicalview::LVBinaryReader::createInstructions() /b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/lib/DebugInfo/LogicalView/Readers/LVBinaryReader.cpp:498:21

Log from the memory tracking:

ERROR: Unallocated 12 objects from:

    1: 'X:\diva-root\llvm-project\llvm\lib\DebugInfo\LogicalView\Readers\LVBinaryReader.cpp':485
    2: 'X:\diva-root\llvm-project\llvm\lib\DebugInfo\LogicalView\Readers\LVBinaryReader.cpp':485
    3: 'X:\diva-root\llvm-project\llvm\lib\DebugInfo\LogicalView\Readers\LVBinaryReader.cpp':485
    4: 'X:\diva-root\llvm-project\llvm\lib\DebugInfo\LogicalView\Readers\LVBinaryReader.cpp':485
    5: 'X:\diva-root\llvm-project\llvm\lib\DebugInfo\LogicalView\Readers\LVBinaryReader.cpp':485
    6: 'X:\diva-root\llvm-project\llvm\lib\DebugInfo\LogicalView\Readers\LVBinaryReader.cpp':485
    7: 'X:\diva-root\llvm-project\llvm\lib\DebugInfo\LogicalView\Readers\LVBinaryReader.cpp':485
    8: 'X:\diva-root\llvm-project\llvm\lib\DebugInfo\LogicalView\Readers\LVBinaryReader.cpp':485
    9: 'X:\diva-root\llvm-project\llvm\lib\DebugInfo\LogicalView\Readers\LVBinaryReader.cpp':485
   10: 'X:\diva-root\llvm-project\llvm\lib\DebugInfo\LogicalView\Readers\LVBinaryReader.cpp':485
   11: 'X:\diva-root\llvm-project\llvm\lib\DebugInfo\LogicalView\Readers\LVBinaryReader.cpp':485
   12: 'X:\diva-root\llvm-project\llvm\lib\DebugInfo\LogicalView\Readers\LVBinaryReader.cpp':485

SUMMARY: Allocated 122, Deleted 110
ERROR: Detected memory leaks

UNREACHABLE executed at X:\diva-root\llvm-project\llvm\include\llvm/DebugInfo/LogicalView/Core/LVSupport.h:84!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Exception Code: 0x80000003
 #0 0x00007ff6a5fc7d7c HandleAbort X:\diva-root\llvm-project\llvm\lib\Support\Windows\Signals.inc:414:0
 #1 0x00007ffd991cbc31 (C:\WINDOWS\SYSTEM32\ucrtbased.dll+0x6bc31)
 #2 0x00007ffd991cd889 (C:\WINDOWS\SYSTEM32\ucrtbased.dll+0x6d889)
 #3 0x00007ff6a5e7566a llvm::llvm_unreachable_internal(char const *, char const *, unsigned int) X:\diva-root\llvm-project\llvm\lib\Support\ErrorHandling.cpp:218:0
 #4 0x00007ff6a559f249 llvm::logicalview::LVAllocations::dump(void) X:\diva-root\llvm-project\llvm\include\llvm\DebugInfo\LogicalView\Core\LVSupport.h:86:0
 #5 0x00007ff6a5596e44 llvm::logicalview::LVAllocations::~LVAllocations(void) X:\diva-root\llvm-project\llvm\include\llvm\DebugInfo\LogicalView\Core\LVSupport.h:51:0
 #6 0x00007ff6a7e78662 `dynamic atexit destructor for '`public: static class logicalview::LVAllocations::getInstance & __cdecl llvm::logicalview::LVAllocations::getInstance(void)'::`2'::Instance''(void) (e:\projects\diva-root\builds\win\debug\Debug\bin\llvm-debuginfo-analyzer.exe+0x3568662)
 #7 0x00007ffd991d4957 (C:\WINDOWS\SYSTEM32\ucrtbased.dll+0x74957)
 #8 0x00007ffd991d4365 (C:\WINDOWS\SYSTEM32\ucrtb

Just as historical note: diva was the tool original name.

The lib/DebugInfo/LogicalView/Readers/LVBinaryReader.cpp:424:31 is the same line as lib\DebugInfo\LogicalView\Readers\LVBinaryReader.cpp':485.

vitalybuka accepted this revision.Nov 1 2022, 10:40 AM

LGTM if this fixes the bug
Still the same questing as before: Can this code avoid using directly new/delete and rely on unique_ptrs?

LGTM if this fixes the bug

Thanks very much for your review.

Still the same questing as before: Can this code avoid using directly new/delete and rely on unique_ptrs?

As per my response to @dblaikie in https://reviews.llvm.org/D125783:

  1. code review feedback (such as memory allocation handling) being pushed back to some much later stage isn't usually the way we do things if it's reasonable observations about how things are done - postcommit (or, it sounds like precommit) feedback is to be addressed "There is a strong expectation that authors respond promptly to post-commit feedback and address it." (perhaps you could link to the other discussion on the raw new usage issue? Might help provide explanation for why it's not already addressed?)

We are fully aware of the issues related with the current memoy allocation and changing it to use smart pointers is a priority.
Based on your suggestion, I can create a GitHub issue to include all the information and add that link to each of the entries in the reviews that refer to the memory handling.

We can't change the new/delete to use unique_ptrs in just a single place.
The change must be done across the tool, as the logical elements (scopes, types, symbols, lines) are used in different modules:

  • creation (debug info parsing)
  • completion (add extra information)
  • comparison/selection
  • logical view generation

Based on your suggestion, I can create a GitHub issue to include all the information and add that link to each of the entries in the reviews that refer to the memory handling.

Sorry, I missed that comment on the original patch.
Thank you!

jryans added a comment.Nov 2 2022, 6:55 AM

Based on your suggestion, I can create a GitHub issue to include all the information and add that link to each of the entries in the reviews that refer to the memory handling.

I think it would be best to prioritise creating this issue quite soon (in the next few days), as it would be good to have on hand when discussing the current status of any other memory-related issues that arise with the tool.

Based on your suggestion, I can create a GitHub issue to include all the information and add that link to each of the entries in the reviews that refer to the memory handling.

I think it would be best to prioritise creating this issue quite soon (in the next few days), as it would be good to have on hand when discussing the current status of any other memory-related issues that arise with the tool.

You are right. The creation of that issue is the next item on my list and I am hoping to finish it by Friday.
Currently I am writing a README.txt for the tool that contains:

  • Know issues
  • Limitations
  • Improvements
  • etc
jryans added a comment.Nov 2 2022, 7:34 AM

The creation of that issue is the next item on my list and I am hoping to finish it by Friday.
Currently I am writing a README.txt for the tool that contains:

  • Know issues
  • Limitations
  • Improvements
  • etc

Sounds great, thanks for all of your work on this tool! 🙂