[PATCH] D54145: [ELF] - Fix R_X86_64_GOTPCRELX/R_X86_64_REX_GOTPCRELX when target is IFUNC.
George Rimar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 6 03:52:07 PST 2018
grimar created this revision.
grimar added a reviewer: ruiu.
Herald added subscribers: arichardson, emaste.
Herald added a reviewer: espindola.
This is https://bugs.llvm.org/show_bug.cgi?id=38074. This simple reproducible is below.
Imagine the following code:
**user.cpp:**
extern "C" int myfunc();
int main() {
int (*p)() = &myfunc;
return p();
}
**library.cpp:**
int myfunc2() {
return 2;
}
extern "C" int myfunc();
__asm__ (".type myfunc, @gnu_indirect_function");
typeof(myfunc) * myfunc_dispatch (void) __asm__ ("myfunc");
typeof(myfunc) * myfunc_dispatch (void) {
return myfunc2;
}
If you run the application linked with gold, the output will be correct:
> clang library.o user.o -fPIC -static -o test
> ./test
> echo $?
2
The application linked with LLD (-fuse-ld=lld) shows `32` for me instead.
The issue is that when calling a function, for example,
LLD generates a .got entry that points to the IFUNC resolver function when
instead, it should use the PLT entries properly for handling the IFUNC.
So we should create a got entry that points to PLT entry, which itself loads the value from
`.got.iplt`, relocated with R_X86_64_IRELATIVE to make things work. Patch do that.
https://reviews.llvm.org/D54145
Files:
ELF/InputSection.cpp
ELF/Relocations.cpp
ELF/Relocations.h
test/ELF/gotpc-relax.s
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54145.172740.patch
Type: text/x-patch
Size: 5478 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181106/cb7cda20/attachment.bin>
More information about the llvm-commits
mailing list