Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp663147rwd; Thu, 1 Jun 2023 05:12:52 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5zBcdrk1TBWugGnBpi1a6/UDP/cb7nrFhlWaQa6dOtcfkwdAo9PMg+VRcSqoQ4vHwfIjGc X-Received: by 2002:a05:6a00:1508:b0:64f:403c:1fe1 with SMTP id q8-20020a056a00150800b0064f403c1fe1mr8314481pfu.21.1685621572204; Thu, 01 Jun 2023 05:12:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685621572; cv=none; d=google.com; s=arc-20160816; b=RhCZMSeUqNYdjYoqtqOw0MkHJQZlhImC1e1w7IcRI5fvwqDuEedgu1GOukLSlJ8DE5 Mt/OmVq5oph6CgUkvtK4Fq1V8rlWG8tXg7K/I5PUNKVqZVJbh+AFsEvsK6fsCpzwI/vE 40WwlpdcBuAcUpFdKrb8p6Vb2zXNb0iX29wDZU2bA7QAoiprpUHzSMhyA+6TBxA9bVF1 Ad78BAdkrYZ2xvqdisScVwQrowxLHtpaFUA37yWqt8ecbUp8qAC3idLeoW8WQ1HO5S/7 Z038t8EZQOLWl4J4vAZKTLxOIppiOQYWGchi/hqE77L+AHKgusfF7VmL8IthLCkj5Ems UtVA== 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=IQntcjI7vDuW0F68zq155wS08PSrji0bEUDrJVrP5Xk=; b=unY5CWSmVrWlm+hT48miEKtIK2B2tI95vILUh6VrjB0KRU0nMXiskeiHuY+6jNyHiT eMzBiNcL3IUgqlrzWkMkw2ZTL+2dma4wrJ29iHY2jQyLHTqxdkuE+2Srsq65fdlp4P0o RyH3q/PS3xfhhY+vqz8rkgsI81GTrJpVeOnb/jd8/uA9dyDHEOudO31sM5o1owuj2zz+ dW79Y1y42cGfcrbgcVEhW5F/0srwztib99ENZk9gdsyCJvRpUEVQEWCxr9WGZ6r8goMy rhf3ay1hiNYu4s4T0Vl16XARAothqCtsmI9wkLVJoDIrMyQy44c86W0CMpvnU1vKKOf4 lVWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KrhuaH7L; 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 d16-20020aa797b0000000b0064f6c2c05bcsi5272903pfq.81.2023.06.01.05.12.39; Thu, 01 Jun 2023 05:12:52 -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=KrhuaH7L; 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 S233291AbjFAMKd (ORCPT + 99 others); Thu, 1 Jun 2023 08:10:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233266AbjFAMK3 (ORCPT ); Thu, 1 Jun 2023 08:10:29 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2CD32FC; Thu, 1 Jun 2023 05:10:28 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B6B4463AD1; Thu, 1 Jun 2023 12:10:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6299FC433A0; Thu, 1 Jun 2023 12:10:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685621427; bh=l8pAEKo80YCNxNTbkTmM13VW7qxFsKV/QhE7nwuJWrQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KrhuaH7LZ/RQ/+MSwWzLiNquVNkd0wGhx/fRtIGdvLCiXXpQqO2FqmGhcSWZXYD1C FIGbKvip4KGcAUy48afS7bWi3lsEKbIf1OedIGJKxtK441R00ObOih5QJnDOpWiFnf LaZzKgcngiLE0AKqyN7xALGJWRlEQ790MDueiPj6itTFSTpBnOE8Lx5nnKSqh/2lpb Nnq5CrlxdbfQoXLODJdV6mQOhNlUsZTwrmSCwrTh9vQIMrnS7lVAbhR76z+dopkW7j IVT7pjpIOUaS8kPmMYR9GplggmIeUn9NeMJiKDIxuyuzAWT9zdprm09VicLdOO8lkv 6T+yeXs8xDLbw== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel , linux-arm-kernel@lists.infradead.org, Russell King , Masahiro Yamada , Nathan Chancellor , Nick Desaulniers , Nicolas Schier Subject: [PATCH 3/7] modpost: detect section mismatch for R_ARM_{MOVW_ABS_NC,MOVT_ABS} Date: Thu, 1 Jun 2023 21:09:57 +0900 Message-Id: <20230601121001.1071533-4-masahiroy@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230601121001.1071533-1-masahiroy@kernel.org> References: <20230601121001.1071533-1-masahiroy@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, 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 For ARM defconfig (i.e. multi_v7_defconfig), modpost fails to detect some types of section mismatches. [test code] #include int __initdata foo; int get_foo(void) { return foo; } It is apparently a bad reference, but modpost does not report anything. The test code above produces the following relocations. Relocation section '.rel.text' at offset 0x200 contains 2 entries: Offset Info Type Sym.Value Sym. Name 00000000 0000062b R_ARM_MOVW_ABS_NC 00000000 .LANCHOR0 00000004 0000062c R_ARM_MOVT_ABS 00000000 .LANCHOR0 Currently, R_ARM_MOVW_ABS_NC and R_ARM_MOVT_ABS are just skipped. Add code to handle them. I checked arch/arm/kernel/module.c to learn how the offset is encoded in the instruction. The referenced symbol in relocation might be a local anchor. If is_valid_name() returns false, let's search for a better symbol name. Signed-off-by: Masahiro Yamada --- scripts/mod/modpost.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index e47bba7cfad2..5a5e802b160c 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -1078,7 +1078,7 @@ static inline int is_valid_name(struct elf_info *elf, Elf_Sym *sym) /** * Find symbol based on relocation record info. * In some cases the symbol supplied is a valid symbol so - * return refsym. If st_name != 0 we assume this is a valid symbol. + * return refsym. If is_valid_name() == true, we assume this is a valid symbol. * In other cases the symbol needs to be looked up in the symbol table * based on section and address. * **/ @@ -1091,7 +1091,7 @@ static Elf_Sym *find_tosym(struct elf_info *elf, Elf64_Sword addr, Elf64_Sword d; unsigned int relsym_secindex; - if (relsym->st_name != 0) + if (is_valid_name(elf, relsym)) return relsym; /* @@ -1297,6 +1297,13 @@ static int addend_arm_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r) inst = TO_NATIVE(*(uint32_t *)loc); r->r_addend = inst + sym->st_value; break; + case R_ARM_MOVW_ABS_NC: + case R_ARM_MOVT_ABS: + inst = TO_NATIVE(*(uint32_t *)loc); + offset = sign_extend32(((inst & 0xf0000) >> 4) | (inst & 0xfff), + 15); + r->r_addend = offset + sym->st_value; + break; case R_ARM_PC24: case R_ARM_CALL: case R_ARM_JUMP24: -- 2.39.2