<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </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-linked FreeBSD/amd64 rtld segfaults after lld r288107"
   href="https://llvm.org/bugs/show_bug.cgi?id=31221">31221</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>lld-linked FreeBSD/amd64 rtld segfaults after lld r288107
          </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>FreeBSD
          </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>emaste@freebsd.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Blocks</th>
          <td>23214
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>I built a FreeBSD installation using lld @ r288228 as the linker, and almost
all userland binaries segfaulted when starting up, in rtld.

Bisecting identified r288107 as the culprit. The problem is not reproducible
after switching back to a rtld linked with lld built at r288102. 

The difference is that rtld built with post-r288107 lld has an entirely zeroed
.got:

% diffoscope old-lld/ld-elf.so.1 new-lld/ld-elf.so.1
--- old-lld/ld-elf.so.1
+++ new-lld/ld-elf.so.1
├── readelf --wide --hex-dump=.got {}
│ @@ -1,16 +1,16 @@
│  
│  Hex dump of section '.got':
│ -  0x00020410 20900000 00000000 70100200 00000000  .......p.......
│ -  0x00020420 e0230200 00000000 e8230200 00000000 .#.......#......
│ -  0x00020430 10030200 00000000 d0b60000 00000000 ................
│ -  0x00020440 18240200 00000000 18230200 00000000 .$.......#......
│ -  0x00020450 68240200 00000000 6c240200 00000000 h$......l$......
│ -  0x00020460 70240200 00000000 74240200 00000000 p$......t$......
│ -  0x00020470 80100200 00000000 18060000 00000000 ................
│ -  0x00020480 00000200 00000000 7c240200 00000000 ........|$......
│ -  0x00020490 10240200 00000000 00100200 00000000 .$..............
│ -  0x000204a0 04100200 00000000 10100200 00000000 ................
│ -  0x000204b0 30160200 00000000 981b0200 00000000 0...............
│ -  0x000204c0 b0100200 00000000 00240200 00000000 .........$......
│ -  0x000204d0 60240200 00000000 84240200 00000000 `$.......$......
│ -  0x000204e0 f8230200 00000000                   .#......
│ +  0x00020410 00000000 00000000 00000000 00000000 ................
│ +  0x00020420 00000000 00000000 00000000 00000000 ................
│ +  0x00020430 00000000 00000000 00000000 00000000 ................
│ +  0x00020440 00000000 00000000 00000000 00000000 ................
│ +  0x00020450 00000000 00000000 00000000 00000000 ................
│ +  0x00020460 00000000 00000000 00000000 00000000 ................
│ +  0x00020470 00000000 00000000 00000000 00000000 ................
│ +  0x00020480 00000000 00000000 00000000 00000000 ................
│ +  0x00020490 00000000 00000000 00000000 00000000 ................
│ +  0x000204a0 00000000 00000000 00000000 00000000 ................
│ +  0x000204b0 00000000 00000000 00000000 00000000 ................
│ +  0x000204c0 00000000 00000000 00000000 00000000 ................
│ +  0x000204d0 00000000 00000000 00000000 00000000 ................
│ +  0x000204e0 00000000 00000000                   ........
├── readelf --wide --string-dump=.comment {}
│ @@ -1,6 +1,6 @@
│  
│  String dump of section '.comment':
│    [     1]  FreeBSD clang version 3.9.0 (tags/RELEASE_390/final 280324)
(based on LLVM 3.9.0)
│    [    53]  $FreeBSD$
│ -  [    5d]  Linker: LLD 4.0.0 (<a href="http://llvm.org/git/lld">http://llvm.org/git/lld</a>
01db8ccdad26c748727d9638c5df3b99c8260ddc)
│ +  [    5d]  Linker: LLD 4.0.0 (<a href="http://llvm.org/git/lld">http://llvm.org/git/lld</a>
326233f95ee6b9c32f19d04ad06a6c369e6acc5a)
│  
├── readelf --wide --hex-dump=.gnu_debuglink {}
│ @@ -1,4 +1,4 @@
│  
│  Hex dump of section '.gnu_debuglink':
│    0x00000000 6c642d65 6c662e73 6f2e312e 64656275 ld-elf.so.1.debu
│ -  0x00000010 67000000 a26ecfb2                   g....n..
│ +  0x00000010 67000000 c1a333a6                   g.....3.


rtld has code to determine if it needs to relocate itself or not, which
defaults to

#ifndef RTLD_IS_DYNAMIC
#define        RTLD_IS_DYNAMIC()       (&_DYNAMIC != NULL)
#endif

RTLD_IS_DYNAMIC is false when linked with lld >= r288107, so rtld does not
apply its own relocations at startup and crashes.

This is arguably a FreeBSD rtld bug (and we could address it there). I'm
submitting this LLD ticket for tracking the issue as it may affect other
projects.</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>