Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp2049005rdb; Mon, 9 Oct 2023 10:44:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEKnlXhC8myhdCreosj/nA/fqBkjhdIbiVjXChewbgLYru1R3QfqUVsxT7uQDbo8F9R6hwW X-Received: by 2002:a17:90b:3b52:b0:273:f017:cac0 with SMTP id ot18-20020a17090b3b5200b00273f017cac0mr12896573pjb.39.1696873471780; Mon, 09 Oct 2023 10:44:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696873471; cv=none; d=google.com; s=arc-20160816; b=M7o5IvaOJ78x7MbDLfLvKtdpkDZENo3aFcnQsjDEAzqXEIXriMmxks8OSXizu9904f H1g7cNuCWUL6NgmzOV+LhhGjpx3uKXzj12sP0ZTMDa0yPo7hZijSsPn/hDMCJ4BAvtw5 sgyBffQL9xM/iGB81bmiLu5pfqU8PL+fMd715oFpvYGHBImKHlQ0eNZWptvg9Fbie7dX mKR7VZtsR7XlmsbNJS8d/LWJrqcJTRHuae9chqR+Ri58dyVHRVS29pkDmju1sEbgE5zk 3B1/sI50Eq2a6Woa97qon5ez1kaqFk+jpZ60aXmodgg3N1L//+KShIQiHVYJQRoomyYf dlIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=STStuPO/b+1eXhTjhf6QGffrCRQ+SU82tm0zQBraBwI=; fh=N7MyQAAWCSXQy5dNgvcvh5SJWZailG0Yojzw8BTWwQ8=; b=aoA1BNqKYLhACuHrYpUEZ1jkAnfVqOKRCxlqycgeIOPwaJNa2hOsQWJmCyHT6lqBZc mttHEuhX2z6iBv3Y+QVfL52zVg3Owj8v3LHWOQgug2fp25nStnU7nCzn4oL1XfL22KqY IdC0zNdQ8bA5wry1ru3+pXruOMxdY1RTWLDXZ318I4gI8d7mCltqg5ei9weO7Jjpzxal zXaSTfJdXRha5zBcDmBMJuNLDjhXzroea1f686oKQY9DceMHsl43r1C4uyVuC0B7NdvJ pxkRiqIH/ORi6GkTUaJZRaggV/OHvSgxYs/xXFLUoDFMKxgfApIradzaiFty+cABTLQX T8kQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="Lq/GzIn+"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id n7-20020a17090a9f0700b00276f10d241fsi12214510pjp.37.2023.10.09.10.44.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 10:44:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="Lq/GzIn+"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 0B8D18043C06; Mon, 9 Oct 2023 10:44:29 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377485AbjJIRoT (ORCPT + 99 others); Mon, 9 Oct 2023 13:44:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233250AbjJIRoR (ORCPT ); Mon, 9 Oct 2023 13:44:17 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE22E9D for ; Mon, 9 Oct 2023 10:44:15 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-4064867903cso48622855e9.2 for ; Mon, 09 Oct 2023 10:44:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696873454; x=1697478254; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=STStuPO/b+1eXhTjhf6QGffrCRQ+SU82tm0zQBraBwI=; b=Lq/GzIn+6AwVnkUmcMRjcvRKYuaLneqf9h8eBuiJbjgDtD+0MmOtQqlnVvnie5A7FN N1cvVjHy199GA1RMfjdBCODs349QQzK3e2TGyOwIe+ux+yurk0bEUloOgLdxI5iEt5G3 q+4cRuEa+MAELnFbOWt36BbJH42y1w6fY99gQZucRxmkPcZsvyXYq/2PMB3TngttzbHs spAzw2aYkBcf3HrnMrcKfLNYc8mQKwk83RI2HteJ8mWBGSY9MRrt/H1mANYkeIRnpMSi 5EW5hPwX1qEuv41yypgzJ6fHNHgP5DK1LqKGYNQ9JGrDWQKpKVlh765eL3KFZ7/xCNoR WALQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696873454; x=1697478254; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=STStuPO/b+1eXhTjhf6QGffrCRQ+SU82tm0zQBraBwI=; b=tq4iwX7SZUvDtvwUViJzhHJG6PFkUfJdwF1nBtDRn1OPcfa3p7d4wG773trPKWSsIP 2fvnqdx8Iun0P3bc0eZDS8BDmlTCmWxU8rn50DlcQ/qPEezPlQ7+a3cPy/2DbvX/aWS0 Heb+c7N4Agiymf9P3IQsruiCQQg5mGkHRpEOemdaBIor3yQyjyxK29cGc+3I4pfFHNfY cJfsjQEo1X9bE91BRVyI6njFOQF5smF/WHOIJhRkD8TZFP+J5nic91j9mSFYWJ8j2DeK KjD81lfaP5hXbV0uXbjkgy30CfZQp1gLMi00FsKsY4oPRrT1+inN0AEWawBCLQPaIZtQ fMbg== X-Gm-Message-State: AOJu0Ywux/ItlpJ2SvpboMALFaKxJIyZ45c1TbREoI/Sv4nEPy7dCFFE ddSNmia7/+twAZBBz1uCHiime/F7mPThVjEQUQSm2A== X-Received: by 2002:adf:e6cd:0:b0:31f:a4fa:130a with SMTP id y13-20020adfe6cd000000b0031fa4fa130amr14430019wrm.14.1696873453889; Mon, 09 Oct 2023 10:44:13 -0700 (PDT) MIME-Version: 1.0 References: <20231007170448.505487-1-masahiroy@kernel.org> <20231007170448.505487-3-masahiroy@kernel.org> In-Reply-To: <20231007170448.505487-3-masahiroy@kernel.org> From: Nick Desaulniers Date: Mon, 9 Oct 2023 10:43:59 -0700 Message-ID: Subject: Re: [PATCH 3/5] modpost: define TO_NATIVE() using bswap_* functions To: Masahiro Yamada Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, Nathan Chancellor , Nicolas Schier Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-4.8 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Mon, 09 Oct 2023 10:44:29 -0700 (PDT) On Sat, Oct 7, 2023 at 10:05=E2=80=AFAM Masahiro Yamada wrote: > > The current TO_NATIVE() has some limitations: > > 1) You cannot cast the argument. > > 2) You cannot pass a variable marked as 'const'. > > 3) Passing an array is a bug, but it is not detected. > > Impelement TO_NATIVE() using bswap_*() functions. These are GNU > extensions. If we face portability issues, we can port the code from > include/uapi/linux/swab.h. > > With this change, get_rel_type_and_sym() can be simplified by casting > the arguments directly. > > Signed-off-by: Masahiro Yamada > --- > > scripts/mod/modpost.c | 13 ++++--------- > scripts/mod/modpost.h | 25 ++++++++++++------------- > 2 files changed, 16 insertions(+), 22 deletions(-) > > diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c > index 2f3b0fe6f68d..99476a9695c5 100644 > --- a/scripts/mod/modpost.c > +++ b/scripts/mod/modpost.c > @@ -1410,15 +1410,10 @@ static void get_rel_type_and_sym(struct elf_info = *elf, uint64_t r_info, > return; > } > > - if (is_64bit) { > - Elf64_Xword r_info64 =3D r_info; > - > - r_info =3D TO_NATIVE(r_info64); > - } else { > - Elf32_Word r_info32 =3D r_info; > - > - r_info =3D TO_NATIVE(r_info32); > - } > + if (is_64bit) > + r_info =3D TO_NATIVE((Elf64_Xword)r_info); > + else > + r_info =3D TO_NATIVE((Elf32_Word)r_info); > > *r_type =3D ELF_R_TYPE(r_info); > *r_sym =3D ELF_R_SYM(r_info); > diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h > index 6413f26fcb6b..1392afec118c 100644 > --- a/scripts/mod/modpost.h > +++ b/scripts/mod/modpost.h > @@ -1,4 +1,5 @@ > /* SPDX-License-Identifier: GPL-2.0 */ > +#include > #include > #include > #include > @@ -51,21 +52,19 @@ > #define ELF_R_TYPE ELF64_R_TYPE > #endif > > +#define bswap(x) \ > +({ \ > + _Static_assert(sizeof(x) =3D=3D 1 || sizeof(x) =3D=3D 2 || \ Seems fine, but do we need to support folks trying to swap 1B values? i.e. is someone calling TO_NATIVE with 1B values? Seems silly unless one of these types is variable length dependent on the target machine type? Reviewed-by: Nick Desaulniers > + sizeof(x) =3D=3D 4 || sizeof(x) =3D=3D 8, "bug"); = \ > + (typeof(x))(sizeof(x) =3D=3D 2 ? bswap_16(x) : \ > + sizeof(x) =3D=3D 4 ? bswap_32(x) : \ > + sizeof(x) =3D=3D 8 ? bswap_64(x) : \ > + x); \ > +}) > + > #if KERNEL_ELFDATA !=3D HOST_ELFDATA > > -static inline void __endian(const void *src, void *dest, unsigned int si= ze) > -{ > - unsigned int i; > - for (i =3D 0; i < size; i++) > - ((unsigned char*)dest)[i] =3D ((unsigned char*)src)[size = - i-1]; > -} > - > -#define TO_NATIVE(x) \ > -({ \ > - typeof(x) __x; \ > - __endian(&(x), &(__x), sizeof(__x)); \ > - __x; \ > -}) > +#define TO_NATIVE(x) (bswap(x)) > > #else /* endianness matches */ > > -- > 2.39.2 > --=20 Thanks, ~Nick Desaulniers