<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 produces an empty relocation if it did target a discarded section"
   href="https://bugs.llvm.org/show_bug.cgi?id=51047">51047</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>lld produces an empty relocation if it did target a discarded section
          </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>jan.kratochvil@redhat.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, smithp352@googlemail.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>echo '__attribute__((__section__("discardme"))) char
x;__attribute__((__section__(".debug_info"))) char *xp = &x;'|clang -Wall -c -o
discard.o -x c -;echo 'SECTIONS { /DISCARD/ : { *(discardme) } }'
<span class="quote">>discard.lds;ld.lld -r -m elf_x86_64 -T discard.lds -o discard2.o</span >
discard.o;llvm-readelf -r discard2.o

Actual:
Relocation section '.rela.debug_info' at offset 0x48 contains 1 entries:
    Offset             Info             Type               Symbol's Value 
Symbol's Name + Addend
0000000000000000  0000000000000001 R_X86_64_64                       0

Expected either - as ld.bfd creates:
Relocation section '.rela.debug_info' at offset 0x140 contains 1 entries:
    Offset             Info             Type               Symbol's Value 
Symbol's Name + Addend
0000000000000000  0000000000000000 R_X86_64_NONE                     0

Expected or (preferred, this is what ld.bfd creates in real world cases):
There are no relocations in this file.

FAIL: lld-12.0.0-1.fc34.x86_64
FAIL: LLD 13.0.0 8cf7ddbdd4e5af966a369e170c73250f2e3920e7 = 2021-07-10
PASS: ld.bfd = binutils-2.35.1-41.fc34.x86_64
FAIL: ld.gold = binutils-gold-2.35.1-41.fc34.x86_64</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>