Hi!
Without this patch e.g. strstr IFUNC looks like:
0000000000089090 <strstr>:
89090: 48 83 ec 08 sub $0x8,%rsp
89094: 8b 05 86 51 2f 00 mov 0x2f5186(%rip),%eax # 37e220 <__cpu_features>
8909a: 85 c0 test %eax,%eax
8909c: 74 22 je 890c0 <strstr+0x30>
8909e: f6 05 8d 51 2f 00 10 testb $0x10,0x2f518d(%rip) # 37e232 <__cpu_features+0x12>
890a5: 48 8b 05 44 fd 2e 00 mov 0x2efd44(%rip),%rax # 378df0 <_DYNAMIC+0x2d0>
890ac: 48 0f 45 05 04 fe 2e cmovne 0x2efe04(%rip),%rax # 378eb8 <_DYNAMIC+0x398>
890b3: 00
890b4: 48 83 c4 08 add $0x8,%rsp
890b8: c3 retq
890b9: 0f 1f 80 00 00 00 00 nopl 0x0(%rax)
890c0: e8 2b 5e f9 ff callq 1eef0 <__init_cpu_features>
890c5: eb d7 jmp 8909e <strstr+0xe>
890c7: 66 0f 1f 84 00 00 00 nopw 0x0(%rax,%rax,1)
890ce: 00 00
Note that __strstr_sse2 and __strstr_sse42 addresses are read from GOT where
they have RELATIVE relocation on them. This is completely unnecessary (they
are not exported from libc.so), and worse it breaks when some library has
e.g. strstr relocation resolved (with LD_BIND_NOW=1) before libc.so has been
relocated. Even with this patch, I still wonder how can fma/fmaf actually
work with LD_BIND_NOW=1, because those IFUNC functions actually make a PLT
call. If libm.so's relocation hasn't been started yet, I wonder what will
happen.
2009-09-02 Jakub Jelinek <jakub@redhat.com>
* sysdeps/x86_64/multiarch/strstr-c.c (__strstr_sse42, __strstr_sse2):
Add attribute_hidden.
* sysdeps/x86_64/multiarch/strcasestr-c.c (__strcasestr_sse42,
__strcasestr_sse2): Likewise.
* sysdeps/x86_64/multiarch/s_fma.c (__fma_sse2): Add attribute_hidden.
(__fma_fma): Make static.
* sysdeps/x86_64/multiarch/s_fmaf.c (__fmaf_sse2): Add attribute_hidden.
(__fmaf_fma): Make static.
--- libc/sysdeps/x86_64/multiarch/strstr-c.c.jj 2009-07-23 08:59:29.000000000 +0200
+++ libc/sysdeps/x86_64/multiarch/strstr-c.c 2009-09-02 10:34:48.000000000 +0200
@@ -7,6 +7,7 @@
#include "string/strstr.c"
-extern char *__strstr_sse42 (const char *, const char *);
+extern char *__strstr_sse42 (const char *, const char *) attribute_hidden;
+extern __typeof (__strstr_sse2) __strstr_sse2 attribute_hidden;
libc_ifunc (strstr, HAS_SSE4_2 ? __strstr_sse42 : __strstr_sse2);
--- libc/sysdeps/x86_64/multiarch/strcasestr-c.c.jj 2009-07-23 08:59:29.000000000 +0200
+++ libc/sysdeps/x86_64/multiarch/strcasestr-c.c 2009-09-02 10:36:07.000000000 +0200
@@ -7,7 +7,8 @@
#include "string/strcasestr.c"
-extern char *__strcasestr_sse42 (const char *, const char *);
+extern char *__strcasestr_sse42 (const char *, const char *) attribute_hidden;
+extern __typeof (__strcasestr_sse2) __strcasestr_sse2 attribute_hidden;
#if 1
libc_ifunc (__strcasestr,
--- libc/sysdeps/x86_64/multiarch/s_fma.c.jj 2009-07-31 12:52:08.000000000 +0200
+++ libc/sysdeps/x86_64/multiarch/s_fma.c 2009-09-02 10:38:00.000000000 +0200
@@ -24,10 +24,10 @@
#ifdef HAVE_AVX_SUPPORT
-extern double __fma_sse2 (double x, double y, double z);
+extern double __fma_sse2 (double x, double y, double z) attribute_hidden;
-double
+static double
__fma_fma (double x, double y, double z)
{
asm ("vfmadd213sd %3, %2, %0" : "=x" (x) : "0" (x), "x" (y), "xm" (z));
--- libc/sysdeps/x86_64/multiarch/s_fmaf.c.jj 2009-07-31 12:52:08.000000000 +0200
+++ libc/sysdeps/x86_64/multiarch/s_fmaf.c 2009-09-02 10:38:22.000000000 +0200
@@ -23,10 +23,10 @@
#ifdef HAVE_AVX_SUPPORT
-extern float __fmaf_sse2 (float x, float y, float z);
+extern float __fmaf_sse2 (float x, float y, float z) attribute_hidden;
-float
+static float
__fmaf_fma (float x, float y, float z)
{
asm ("vfmadd213ss %3, %2, %0" : "=x" (x) : "0" (x), "x" (y), "xm" (z));
Jakub