From patchwork Wed Mar 23 23:05:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 12790208 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C8ABDC433F5 for ; Wed, 23 Mar 2022 23:05:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5B8156B007D; Wed, 23 Mar 2022 19:05:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 53DC68D0003; Wed, 23 Mar 2022 19:05:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 391246B0080; Wed, 23 Mar 2022 19:05:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0248.hostedemail.com [216.40.44.248]) by kanga.kvack.org (Postfix) with ESMTP id 28B106B007D for ; Wed, 23 Mar 2022 19:05:44 -0400 (EDT) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id DC4A81829201A for ; Wed, 23 Mar 2022 23:05:43 +0000 (UTC) X-FDA: 79277184966.28.F184003 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf12.hostedemail.com (Postfix) with ESMTP id 80F874003B for ; Wed, 23 Mar 2022 23:05:43 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D078D617C1; Wed, 23 Mar 2022 23:05:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 31BADC340E9; Wed, 23 Mar 2022 23:05:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1648076742; bh=ZSUGD+mrQa3Q1UKfR8qnB3RqEUpT01XGqKUHaWZoNxM=; h=Date:To:From:In-Reply-To:Subject:From; b=XwPDlWMKamsph+HZdGmIZQ0qh2miIXzRvgQoHtbjQ9oLOblLVgSaGC7WmDCZtNbx3 4sZMFRh+qEmAbEm1dx+RmlBy2rOZFCrbYTYLPUeCPRim3BybaepdeRTkuef+cw/BmH K1cBEgLCZzorqSAy5XisQBDFkFS2m9AYqzHlG3SM= Date: Wed, 23 Mar 2022 16:05:41 -0700 To: ojeda@kernel.org,ndesaulniers@google.com,nathan@kernel.org,keescook@chromium.org,linux@rasmusvillemoes.dk,akpm@linux-foundation.org,patches@lists.linux.dev,linux-mm@kvack.org,mm-commits@vger.kernel.org,torvalds@linux-foundation.org,akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <20220323160453.65922ced539cbf445b191555@linux-foundation.org> Subject: [patch 08/41] include: drop pointless __compiler_offsetof indirection Message-Id: <20220323230542.31BADC340E9@smtp.kernel.org> X-Rspam-User: X-Stat-Signature: i9qr5x13xod1bgzruwcsgu3fjb746kna Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=XwPDlWMK; spf=pass (imf12.hostedemail.com: domain of akpm@linux-foundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 80F874003B X-HE-Tag: 1648076743-432475 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: From: Rasmus Villemoes Subject: include: drop pointless __compiler_offsetof indirection (1) compiler_types.h is unconditionally included via an -include flag (see scripts/Makefile.lib), and it defines __compiler_offsetof unconditionally. So testing for definedness of __compiler_offsetof is mostly pointless. (2) Every relevant compiler provides __builtin_offsetof (even sparse has had that for 14 years), and if for whatever reason one would end up picking up the poor man's fallback definition (C file compiler with completely custom CFLAGS?), newer clang versions won't treat the result as an Integer Constant Expression, so if used in place where such is required (static initializer or static_assert), one would get errors like t.c:11:16: error: static_assert expression is not an integral constant expression t.c:11:16: note: cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression t.c:4:33: note: expanded from macro 'offsetof' #define offsetof(TYPE, MEMBER) ((size_t)&((TYPE *)0)->MEMBER) So just define offsetof unconditionally and directly in terms of __builtin_offsetof. Link: https://lkml.kernel.org/r/20220202102147.326672-1-linux@rasmusvillemoes.dk Signed-off-by: Rasmus Villemoes Reviewed-by: Miguel Ojeda Reviewed-by: Nathan Chancellor Reviewed-by: Kees Cook Acked-by: Nick Desaulniers Signed-off-by: Andrew Morton --- include/linux/compiler_types.h | 2 -- include/linux/stddef.h | 6 +----- 2 files changed, 1 insertion(+), 7 deletions(-) --- a/include/linux/compiler_types.h~include-drop-pointless-__compiler_offsetof-indirection +++ a/include/linux/compiler_types.h @@ -138,8 +138,6 @@ struct ftrace_likely_data { */ #define __naked __attribute__((__naked__)) notrace -#define __compiler_offsetof(a, b) __builtin_offsetof(a, b) - /* * Prefer gnu_inline, so that extern inline functions do not emit an * externally visible function. This makes extern inline behave as per gnu89 --- a/include/linux/stddef.h~include-drop-pointless-__compiler_offsetof-indirection +++ a/include/linux/stddef.h @@ -13,11 +13,7 @@ enum { }; #undef offsetof -#ifdef __compiler_offsetof -#define offsetof(TYPE, MEMBER) __compiler_offsetof(TYPE, MEMBER) -#else -#define offsetof(TYPE, MEMBER) ((size_t)&((TYPE *)0)->MEMBER) -#endif +#define offsetof(TYPE, MEMBER) __builtin_offsetof(TYPE, MEMBER) /** * sizeof_field() - Report the size of a struct field in bytes