Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp7711634rwd; Tue, 20 Jun 2023 05:20:57 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ45bkeu7m4v/ZDYLEB3ZWrMJmsvqYDm4ITs2Uns3ob3BOojGmsShkzDTYY2S+qFSpivF1ZW X-Received: by 2002:a05:6a00:3a14:b0:668:846b:9b5d with SMTP id fj20-20020a056a003a1400b00668846b9b5dmr3742314pfb.5.1687263654905; Tue, 20 Jun 2023 05:20:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687263654; cv=none; d=google.com; s=arc-20160816; b=xjsblwoL0LQbODMJbTYuEZF4ZHI+16G4YdsKXTAYZWTZLZY5jHx37XnVRKIyxi//pR vZhOwDtxgRaJpj/rDxZonbnNMQ3A3DKhnMH1EsJVSHeIHuJWoTdyvVatyEaKpRoF02cI UeYSwhQSFjZImb00eLbmgUlw/ArL6faH8XuwC3Y2DB2RKr+1tAESq+cuagVgBhpauul3 HWvMtjZtSkROenfibMu5DIJHNXhD0AYDDa8TIDmN6jELYZd1hnG74lFW/HOqcpbaupuc dW8J32KjIw9vxaY4AbOvs/cl51ZzwIf8RECflW2uy1Bw3mHMCWS/4kjdd0kwm+c7oZWY 10ng== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=j6RF82dUnPLYe1XOFJJVvMTnK1ThVPlIi2VmMihmVig=; b=PuXz6/u3n7EYD8lZuaBNfltFs7tpBzjMGj0tBghzYnk2z9U7XCoLeTsLkRV2l/a7XN s2EiINwz0EHCZ5J3juv+AIrRxOFPUlzY0RRZUh6khubCq3iu92RwunKEzzUmiqPC3KZR M9GxlFj9vKmx6xPhfV2yJiGt9vn9C3A3IGaVnqrFOO4kAEGZWF7SP7SNiyKe/LV8h3F3 eq8dtWrSw+MdHp14dvEI8j4COqQUPqDOCUONKKgvXsP4VAzYjjgMQyJDMOpLTLjTv4oD EvUqhaZh2WQe/sijjSY9R2Swm5o5Bmd8GzQTwBujDF+z6QaKgDPWav5snBMaK0brwFl4 68pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BdJBhZ2p; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w186-20020a6262c3000000b0066887057a46si1517214pfb.120.2023.06.20.05.20.39; Tue, 20 Jun 2023 05:20:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BdJBhZ2p; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230451AbjFTMFh (ORCPT + 99 others); Tue, 20 Jun 2023 08:05:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232574AbjFTMF3 (ORCPT ); Tue, 20 Jun 2023 08:05:29 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39DFE170C; Tue, 20 Jun 2023 05:05:28 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C1F1C611EA; Tue, 20 Jun 2023 12:05:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C678FC433C8; Tue, 20 Jun 2023 12:05:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1687262727; bh=fo/HY+4/U2YoL8+5myRX8J+xt11fEMJWxO7l4IEHPH8=; h=From:To:Cc:Subject:Date:From; b=BdJBhZ2pi6yfDXYGE1RXqL+cmvlCGxYZJ3/FD0mqpEWoHOfavsABlo5ii6L5HoPvl GeQsxNRHs3NimIw8hB438iHjwAHWncN5XGRiyYI0iourWuzGJEGmlwXSskFvi4ncGe +Q6fqMMSS5Bc/DgF/2wElaJuuBTg5WUfyt2kUp6LRKFXGT/ruYPee1WJ0JWdzY6xh9 kWzscZNA0+18nP8SJedpsX83oTz+CRHvV1V9Iha53KJSKjMQAudIZTNEIN+VlQejgB 7e1MDtVirm4VgCZJNHTkVkb7noEd794QJ+GcEe2P78q8TsQWtB/BmJFRHSahjTQ6kz B4gaoRVlkLHqQ== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada , Nathan Chancellor , Nick Desaulniers , Nicolas Schier Subject: [PATCH 1/3] modpost: factor out inst location calculation to section_rel() Date: Tue, 20 Jun 2023 21:05:19 +0900 Message-Id: <20230620120521.688124-1-masahiroy@kernel.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org All the addend_*_rel() functions calculate the instruction location in the same way. Factor out the similar code to the caller. Squash reloc_location() too. Signed-off-by: Masahiro Yamada --- scripts/mod/modpost.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 6e0b8be32648..2551ac9d5bd3 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -1256,16 +1256,9 @@ static void check_section_mismatch(struct module *mod, struct elf_info *elf, tosec, taddr); } -static unsigned int *reloc_location(struct elf_info *elf, - Elf_Shdr *sechdr, Elf_Rela *r) -{ - return sym_get_data_by_offset(elf, sechdr->sh_info, r->r_offset); -} - -static int addend_386_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r) +static int addend_386_rel(uint32_t *location, Elf_Rela *r) { unsigned int r_typ = ELF_R_TYPE(r->r_info); - unsigned int *location = reloc_location(elf, sechdr, r); switch (r_typ) { case R_386_32: @@ -1302,11 +1295,10 @@ static int32_t sign_extend32(int32_t value, int index) return (int32_t)(value << shift) >> shift; } -static int addend_arm_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r) +static int addend_arm_rel(void *loc, struct elf_info *elf, Elf_Rela *r) { unsigned int r_typ = ELF_R_TYPE(r->r_info); Elf_Sym *sym = elf->symtab_start + ELF_R_SYM(r->r_info); - void *loc = reloc_location(elf, sechdr, r); uint32_t inst, upper, lower, sign, j1, j2; int32_t offset; @@ -1396,11 +1388,10 @@ static int addend_arm_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r) return 0; } -static int addend_mips_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r) +static int addend_mips_rel(uint32_t *location, Elf_Rela *r) { unsigned int r_typ = ELF_R_TYPE(r->r_info); - unsigned int *location = reloc_location(elf, sechdr, r); - unsigned int inst; + uint32_t inst; if (r_typ == R_MIPS_HI16) return 1; /* skip this */ @@ -1502,6 +1493,8 @@ static void section_rel(struct module *mod, struct elf_info *elf, return; for (rel = start; rel < stop; rel++) { + void *loc; + r.r_offset = TO_NATIVE(rel->r_offset); #if KERNEL_ELFCLASS == ELFCLASS64 if (elf->hdr->e_machine == EM_MIPS) { @@ -1519,17 +1512,20 @@ static void section_rel(struct module *mod, struct elf_info *elf, r_sym = ELF_R_SYM(r.r_info); #endif r.r_addend = 0; + + loc = sym_get_data_by_offset(elf, fsecndx, r.r_offset); + switch (elf->hdr->e_machine) { case EM_386: - if (addend_386_rel(elf, sechdr, &r)) + if (addend_386_rel(loc, &r)) continue; break; case EM_ARM: - if (addend_arm_rel(elf, sechdr, &r)) + if (addend_arm_rel(loc, elf, &r)) continue; break; case EM_MIPS: - if (addend_mips_rel(elf, sechdr, &r)) + if (addend_mips_rel(loc, &r)) continue; break; default: -- 2.39.2