<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 - After r307100, segfaults when linking FreeBSD aarch64 kernel"
   href="https://bugs.llvm.org/show_bug.cgi?id=33821">33821</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>After r307100, segfaults when linking FreeBSD aarch64 kernel
          </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>normal
          </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>dimitry@andric.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>As reported on <a href="https://reviews.llvm.org/rL307100">https://reviews.llvm.org/rL307100</a>, after this change linking the
FreeBSD aarch64 kernel results in lld segfaulting:

Thread 1 received signal SIGSEGV, Segmentation fault.
lld::elf::OutputSection::addSection (this=0x0, S=0x813b2d008)
    at /home/dim/src/llvm-trunk/tools/lld/ELF/OutputSections.cpp:84
84        Sections.push_back(S);
(gdb) bt
#0  lld::elf::OutputSection::addSection (this=0x0, S=0x813b2d008) at
/home/dim/src/llvm-trunk/tools/lld/ELF/OutputSections.cpp:84
#1  0x00000000009506eb in (anonymous
namespace)::Writer<llvm::object::ELFType<(llvm::support::endianness)1, true>
<span class="quote">>::addPredefinedSections (this=0x7fffffff6e30) at</span >
/home/dim/src/llvm-trunk/tools/lld/ELF/Writer.cpp:1338
#2  0x0000000000949423 in (anonymous
namespace)::Writer<llvm::object::ELFType<(llvm::support::endianness)1, true>
<span class="quote">>::finalizeSections (this=0x7fffffff6e30) at</span >
/home/dim/src/llvm-trunk/tools/lld/ELF/Writer.cpp:1243
#3  0x0000000000914495 in (anonymous
namespace)::Writer<llvm::object::ELFType<(llvm::support::endianness)1, true>
<span class="quote">>::run (this=0x7fffffff6e30) at</span >
/home/dim/src/llvm-trunk/tools/lld/ELF/Writer.cpp:207
#4  0x0000000000973192 in
lld::elf::writeResult<llvm::object::ELFType<(llvm::support::endianness)1, true>
<span class="quote">> () at /home/dim/src/llvm-trunk/tools/lld/ELF/Writer.cpp:126</span >
#5  0x000000000066c7ff in
lld::elf::LinkerDriver::link<llvm::object::ELFType<(llvm::support::endianness)1,
true> > (this=0x805ce2000, Args=...) at
/home/dim/src/llvm-trunk/tools/lld/ELF/Driver.cpp:1056
#6  0x0000000000655585 in lld::elf::LinkerDriver::main (this=0x805ce2000,
ArgsArr=..., CanExitEarly=true) at
/home/dim/src/llvm-trunk/tools/lld/ELF/Driver.cpp:386
#7  0x00000000006547a3 in lld::elf::link (Args=..., CanExitEarly=true,
Error=...) at /home/dim/src/llvm-trunk/tools/lld/ELF/Driver.cpp:85
#8  0x0000000000457809 in main (Argc=1245, Argv=0x7fffffff8580) at
/home/dim/src/llvm-trunk/tools/lld/tools/lld/lld.cpp:104
(gdb) up
#1  0x00000000009506eb in (anonymous
namespace)::Writer<llvm::object::ELFType<(llvm::support::endianness)1, true>
<span class="quote">>::addPredefinedSections (this=0x7fffffff6e30) at</span >
/home/dim/src/llvm-trunk/tools/lld/ELF/Writer.cpp:1338
1338      Cmd->Sec->addSection(Sentinel);
(gdb) print Cmd->Sec
$5 = (lld::elf::OutputSection *) 0x0

At this point findSectionCommand() was looping through Script->Opt.Commands,
found a not-completely initialized .ARM.exidx section, which still had its null
Sec member.

Reverting the findSectionCommand() implementation to its previous version
prevents crashing, but it may not be the correct solution

The reproduction test case is unfortunately too large to be attached, find it
here:
<a href="http://www.andric.com/freebsd/clang/lld-arm64-segfault.tar.xz">http://www.andric.com/freebsd/clang/lld-arm64-segfault.tar.xz</a>  (18 MiB)</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>