<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - Section's m_file_addr left unset after Mach-O parsing"
   href="http://llvm.org/bugs/show_bug.cgi?id=18648">18648</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Section's m_file_addr left unset after Mach-O parsing
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>lldb
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>MacOS X
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>All Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>lldb-dev@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>josharian@gmail.com
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=11965" name="attach_11965" title="Compiled executable (simple.go)">attachment 11965</a> <a href="attachment.cgi?id=11965&action=edit" title="Compiled executable (simple.go)">[details]</a></span>
Compiled executable (simple.go)

I found this while digging into golang.org/issue/7070.

Reproduce:

(1) Compile <a href="http://play.golang.org/p/i_6zF3EoLG">http://play.golang.org/p/i_6zF3EoLG</a> using Go 1.2. I have attached a
compiled version for reference, called just simple.
(2) lldb simple
(3) breakpoint set -a 0x2000
(4) run


Result:

Assertion failed: (sizeof(arangeDescriptor.address) >= m_header.addr_size),
function Extract, file
/SourceCache/lldb/lldb-300.2.53/source/Plugins/SymbolFile/DWARF/DWARFDebugArangeSet.cpp,
line 208.


Diagnosis:

In the executable attached, __debug_aranges is at offset 514379. The data being
parsed to construct m_header in DWARFDebugArangeSet::Extract, however, is at
offset 360448, which is the beginning of the DWARF segment, not the
__debug_aranges section. This junk data causes the assertion failure.

The aranges data is prepared in SymbolFileDWARF::GetCachedSectionData, at
SymbolFileDWARF.cpp:716. The data offset calculation uses
section_sp->GetOffset(), which should be the offset of the __debug_aranges
section relative to the containing DWARF segment. That is, it should return
153931. In this case, however, it returns 0.

This is because Section::GetOffset returns m_file_addr, which is documented to
be the file offset relative to the parent. However, m_file_addr never gets set
in ObjectFileMachO::CreateSections (or anywhere else). There is one call to
Section::SetFileAddress, at line 1124, but it does not get hit during parsing
of the attached executable.

The following patch fixes the problem by using m_file_offset in
Section::GetOffset. I suspect, however, that the correct fix is to populate
m_file_addr during Mach-O parsing.


diff --git a/source/Core/Section.cpp b/source/Core/Section.cpp
index 28d7d93..f6f6fe2 100644
--- a/source/Core/Section.cpp
+++ b/source/Core/Section.cpp
@@ -123,7 +123,7 @@ Section::GetOffset () const
     // This section has a parent which means m_file_addr is an offset.
     SectionSP parent_sp (GetParent ());
     if (parent_sp)
-        return m_file_addr;
+        return m_file_offset - parent_sp->m_file_offset;

     // This section has no parent, so there is no offset to be had
     return 0;</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>