<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 crashes on partial discard of .ARM.exidx sections"
   href="https://bugs.llvm.org/show_bug.cgi?id=42890">42890</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>LLD crashes on partial discard of .ARM.exidx sections
          </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>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>ELF
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>peter.smith@linaro.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, peter.smith@linaro.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Cut down reproducer for: <a href="https://github.com/ClangBuiltLinux/linux/issues/626">https://github.com/ClangBuiltLinux/linux/issues/626</a>

When the .ARM.exidx sections are partially but not totally discarded LLD
crashes. It is highly likely that a partial discard is user-error [*], but LLD
should be robust against this.

cat t1.s
        .section .exit.text, "ax", %progbits
        .globl foo
        .type foo, %function
foo:    
        .fnstart        
        bx lr
        .cantunwind
        .fnend

cat t2.s
        .text
        .globl _start
        .type _start, %function
_start:
        .fnstart        
        bx lr
        .cantunwind
        .fnend

cat t.lds
SECTIONS
{
 /DISCARD/ : { *(.exit.text) }
}

clang -c --target=armv7a-linux-gnu t.s t2.s
ld.lld t.o t2.o -T t.lds
Stack dump:
0.      Program arguments: bin/ld.lld t.o t2.o -o t.axf -T t.lds 
 #0 0x000000000049fab4 PrintStackTraceSignalHandler(void*)
(bin/ld.lld+0x49fab4)
 #1 0x000000000049d680 llvm::sys::RunSignalHandlers() (bin/ld.lld+0x49d680)
 #2 0x00000000004a0048 SignalHandler(int) (bin/ld.lld+0x4a0048)
 #3 0x00007f2d200b0390 __restore_rt
(/lib/x86_64-linux-gnu/libpthread.so.0+0x11390)
 #4 0x00000000006d9eef void
std::__merge_adaptive<__gnu_cxx::__normal_iterator<lld::elf::InputSection**,
std::vector<lld::elf::InputSection*, std::allocator<lld::elf::InputSection*> >
<span class="quote">>, long, lld::elf::InputSection**,</span >
__gnu_cxx::__ops::_Iter_comp_iter<lld::elf::ARMExidxSyntheticSection::finalizeContents()::$_18>
<span class="quote">>(__gnu_cxx::__normal_iterator<lld::elf::InputSection**,</span >
std::vector<lld::elf::InputSection*, std::allocator<lld::elf::InputSection*> >
<span class="quote">>, __gnu_cxx::__normal_iterator<lld::elf::InputSection**,</span >
std::vector<lld::elf::InputSection*, std::allocator<lld::elf::InputSection*> >
<span class="quote">>, __gnu_cxx::__normal_iterator<lld::elf::InputSection**,</span >
std::vector<lld::elf::InputSection*, std::allocator<lld::elf::InputSection*> >
<span class="quote">>, long, long, lld::elf::InputSection**, long,</span >
__gnu_cxx::__ops::_Iter_comp_iter<lld::elf::ARMExidxSyntheticSection::finalizeContents()::$_18>)
(bin/ld.lld+0x6d9eef)
...

[*] A partial discard does not make a lot of sense as the way that the table is
defined (PC range of entry N is terminated by start of entry N + 1) means that
a partial table is potentially dangerous and the linker must already fill in
the gaps. The only use case I can see is for a discard of table entries with
unwinding info so that the linker can regenerate cantunwind tables but this
does not seem likely. 

I think that there are 3 alternatives to resolve this:
1.) A partial discard is treated as a total discard.
2.) A partial discard suppresses linker generation of missing table entries.
3.) The linker recreates the discarded table entries.</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>