<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 - LLD leaves empty sections in header size calculation"
   href="https://bugs.llvm.org/show_bug.cgi?id=40381">40381</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>LLD leaves empty sections in header size calculation
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>lld
          </td>
        </tr>

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

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

        <tr>
          <th>OS</th>
          <td>Windows NT
          </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>COFF
          </td>
        </tr>

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

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

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>When linking a PE image with empty sections, space for their section headers is
included in the size of the output headers, while the sections themselves are
removed.

For example, building this C file:

    int __stdcall mainCRTStartup(void) { return 0; }

with this invocation:

    clang-cl /Zl compiler.c -fuse-ld=lld /link /subsystem:console
/entry:mainCRTStartup

produces an image with SizeOfHeaders set to 0x400, but only a single section
(.text). The equivalent invocation of cl/link produces an image with
SizeOfHeaders set to 0x200:

    cl /Zl compiler.c /link /subsystem:console /entry:mainCRTStartup
/novcfeature /nocoffgrpinfo

This happens because of the dependence between Writer::assignAddresses and
Writer::removeEmptySections, in lld/COFF/Writer.cpp- section sizes (and thus
emptiness) are computed at the same time as the header size, before empty
sections are removed.</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>