llvm-project/lld/test/ELF/aarch64-gnu-ifunc-nonpreemp...

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

73 lines
2.2 KiB
ArmAsm
Raw Normal View History

# REQUIRES: aarch64
# RUN: llvm-mc -filetype=obj -triple=aarch64-none-linux-gnu %s -o %t.o
# RUN: ld.lld %t.o -o %t
# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s --check-prefix=PDE
# RUN: llvm-readobj -r %t | FileCheck %s --check-prefix=PDE-RELOC
# RUN: ld.lld -pie %t.o -o %t
# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s --check-prefix=PIE
# RUN: llvm-readobj -r %t | FileCheck %s --check-prefix=PIE-RELOC
## When compiling with -fno-PIE or -fPIE, if the ifunc is in the same
## translation unit as the address taker, the compiler knows that ifunc is not
## defined in a shared library so it can use a non GOT generating relative reference.
.text
.globl myfunc
.type myfunc,@gnu_indirect_function
myfunc:
.globl myfunc_resolver
.type myfunc_resolver,@function
myfunc_resolver:
ret
.text
.globl main
.type main,@function
main:
adrp x8, myfunc
add x8, x8, :lo12: myfunc
ret
## The address of myfunc is the address of the PLT entry for myfunc.
# PDE: <myfunc_resolver>:
# PDE-NEXT: 210170: ret
# PDE: <main>:
# PDE-NEXT: 210174: adrp x8, #0
# PDE-NEXT: 210178: add x8, x8, #384
# PDE-NEXT: 21017c: ret
# PDE-EMPTY:
# PDE-NEXT: Disassembly of section .iplt:
# PDE-EMPTY:
# PDE-NEXT: <myfunc>:
## page(.got.plt) - page(0x210010) = 65536
# PDE-NEXT: 210180: adrp x16, #65536
# PDE-NEXT: 210184: ldr x17, [x16, #400]
# PDE-NEXT: 210188: add x16, x16, #400
# PDE-NEXT: 21018c: br x17
## The adrp to myfunc should generate a PLT entry and a GOT entry with an
## irelative relocation.
[ELF] Move R_*_IRELATIVE from .rel[a].plt to .rel[a].dyn unless --pack-dyn-relocs=android[+relr] An R_*_IRELATIVE represents the address of a STT_GNU_IFUNC symbol (redirected at runtime) which is non-preemptable and is not associated with a canonical PLT (associated with a symbol with a section index of SHN_UNDEF but a non-zero st_value). .rel[a].plt [DT_JMPREL, DT_JMPREL+DT_JMPRELSZ) contains relocations that can be lazily resolved. R_*_IRELATIVE are always eagerly resolved, so conceptually they do not belong to .rela.plt. "iplt" is mostly a misnomer. glibc powerpc and powerpc64 do not resolve R_*_IRELATIVE if they are in .rela.plt. // a.o - synthesized PLT call stub has an R_*_IRELATIVE void ifunc(); int main() { ifunc(); } // b.o static void real() {} asm (".type ifunc, %gnu_indirect_function"); void *ifunc() { return &real; } The lld-linked executable crashes. ld.bfd places R_*_IRELATIVE in .rela.dyn and the executable works. glibc i386, x86_64, and aarch64 have logic (glibc/sysdeps/*/dl-machine.h:elf_machine_lazy_rel) to eagerly resolve R_*_IRELATIVE in .rel[a].plt so the lld-linked executable works. Move R_*_IRELATIVE from .rel[a].plt to .rel[a].dyn to fix the crashes on glibc powerpc/powerpc64. This also helps simplifying ifunc implementation in FreeBSD rtld-elf powerpc64. If --pack-dyn-relocs=android[+relr] is specified, the Android packed dynamic relocation format is used for .rela.dyn. We cannot name in.relaIplt ".rela.dyn" because the output section will have mixed formats. This can be improved in the future. Reviewed By: pcc Differential Revision: https://reviews.llvm.org/D65651 llvm-svn: 367745
2019-08-03 10:26:52 +08:00
# PDE-RELOC: .rela.dyn {
# PDE-RELOC-NEXT: 0x220190 R_AARCH64_IRELATIVE - 0x210170
# PDE-RELOC-NEXT: }
# PIE: <myfunc_resolver>:
# PIE-NEXT: 10260: ret
# PIE: <main>:
# PIE-NEXT: 10264: adrp x8, #0
# PIE-NEXT: 10268: add x8, x8, #624
# PIE-NEXT: 1026c: ret
# PIE-EMPTY:
# PIE-NEXT: Disassembly of section .iplt:
# PIE-EMPTY:
# PIE-NEXT: <myfunc>:
# PIE-NEXT: 10270: adrp x16, #131072
# PIE-NEXT: 10274: ldr x17, [x16, #896]
# PIE-NEXT: 10278: add x16, x16, #896
# PIE-NEXT: 1027c: br x17
[ELF] Move R_*_IRELATIVE from .rel[a].plt to .rel[a].dyn unless --pack-dyn-relocs=android[+relr] An R_*_IRELATIVE represents the address of a STT_GNU_IFUNC symbol (redirected at runtime) which is non-preemptable and is not associated with a canonical PLT (associated with a symbol with a section index of SHN_UNDEF but a non-zero st_value). .rel[a].plt [DT_JMPREL, DT_JMPREL+DT_JMPRELSZ) contains relocations that can be lazily resolved. R_*_IRELATIVE are always eagerly resolved, so conceptually they do not belong to .rela.plt. "iplt" is mostly a misnomer. glibc powerpc and powerpc64 do not resolve R_*_IRELATIVE if they are in .rela.plt. // a.o - synthesized PLT call stub has an R_*_IRELATIVE void ifunc(); int main() { ifunc(); } // b.o static void real() {} asm (".type ifunc, %gnu_indirect_function"); void *ifunc() { return &real; } The lld-linked executable crashes. ld.bfd places R_*_IRELATIVE in .rela.dyn and the executable works. glibc i386, x86_64, and aarch64 have logic (glibc/sysdeps/*/dl-machine.h:elf_machine_lazy_rel) to eagerly resolve R_*_IRELATIVE in .rel[a].plt so the lld-linked executable works. Move R_*_IRELATIVE from .rel[a].plt to .rel[a].dyn to fix the crashes on glibc powerpc/powerpc64. This also helps simplifying ifunc implementation in FreeBSD rtld-elf powerpc64. If --pack-dyn-relocs=android[+relr] is specified, the Android packed dynamic relocation format is used for .rela.dyn. We cannot name in.relaIplt ".rela.dyn" because the output section will have mixed formats. This can be improved in the future. Reviewed By: pcc Differential Revision: https://reviews.llvm.org/D65651 llvm-svn: 367745
2019-08-03 10:26:52 +08:00
# PIE-RELOC: .rela.dyn {
# PIE-RELOC-NEXT: 0x30380 R_AARCH64_IRELATIVE - 0x10260
# PIE-RELOC-NEXT: }