<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 - ld.lld crashes while linking baremetal RISC-V binary"
   href="https://bugs.llvm.org/show_bug.cgi?id=42038">42038</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>ld.lld crashes while linking baremetal RISC-V binary
          </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>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>aykevanlaethem@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, peter.smith@linaro.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=22024" name="attach_22024" title="The 3 files to reproduce">attachment 22024</a> <a href="attachment.cgi?id=22024&action=edit" title="The 3 files to reproduce">[details]</a></span>
The 3 files to reproduce

ld.lld crashes while trying to link some RISC-V firmware.

The full backtrace is here:
<a href="https://gist.github.com/aykevl/b4220bcd8637106f2a53146b6557bfbd">https://gist.github.com/aykevl/b4220bcd8637106f2a53146b6557bfbd</a> (with LLVM
compiled using RelWithDebInfo)

Here is the part that looks the most interesting to me:

 #4 0x0000000000bfe2b5 getRISCVPCRelHi20(lld::elf::Symbol const*, unsigned
long)::$_1::operator()(lld::elf::Relocation const&, lld::elf::Relocation
const&) const
/home/ayke/src/github.com/tinygo-org/tinygo/llvm/tools/lld/ELF/InputSection.cpp:572:37
 #5 0x0000000000bfe2b5 bool
__gnu_cxx::__ops::_Iter_comp_val<getRISCVPCRelHi20(lld::elf::Symbol const*,
unsigned
long)::$_1>::operator()<__gnu_cxx::__normal_iterator<lld::elf::Relocation*,
std::vector<lld::elf::Relocation, std::allocator<lld::elf::Relocation> > >,
lld::elf::Relocation const>(__gnu_cxx::__normal_iterator<lld::elf::Relocation*,
std::vector<lld::elf::Relocation, std::allocator<lld::elf::Relocation> > >,
lld::elf::Relocation const&)
/usr/bin/../lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/bits/predefined_ops.h:147:0
 #6 0x0000000000bfe2b5
std::pair<__gnu_cxx::__normal_iterator<lld::elf::Relocation*,
std::vector<lld::elf::Relocation, std::allocator<lld::elf::Relocation> > >,
__gnu_cxx::__normal_iterator<lld::elf::Relocation*,
std::vector<lld::elf::Relocation, std::allocator<lld::elf::Relocation> > > >
std::__equal_range<__gnu_cxx::__normal_iterator<lld::elf::Relocation*,
std::vector<lld::elf::Relocation, std::allocator<lld::elf::Relocation> > >,
lld::elf::Relocation,
__gnu_cxx::__ops::_Iter_comp_val<getRISCVPCRelHi20(lld::elf::Symbol const*,
unsigned long)::$_1>,
__gnu_cxx::__ops::_Val_comp_iter<getRISCVPCRelHi20(lld::elf::Symbol const*,
unsigned long)::$_1> >(__gnu_cxx::__normal_iterator<lld::elf::Relocation*,
std::vector<lld::elf::Relocation, std::allocator<lld::elf::Relocation> > >,
__gnu_cxx::__normal_iterator<lld::elf::Relocation*,
std::vector<lld::elf::Relocation, std::allocator<lld::elf::Relocation> > >,
lld::elf::Relocation const&,
__gnu_cxx::__ops::_Iter_comp_val<getRISCVPCRelHi20(lld::elf::Symbol const*,
unsigned long)::$_1>,
__gnu_cxx::__ops::_Val_comp_iter<getRISCVPCRelHi20(lld::elf::Symbol const*,
unsigned long)::$_1>)
/usr/bin/../lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/bits/stl_algo.h:2135:0
 #7 0x0000000000bfe2b5
std::pair<__gnu_cxx::__normal_iterator<lld::elf::Relocation*,
std::vector<lld::elf::Relocation, std::allocator<lld::elf::Relocation> > >,
__gnu_cxx::__normal_iterator<lld::elf::Relocation*,
std::vector<lld::elf::Relocation, std::allocator<lld::elf::Relocation> > > >
std::equal_range<__gnu_cxx::__normal_iterator<lld::elf::Relocation*,
std::vector<lld::elf::Relocation, std::allocator<lld::elf::Relocation> > >,
lld::elf::Relocation, getRISCVPCRelHi20(lld::elf::Symbol const*, unsigned
long)::$_1>(__gnu_cxx::__normal_iterator<lld::elf::Relocation*,
std::vector<lld::elf::Relocation, std::allocator<lld::elf::Relocation> > >,
__gnu_cxx::__normal_iterator<lld::elf::Relocation*,
std::vector<lld::elf::Relocation, std::allocator<lld::elf::Relocation> > >,
lld::elf::Relocation const&, getRISCVPCRelHi20(lld::elf::Symbol const*,
unsigned long)::$_1)
/usr/bin/../lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/bits/stl_algo.h:2225:0
 #8 0x0000000000bfe2b5 getRISCVPCRelHi20(lld::elf::Symbol const*, unsigned
long)
/home/ayke/src/github.com/tinygo-org/tinygo/llvm/tools/lld/ELF/InputSection.cpp:570:0
 #9 0x0000000000bfe2b5 getRelocTargetVA(lld::elf::InputFile const*, unsigned
int, long, unsigned long, lld::elf::Symbol const&, lld::elf::RelExpr)
/home/ayke/src/github.com/tinygo-org/tinygo/llvm/tools/lld/ELF/InputSection.cpp:691:0
#10 0x0000000000bfd848 lld::elf::InputSectionBase::relocateAlloc(unsigned
char*, unsigned char*)
/home/ayke/src/github.com/tinygo-org/tinygo/llvm/tools/lld/ELF/InputSection.cpp:888:9
#11 0x0000000000c2f2bf void
lld::elf::OutputSection::writeTo<llvm::object::ELFType<(llvm::support::endianness)1,
false> >(unsigned char*)::'lambda'(unsigned long)::operator()(unsigned long)
const
/home/ayke/src/github.com/tinygo-org/tinygo/llvm/tools/lld/ELF/OutputSections.cpp:243:9


LLVM (including Clang and LLD) was compiled with the following configuration:

cmake -G Ninja ../llvm "-DLLVM_TARGETS_TO_BUILD=X86;ARM;AArch64;WebAssembly"
"-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=AVR;RISCV"
-DCMAKE_BUILD_TYPE=RelWithDebInfo -DLLVM_ENABLE_ASSERTIONS=OFF
-DLIBCLANG_BUILD_STATIC=ON -DLLVM_ENABLE_TERMINFO=OFF -DLLVM_ENABLE_ZLIB=OFF

I have attached the files I tried to link, so it should be possible to
reproduce.</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>