<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 doesn't permit read-only relocations (-z text) as default compared to ld.bfd and ld.gold"
   href="https://bugs.llvm.org/show_bug.cgi?id=49810">49810</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>ld.lld doesn't permit read-only relocations (-z text) as default compared to ld.bfd and ld.gold
          </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>axel.y.rivera@intel.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, smithp352@googlemail.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>I noticed that lld doesn't allow to relocate read-only sections by default (-z
text), while ld.bfd and ld.gold does (-z notext). This behavior was mentioned
in the following changes: <a href="https://reviews.llvm.org/D30530">https://reviews.llvm.org/D30530</a> . This is the example
from the same code review but modified for 32bits.

test2> cat simple.s
foo:
.long foo

test2> llvm-mc -filetype=obj -triple=i386-pc-linux simple.s -o simple.o
test2> ld.lld -m elf_i386 simple.o -o simple -shared
ld.lld: error: can't create dynamic relocation R_386_32 against local symbol in
readonly segment; recompile object files with -fPIC or pass '-Wl,-z,notext' to
allow text relocations in the output
<span class="quote">>>> defined in simple.o
>>> referenced by simple.o:(.text+0x0)</span >

But it links successfully for ld.bfd and ld.gold:

test2> ld.bfd -m elf_i386 simple.o -o simple -shared
test2> ld.gold -m elf_i386 simple.o -o simple -shared

If I add -z text to ld.bfd and ld.gold then I get the same failure:

test2> ld.bfd -z text -m elf_i386 simple.o -o simple -shared
ld.bfd: simple.o: warning: relocation in read-only section `.text'
ld.bfd: read-only segment has dynamic relocations.

test2> ld.gold -z text -m elf_i386 simple.o -o simple -shared
ld.gold: error: read-only segment has dynamic relocations


As mentioned in the test case, I can use -z notext and link in lld:

test2> ld.lld -z notext -m elf_i386 simple.o -o simple -shared


Is there a reason why lld doesn't permit the relocation for read-only sections
by default compared to bfd and gold?</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>