From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19954 invoked by alias); 2 Sep 2009 09:32:03 -0000 Received: (qmail 19936 invoked by uid 22791); 2 Sep 2009 09:32:03 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00,J_CHICKENPOX_42,SARE_SUB_6CONS_WORD X-Spam-Check-By: sourceware.org Received: from sunsite.ms.mff.cuni.cz (HELO sunsite.mff.cuni.cz) (195.113.15.26) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 02 Sep 2009 09:31:58 +0000 Received: from sunsite.mff.cuni.cz (localhost [127.0.0.1]) by sunsite.mff.cuni.cz (8.14.3/8.14.3) with ESMTP id n829VsV1028360 for ; Wed, 2 Sep 2009 11:31:54 +0200 Received: (from jakub@localhost) by sunsite.mff.cuni.cz (8.14.3/8.14.3/Submit) id n829Vssh028359 for libc-hacker@sources.redhat.com; Wed, 2 Sep 2009 11:31:54 +0200 Resent-From: jakub@sunsite.ms.mff.cuni.cz Resent-Date: Wed, 2 Sep 2009 11:31:54 +0200 Resent-Message-ID: <20090902093154.GA28318@sunsite.ms.mff.cuni.cz> Resent-To: libc-hacker@sources.redhat.com Date: Wed, 02 Sep 2009 09:32:00 -0000 From: Jakub Jelinek To: Ulrich Drepper Cc: Glibc hackers Subject: [PATCH] Fix strstr/strcasestr/fma/fmaf on x86_64 Message-ID: <20090902085848.GC3611@sunsite.ms.mff.cuni.cz> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.19 (2009-01-05) Mailing-List: contact libc-hacker-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-hacker-owner@sourceware.org X-SW-Source: 2009-09/txt/msg00001.txt.bz2 Hi! Without this patch e.g. strstr IFUNC looks like: 0000000000089090 : 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 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 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 * 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