Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3411202pxj; Mon, 14 Jun 2021 23:48:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzdGrULNUh/QeMhZvlG+Q/HR2I7JlnbbnuTKYO9eqgUXC/68xGoH/NdwmKgGwd8HiP8wiSM X-Received: by 2002:a02:8807:: with SMTP id r7mr20604110jai.12.1623739702026; Mon, 14 Jun 2021 23:48:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623739702; cv=none; d=google.com; s=arc-20160816; b=Q8xzWyVeAwAclkGxLljldJU1Xe+c4uxgoBPBxlLkZLrhyl5UR9HORJGWRD5Ad07IOT TN3tKQ5MuMlnwoJ+WKx/E3G8BG6A8QCx/8pVp/vx9NuIAIyUZpEQyGq8gjpOLb+z2hp4 l++bVCq2fvHC5IHKZ/TwC2TihXIazJEqBavKYfo+MY2yIMbg+99vW/zE6sdl6wQXvK1p t8UAsj1pDAWVxHA3I3/9vPopxXphWuNryHStdH9+edBHr+eRD49Q9Vr4fb9D8uScnS8Y u7pH0LyaXKgPt3ALSnPFdXOmCN0vEbzFz4h1+8KWa6EyuKhPYJSl+r9o48eRWTbPD8IR 30Bw== 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=5h9zWTnGdffF8MZKPYVX2RS4bPAdS9JE8sXOk/bwAlc=; b=GJG5+aSD76ByObsGaT6Eux/vgz7rsldCtwlc1wn1swFlHOy9zsEGgiHXNqmFcjpovW ryeRTpt99hoDRhd9nh+9aJ95HnDPWTp5iZqcBv1HkAQuyTOppqLTEQrRmcmtZTmHAikS J9CRIcj2mNLA0g1w+yKQ3/SkQFyE7q5llJMlu/9u7fgrGLqLvsEcmyjEssmZO2nk0N6s j29q4CTRqI/ClmCmXr6+RJGcpDH41I6Pkohwa5BUjvfY9Xuf4+7Dibdr7bESlILl3qgn xvvAkqnKeWxV0hVKVKf0xg9KC6kypazn+feSuKZp1hKgLU8108u8Fha2lOkAnWnOzPZe AXaA== 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 p16si10716450jan.14.2021.06.14.23.48.09; Mon, 14 Jun 2021 23:48:22 -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 S229992AbhFOGtl (ORCPT + 99 others); Tue, 15 Jun 2021 02:49:41 -0400 Received: from mailgw01.mediatek.com ([210.61.82.183]:34620 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S229494AbhFOGti (ORCPT ); Tue, 15 Jun 2021 02:49:38 -0400 X-UUID: 51aefbf2839041f3823ad97494ef4af6-20210615 X-UUID: 51aefbf2839041f3823ad97494ef4af6-20210615 Received: from mtkexhb01.mediatek.inc [(172.21.101.102)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 1787216130; Tue, 15 Jun 2021 14:47:31 +0800 Received: from mtkcas11.mediatek.inc (172.21.101.40) by mtkmbs08n2.mediatek.inc (172.21.101.56) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 15 Jun 2021 14:47:23 +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; Tue, 15 Jun 2021 14:47:23 +0800 From: Mark-PK Tsai To: CC: Matthias Brugger , Matt Helsley , Sami Tolvanen , Mark-PK Tsai , , , , , Subject: [PATCH v2] recordmcount: Correct st_shndx handling Date: Tue, 15 Jun 2021 14:47:20 +0800 Message-ID: <20210615064720.21950-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 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 Signed-off-by: Mark-PK Tsai --- scripts/recordmcount.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/scripts/recordmcount.h b/scripts/recordmcount.h index f9b19524da11..ef9c3425f86b 100644 --- a/scripts/recordmcount.h +++ b/scripts/recordmcount.h @@ -194,13 +194,18 @@ static unsigned int get_symindex(Elf_Sym const *sym, Elf32_Word const *symtab, unsigned long offset; int index; - if (sym->st_shndx != SHN_XINDEX) + if (w2(sym->st_shndx) > SHN_UNDEF && + w2(sym->st_shndx) < SHN_LORESERVE) return w2(sym->st_shndx); - offset = (unsigned long)sym - (unsigned long)symtab; - index = offset / sizeof(*sym); + if (w2(sym->st_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