[llvm-bugs] [Bug 40501] New: LLD does not maintain address equivalence with DSO for ifunc defined in PIE executable.

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Jan 28 10:29:49 PST 2019


https://bugs.llvm.org/show_bug.cgi?id=40501

            Bug ID: 40501
           Summary: LLD does not maintain address equivalence with DSO for
                    ifunc defined in PIE executable.
           Product: lld
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: ELF
          Assignee: unassignedbugs at nondot.org
          Reporter: peter.smith at linaro.org
                CC: llvm-bugs at lists.llvm.org, peter.smith at linaro.org

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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190128/f20f03cf/attachment.html>


More information about the llvm-bugs mailing list