From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3514 invoked by alias); 3 Oct 2007 09:18:21 -0000 Received: (qmail 3498 invoked by uid 22791); 3 Oct 2007 09:18:21 -0000 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.31) with ESMTP; Wed, 03 Oct 2007 09:18:19 +0000 Received: from sunsite.mff.cuni.cz (localhost.localdomain [127.0.0.1]) by sunsite.mff.cuni.cz (8.13.8/8.13.8) with ESMTP id l939KjEj010444; Wed, 3 Oct 2007 11:20:45 +0200 Received: (from jj@localhost) by sunsite.mff.cuni.cz (8.13.8/8.13.8/Submit) id l939Kjhc010443; Wed, 3 Oct 2007 11:20:45 +0200 Date: Wed, 03 Oct 2007 09:18:00 -0000 From: Jakub Jelinek To: Ulrich Drepper Cc: Glibc hackers Subject: [PATCH] Fix -D_FORTIFY_SOURCE=1 swprintf/vswprintf on ppc*/s390*/sparc* Message-ID: <20071003092045.GD2896@sunsite.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.4.2.2i 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: 2007-10/txt/msg00002.txt.bz2 Hi! #include #include int main (void) { wchar_t buf[120], *buf2; swprintf (buf, 120, L"%La %La", 2.3L, 4.6L); printf ("%S\n", buf); asm ("" : "=r" (buf2) : "r" (buf)); swprintf (buf2, 120, L"%La %La", 2.3L, 4.6L); printf ("%S\n", buf2); return 0; } built with -O2 -D_FORTIFY_SOURCE=1 -mlong-double-64 on ppc gives: 0x1.2666666666666p+1 0x1.2666666666666p+2 0x1.26666666666669333333333333p+1 0x0p+0 rather than the correct: 0x1.2666666666666p+1 0x1.2666666666666p+2 0x1.2666666666666p+1 0x1.2666666666666p+2 The problem is that when we use __{,v}swprintf_alias, it is redirected to {,v}swprintf while we need __nldbl__{,v}swprintf. Unfortunately, as one redirection is already used, we can't fix this just in bits/wchar-ldbl.h. The following patch is IMHO still bearable. {,v}s{,n}printf is ok, as we are using GCC builtins which will DTRT. Unfortunately, there are no wide equivalent builtins. 2007-10-03 Jakub Jelinek * misc/sys/cdefs.h (__REDIRECT_LDBL, __REDIRECT_NTH_LDBL): New macros. * wcsmbs/bits/wchar2.h (__swprintf_alias, __vswprintf_alias): Use __REDIRECT_NTH_LDBL macro rather than __REDIRECT_NTH. --- libc/misc/sys/cdefs.h.jj 2007-09-29 20:51:57.000000000 +0200 +++ libc/misc/sys/cdefs.h 2007-10-01 10:05:29.000000000 +0200 @@ -355,6 +360,10 @@ extern __typeof (name) name __asm (__ASMNAME (#alias)); # define __LDBL_REDIR_DECL(name) \ extern __typeof (name) name __asm (__ASMNAME ("__nldbl_" #name)); +# define __REDIRECT_LDBL(name, proto, alias) \ + __LDBL_REDIR1 (name, proto, __nldbl_##alias) +# define __REDIRECT_NTH_LDBL(name, proto, alias) \ + __LDBL_REDIR1_NTH (name, proto, __nldbl_##alias) # endif #endif #if !defined __LDBL_COMPAT || !defined __REDIRECT @@ -363,6 +372,11 @@ # define __LDBL_REDIR1_NTH(name, proto, alias) name proto __THROW # define __LDBL_REDIR_NTH(name, proto) name proto __THROW # define __LDBL_REDIR_DECL(name) +# ifdef __REDIRECT +# define __REDIRECT_LDBL(name, proto, alias) __REDIRECT (name, proto, alias) +# define __REDIRECT_NTH_LDBL(name, proto, alias) \ + __REDIRECT_NTH (name, proto, alias) +# endif #endif #endif /* sys/cdefs.h */ --- libc/wcsmbs/bits/wchar2.h.jj 2007-09-29 20:51:58.000000000 +0200 +++ libc/wcsmbs/bits/wchar2.h 2007-10-01 10:07:22.000000000 +0200 @@ -274,10 +274,10 @@ extern int __swprintf_chk (wchar_t *__re __const wchar_t *__restrict __format, ...) __THROW /* __attribute__ ((__format__ (__wprintf__, 5, 6))) */; -extern int __REDIRECT_NTH (__swprintf_alias, - (wchar_t *__restrict __s, size_t __n, - __const wchar_t *__restrict __fmt, ...), - swprintf); +extern int __REDIRECT_NTH_LDBL (__swprintf_alias, + (wchar_t *__restrict __s, size_t __n, + __const wchar_t *__restrict __fmt, ...), + swprintf); #ifdef __va_arg_pack __extern_always_inline int @@ -305,10 +305,10 @@ extern int __vswprintf_chk (wchar_t *__r __gnuc_va_list __arg) __THROW /* __attribute__ ((__format__ (__wprintf__, 5, 0))) */; -extern int __REDIRECT_NTH (__vswprintf_alias, - (wchar_t *__restrict __s, size_t __n, - __const wchar_t *__restrict __fmt, - __gnuc_va_list __ap), vswprintf); +extern int __REDIRECT_NTH_LDBL (__vswprintf_alias, + (wchar_t *__restrict __s, size_t __n, + __const wchar_t *__restrict __fmt, + __gnuc_va_list __ap), vswprintf); __extern_always_inline int __NTH (vswprintf (wchar_t *__restrict __s, size_t __n, Jakub