<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </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 - baremetal DWARF leaves dso_base uninitialized"
   href="https://bugs.llvm.org/show_bug.cgi?id=47335">47335</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>baremetal DWARF leaves dso_base uninitialized
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>Runtime Libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>libunwind
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>rprichard@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>For a -DLIBUNWIND_IS_BAREMETAL=ON configuration that uses DWARF EH (rather than
ARM EHABI), the UnwindInfoSections::dso_base field is read, but never
initialized.

The uninitialized field is copied to unw_proc_info_t::extra, which is also
exposed via _Unwind_Find_FDE's dwarf_eh_bases::tbase field.

dso_base is also used as the key to DwarfFDECache (as the "mh" value -- "mach
header").

An obvious fix is to set dso_base to 0, but then the first
DwarfFDECache::findFDE call ("otherwise, search cache of previously found
FDEs.") will search the entire cache (whereas dynamically-registered are
expected to be searched in a later pass). We could change the full-search
sentinel value to ~0, or add a parameter instead of a sentinel value.

After I make unrelated changes, gcc (but not clang) is able to detect the
uninitialized field:

/x/llvm-upstream/llvm-project/libunwind/src/UnwindCursor.hpp: In member
function ‘void libunwind::UnwindCursor<A, R>::setInfoBasedOnIPRegister(bool)
[with A = libunwind::LocalAddressSpace; R = libunwind::Registers_x86_64]’:
/x/llvm-upstream/llvm-project/libunwind/src/UnwindCursor.hpp:1924:9: warning:
‘sects.libunwind::UnwindInfoSections::dso_base’ may be used uninitialized in
this function [-Wmaybe-uninitialized]
 1924 |         if (getInfoFromFdeCie(fdeInfo, cieInfo, pc, sects.dso_base))
      |         ^~</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>