From patchwork Fri Jan 8 12:01:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Clifton X-Patchwork-Id: 564743 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48EA81402A1 for ; Fri, 8 Jan 2016 23:01:32 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=GYvhdttH; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; q=dns; s= default; b=ZQTpsaaleP/QcXPZ7o2QTAi1qcOoOv3twq2ruRotlx42g6piOQ9SD B4D+vXTmQFw0JiqaX6zDOzvD31DxIjoV7laDR1XRYFxD65KMSFpXimIc6RW34k8j F5fV6c5djl7/Z1qsUnpgt/RTaeCVJ4dpzzodiv2EuebKSFZICE7cj4= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=default; bh=IQMrcRB6797nW2+qLK9dk9nufgs=; b=GYvhdttHFPYyrvHyPhVihs1JOI5e A78xUOsTEYZ4ah5A1hRVy5kSBn9uM5sCJlMkGWrS5+Ca+MD6hg/B7P3HZR02NOZK VE/YgE9BiLz+wdQdV9URqDpvJrsnKpvAgxNm6hgmYIIwLUCF/CZNcoWNbLzDDw46 kLwkRHMXrxH8u3s= Received: (qmail 97559 invoked by alias); 8 Jan 2016 12:01:25 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 97499 invoked by uid 89); 8 Jan 2016 12:01:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.2 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=179, sk:__buil, sk:!__buil, file_contents X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Fri, 08 Jan 2016 12:01:20 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id 7179A2190 for ; Fri, 8 Jan 2016 12:01:18 +0000 (UTC) Received: from [10.36.7.109] (vpn1-7-109.ams2.redhat.com [10.36.7.109]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u08C1GdJ000573 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 8 Jan 2016 07:01:17 -0500 Subject: Re: RFA: PR 68913: Provide weak version of __fread_chk for PR61886 test To: Jakub Jelinek , Jeff Law References: <87egejk7mj.fsf@redhat.com> <56785A36.60507@redhat.com> <56791DBB.3050800@redhat.com> <568C1777.8070801@redhat.com> <568E6A14.1030007@redhat.com> <568E8B94.5030606@redhat.com> <568EA0E1.6060801@redhat.com> <20160107174159.GH18720@tucnak.redhat.com> Cc: gcc-patches@gcc.gnu.org From: Nick Clifton Message-ID: <568FA50C.9070601@redhat.com> Date: Fri, 8 Jan 2016 12:01:16 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0 MIME-Version: 1.0 In-Reply-To: <20160107174159.GH18720@tucnak.redhat.com> X-IsSubscribed: yes Hi Guys, OK - how about this reformulation of the pr61886 test ? The patch changes references to __fread_chk with references to just fread, which I assume will be present in all target runtime libraries. I had to add some preprocessor trickery in order to ensure that __USER_LABEL_PREFIX__ is correctly prepended to the assembler name of the functions, but other than that the test remains the same. No linker funny business this time. I have tested this patch with an x86_64 native (whose C runtime does include __fread_chk), an ARM cross compiler (using newlib, which does not provide __fread_chk) and with a V850 cross compiler (which uses newlib and which also defines __USER_LABEL_PREFIX to "_"). Prior to Honza's r231548 patch all three toolchains fail this patched test. Using today#s latest and greatest mainline gcc sources, all three toolchains pass the patched test. OK to apply ? Cheers Nick gcc/testsuite/ChangeLog 2016-01-08 Nick Clifton PR target/68913 * gcc.dg/lto/pr61886_0.c: Rename the external function called to fread so that it will be found in all target runtimes. ((__warn_unused_result__)); +extern size_t fread_warn (void *__restrict __ptr, size_t __ptrlen, size_t __size, size_t __n, FILE *__restrict __stream) __asm__ (STRING2(__USER_LABEL_PREFIX__) "fread") __attribute__ ((__warn_unused_result__)) __attribute__((__warning__ ("fread called with bigger size * nmemb than length " "of destination buffer"))); + extern __inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) __attribute__ ((__artificial__)) __attribute__ ((__warn_unused_result__)) size_t -fread (void *__restrict __ptr, size_t __size, size_t __n, +local_fread (void *__restrict __ptr, size_t __size, size_t __n, FILE *__restrict __stream) { if (__builtin_object_size (__ptr, 0) != (size_t) -1) @@ -17,9 +20,9 @@ if (!__builtin_constant_p (__size) || !__builtin_constant_p (__n) || (__size | __n) >= (((size_t) 1) << (8 * sizeof (size_t) / 2))) - return __fread_chk (__ptr, __builtin_object_size (__ptr, 0), __size, __n, __stream); + return fread (__ptr, __builtin_object_size (__ptr, 0), __size, __n, __stream); if (__size * __n > __builtin_object_size (__ptr, 0)) - return __fread_chk_warn (__ptr, __builtin_object_size (__ptr, 0), __size, __n, __stream); + return fread_warn (__ptr, __builtin_object_size (__ptr, 0), __size, __n, __stream); } } @@ -28,6 +31,6 @@ int main () { char file_contents[4096]; - /* We shouldn't get this resolved to a call to __fread_chk_warn. */ - return fread (file_contents, 1, nmemb, fp); + /* We shouldn't get this resolved to a call to fread_warn. */ + return local_fread (file_contents, 1, nmemb, fp); } Index: gcc/testsuite/gcc.dg/lto/pr61886_0.c =================================================================== --- gcc/testsuite/gcc.dg/lto/pr61886_0.c (revision 232157) +++ gcc/testsuite/gcc.dg/lto/pr61886_0.c (working copy) @@ -4,12 +4,15 @@ typedef __SIZE_TYPE__ size_t; typedef struct _IO_FILE FILE; -extern size_t __fread_chk (void *__restrict __ptr, size_t __ptrlen, size_t __size, size_t __n, FILE *__restrict __stream) __asm__ ("" "__fread_chk") __attribute__ ((__warn_unused_result__)); -extern size_t __fread_chk_warn (void *__restrict __ptr, size_t __ptrlen, size_t __size, size_t __n, FILE *__restrict __stream) __asm__ ("" "__fread_chk") __attribute__ ((__warn_unused_result__)) __attribute__((__warning__ ("fread called with bigger size * nmemb than length " "of destination buffer"))); +#define STRING1(a) #a +#define STRING2(a) STRING1(a) +extern size_t fread (void *__restrict __ptr, size_t __ptrlen, size_t __size, size_t __n, FILE *__restrict __stream) __asm__ (STRING2(__USER_LABEL_PREFIX__) "fread") __attribute__