This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH 3/8] i386, x86: Use libc_ifunc macro for time, gettimeofday.
- From: Adhemerval Zanella <adhemerval dot zanella at linaro dot org>
- To: libc-alpha at sourceware dot org
- Date: Mon, 4 Jul 2016 10:40:54 -0300
- Subject: Re: [PATCH 3/8] i386, x86: Use libc_ifunc macro for time, gettimeofday.
- Authentication-results: sourceware.org; auth=none
- References: <1466682952-6301-1-git-send-email-stli@linux.vnet.ibm.com> <1466682952-6301-3-git-send-email-stli@linux.vnet.ibm.com> <f04bfe8f-0849-1813-a020-94ddf14c89a4@redhat.com>
On 04/07/2016 05:54, Florian Weimer wrote:
> On 06/23/2016 01:55 PM, Stefan Liebler wrote:
>> This patch uses the libc_ifunc macro to create already existing ifunc functions
>> time and gettimeofday on intel. This way, the libc_hidden_def macro can be used
>> instead of the libc_ifunc_hidden_def one which was only used here. Thus the
>> macro is removed from libc-symbols.h.
>> On i386, the __GI_* symbols do not target the ifunc symbol and thus the
>> redirection construct has to be applied here.
>
> I'm not sure if I understand what is going on here. sysdeps/unix/sysv/linux/x86/gettimeofday.c is compiled straight for x86_64, but wrapped on i386, right?
>
If I recall correctly i686 has the same issue as powerpc32, where ifunc for local
hidden symbols fails to resolve where called by another function library function.
This examples shows the issue:
$ cat test.c
#define libc_ifunc_hidden_def1(local, name) \
__asm__ (".globl " #local "\n\t" \
".hidden " #local "\n\t" \
#local " = " #name);
#define libc_ifunc_hidden_def(name) \
libc_ifunc_hidden_def1 (__GI_##name, name)
int foo (void) __attribute__ ((ifunc ("foo_ifunc")));
static int global = 1;
static int
f1 (void)
{
return 0;
}
static int
f2 (void)
{
return 1;
}
void *
foo_ifunc (void)
{
return global == 1 ? f1 : f2;
}
libc_ifunc_hidden_def (foo)
$ cat test2.c
#define __hidden_proto_hiddenattr(attrs...) \
__attribute__ ((visibility ("hidden"), ##attrs))
#define hidden_proto(name, attrs...) \
__hidden_proto (name, , __GI_##name, ##attrs)
#define __hidden_proto(name, thread, internal, attrs...) \
extern thread __typeof (name) name __asm__ (#internal) \
__hidden_proto_hiddenattr (attrs);
int foo (void);
hidden_proto (foo)
int bar (void)
{
return foo ();
}
$ cat main.c
int bar (void);
int main ()
{
return bar ();
}
$ gcc -Wall -fpic test.c -c -m32
$ gcc -Wall -fpic test2.c -c -m32
$ gcc -shared test.o test2.o -o libtest.so -m32
$ gcc -Wall main.c -c -m32
$ gcc main.o -o main -L. -ltest -m32
$ LD_LIBRARY_PATH=. ./main
Segmentation fault (core dumped)
I am using binutils 2.26 from Ubuntu 16.04 and I am not sure if it has been fixed
in more recent versions.
> I wonder if it possible to avoid some of the preprocessor magic by introducing a separate x86_64 file.
I am not sure if it would be gain, the i386/gettimeofday.c is doing exactly what
it does not support (libc_ifunc_hidden_def symbol being called from other library
calls). I think it worth a comment though.
Another possible cleanup could be consolidate powerpc and x86 gettimeofday
gettimeofay.