Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp1567518rdg; Sat, 14 Oct 2023 07:28:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE5YpS8KJLX4nJ7C66uXO2Fl8oV2U9sKva7tPYN//z55AsRaJ/EGeab1QXwkpJf/E7pnnBn X-Received: by 2002:a05:6a20:918d:b0:15d:8366:65be with SMTP id v13-20020a056a20918d00b0015d836665bemr3993009pzd.9.1697293711312; Sat, 14 Oct 2023 07:28:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697293711; cv=none; d=google.com; s=arc-20160816; b=FOieke11NyrUR0kqqRDkjDdNp723rC5GiiBR6CSY8st1xZ5TcNh6+FrDBzbkw+s3GA +EmkXcUcOJre4+CWnBSQpFwx10C/3VcHFBRdEOSYdKecbLP5A9wXXxxatxOIoDlLnrY/ LNEQNz1MwJvG9LyFdNSZpy7+Rs8H7O8/Y7eiBF0pxLNGIMpLprAixUvt2t4AwHgCk3zB djBF6JHEfliU12yp8wY4HXyDCufHaIiizqyx96yFdbyzl709XmwES6oc45b1Raw4btUs BUqAcdOml0Ei9ATme4xAokG06DgUFlHGoStR+X+mxOCoINEHH1xAMCYaoWzG86VckrEe tNBw== 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=OUFnk8toz85J/5y39+ALSHmfOA0FCObzsfIQtX+iIVI=; fh=m6x/6LN+jStJhjVltSQCrMZn00nrQmxPRqcJuj9CWeA=; b=iFWt1YPSRUqbvDNEpYmhUJ3vFPFtaGL06DjATh7CdiHiO1yPtkp4vexK12oNC5mjfz xDFK0fJxDF9NVa7XRBXKqqByTqH8q3A3jDHyhu9vOL8/2Av9ug5P/QRDcRvMe8aB3O7y 7uho0iMiFlCjoDXhsnNscoXZTML0vW5asHrNdIzUD9/xQtdL0unmCseZQPny8bhGUGNY oiWGDF6ds2nEhFodGnMRneMm1dmu0R+wnS7H6V4kSHwsuGUmUQ3ViyjL5KoyLN2J00zY 5Q7O/BaZ9hFW93rTwoYBbaO9S8E1Nppj2ugGAekY53Ag4XUm+Ye+KNtgmCf4YNzC64dg rWiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fx2gYUIN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id z11-20020a6552cb000000b0055c8fd5fe00si6865681pgp.886.2023.10.14.07.28.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Oct 2023 07:28:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fx2gYUIN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id C79BA80A2238; Sat, 14 Oct 2023 07:28:28 -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 S233130AbjJNORP (ORCPT + 99 others); Sat, 14 Oct 2023 10:17:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233033AbjJNORO (ORCPT ); Sat, 14 Oct 2023 10:17:14 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18E04BF; Sat, 14 Oct 2023 07:17:12 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1E8CAC433CA; Sat, 14 Oct 2023 14:17:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697293029; bh=oY4N7B1cssGb//2bLUaPZGK5pA0Y2aIN4WuHi9fFUOw=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=fx2gYUINh29tf2PMvvVM7XoJINXX3Y+gTKFc4yszNgplRDfOraI7Y3+BWwCUvnZEj /RyQ+zMdN9tNVhql1ijYLaM0f8/IclhEmjIVuH4XkuTw/qL/T0bgRXp/FPVLMkeWZe RqmhtiiTPTLCScYMdyLmtTk3etzaTMP+kuAScXxdhxw+/5PNFhK3AkNT1jXb1XwM5T mO4Kme4TLx0PDmqazNlCferEgyvMymm8auYVIiyPrpHDueLuk4AyOJiIdtFhUYa3qJ +6zjrI2EbC+oVcH7vbNHWEUvaSdoRHPUaoUvq9dCSXRFGld88LRRAKQd3D5RuSi5Nc 8mxKWzWQwM0qg== Received: by mail-oa1-f45.google.com with SMTP id 586e51a60fabf-1e98e97c824so2056854fac.1; Sat, 14 Oct 2023 07:17:09 -0700 (PDT) X-Gm-Message-State: AOJu0YyTNTQbsDJTg1gs6nAI7RpM2RwGbgD9mPDG6Kz4JAkQELaE4oKf 0fYoiKzCpMzflnRgphcCHawN3Kdk7dkRDiRXc9o= X-Received: by 2002:a05:6870:1256:b0:1d5:8d6a:18f0 with SMTP id 22-20020a056870125600b001d58d6a18f0mr1537561oao.27.1697293028476; Sat, 14 Oct 2023 07:17:08 -0700 (PDT) MIME-Version: 1.0 References: <20231007170448.505487-1-masahiroy@kernel.org> <20231007170448.505487-3-masahiroy@kernel.org> In-Reply-To: From: Masahiro Yamada Date: Sat, 14 Oct 2023 23:16:32 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 3/5] modpost: define TO_NATIVE() using bswap_* functions To: Nick Desaulniers 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=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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]); Sat, 14 Oct 2023 07:28:29 -0700 (PDT) On Tue, Oct 10, 2023 at 2:44=E2=80=AFAM Nick Desaulniers wrote: > > 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_inf= o *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? Yes. In scripts/mod/file2alias.c, DEF_FIELD() calls TO_NATIVE(). DEF_FIELD() is also used to get access to 1-byte fields. So, TO_NATIVE() needs to accept sizeof(x)=3D=3D1. > Seems silly unless > one of these types is variable length dependent on the target machine > type? You can use DEF_FIELD() without knowing the field width. This is good. --=20 Best Regards Masahiro Yamada