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 X-Patchwork-Id: 16166 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 *