<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 - ICF causes section ordering to segfault on ARM"
   href="https://bugs.llvm.org/show_bug.cgi?id=32614">32614</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>ICF causes section ordering to segfault on ARM
          </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>All
          </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>ELF
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>smeenai@fb.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>% cat reduced.s
        .section        .text.f,"axG",%progbits,f,comdat
        .code   32
f:
        .fnstart
        bx      lr
        .fnend

        .section        .text.g,"axG",%progbits,g,comdat
        .code   32
g:
        .fnstart
        bx      lr
        .fnend

% clang -target armv7-linux-gnueabi -shared -nostdlib -fuse-ld=lld -Xlinker
--icf=all -o /dev/null reduced.s
(lld crashes during the link)

The assembly is reduced from a C++ source file, so it may not be 100% sensible
(I got rid of a bunch of directives), but it reproduces the segfault. It occurs
in compareByFilePosition [1] because of AOut being null.

My understanding is that, because of ICF, only one of f and g will actually be
output, hence the OutSec for the other will be null. Adding null checks before
the SectionIndex comparison should get rid of the segfault, but I'm not sure if
there's a better solution.

[1]
<a href="https://reviews.llvm.org/diffusion/L/browse/lld/trunk/ELF/OutputSections.cpp;299911$82?color=1">https://reviews.llvm.org/diffusion/L/browse/lld/trunk/ELF/OutputSections.cpp;299911$82?color=1</a></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>