Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4025262ybl; Mon, 3 Feb 2020 11:05:22 -0800 (PST) X-Google-Smtp-Source: APXvYqz3RNlWAtgl2HAto2vvU4RH1O6HwQ96NsTY8yf8GXpfm5xob4PuBPd4ansepj9aX78QztK+ X-Received: by 2002:a05:6830:2361:: with SMTP id r1mr18079167oth.88.1580756722118; Mon, 03 Feb 2020 11:05:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580756722; cv=none; d=google.com; s=arc-20160816; b=hgWrmI/D2khjI36dfCp2wvElLLPZJ9woefFT85rZ/U4CfZxJf4uAPm/Rnk6jask87V fcrTdBdjdb4V6lez/Y6xEmyzHRFJSTm4z+DKvQOZxb5kSv2rlTZydMXkyGfOyCJF4t78 3T6xv5PTma8hjG9l5s9GhCaD5MSb5zbAZwGBIbcv2eyglAd6my/XM4SG6oKXobdjw8CL r7A5GT8AJSQxUPwhPSbqvPB4r3g0KkmR1S8flMK2zsZfc8MgLimHgrqx2AKPOrjJnnBe zWoLhBjOi7YLXCIYLsfQgRQqu95HsMGyjiCOSJW34VE2ffny58R3nr3459iwXvS9HSnR 88Yg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=MPoYYIAq+8IWAekMybKRX0fjG2nkb7hVgzHvIW8ukdY=; b=SbTxbA54Qe9pQLqr39i9Z9Cojs3UsefMM7CJRWz2bs0ZOhUjSz7A3e8vXvkC34q34a nPCWvaWTcntRxFu7Ctd0h1STUcqBnvawg1rvvl7VD92/OZPfgLVIor7cwgcEps4I1+bD hAywICNYZQE6LFPauWufUKTSQloz+d//Em+qiBR2QpNLAK/X+Av7cwbOwBahuZQj/7p9 xqUrfGOcq0khOWpZPNou4I9cfzUwKLhOHXaNoQbPofTXAlKTH+ajMr52uCUeAo6pUg5C YU2Y9aspsOPl8QZujipR+hSMd82Dk2Tds3bU0Rj+CQ8w3chfEyHaVXD2moKPR1DOShxF j+nw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="0t/d0alg"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h3si10146258otq.203.2020.02.03.11.05.09; Mon, 03 Feb 2020 11:05:22 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="0t/d0alg"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727720AbgBCQ25 (ORCPT + 99 others); Mon, 3 Feb 2020 11:28:57 -0500 Received: from mail.kernel.org ([198.145.29.99]:40684 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729678AbgBCQ2z (ORCPT ); Mon, 3 Feb 2020 11:28:55 -0500 Received: from localhost (unknown [104.132.45.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4FB1A2051A; Mon, 3 Feb 2020 16:28:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1580747334; bh=SCJEmv0iAHFTm4Tp6DgzuSw1c6tPFAGLtEas5RCywVw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0t/d0algb5UcwvjV2OaE7fXk6I4moDYFCcD7qE9VkGUnxLZ2rNpkr9Wt+6hZZQs2w cDX5YliLGcd7L/TokJ4+ypx0Q0hdutzXWdS3+Lsc8V+cyx7jSLlPQ6WJUmRXUnoK9X 0SHyG8N9aRfXlcooQBJbCMnfqydP67z0YQu9k0bs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vitaly Chikunov , Dmitry Levin , Josh Poimboeuf , kbuild test robot , Peter Zijlstra , Vineet Gupta , Arnaldo Carvalho de Melo Subject: [PATCH 4.14 40/89] tools lib: Fix builds when glibc contains strlcpy() Date: Mon, 3 Feb 2020 16:19:25 +0000 Message-Id: <20200203161922.349505858@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200203161916.847439465@linuxfoundation.org> References: <20200203161916.847439465@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vitaly Chikunov commit 6c4798d3f08b81c2c52936b10e0fa872590c96ae upstream. Disable a couple of compilation warnings (which are treated as errors) on strlcpy() definition and declaration, allowing users to compile perf and kernel (objtool) when: 1. glibc have strlcpy() (such as in ALT Linux since 2004) objtool and perf build fails with this (in gcc): In file included from exec-cmd.c:3: tools/include/linux/string.h:20:15: error: redundant redeclaration of ‘strlcpy’ [-Werror=redundant-decls] 20 | extern size_t strlcpy(char *dest, const char *src, size_t size); 2. clang ignores `-Wredundant-decls', but produces another warning when building perf: CC util/string.o ../lib/string.c:99:8: error: attribute declaration must precede definition [-Werror,-Wignored-attributes] size_t __weak strlcpy(char *dest, const char *src, size_t size) ../../tools/include/linux/compiler.h:66:34: note: expanded from macro '__weak' # define __weak __attribute__((weak)) /usr/include/bits/string_fortified.h:151:8: note: previous definition is here __NTH (strlcpy (char *__restrict __dest, const char *__restrict __src, Committer notes: The #pragma GCC diagnostic directive was introduced in gcc 4.6, so check for that as well. Fixes: ce99091 ("perf tools: Move strlcpy() from perf to tools/lib/string.c") Fixes: 0215d59 ("tools lib: Reinstate strlcpy() header guard with __UCLIBC__") Resolves: https://bugzilla.kernel.org/show_bug.cgi?id=118481 Signed-off-by: Vitaly Chikunov Reviewed-by: Dmitry Levin Cc: Dmitry Levin Cc: Josh Poimboeuf Cc: kbuild test robot Cc: Peter Zijlstra Cc: stable@vger.kernel.org Cc: Vineet Gupta Link: http://lore.kernel.org/lkml/20191224172029.19690-1-vt@altlinux.org Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Greg Kroah-Hartman --- tools/include/linux/string.h | 8 ++++++++ tools/lib/string.c | 7 +++++++ 2 files changed, 15 insertions(+) --- a/tools/include/linux/string.h +++ b/tools/include/linux/string.h @@ -14,7 +14,15 @@ int strtobool(const char *s, bool *res); * However uClibc headers also define __GLIBC__ hence the hack below */ #if defined(__GLIBC__) && !defined(__UCLIBC__) +// pragma diagnostic was introduced in gcc 4.6 +#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wredundant-decls" +#endif extern size_t strlcpy(char *dest, const char *src, size_t size); +#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) +#pragma GCC diagnostic pop +#endif #endif char *str_error_r(int errnum, char *buf, size_t buflen); --- a/tools/lib/string.c +++ b/tools/lib/string.c @@ -95,6 +95,10 @@ int strtobool(const char *s, bool *res) * If libc has strlcpy() then that version will override this * implementation: */ +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wignored-attributes" +#endif size_t __weak strlcpy(char *dest, const char *src, size_t size) { size_t ret = strlen(src); @@ -106,3 +110,6 @@ size_t __weak strlcpy(char *dest, const } return ret; } +#ifdef __clang__ +#pragma clang diagnostic pop +#endif