Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3036889pxj; Mon, 7 Jun 2021 00:01:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwbYGN30xQmWzHEYP7vPk/TW9zUVwOixyvYZ4iKqbNgk89UyyLRB+R8K4+qB/WaR1DZIl1A X-Received: by 2002:a17:907:270c:: with SMTP id w12mr16860490ejk.175.1623049287123; Mon, 07 Jun 2021 00:01:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623049287; cv=none; d=google.com; s=arc-20160816; b=SMozl2/Annj4ceQLvpHNL6oEnFZ5oPaDPBveNAZ2aNfG+o6f8xfahAkzA937MkvxKo FvXuA0zG5Zd7jTL1Tu9vzeD+FxRpjVEJs9MdloPOPFF0g41EbseU+btxPV83KCn04/9c 9fp4r2FBJ1xDga4HJHtV8zilZKXLeYY3pHw4xNWjpvWqj45/1H9zk/CToWZpFC7f0b1q pKh7C233Wafj1hHHSluU77m98bH5NEXQZ0INv5YoFNz0JIktiQ7mz+4YG8h+JOvKDTEg FSbJXHHovUh3TawHdm5xyNYPNK3C+WoL8iPGsFdEfdIh9HLgRYYNWnuUJlY9wYvXkDPI sBRg== 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=/XZ7LL/O844uMJF/zkV0sQ5aPqVsTlBxXxwPAKa3xjI=; b=LCSbL1uHyyh+uGDP/RvUwrno0tq3GJYxGMmbjWADBPFAvUGlpYGQ6gkYhA9lI1bIa+ Uc8YQy4MnN/ign8JSMGCS+gy6AohIsCSbGmLG/PmptWfx65/OSOpEBGyDYcxMQonBld8 Kv8ZpF+jXjRq2tLCeYWJmOS3oJVoPRffVtBPHDJjIdUJqam2STfHplnxWU58ZIYZambk A5E4/qcSwxaHffgpVcsCTfXYHn2nTj25h2GXMAp7p45+FXPdctLesn8cvuw3UYk7lMv6 ZjKVXR+ESo+f6q/WOuwT2h0o4hhmv826StMG0FLwoqY8Nwalvb6fdQcjrLpEgB5dOs1X jUzw== 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 g3si12569202edv.12.2021.06.07.00.01.04; Mon, 07 Jun 2021 00:01:27 -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 S230242AbhFGHBo (ORCPT + 99 others); Mon, 7 Jun 2021 03:01:44 -0400 Received: from mailgw01.mediatek.com ([210.61.82.183]:54761 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S229436AbhFGHBo (ORCPT ); Mon, 7 Jun 2021 03:01:44 -0400 X-UUID: e2d4cd33c0544e2c9a862bef06d87a8e-20210607 X-UUID: e2d4cd33c0544e2c9a862bef06d87a8e-20210607 Received: from mtkcas11.mediatek.inc [(172.21.101.40)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 1830994713; Mon, 07 Jun 2021 14:59:49 +0800 Received: from mtkcas11.mediatek.inc (172.21.101.40) by mtkmbs05n2.mediatek.inc (172.21.101.140) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 7 Jun 2021 14:59:48 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas11.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Mon, 7 Jun 2021 14:59:47 +0800 From: Mark-PK Tsai To: CC: , , , , , , , , Subject: Re: [PATCH] recordmcount: avoid using ABS symbol as reference Date: Mon, 7 Jun 2021 14:59:48 +0800 Message-ID: <20210607065948.31632-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 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), find_secsym_ndx() will use it to find the base symbol. 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. > > > find_secsym_ndx, which use r_info in rela section to find the reference > > 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. > > > 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)) {