Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp3949155rwd; Tue, 23 May 2023 00:26:07 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ69i6J4gl8CDgLM5gI/q6qEoIauZ0KLTLFRdV0rIefM7pp8FCDYaEqdCa8rn3tq38nLwybb X-Received: by 2002:a05:6a00:228d:b0:64d:1c59:6767 with SMTP id f13-20020a056a00228d00b0064d1c596767mr20350498pfe.24.1684826767313; Tue, 23 May 2023 00:26:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684826767; cv=none; d=google.com; s=arc-20160816; b=pXM/sNIXiWriMjmSbk319uD+az6bKqgNmoDl/epDoxqEEW2Q3F96UojZ/H5uZxp8gO sEm0/V6dK3awEvTZ6lcKQSK+QvhSzjfUTCB9XoZuhstnbjR9HsQkBG/z1mJhIfRQNgtv VEm6bgL6tD8frY00zudTvwN4Z9RzpszCX4BQOTNIN4j19mNzQBUZOACaYv37GZM14NUz rXmLSJjXUQwFvamk5pwez6nKDogq1jI9yHj8OS0yzQmS4KOtiGFqJFjBrtCJLZSzmJYp ECmP2oOInsgb9UngSdBsiT4iG0TWnnhss+c6T3vYRv6uzH/TTyEadbdz4xtB69D08nOR fZow== 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=+nzMzF0YFhQ3nM8ptyJLZrUb92OXMgx60bcE1OD8NoE=; b=sp1yDaeM/qNBEAU79085kVcmT8E/IXwUdZvYvPHxqVAlSjltLBHQSCcaemiMI/MuBP 8gqiAcEGRELF4DqAbNCZ5RkAnpzIBnfmMhkGVfl7L1maD/hM3WvKJkPX/XkssTM5W0ny BBAFypGcOU3cFvA3HmL0VFGuyptJysHcDXyLQ+4xLHBui9D5mb/xMVfoCQMyolpeH737 WU9Oy7d+V83DVL4gF+RTBVnv3nDouU7dtGKeVKYSPqNd6WzqsxuC1hnrSSlkCH4Elg5d kWwzRS55+N3XTbYG62Dtxkyg3GHl1RS2mlT2V9anJe4Lrf5kTAavnYd+/odikb/A17zM 4eng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hUsQn6aL; 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 23-20020a621917000000b0064d3a44770esi6009888pfz.84.2023.05.23.00.25.54; Tue, 23 May 2023 00:26:07 -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=hUsQn6aL; 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 S235351AbjEWHNZ (ORCPT + 99 others); Tue, 23 May 2023 03:13:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235349AbjEWHNX (ORCPT ); Tue, 23 May 2023 03:13:23 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D48211F; Tue, 23 May 2023 00:13:22 -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 7785062FDA; Tue, 23 May 2023 07:13:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D36F3C4339C; Tue, 23 May 2023 07:13:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1684826000; bh=f5z4FLxDPgETOy7aL9gv81CZdcHctDIyTnnjcI7c4f0=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=hUsQn6aLonY9QrGoN/zY5Fy2gZNRNBSW17CCHjQJRjGNfe1+UtWCrahIqFnZNwuDt P1XHTx3D6qacQEP3cu7oPLlUoeTBYY3PVpdmeUER2QxvELZnHYkWE1lU7pcU4EUFIA 2PHDwNEHGL+nP3lfvl5ltufWbZUawa3YAlogmd+e5+/2BUUD/sfnJ11IlyiVduINSj tC8TR1VplD9R73elsuEmug4gjeusw4oP48jMH3pcZib8nsUKhAF7CAfIrny5Ylbsgv nxb50lKNX6nCy4D3xxaRgE5IIeanrg8ss/1E/6F2ic6zSxEt2YkmryMjx1jAlGhJIE eb8AJtbFuM9iQ== Received: by mail-lf1-f44.google.com with SMTP id 2adb3069b0e04-4f3b9e54338so3266667e87.0; Tue, 23 May 2023 00:13:20 -0700 (PDT) X-Gm-Message-State: AC+VfDyKOlrH/9A4QgWUIUIWDdKlKx/3t7+qSfkP37xcol1p86pVT2hH k/OHH6gmfon1LrXNw0jBgI0X/qn6j8+TREvtSBU= X-Received: by 2002:a2e:9097:0:b0:2a8:d1cd:a04 with SMTP id l23-20020a2e9097000000b002a8d1cd0a04mr4353123ljg.48.1684825998766; Tue, 23 May 2023 00:13:18 -0700 (PDT) MIME-Version: 1.0 References: <20230521160426.1881124-1-masahiroy@kernel.org> <20230521160426.1881124-3-masahiroy@kernel.org> In-Reply-To: From: Ard Biesheuvel Date: Tue, 23 May 2023 09:13:07 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v6 02/20] modpost: fix section mismatch message for R_ARM_ABS32 To: Masahiro Yamada Cc: Nick Desaulniers , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, Nathan Chancellor , Nicolas Schier , Linux ARM , Fangrui Song Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 On Tue, 23 May 2023 at 07:08, Masahiro Yamada wrote: > > On Tue, May 23, 2023 at 6:36=E2=80=AFAM Ard Biesheuvel = wrote: > > > > On Mon, 22 May 2023 at 19:56, Nick Desaulniers wrote: > > > > > > + linux-arm-kernel and some folks who might know another idea. > > > > > > On Sun, May 21, 2023 at 9:05=E2=80=AFAM Masahiro Yamada wrote: > > > > > > > > addend_arm_rel() processes R_ARM_ABS32 in a wrong way. > > > > > > > > Here, simple test code. > > > > > > > > [test code 1] > > > > > > > > #include > > > > > > > > int __initdata foo; > > > > int get_foo(int x) { return foo; } > > > > > > > > If you compile it with ARM versatile_defconfig, modpost will show t= he > > > > symbol name, (unknown). > > > > > > > > WARNING: modpost: vmlinux.o: section mismatch in reference: get_f= oo (section: .text) -> (unknown) (section: .init.data) > > > > > > > > If you compile it for other architectures, modpost will show the co= rrect > > > > symbol name. > > > > > > > > WARNING: modpost: vmlinux.o: section mismatch in reference: get_f= oo (section: .text) -> foo (section: .init.data) > > > > > > > > For R_ARM_ABS32, addend_arm_rel() sets r->r_addend to a wrong value= . > > > > > > > > I just mimicked the code in arch/arm/kernel/module.c. > > > > > > > > However, there is more difficulty for ARM. > > > > > > > > Here, test code. > > > > > > > > [test code 2] > > > > > > > > #include > > > > > > > > int __initdata foo; > > > > int get_foo(int x) { return foo; } > > > > > > > > int __initdata bar; > > > > int get_bar(int x) { return bar; } > > > > > > > > With this commit applied, modpost will show the following messages > > > > for ARM versatile_defconfig: > > > > > > > > WARNING: modpost: vmlinux.o: section mismatch in reference: get_f= oo (section: .text) -> foo (section: .init.data) > > > > WARNING: modpost: vmlinux.o: section mismatch in reference: get_b= ar (section: .text) -> foo (section: .init.data) > > > > > > > > The reference from 'get_bar' to 'foo' seems wrong. > > > > > > > > I have no solution for this because it is true in assembly level. > > > > > > > > In the following output, relocation at 0x1c is no longer associated > > > > with 'bar'. The two relocation entries point to the same symbol, an= d > > > > the offset to 'bar' is encoded in the instruction 'r0, [r3, #4]'. > > > > > > > > These are section relative relocations - this is unusual but not > > incorrect. Normally, you only see this if the symbols in question have > > static linkage. > > > I noticed this usually happens in reference to 'static', > but on ARM, it happens even without 'static'. > See the [test code 1]. > > > > It does mean that the symbol is not preemptible, which is what makes > > this somewhat surprising. > > > > Generally, you cannot resolve a relocation to a symbol without taking > > the addend into account, so looking up the address of .init.data in > > the symbol table is not quite the right approach here. If anything, > > the symbol should be reported as [.init.data+0x4] in the second case. > > > In the old days, section mismatch warnings showed > only the referenced section name. > > Since [1], modpost started to show the referenced symbol name too. > Modpost did it in the past 17 years. > It sometimes shows a wrong name, but works in most architectures. > Unfortunately, I noticed ARM was an unfortunate case. > > Do you suggest removing it entirely? > No, not at all. But resolving the symbol should take the addend into account, and this is essentially what you are doing in your patch. The point is really that the relocation in question does not refer to the symbol - it refers to a section+offset that we /think/ corresponds with a certain symbol. But for example, if the symbol is weak and another definition exists, the section based relocation will refer to one version, and a relocation that references the symbol name will refer to the other version. > > If (elf->symtab_start + ELF_R_SYM(r.r_info)) has a sensible > symbol name, print it. Otherwise, print only the section name. > Is this what you mean? > > That means, we will lose the symbol name info of 'static' > (and even global symbols on ARM) > > > That is what I wrote in the commit description. > > "I am keeping the current logic because it is useful in many architecture= s, > but the symbol name is not always correct depending on the optimization > of the relocation. I left some comments in find_tosym()." > Fair enough.