This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: Proposal for STT_GNU_IFUNC and R_*_IRELATIVE
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: Generic System V Application Binary Interface <generic-abi at googlegroups dot com>
- Cc: GNU C Library <libc-alpha at sourceware dot org>, discuss at x86-64 dot org, Binutils <binutils at sourceware dot org>, IA32 System V Application Binary Interface <ia32-abi at googlegroups dot com>, Nick Clifton <nickc at redhat dot com>, Ulrich Drepper <drepper at redhat dot com>
- Date: Mon, 1 Jun 2009 12:46:26 -0700
- Subject: Re: Proposal for STT_GNU_IFUNC and R_*_IRELATIVE
- References: <6dc9ffc80905251156p1ab274aey8e52be086fd88749@mail.gmail.com>
Hi,
Here is the current proposal implemented in the Linux binutils
2.19.51.0.7.
H.J.
---
STT_GNU_IFUNC
This symbol type is the same as STT_FUNC except that it always
points to a function or piece of executable code which takes no
arguments and returns a function pointer. If an STT_GNU_IFUNC
symbol is referred to by a relocation, then evaluation of that
relocation is delayed until load-time. The value used in the
relocation is the function pointer returned by an invocation
of the STT_GNU_IFUNC symbol.
The purpose of this symbol type is to allow the run-time to
select between multiple versions of the implementation of a
specific function. The selection made in general will take the
currently available hardware into account and select the most
appropriate version.
STT_GNU_IFUNC is defined in OS-specific range:
#define STT_LOOS 10 /* OS-specific semantics */
#define STT_GNU_IFUNC 10 /* Symbol is an indirect code object */
#define STT_HIOS 12 /* OS-specific semantics */
R_*_IRELATIVE
This relocation is similar to R_*_RELATIVE except that the
value used in this relocation is the program address returned
by the function, which takes no arguments, at the address of
the result of the corresponding R_*_RELATIVE relocation.
The purpose of this relocation to avoid name lookup for locally
defined STT_GNU_IFUNC symbols at load-time.
R_*_IRELATIVE is defined for i386 and x86-64:
#define R_386_IRELATIVE 42 /* Adjust indirectly by program base */
#define R_X86_64_IRELATIVE 37 /* Adjust indirectly by program base */
All references to a STT_GNU_IFUNC symbol, including function call and
function pointer, will go through a PLT slot, which jumps to the address
stored in the GOT entry. If the STT_GNU_IFUNC symbol is locally defined,
a R_*_IRELATIVE relocation will be applied to the GOT entry at load time.
Otherwise, dynamic linker will lookup the symbol at the first call to the
function and update the GOT entry. This applies to all usages of
STT_GNU_IFUNC symbols in shared library, dynamic executable and static
executable.