<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 - Unsupported SBREL32 relocation emitted by LLVM"
   href="https://bugs.llvm.org/show_bug.cgi?id=32924">32924</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Unsupported SBREL32 relocation emitted by LLVM
          </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>amit@amitlevy.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>compnerd@compnerd.org, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=18409" name="attach_18409" title="C test file">attachment 18409</a> <a href="attachment.cgi?id=18409&action=edit" title="C test file">[details]</a></span>
C test file

I'm trying to compile bare-metal relocatable binaries for Thumb using
the RWPI/ROPI relocation models in the recently released version 4. The
code is coming out great from clang as well as Rust.

However, I'm unable to link this code since LLD seems to be
missing support for the ARM relocation type R_ARM_SBREL32 (relocation
type 9 in
<a href="http://infocenter.arm.com/help/topic/com.arm.doc.ihi0044f/IHI0044F_aaelf.pdf">http://infocenter.arm.com/help/topic/com.arm.doc.ihi0044f/IHI0044F_aaelf.pdf</a>)
which is emitted by LLVM for the RWPI relocation model.

I believe the relevant function in LLD is here:
<a href="https://github.com/llvm-mirror/lld/blob/f78635b8b05285750ef76b56e3b696cb34a0c49b/ELF/Target.cpp#L1856">https://github.com/llvm-mirror/lld/blob/f78635b8b05285750ef76b56e3b696cb34a0c49b/ELF/Target.cpp#L1856</a>

I'm attaching a very simple file, `test.c`, which simply dereferences a
global volatile int in `_start`. The assembly equivalent with the failing
relocation is:

        .text
        .syntax unified
        .eabi_attribute 67, "2.09"      @ Tag_conformance
        .cpu    arm7tdmi
        .eabi_attribute 6, 2    @ Tag_CPU_arch
        .eabi_attribute 8, 1    @ Tag_ARM_ISA_use
        .eabi_attribute 15, 2   @ Tag_ABI_PCS_RW_data
        .eabi_attribute 16, 1   @ Tag_ABI_PCS_RO_data
        .eabi_attribute 17, 1   @ Tag_ABI_PCS_GOT_use
        .eabi_attribute 20, 1   @ Tag_ABI_FP_denormal
        .eabi_attribute 21, 1   @ Tag_ABI_FP_exceptions
        .eabi_attribute 23, 3   @ Tag_ABI_FP_number_model
        .eabi_attribute 34, 0   @ Tag_CPU_unaligned_access
        .eabi_attribute 24, 1   @ Tag_ABI_align_needed
        .eabi_attribute 25, 1   @ Tag_ABI_align_preserved
        .eabi_attribute 38, 1   @ Tag_ABI_FP_16bit_format
        .eabi_attribute 18, 4   @ Tag_ABI_PCS_wchar_t
        .eabi_attribute 26, 2   @ Tag_ABI_enum_size
        .eabi_attribute 14, 1   @ Tag_ABI_PCS_R9_use
        .file   "test.c"
        .globl  _start
        .p2align        2
        .type   _start,%function
        .code   32                      @ @_start
_start:
        .fnstart
@ BB#0:
        ldr     r0, .LCPI0_0
        mov     r1, r9
        ldr     r0, [r1, r0]
        bx      lr
        .p2align        2
@ BB#4:
.LCPI0_0:
        .long   foo(sbrel)


Compiling it without RWPI relocations
works as expected:

$ clang --target=thumbv7-eabi -fropi -o test.o -c test.c
$ ld.lld -o test test.o

However, compiling with RWPI turned on errors with `unrecognized reloc
9` from LLD:

$ clang --target=thumbv7-eabi -fropi -frwpi -o test.o -c test.c
$ ld.lld -o test test.o
ld.lld: error: test.c:(function _start): unrecognized reloc 9</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>