<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 maintain address equivalence with DSO for ifunc defined in PIE executable."
   href="https://bugs.llvm.org/show_bug.cgi?id=40501">40501</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>LLD does not maintain address equivalence with DSO for ifunc defined in PIE executable.
          </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>peter.smith@linaro.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, peter.smith@linaro.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>When -fpie is used, the address of an ifunc defined in an executable should be
the same when referenced by a shared library. This can be shown to be the case
for ld.gold and ld.bfd but not ld.lld. I've tried this on x86_64 and AArch64.

Consider the example:
// FILE dso.c
typedef void fptr(void);
extern void fff(void);

fptr *global_fptr = &fff;

// FILE main.c
#include <stdio.h>

static void fff_impl() {
    printf("fff_impl()\n");
}

void *fff_resolver() {
    return (void *)&fff_impl;
}

__attribute__((ifunc("fff_resolver"))) void fff();
typedef void fptr(void);
fptr *local_fptr = fff;
extern fptr *global_fptr;

int main()
{
  printf("local %p global %p\n", local_fptr, global_fptr);
  return 0;
}

With:
clang -fpic dso.c -o dso.so --shared
bin/clang -fpie -pie main.c dso.so -o main.exe
LD_LIBRARY_PATH=. ./main.exe

With -fuse-ld=gold:
local 0x559bbd215810 global 0x559bbd215810
With -fuse-ld=bfd:
local 0x562c653647f0 global 0x562c653647f0
With -fuse-ld=lld
local 0x55b9fda0e0f0 global 0x55b9fda0e140

On AArch64 the problem is that LLD generates a GOT entry for fff (local_fptr)
that points to the PLT entry for fff. If we call local_fptr() we get the
correct result after going through the PLT, but global_fptr gets the address of
fff_impl from the dynamic loader (fff_impl is the result of the
ifunc_resolver).

PR40474 has some more information about what ld.bfd and ld.gold do for AArch64
in this case.</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>