]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
Add an lld option to emit PC-relative relocations for ifunc calls.
authorMark Johnston <markj@FreeBSD.org>
Thu, 23 Aug 2018 14:58:19 +0000 (14:58 +0000)
committerMark Johnston <markj@FreeBSD.org>
Thu, 23 Aug 2018 14:58:19 +0000 (14:58 +0000)
commit4023442dc9e8eb123be1bdbc5ebb97328c8ff732
tree212d788dd1ba12e875b661bf694f32607c9d573e
parent35437b1f161f30bb489772428bea77f2b1a2ab95
Add an lld option to emit PC-relative relocations for ifunc calls.

The current kernel ifunc implementation creates a PLT entry for each
ifunc definition.  ifunc calls therefore consist of a call to the
PLT entry followed by an indirect jump.  The jump target is written
during boot when the kernel linker resolves R_[*]_IRELATIVE relocations.
This implementation is defined by requirements for userland code, where
text relocations are avoided.  This requirement is not present for the
kernel, so the implementation has avoidable overhead (namely, an extra
indirect jump per call).

Address this for now by adding a special option to the static linker
to inhibit PLT creation for ifuncs.  Instead, relocations to ifunc call
sites are passed through to the output file, so the kernel linker can
enumerate such call sites and apply PC-relative relocations directly
to the text section.  Thus the overhead of an ifunc call becomes exactly
the same as that of an ordinary function call.  This option is only for
use by the kernel and will not work for regular programs.

The final form of this optimization is up for debate; for now, this
change is simple and static enough to be acceptable as an interim
solution.

Reviewed by: emaste
Discussed with: arichardson, dim
MFC after: 1 month
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D16748
contrib/llvm/tools/lld/ELF/Config.h
contrib/llvm/tools/lld/ELF/Driver.cpp
contrib/llvm/tools/lld/ELF/Relocations.cpp
contrib/llvm/tools/lld/ELF/Writer.cpp
usr.bin/clang/lld/ld.lld.1