Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3057811pxj; Mon, 7 Jun 2021 00:45:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwa7H3gKzajy077m6EHfVzCk7TNgXnV7e6yzKEgfT630kdYAp/BnNuKT4FQahFf29/KJ/YZ X-Received: by 2002:a17:906:b296:: with SMTP id q22mr6821373ejz.397.1623051912267; Mon, 07 Jun 2021 00:45:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623051912; cv=none; d=google.com; s=arc-20160816; b=IABwNap0qF8iD7oaOnf2MJ0BUKdtwIEnk6cLRh6/mB5j+/8WSKgrbTGbSDh+LVIq8R tiBqBEj/kpfcTgcW+3lrzXbCSIBzWhNbdumin7/jV/LACoh+Yjx5wv/7tJw+UEEp1z9h s5QozLJwzX9CV15vtzCYpSraairGZUYzLM5RVjfZbmveYhc5NDr2wHxdgxZdfDcTfohv ZNBBeF31Jq9+6KsPDZNc1QUbVXgT323YLoguB7FOMSJSucUJhR4NV5voKKQBKHas6PcX S8hCoJoEwzMM6tf7LFKRy6rpFikmhUZbDmxYcbIbatyYr3lkUDDpyhQCk/q8zw55ccKc tbLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=8nTsd17B5owimvOVWI6NN2kN+krNNdgE+kZKVkuAqt4=; b=dHd4RkyT/3P+PO+w0k7xqmrUiGQ2J9JMFfQ73JA6KWcO+8zNrxiz4oP71Nne0UznFw brM32M+l2jCnPtUdq2xh6apyuf6fcvQc8xEM6q7t3JDeoEd0OLEyqKeqRjsmQduKA3Tg LOJnkaRCo3PaKmf/+a4K3MtRyPrVi/RSPUrFg0A68X7Hz0zCrD+wvVtqB5h7eQChQ9fV f03X8AjSQ82ekMyVWtLZ/imQrbC7vghVm3k0JNCzYBTyn9OCUojqJXTGEWqvtuXM3yqw 3QvDP6+4v1U1bJwOq56dgV1ylOUtEmlvonFuY8Ci9PXusxXHe7fwrdLirnIfDHkYUACh ByeQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b14si11821094ejq.311.2021.06.07.00.44.50; Mon, 07 Jun 2021 00:45:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230139AbhFGHox (ORCPT + 99 others); Mon, 7 Jun 2021 03:44:53 -0400 Received: from mailgw01.mediatek.com ([210.61.82.183]:33633 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S229545AbhFGHow (ORCPT ); Mon, 7 Jun 2021 03:44:52 -0400 X-UUID: 630e51a5b9cc4fc6bf648eac3de81e62-20210607 X-UUID: 630e51a5b9cc4fc6bf648eac3de81e62-20210607 Received: from mtkmbs10n2.mediatek.inc [(172.21.101.183)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 305752430; Mon, 07 Jun 2021 15:42:59 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs08n2.mediatek.inc (172.21.101.56) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 7 Jun 2021 15:42:58 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Mon, 7 Jun 2021 15:42:58 +0800 From: Mark-PK Tsai To: CC: , , , , , , , , Subject: Re: [PATCH] recordmcount: avoid using ABS symbol as reference Date: Mon, 7 Jun 2021 15:42:58 +0800 Message-ID: <20210607074258.32322-1-mark-pk.tsai@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > On Mon, 7 Jun 2021 at 08:59, Mark-PK Tsai wrote: > > > > > > On Mon, 7 Jun 2021 at 04:42, Mark-PK Tsai wrote: > > > > > > > > Avoid using ABS symbol, which won't be relocate, as reference. > > > > > > > > On arm64 platform, if there's shndx equals SHN_ABS(0xfff1). > > > > > > > > Section Headers: > > > > [Nr] Name Type Address Off Size ES Flg Lk Inf Al > > > > [65521] .text.n_tty_receive_buf PROGBITS 0000000000000000 3cdab520 000054 00 AX 0 0 4 > > > > [65522] .rela.text.n_tty_receive_buf RELA 0000000000000000 3cdab578 000030 18 I 152076 65521 8 > > > > > > > > > > A RELA section's r_info field points to the section to which it > > > applies. This is why in the example above section #65522 points to > > > section #65521. This has nothing to do with the numerical value of > > > SHN_ABS. > > > > If the r_info of RELA section is 65521(0xfff1), Oh sorry, I mean sh_info here. > > find_secsym_ndx() will use it to find the base symbol. > > > > But what does that have to do with the sh_info field of the RELA > section's Elf_Shdr struct? IOW, what is the relevance of section > #65521 here? > So what I mean is the problem occur if the sh_info of a RELA section is #65521. > > And in the symbol search loop in find_secsym_ndx(), get_symindex will > > return 0xfff1 if the symbol is in ABS section. > > > > In this case, find_secsym_ndx() will return a absolute symbol as > > base, which won't be relocate, if an ABS symbol is found before the > > real symbol in section 65521. > > > > I see your point here. > > > > > > > > find_secsym_ndx, which use r_info in rela section to find the reference sh_info. > > > > symbol, may take ABS symbol as base. > > > > > > > > Symbol table '.symtab' contains 453285 entries: > > > > Num: Value Size Type Bind Vis Ndx Name > > > > 6: 0000000000000002 0 NOTYPE LOCAL DEFAULT ABS section_count > > > > > > > > Which cause an invalid address in __mcount_loc. > > > > > > > > > > Could you give a better account of the error you are trying to address? > > > > > > Also, arm64 no longer defines a section_count symbol (since v5.11), so > > > please make sure that the diagnostics of the issue you are addressing > > > are accurate for mainline. > > > > > > > My kernel version is 5.4.61. > > But as I explained, I suppose mainline also have this issue. > > > > Mainline is what we work on. So please base your changes (and your > commit log) on mainline. > I understand it. But the platform I can reproduce the problem is only support to 5.4 LTS now. And port it to the latest mainline kernel have much more work to do, can I just keep this commit log? Or just remove the example I posted in the commit messsage? > > > > > > > > Signed-off-by: Mark-PK Tsai > > > > --- > > > > scripts/recordmcount.h | 4 ++++ > > > > 1 file changed, 4 insertions(+) > > > > > > > > diff --git a/scripts/recordmcount.h b/scripts/recordmcount.h > > > > index f9b19524da11..9b69167fb7ff 100644 > > > > --- a/scripts/recordmcount.h > > > > +++ b/scripts/recordmcount.h > > > > @@ -526,6 +526,10 @@ static int find_secsym_ndx(unsigned const txtndx, > > > > for (symp = sym0, t = nsym; t; --t, ++symp) { > > > > unsigned int const st_bind = ELF_ST_BIND(symp->st_info); > > > > > > > > + /* avoid absolute symbols */ > > > > + if (symp->st_shndx == SHN_ABS) > > > > + continue; > > > > + > > > > if (txtndx == get_symindex(symp, symtab, symtab_shndx) > > > > /* avoid STB_WEAK */ > > > > && (STB_LOCAL == st_bind || STB_GLOBAL == st_bind)) {