<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/58349>58349</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            LLD incorrectly handles armeb targets  
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          eigenform
      </td>
    </tr>
</table>

<pre>
    It seems like `ld.lld` will accept armeb input files, but proceeds to handle the relocations in little-endian (?) and silently produces invalid encodings for branches:

```
$ clang --target=armebv5te-none-eabi -mcpu=arm926ej-s -c start.s
$ ld.lld -Ttext=0 start.o -o start.lld.elf
$ arm-none-eabi-ld -Ttext=0 -EB start.o -o start.gcc.elf 
$ arm-none-eabi-objdump -d start.lld.elf start.gcc.elf

start.lld.elf:     file format elf32-bigarm


Disassembly of section .text:

00000000 <_start>:
   0:   e1a00000        nop                     ; (mov r0, r0)
   4:   edffffeb        ldcl    15, cr15, [pc, #940]!   ; 3b8 <bar+0x3a4>
   8:   eeffffeb        cdp     15, 15, cr15, cr15, cr11, {7}

0000000c <foo>:
   c:   e1a00000        nop                     ; (mov r0, r0)
  10:   e12fff1e        bx      lr

00000014 <bar>:
  14:   e1a00000        nop                     ; (mov r0, r0)
  18:   e12fff1e        bx      lr

start.gcc.elf:     file format elf32-bigarm


Disassembly of section .text:

00000000 <_start>:
   0:   e1a00000        nop                     ; (mov r0, r0)
   4:   eb000000        bl      c <foo>
   8:   eb000001        bl      14 <bar>

0000000c <foo>:
   c:   e1a00000        nop                     ; (mov r0, r0)
  10:   e12fff1e        bx      lr

00000014 <bar>:
  14:   e1a00000        nop                     ; (mov r0, r0)
  18:   e12fff1e        bx      lr
```

This seems similar to the behavior addressed in 7605a9a009b5fa3bdac07e3131c8d82f6d08feb7 for Aarch64 (see https://reviews.llvm.org/D96188)?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llv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