From patchwork Fri Sep 30 20:26:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 77176 Delivered-To: patch@linaro.org Received: by 10.140.106.72 with SMTP id d66csp488062qgf; Fri, 30 Sep 2016 13:27:15 -0700 (PDT) X-Received: by 10.66.48.8 with SMTP id h8mr14759365pan.92.1475267235033; Fri, 30 Sep 2016 13:27:15 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id l5si21566185pay.57.2016.09.30.13.27.14 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 Sep 2016 13:27:15 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-return-73639-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org; spf=pass (google.com: domain of libc-alpha-return-73639-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-73639-patch=linaro.org@sourceware.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe: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=Ef/fpZTd1ZdW+YzA oEC1iR6WLz0QKPMk2vV8fGaRIjwuv1u8sZ0tiBbVqVheE1tBxkN5JOzcNQzhOt3D Q1dK1ri9djEu/LSL2hYLnNjOqUijGVsNsMONo6OFRUynRzoP0hIzulIMzmupC00G 6kksuV5Wto2nDL0L+LHt63JxyTg= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe: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=inlAMGvNkToC5DgdVeihB4 c9D0U=; b=EmP5sZxbh8oe01pUg4PxQTHZbN38S2dEsBtmnGOePblfSrEO+bK7Jo mh1SlkyeqC3JZxnDWujLmsQYCD30+StlJ+VnduXROaxm+qOEhhJc0Fswhj2ftrx0 cF6Xmdf0ykRAkcu5PFxlOaU26cHK/wHrGY4L2mcRegly/9GgrBHis= Received: (qmail 90322 invoked by alias); 30 Sep 2016 20:27:05 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 90291 invoked by uid 89); 30 Sep 2016 20:27:04 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=43, 4.3, xxx X-HELO: mail-pf0-f170.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=4sBVaux3dgQdvfP7kl2Emc/ndePdPWr+d+8SLJqDE78=; b=i+Pfl/eSXUEahhLpaxMGWfrnn7t7a9lUrr7Vo7enx2keIZr2l3/smRhWPhif7w7Cgm TW0hbinX+Q4GHnO7m2aVnnBVMT4cIOer6hVLpRkkvx1ZV8zr76gpq8o04TaPvuTg4FVc 1DoW7ggV6wAgBywTWlaq8kY6KmddQA8tAx7KZSWbUWhWndE/xTc+CV81/I6klYPqpjoV b0vmd/skDvU5vVJwJ0SJ6HDarMoTTUNtwtdWVSZu8w3MV6O6DT5MLyliMHCoV3xS6z5H TcmbquemNThTM6qHwhDS32X5s+R5aXbRy6d3dEs7KMbm9mNWUZPrEjYfgi1XI45B/xtQ 1o4w== X-Gm-Message-State: AA6/9RkmkSQ8AHHiMIP7WMem9RXZ7Ue/S+n6qQXaZ2FkuNMVMRu6tJyJvUt0APdKjfcVrWG9 X-Received: by 10.98.67.139 with SMTP id l11mr14444672pfi.16.1475267212436; Fri, 30 Sep 2016 13:26:52 -0700 (PDT) Subject: Re: [PATCH] Use gcc stpncpy chk builtin (BZ #20661) To: Joseph Myers References: <1475262842-6724-1-git-send-email-adhemerval.zanella@linaro.com> Cc: libc-alpha@sourceware.org From: Adhemerval Zanella Message-ID: Date: Fri, 30 Sep 2016 13:26:48 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 MIME-Version: 1.0 In-Reply-To: On 30/09/2016 13:10, Joseph Myers wrote: > On Fri, 30 Sep 2016, Adhemerval Zanella wrote: > >> Since r182378 GCC provides stpncpy_chk builtin support and it is >> included in official GCC 4.7.4 package. It allows GLIBC to use it >> on string3.h headers without any additional guards. > > You'll need to explain this more. The installed glibc headers support GCC > 2.7 and later. What is the minimum GCC version for which the installed > headers will end up including ? Is it more recent than > the minimum version that has this built-in function? Right, I did not take in consideration case for older GCC using newer GLIBC. Since builtin stpncpy_chk was only added on GCC 4.7 and string3.h is included for GCC 4.3+ it will required to be guarded with __GNUC_PREREQ. What about this: [BZ #20661] * string/bits/string3 [__USE_GNU] (stpncpy): Add fortify version based on GCC builtin for GCC 4.7 and later. (__stpncpy_chk): Define only for !__GNUC_PREREQ (4,7). (__stpncpy_alias): Likewise. diff --git a/string/bits/string3.h b/string/bits/string3.h index 8f13b65..d7440cc 100644 --- a/string/bits/string3.h +++ b/string/bits/string3.h @@ -38,6 +38,7 @@ __warndecl (__warn_memset_zero_len, # ifdef __USE_GNU # undef mempcpy # undef stpcpy +# undef stpncpy # endif # ifdef __USE_MISC # undef bcopy @@ -126,20 +127,29 @@ __NTH (strncpy (char *__restrict __dest, const char *__restrict __src, return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest)); } -/* XXX We have no corresponding builtin yet. */ + +#ifdef __USE_GNU + +# if !__GNUC_PREREQ (4,7) extern char *__stpncpy_chk (char *__dest, const char *__src, size_t __n, size_t __destlen) __THROW; extern char *__REDIRECT_NTH (__stpncpy_alias, (char *__dest, const char *__src, size_t __n), stpncpy); +# endif __fortify_function char * __NTH (stpncpy (char *__dest, const char *__src, size_t __n)) { +# if !__GNUC_PREREQ (4,7) if (__bos (__dest) != (size_t) -1 && (!__builtin_constant_p (__n) || __n > __bos (__dest))) return __stpncpy_chk (__dest, __src, __n, __bos (__dest)); return __stpncpy_alias (__dest, __src, __n); +# else + return __builtin___stpncpy_chk (__dest, __src, __n, __bos (__dest)); +# endif } +#endif __fortify_function char *