From patchwork Wed Aug 3 13:50:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 12935525 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D7B45C19F28 for ; Wed, 3 Aug 2022 13:54:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238304AbiHCNyp (ORCPT ); Wed, 3 Aug 2022 09:54:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238326AbiHCNy0 (ORCPT ); Wed, 3 Aug 2022 09:54:26 -0400 Received: from conuserg-07.nifty.com (conuserg-07.nifty.com [210.131.2.74]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8158343E6B; Wed, 3 Aug 2022 06:52:02 -0700 (PDT) Received: from grover.sesame (133-32-177-133.west.xps.vectant.ne.jp [133.32.177.133]) (authenticated) by conuserg-07.nifty.com with ESMTP id 273DokZX018578; Wed, 3 Aug 2022 22:50:46 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-07.nifty.com 273DokZX018578 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1659534646; bh=4lNUVwZLKGFu7RDUkST96BO8Yb9Fnq+wtWdIdDRUbnQ=; h=From:To:Cc:Subject:Date:From; b=D67NGJDpiuW4RkHT362dOxIXziItoAApb9cP0KVmchF3oKAjGnCacLheNCXO42Lmw OQNEcFXt21Bb/t6m1mnjLbDX4yrWMA9vGq0UdtIQGT9HCJ+jolTHz1396+sfS8Qgfw +lUDpqYuAT+pX77MpDUtNfiaftRPYZlgD6cxeBdixkbowtEruIJ4PVt1M035Tq3uTo KgNDtLF+Qpz2r37AOXQBZKia64LZzBDez9eDURgl+ZXmUr/D16bvfF2ZdN8LVE5lqb +8I38UlK28pNCwvQifXOlLLYLGnbXHKAwa1iX+ZPtAGyyqiPxKo/Jj54YVJuNAGwuL MFed38GPKUW6w== X-Nifty-SrcIP: [133.32.177.133] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Masahiro Yamada , Michal Marek , Nick Desaulniers , linux-kernel@vger.kernel.org Subject: [PATCH v2] modpost: refactor get_secindex() Date: Wed, 3 Aug 2022 22:50:13 +0900 Message-Id: <20220803135013.1818199-1-masahiroy@kernel.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org SPECIAL() is only used in get_secindex(). Squash it. Make the code more readable with more comments. Signed-off-by: Masahiro Yamada --- Changes in v2: - Revive 'index <= SHN_HIRESERVE)' check scripts/mod/modpost.h | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h index bd874f906781..1178f40a73f3 100644 --- a/scripts/mod/modpost.h +++ b/scripts/mod/modpost.h @@ -156,22 +156,28 @@ static inline int is_shndx_special(unsigned int i) return i != SHN_XINDEX && i >= SHN_LORESERVE && i <= SHN_HIRESERVE; } -/* - * Move reserved section indices SHN_LORESERVE..SHN_HIRESERVE out of - * the way to -256..-1, to avoid conflicting with real section - * indices. - */ -#define SPECIAL(i) ((i) - (SHN_HIRESERVE + 1)) - /* Accessor for sym->st_shndx, hides ugliness of "64k sections" */ static inline unsigned int get_secindex(const struct elf_info *info, const Elf_Sym *sym) { - if (is_shndx_special(sym->st_shndx)) - return SPECIAL(sym->st_shndx); - if (sym->st_shndx != SHN_XINDEX) - return sym->st_shndx; - return info->symtab_shndx_start[sym - info->symtab_start]; + unsigned int index = sym->st_shndx; + + /* + * Elf{32,64}_Sym::st_shndx is 2 byte. Big section numbers are available + * in the .symtab_shndx section. + */ + if (index == SHN_XINDEX) + return info->symtab_shndx_start[sym - info->symtab_start]; + + /* + * Move reserved section indices SHN_LORESERVE..SHN_HIRESERVE out of + * the way to UINT_MAX-255..UINT_MAX, to avoid conflicting with real + * section indices. + */ + if (index >= SHN_LORESERVE && index <= SHN_HIRESERVE) + return index - SHN_HIRESERVE - 1; + + return index; } /* file2alias.c */