From patchwork Wed Feb 19 04:54:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Chancellor X-Patchwork-Id: 11390331 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9833F924 for ; Wed, 19 Feb 2020 04:54:36 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 650AF24672 for ; Wed, 19 Feb 2020 04:54:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GxU8H+8w" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 650AF24672 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 32D006B0006; Tue, 18 Feb 2020 23:54:34 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2DCEF6B0007; Tue, 18 Feb 2020 23:54:34 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1A52B6B0008; Tue, 18 Feb 2020 23:54:34 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0199.hostedemail.com [216.40.44.199]) by kanga.kvack.org (Postfix) with ESMTP id 042E76B0006 for ; Tue, 18 Feb 2020 23:54:33 -0500 (EST) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 756D84405 for ; Wed, 19 Feb 2020 04:54:33 +0000 (UTC) X-FDA: 76505660826.18.shoe53_aa31a2205103 X-Spam-Summary: 2,0,0,ba85fbf3117fb812,d41d8cd98f00b204,natechancellor@gmail.com,:masahiroy@kernel.org:michal.lkml@markovi.net:arnd@arndb.de:rostedt@goodmis.org:mingo@redhat.com:jbaron@akamai.com:catalin.marinas@arm.com:akpm@linux-foundation.org:linux-kernel@vger.kernel.org:linux-kbuild@vger.kernel.org:linux-arch@vger.kernel.org::clang-built-linux@googlegroups.com:natechancellor@gmail.com,RULES_HIT:41:355:379:541:800:960:967:973:988:989:1260:1311:1314:1345:1359:1437:1515:1535:1542:1711:1730:1747:1777:1792:1981:2194:2199:2393:2525:2559:2563:2682:2685:2693:2859:2902:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3165:3354:3865:3866:3867:3868:3870:3871:3872:3874:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4250:4321:4605:5007:6119:6261:6653:7514:7903:8957:9025:9413:10004:11026:11473:11658:11914:12043:12048:12297:12438:12517:12519:12555:12679:12895:13161:13229:13894:14181:14394:14687:14721:21080:21433:21444:21451:21627:21666:21939:21990:30003:30054,0,R BL:209.8 X-HE-Tag: shoe53_aa31a2205103 X-Filterd-Recvd-Size: 5919 Received: from mail-oi1-f194.google.com (mail-oi1-f194.google.com [209.85.167.194]) by imf18.hostedemail.com (Postfix) with ESMTP for ; Wed, 19 Feb 2020 04:54:32 +0000 (UTC) Received: by mail-oi1-f194.google.com with SMTP id z2so22579826oih.6 for ; Tue, 18 Feb 2020 20:54:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=z4GEXAYyqQWsp025ogzeKnxOXkjpBM0jeh4Jkb1AQ/E=; b=GxU8H+8wHFYPadW4JaajZHSEVBcXNLGzyU3EcBZXx+nG/SCQ/ASmuoJLfPCPUeuTcU FPKoRZq2suxke3wLsTkQ3/gIM1UWeWVU52/tJzPsh7F9zxB1xTyPTqbDXA2XcyCzn8kA iWG/YrzUa7yE/uj8JF+ADOrARv+qXt5jGgHTl3dGWyQcvrNsChBzUM6v8hKbMjzOjbne Dv7HJtHNa1r3sg4kQxML6Nc9dqgwX2cEoYxS/8LynvMCvXhgd/YzZn9ZWcXiUNKliTpN gvs8opTGiEwt6oK3ylCI00rjpTlVbwmdaK08ckbydc41KM39Ff9Rfz2SBcq1CUbJye9R M1NQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=z4GEXAYyqQWsp025ogzeKnxOXkjpBM0jeh4Jkb1AQ/E=; b=GoMwayOj4OucOZ2UluFDXK6uX8tYephspgjuuC5jowkym67ESfbmK2ufVdVqgIYTRZ 9WfeMsp64yPNKhkJjk+NAULekcWxi/elA9Z7UwSseLgUdOEOpJF2j19iSrhiBZKy3mwC DPIPGUkDq7QbaK9QO0uCnKRRYfUVCftTzCE2hqkX7KSSbZYgFff5kZcTD7ulxDv+bsDt q2fGCGb+iG/WpZ6j1lOTYCvFTyLghmpjhB/dvOVuIW07XS+bwf937z3Z55DbbUySsRp0 CM7iF5aNuCcchsiYlXU0QUGmUScDnnme3fnElmQo6q0jd3p+zWMh1bABNAx5E3yZoYzA fraA== X-Gm-Message-State: APjAAAU4K8GQ6Vk6ZDAfiECxxG67jllqlpgd1RsNoOCgZT7pVEqU4/vl IDPnUise4b3Yy8J1RMHKHrM= X-Google-Smtp-Source: APXvYqzPqnhDSnUTxbnbVTbSbPmWK7BxoBMVOIdmKFVTG3pZ9TJDv5U6RijdtiI3Af1f4g1Jjlyyqw== X-Received: by 2002:aca:c7ca:: with SMTP id x193mr3514163oif.70.1582088072470; Tue, 18 Feb 2020 20:54:32 -0800 (PST) Received: from localhost.localdomain ([2604:1380:4111:8b00::1]) by smtp.gmail.com with ESMTPSA id c7sm288894otn.81.2020.02.18.20.54.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Feb 2020 20:54:32 -0800 (PST) From: Nathan Chancellor To: Masahiro Yamada , Michal Marek , Arnd Bergmann , Steven Rostedt , Ingo Molnar , Jason Baron , Catalin Marinas , Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, clang-built-linux@googlegroups.com, Nathan Chancellor Subject: [PATCH 1/6] asm/sections: Add COMPARE_SECTIONS macro Date: Tue, 18 Feb 2020 21:54:18 -0700 Message-Id: <20200219045423.54190-2-natechancellor@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200219045423.54190-1-natechancellor@gmail.com> References: <20200219045423.54190-1-natechancellor@gmail.com> MIME-Version: 1.0 X-Patchwork-Bot: notify X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: When building with clang's -Wtautological-compare, there are a few warnings around the comparison of section boundaries, which are linker defined symbols and just contain an address. Clang says that these comparisons always evaluate to a constant because it thinks they are regular arrays. This result is expected and reasonable since we just care about its boolean value. The kernel does this to figure out how exactly it was laid out during link time so that it can make certain run time decisions without hard coding them via preprocessor macros. These comparisons always evaluate the way that the kernel wants (done by comparing a Clang built kernel to a GCC built kernel). As a result, this warning should be silenced in these particular instances so that -Wtautological-compare can be enabled for the kernel globally since it brings several useful warnings within its group. In other words, by disabling -Wtautological-compare, the kernel misses out on several useful subwarnings that are found with existing static checkers; catching things with the compiler at build time will make it easier to catch issues, especially as clang starts to be integrated into CI systems. The warnings can be silenced by casting the linked defined symbols to unsigned long (normally uintptr_t but the kernel typedef's uintptr_t to unsigned long and some kernel developers prefer unsigned long) to make them purely numeric comparisons, which will be converted to a boolean without any warning from Clang. The casting is done within a macro so that it can be documented why this casting happens, rather than sprinkling random casts in the few places that this happens within the kernel. Link: https://github.com/ClangBuiltLinux/linux/issues/765 Signed-off-by: Nathan Chancellor --- include/asm-generic/sections.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/asm-generic/sections.h b/include/asm-generic/sections.h index d1779d442aa5..e1f3095a50c1 100644 --- a/include/asm-generic/sections.h +++ b/include/asm-generic/sections.h @@ -169,4 +169,11 @@ static inline bool is_kernel_rodata(unsigned long addr) addr < (unsigned long)__end_rodata; } +/* + * Comparing section boundaries trips clang's -Wtautological-compare + * This silences that warning by making the comparisons purely numeric + */ +#define COMPARE_SECTIONS(section_one, op, section_two) \ + ((unsigned long)(section_one) op (unsigned long)(section_two)) + #endif /* _ASM_GENERIC_SECTIONS_H_ */