<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 does not preserve symbol types for defsym"
   href="https://bugs.llvm.org/show_bug.cgi?id=46970">46970</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>LLD does not preserve symbol types for defsym
          </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>All
          </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>smeenai@fb.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>grimar@accesssoftek.com, i@maskray.me, llvm-bugs@lists.llvm.org, ruiu@google.com, smithp352@googlemail.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>$ cat f.c
void f() {}

$ clang -c f.c
$ ld.lld -shared --defsym=g=f f.o
$ objdump -T a.out
DYNAMIC SYMBOL TABLE:
00000000000012a0 g    DF .text  0000000000000006 f
00000000000012a0 g    D  .text  0000000000000000 g

f is marked STT_FUNC, but g is not. It might be hard to do in the general case
(where e.g. you can have arithmetic in the defsym expression), but in this
case, it seems desirable for the alias to get the same symbol type as the
original.

>From Peter Smith:

There can be a problem on Arm as no interworking will be performed for symbols
that are not STT_FUNC.

$ cat h.c
extern void f();
extern void g();
void h() { f(); g(); }

$ clang --target=armv7a-none-eabi -c f.c
$ clang --target=armv7a-none-eabi -c h.c -mthumb
$ ld.lld f.o h.o --defsym g=f  # No --shared to prevent a PLT entry.
$ objdump -d a.out
000200e8 <h>:
   200e8:       b580            push    {r7, lr}
   200ea:       466f            mov     r7, sp
   200ec:       f7ff effa       blx     200e4 <f>
   200f0:       f7ff fff8       bl      200e4 <f>
   200f4:       bd80            pop     {r7, pc}

The blx to f() is correct as a state change is required. The bl to f() will
likely crash the program.

ld.bfd correctly marks g as STT_FUNC so it gets the state change correct for
both calls.
00008004 <h>:
    8004:       b580            push    {r7, lr}
    8006:       466f            mov     r7, sp
    8008:       f7ff effa       blx     8000 <f>
    800c:       f7ff eff8       blx     8000 <f>
    8010:       bd80            pop     {r7, pc}</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>