[PATCH, 2.27] x86-64: Use IFUNC memcpy and mempcpy in libc.a
H.J. Lu
hjl.tools@gmail.com
Wed Aug 2 18:36:00 GMT 2017
On Wed, Aug 2, 2017 at 11:27 AM, Florian Weimer <fweimer@redhat.com> wrote:
> On 08/02/2017 05:53 PM, H.J. Lu wrote:
>> On Sun, Jul 9, 2017 at 7:59 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>> test-ifloat128%): Force
>>>
>>> FYI, this is the patch I am submitting for glibc 2.27.
>>
>> Any comments or objections?
>
> I have not reviewed if there are any static library initialization
> issues caused by IFUNC use for string functions, but I agree in
> principle that something like this should be possible.
>
The entry point of static executable is
STATIC int
LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL),
int argc, char **argv,
#ifdef LIBC_START_MAIN_AUXVEC_ARG
ElfW(auxv_t) *auxvec,
#endif
__typeof (main) init,
void (*fini) (void),
void (*rtld_fini) (void), void *stack_end)
{
/* Result of the 'main' function. */
int result;
__libc_multiple_libcs = &_dl_starting_up && !_dl_starting_up;
#ifndef SHARED
char **ev = &argv[argc + 1];
__environ = ev;
/* Store the lowest stack address. This is done in ld.so if this is
the code for the DSO. */
__libc_stack_end = stack_end;
# ifdef HAVE_AUX_VECTOR
/* First process the auxiliary vector since we need to find the
program header to locate an eventually present PT_TLS entry. */
# ifndef LIBC_START_MAIN_AUXVEC_ARG
ElfW(auxv_t) *auxvec;
{
char **evp = ev;
while (*evp++ != NULL)
;
auxvec = (ElfW(auxv_t) *) evp;
}
# endif
_dl_aux_init (auxvec);
if (GL(dl_phdr) == NULL)
# endif
{
/* Starting from binutils-2.23, the linker will define the
magic symbol __ehdr_start to point to our own ELF header
if it is visible in a segment that also includes the phdrs.
So we can set up _dl_phdr and _dl_phnum even without any
information from auxv. */
extern const ElfW(Ehdr) __ehdr_start
__attribute__ ((weak, visibility ("hidden")));
if (&__ehdr_start != NULL)
{
assert (__ehdr_start.e_phentsize == sizeof *GL(dl_phdr));
GL(dl_phdr) = (const void *) &__ehdr_start + __ehdr_start.e_phoff;
GL(dl_phnum) = __ehdr_start.e_phnum;
}
}
/* Initialize very early so that tunables can use it. */
__libc_init_secure ();
__tunables_init (__environ);
ARCH_INIT_CPU_FEATURES ();
/* Perform IREL{,A} relocations. */
ARCH_SETUP_IREL ();
If there is no memcpy/mempcpy call before ARCH_SETUP_IREL (),
we can use IFUNC memcpy and mempcpy in static executable.
Since the code path up to ARCH_SETUP_IREL () is the same for
all static executables, the static executable tests within glibc are
sufficient to verify that it is safe to do so.
--
H.J.
More information about the Libc-alpha
mailing list