Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp864711pxj; Wed, 16 Jun 2021 15:44:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzfJrjHj7lDdvonIHPu0HKHlEaG4QUXXI9J/nYfZRsf6Jt4HVQLUc9G4hGHQ8K5y9uc3DS3 X-Received: by 2002:a17:907:20f7:: with SMTP id rh23mr1851561ejb.414.1623883446507; Wed, 16 Jun 2021 15:44:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623883446; cv=none; d=google.com; s=arc-20160816; b=jnFecXYmbIwNRzE65SAJuCS7QLXlueqUtVTCzl5rShOh9Zj5eScH59EcmUZ5y+ARYI 2vCrxQl4Xaarv6lRuek0fWeKqoGCXIu8FL7VTknneITJbiPLAmxHyKxnZcaszPwBUOmN gXGK617o30uv0YiIl8S3be73g5uNSGi6OCIGrPeE2IJ4tkSRcfW1LDiPQEu/Voj54Crr I4gaL9pKcT1FarCXeqoU5+UWHKyMCgFqOMl+jAEv3UfZcwk8zRWIUAK2dcs7n7f5x7Pv jMVOjrnMZ0ojaUnnBNjO59iaz6EFXAuCGQilVLGPtrTlny3RajEfFb4CFX0iZ13sKFTQ xCwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=yblG4yN1mzROkB8SeXRkjCzkzM4pqWQLUOotmCWdfnI=; b=J16j0oxF+1cRlaAgbFjbpEfTo5N1DFLLWuy6+PMZOA54Kg/9BxaWLZrdoI9p6MaC6k yx4zFVrvWg8vIulXgJ4nZhB834TVmusFCDHn0H5/IlFXwRiuBDtsARCnpSQIx5ZgOxxZ bGAq7ZDCYn4tyeF9QABUNvKyb9h88XcPgpv4oQBS1mmGABnafeOFRRKzRs60pCzoIeXY sF4p1ouRi+eef2qysBIl8Wy4kybrD5qOEIkGkuYL1/VUaR82AkTFBL6psJVTPnyfzbPm oemxMsijEOPlL0NPYQMeaSVvpYgtUMn6PtL2lqfQSaR1KSJchRVmPqpnwp+1bGmRv7f5 WX1A== 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 ck28si3417832edb.315.2021.06.16.15.43.43; Wed, 16 Jun 2021 15:44:06 -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 S235737AbhFPPqd (ORCPT + 99 others); Wed, 16 Jun 2021 11:46:33 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:51716 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S235696AbhFPPnj (ORCPT ); Wed, 16 Jun 2021 11:43:39 -0400 X-UUID: 040684fa75ff4f7b84c23e77a91e5f21-20210616 X-UUID: 040684fa75ff4f7b84c23e77a91e5f21-20210616 Received: from mtkmbs10n2.mediatek.inc [(172.21.101.183)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1784630972; Wed, 16 Jun 2021 23:41:30 +0800 Received: from mtkcas11.mediatek.inc (172.21.101.40) by mtkmbs08n1.mediatek.inc (172.21.101.55) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 16 Jun 2021 23:41:28 +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; Wed, 16 Jun 2021 23:41:28 +0800 From: Mark-PK Tsai To: CC: , , , , , , , , Subject: [PATCH v4] recordmcount: Correct st_shndx handling Date: Wed, 16 Jun 2021 23:41:26 +0800 Message-ID: <20210616154126.2794-1-mark-pk.tsai@mediatek.com> X-Mailer: git-send-email 2.18.0 MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Peter Zijlstra One should only use st_shndx when >SHN_UNDEF and = SHN_LORESERVE && st_shndx != SHN_XINDEX. Reported-by: Mark-PK Tsai Signed-off-by: Peter Zijlstra (Intel) Tested-by: Mark-PK Tsai [handle endianness of sym->st_shndx] Signed-off-by: Mark-PK Tsai --- scripts/recordmcount.h | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/scripts/recordmcount.h b/scripts/recordmcount.h index f9b19524da11..1e9baa5c4fc6 100644 --- a/scripts/recordmcount.h +++ b/scripts/recordmcount.h @@ -192,15 +192,20 @@ static unsigned int get_symindex(Elf_Sym const *sym, Elf32_Word const *symtab, Elf32_Word const *symtab_shndx) { unsigned long offset; + unsigned short shndx = w2(sym->st_shndx); int index; - if (sym->st_shndx != SHN_XINDEX) - return w2(sym->st_shndx); + if (shndx > SHN_UNDEF && shndx < SHN_LORESERVE) + return shndx; - offset = (unsigned long)sym - (unsigned long)symtab; - index = offset / sizeof(*sym); + if (shndx == SHN_XINDEX) { + offset = (unsigned long)sym - (unsigned long)symtab; + index = offset / sizeof(*sym); - return w(symtab_shndx[index]); + return w(symtab_shndx[index]); + } + + return 0; } static unsigned int get_shnum(Elf_Ehdr const *ehdr, Elf_Shdr const *shdr0) -- 2.18.0