Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp1063190rdb; Sat, 7 Oct 2023 10:05:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHtllo/xY+UagJexm0WhBwgp1qpIpHMWKbEvzHonhHkWTz+5su+oJ8K5taz6+2XxHXscce9 X-Received: by 2002:a05:6a00:99b:b0:690:3f29:a874 with SMTP id u27-20020a056a00099b00b006903f29a874mr12586114pfg.23.1696698340057; Sat, 07 Oct 2023 10:05:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696698340; cv=none; d=google.com; s=arc-20160816; b=zlsM3bkupBD2Yc2XzwUWPaBjPWaJFzA3pBGuTpRZVoLxFjrWLPQUSApc1RsZyrpxws aEqhM5SFXjzkp9L9BiF5pZHehXF62ZexmcCDjL0HO1XTE2HW+/nyiGd7sIf8Z/8C+Q/r 1iEU03hvssnlV18EhLG321t/zs9AI1Edkf84IvcimNW1xo7TKeI2+lSDpRk79BsQf79R Lob/UFmw12A32i/rQE+jJHPTmjzi5ZrRlNmppddsv2Wtsayxc/WY1VAj1XSk4PcYLvlJ Y41p+6tLnm2tEGfPNriJ/a4sjiA0lbkct4B+iRfBGcb3tiZwnM+fmpF4BWPSAjCEUG9g KMRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=w/ZPB4MQ6kjaBJ7EfiZHhd8h0lPAa6J0DzKPZbShzW4=; fh=DNUEAfFafydB9vNApmSaMnjQC4olHhINF4DqgGQv3/I=; b=ZKt0mk4WDN0zlf+Vd51l+N5l/P6kV16COK1OZHZ46OUN3DUKalQ/C0JAdcfV8NSJbA A4S/1nenqT/wdgPrkWSFVDSY489gYiJ6BAY6hRl0cbl0OG8n6ia24zv7n9XfJIo1bvf6 F6rzKcWHwPEtYo82YcoNq5GfXd1AmmIAqMq+hteJfogTvzO/pbxS53Nt8JzLLVPCM5BO iEbR5PU0+fFJAAiZyYGZ0zfi4NZdAbqMIMKKASnb3W4spHO30SySY6tmgJRRzGgvjtq9 pLxIFIvW+kTNfJuDkfYSOJYiuEjl2u0eoCwAEmAZC2SH7gZ7AnRqRhzdkLfiUuiMYXjc YQMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=sBynyLUd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id ca8-20020a056a00418800b0069d1639f09esi3169195pfb.190.2023.10.07.10.05.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Oct 2023 10:05:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=sBynyLUd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (Postfix) with ESMTP id 030FD80BE7E0; Sat, 7 Oct 2023 10:05:38 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344133AbjJGRFJ (ORCPT + 99 others); Sat, 7 Oct 2023 13:05:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344120AbjJGRFE (ORCPT ); Sat, 7 Oct 2023 13:05:04 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5EF2FB9; Sat, 7 Oct 2023 10:05:03 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9964FC433C8; Sat, 7 Oct 2023 17:05:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1696698303; bh=VFhwLN6cPSTo8azgI6QvVm2lvfds7OQ34SuiYHF6MzU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sBynyLUd1/uJaABdRrkJDXMqCBr6rKnMibc1ZccirbcOVP0DwA/e6rFwgRutM+vYO C4kcvfL+Ojlxuec+WLBCy7aRXhcVG9AopB9Q6UBjRY593Srgrp7kt6kAUNcJsUzyzx tJX4/8N4Vlg2L0zkVrmGv2n83/MVoStZQbTb8ETiJeaKFuR7gNiG45L5z3WhNzAnT6 0RPHK8V1m/jU2/2iIyjugJDYW1Ct2Yw/Uhii6rDcnnA2A1pNTMvF6f8hiFCouxgYbl sBayNGlrDVh/ixc8rMSgyy69ofVu+BLzBwH2Bvae06izplRquNEs7i2VGiBvvqje+L UzfP+q5pGXKkg== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada , Nick Desaulniers , Nathan Chancellor , Nicolas Schier Subject: [PATCH 5/5] modpost: factor out the common boilerplate of section_rel(a) Date: Sun, 8 Oct 2023 02:04:48 +0900 Message-Id: <20231007170448.505487-5-masahiroy@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231007170448.505487-1-masahiroy@kernel.org> References: <20231007170448.505487-1-masahiroy@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=2.4 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.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 (morse.vger.email [0.0.0.0]); Sat, 07 Oct 2023 10:05:38 -0700 (PDT) X-Spam-Level: ** The first few lines of section_rel() and section_rela() are the same. They both retrieve the index of the section to which the relocaton applies, and skip known-good sections. This common code should be moved to check_sec_ref(). Avoid ugly casts when computing 'start' and 'stop', and also make the Elf_Rel and Elf_Rela pointers const. Signed-off-by: Masahiro Yamada Reviewed-by: Nick Desaulniers --- scripts/mod/modpost.c | 50 ++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 441d57ee3275..f1f658122ad8 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -1420,17 +1420,10 @@ static void get_rel_type_and_sym(struct elf_info *elf, uint64_t r_info, } static void section_rela(struct module *mod, struct elf_info *elf, - Elf_Shdr *sechdr) + unsigned int fsecndx, const char *fromsec, + const Elf_Rela *start, const Elf_Rela *stop) { - Elf_Rela *rela; - unsigned int fsecndx = sechdr->sh_info; - const char *fromsec = sec_name(elf, fsecndx); - Elf_Rela *start = (void *)elf->hdr + sechdr->sh_offset; - Elf_Rela *stop = (void *)start + sechdr->sh_size; - - /* if from section (name) is know good then skip it */ - if (match(fromsec, section_white_list)) - return; + const Elf_Rela *rela; for (rela = start; rela < stop; rela++) { Elf_Addr taddr, r_offset; @@ -1460,17 +1453,10 @@ static void section_rela(struct module *mod, struct elf_info *elf, } static void section_rel(struct module *mod, struct elf_info *elf, - Elf_Shdr *sechdr) + unsigned int fsecndx, const char *fromsec, + const Elf_Rel *start, const Elf_Rel *stop) { - Elf_Rel *rel; - unsigned int fsecndx = sechdr->sh_info; - const char *fromsec = sec_name(elf, fsecndx); - Elf_Rel *start = (void *)elf->hdr + sechdr->sh_offset; - Elf_Rel *stop = (void *)start + sechdr->sh_size; - - /* if from section (name) is know good then skip it */ - if (match(fromsec, section_white_list)) - return; + const Elf_Rel *rel; for (rel = start; rel < stop; rel++) { Elf_Sym *tsym; @@ -1525,10 +1511,26 @@ static void check_sec_ref(struct module *mod, struct elf_info *elf) check_section(mod->name, elf, sechdr); /* We want to process only relocation sections and not .init */ - if (sechdr->sh_type == SHT_RELA) - section_rela(mod, elf, sechdr); - else if (sechdr->sh_type == SHT_REL) - section_rel(mod, elf, sechdr); + if (sechdr->sh_type == SHT_REL || sechdr->sh_type == SHT_RELA) { + /* section to which the relocation applies */ + unsigned int secndx = sechdr->sh_info; + const char *secname = sec_name(elf, secndx); + const void *start, *stop; + + /* If the section is known good, skip it */ + if (match(secname, section_white_list)) + continue; + + start = sym_get_data_by_offset(elf, i, 0); + stop = start + sechdr->sh_size; + + if (sechdr->sh_type == SHT_RELA) + section_rela(mod, elf, secndx, secname, + start, stop); + else + section_rel(mod, elf, secndx, secname, + start, stop); + } } } -- 2.39.2