Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3827099pxj; Tue, 15 Jun 2021 09:26:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwlcNLSn2iSht50MSDhlJrVto1o2ETN/Z+UWK3urUg6aJbUAmK6O8OAjZCEPgllp0TU5j9S X-Received: by 2002:aa7:c818:: with SMTP id a24mr334920edt.53.1623774406065; Tue, 15 Jun 2021 09:26:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623774406; cv=none; d=google.com; s=arc-20160816; b=FwInwWQiwYzz2V5uofhOHrTa0bLs+4odWIuzCG+YNlrvzxXOFAgYqbE56jwB7zN2b/ RmljcehwDHVMH0QEm3+GT4ByfcxfziBSb3semtJTgPlUqALMANcPPUKL3qyAfTwGM1qV +AygHtOaWTKyPZ3tbUNxBGOwJFYZ8hZVoUB0eXWaRtvhsPbGBwWQ1oznNJRI99zb+DEF eAzHKIyMLvXuJBz9gOyA1rcHgSKmjC/JeVKbyDPv7yqEF7lxp1yM5p04+yfwV8oWvPRI /3fnJP49tocmR4jg2lRG5+2aOf19UMYPaSk1Mo0ZrQ314Zi0KMbGtYJS9wMLjSKlLsvM HYAQ== 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=XCyOuqUUz46TeLLTKIMeEjprzWUHpKsiDycxn8OTVC4=; b=sBSUmrz/Pgh6x/bdWGfafVwjiYQkZiVdit9UMc1j9WtEeM19aG3xhSKyhjmjXLa8W9 kFa9ZJ81jUwXG8s3eu+QhyAANdXKxThWNMQsq0AcAj2suCVVvrLqnn0zv2gBxYHVruxX f1Bu+1Qz2QtxxZFXSZLxEmUaelUBU09OnJdY/vUMiv9Pg45pmg7S98ZGTzwNdqO9i1wO /ylOIILkWF9ph/oc6xurU2Lrot+THE3IQS554BhLu2n9OSlBkMxG0HDH98h6Iya0zkXK kGSArO0LheHPSlturNcJzn2uB07vm5VA/QsC9ZWGyZ8NBK2IeQPFykfGIKd796PFosvO kvcQ== 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 m6si15264362ejn.354.2021.06.15.09.26.23; Tue, 15 Jun 2021 09:26:46 -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 S230060AbhFOQZ0 (ORCPT + 99 others); Tue, 15 Jun 2021 12:25:26 -0400 Received: from mailgw01.mediatek.com ([210.61.82.183]:60368 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S229757AbhFOQZZ (ORCPT ); Tue, 15 Jun 2021 12:25:25 -0400 X-UUID: 4c58e13843204dc49794def372562b3f-20210616 X-UUID: 4c58e13843204dc49794def372562b3f-20210616 Received: from mtkcas06.mediatek.inc [(172.21.101.30)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 1553996560; Wed, 16 Jun 2021 00:23:16 +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; Wed, 16 Jun 2021 00:23:15 +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 00:23:15 +0800 From: Mark-PK Tsai To: CC: , , , , , , , , Subject: [PATCH v3] recordmcount: Correct st_shndx handling Date: Wed, 16 Jun 2021 00:23:13 +0800 Message-ID: <20210615162313.26081-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 | 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