Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp4561894rdh; Wed, 29 Nov 2023 05:08:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IF9kfQC+sgR2ECdlL/kDB3jtDpFworXPAbNkOLctgmmPSnfCZXr6ESrfW7SIMLcjDE/FTk6 X-Received: by 2002:a05:6e02:1245:b0:35c:8572:ed79 with SMTP id j5-20020a056e02124500b0035c8572ed79mr14695917ilq.25.1701263287513; Wed, 29 Nov 2023 05:08:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701263287; cv=none; d=google.com; s=arc-20160816; b=uKwuD/n7/N733Ge1tK19jMMsl9c/Idbb0CoBzWlsaH5QPViDw25NGaBm6A8x/jezCC lBXvW8IyTxAPAvocFhgJpL10rgrrQzwBgrgxVKPMPkdqjMxqm2xhWlxsuhQQGFmfMr30 lxrbSdCgyvcMVxu+xv16zQXguNOEHX+UI9zbhpY+0hQHdyHsvi+pH6Wnx+ryBdag7iON HlOgtOiGWo8eIdRU9xnhjbjTXK8N0gOY9pen6T0Gp93Sz3jVWgSUa6uP5c9wt1EA/2Y/ lktwL75HcseZc5EGeCBQuerRRCssCLQLaO1wI6QqN4Cj2YjMaurZEmtxWVPd31cqYnK5 J7LA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=JgzmvGaC5EOxSK/yymeYkBWWyqGczvk1HmLhIgLSdlE=; fh=3JsZntdbC0M+r2W9mBgl7JRPxEEj/7A1ld74TBnFi8o=; b=ZHXXGszwCixFAApFGZt6hiQzUrta+2l1JVgVz/ugo1ChU9Ntk7BVRlMwmPr//Mm8OC SSjjA2oC8HkqoeAj/i2xUToDj1GPbaDjWYxkAo2sZsazj9nnk0LXHLinLQbgR5pxbm3c Y54PsjtIzxq6M3dSZl4wTQQ4eRM8ISG/DPE77idjqC6G3g/Z+YU5o96JBequmv0sqW// 9rrCbn04fPb5n3YswKt2S2TXxE/QaS2aS+k58KvVQ7CWUBOQnHZcCnOzkpfWpIPREFla b76mo6/SWS9qwdpTTB7ljicMB+d5kk5luStZDXqtIzrVuZ3AJX0KF9qLZWjEKLBfG+IB /gkg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id a22-20020a63d216000000b005bd9fc46b76si14119937pgg.302.2023.11.29.05.08.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 05:08:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 6CC57804434A; Wed, 29 Nov 2023 05:08:04 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233836AbjK2NHL (ORCPT + 99 others); Wed, 29 Nov 2023 08:07:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233384AbjK2NHD (ORCPT ); Wed, 29 Nov 2023 08:07:03 -0500 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id F38C610DA for ; Wed, 29 Nov 2023 05:07:08 -0800 (PST) Received: from loongson.cn (unknown [113.200.148.30]) by gateway (Coremail) with SMTP id _____8Cxrut7N2dlcqc9AA--.54171S3; Wed, 29 Nov 2023 21:07:07 +0800 (CST) Received: from linux.localdomain (unknown [113.200.148.30]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Axzy91N2dlVtNPAA--.45987S8; Wed, 29 Nov 2023 21:07:07 +0800 (CST) From: Tiezhu Yang To: Josh Poimboeuf , Peter Zijlstra , Huacai Chen Cc: loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v5 6/8] objtool: Check local label in add_dead_ends() Date: Wed, 29 Nov 2023 21:06:59 +0800 Message-ID: <20231129130701.27744-7-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231129130701.27744-1-yangtiezhu@loongson.cn> References: <20231129130701.27744-1-yangtiezhu@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8Axzy91N2dlVtNPAA--.45987S8 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBj93XoWxWryUXry8JF1rCw47Gr1fKrX_yoWrXry8pF 43C343Kr42vr13Zw47tFyxWasxWws7WFnrJ3y7GF1rAry2van0gw12yw15Zas8Gr12vw45 XayYgay3uryDAwcCm3ZEXasCq-sJn29KB7ZKAUJUUUUr529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUU9Fb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r126r13M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVCY1x0267AK xVW8Jr0_Cr1UM2kKe7AKxVWUXVWUAwAS0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07 AIYIkI8VC2zVCFFI0UMc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWU tVWrXwAv7VC2z280aVAFwI0_Gr0_Cr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7V AKI48JMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMxCIbckI1I0E14v2 6r1Y6r17MI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17 CEb7AF67AKxVWUAVWUtwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26ryj6F1UMIIF 0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIx AIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2 KfnxnUUI43ZEXa7IU8XyCJUUUUU== X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Wed, 29 Nov 2023 05:08:04 -0800 (PST) When update the latest upstream gcc and binutils which enables linker relaxation by default, it generates more objtool warnings on LoongArch, like this: init/main.o: warning: objtool: unexpected relocation symbol type in .rela.discard.unreachable We can see that the reloc sym name is local label instead of section in relocation section '.rela.discard.unreachable', in this case, the reloc sym type is STT_NOTYPE instead of STT_SECTION. Let us check it to not return -1, then use reloc->sym->offset instead of reloc addend which is 0 to find the corresponding instruction. At the same time, replace the variable "addend" with "offset" to reflect the reality. Here are some detailed info: [fedora@linux 6.7.test]$ gcc --version gcc (GCC) 14.0.0 20231127 (experimental) [fedora@linux 6.7.test]$ as --version GNU assembler (GNU Binutils) 2.41.50.20231127 [fedora@linux 6.7.test]$ readelf -r init/main.o | grep -A 2 "rela.discard.unreachable" Relocation section '.rela.discard.unreachable' at offset 0x4b58 contains 1 entry: Offset Info Type Sym. Value Sym. Name + Addend 000000000000 00de00000063 R_LARCH_32_PCREL 0000000000000220 .L467^B1 + 0 Signed-off-by: Tiezhu Yang --- tools/objtool/check.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 29b3c5495901..395fce41fb81 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -611,7 +611,7 @@ static int add_dead_ends(struct objtool_file *file) struct section *rsec; struct reloc *reloc; struct instruction *insn; - s64 addend; + unsigned long offset; /* * Check for manually annotated dead ends. @@ -622,26 +622,28 @@ static int add_dead_ends(struct objtool_file *file) for_each_reloc(rsec, reloc) { - if (reloc->sym->type != STT_SECTION) { + if (reloc->sym->type == STT_SECTION) { + offset = reloc_addend(reloc); + } else if (reloc->sym->local_label) { + offset = reloc->sym->offset; + } else { WARN("unexpected relocation symbol type in %s", rsec->name); return -1; } - addend = reloc_addend(reloc); - - insn = find_insn(file, reloc->sym->sec, addend); + insn = find_insn(file, reloc->sym->sec, offset); if (insn) insn = prev_insn_same_sec(file, insn); - else if (addend == reloc->sym->sec->sh.sh_size) { + else if (offset == reloc->sym->sec->sh.sh_size) { insn = find_last_insn(file, reloc->sym->sec); if (!insn) { WARN("can't find unreachable insn at %s+0x%" PRIx64, - reloc->sym->sec->name, addend); + reloc->sym->sec->name, offset); return -1; } } else { WARN("can't find unreachable insn at %s+0x%" PRIx64, - reloc->sym->sec->name, addend); + reloc->sym->sec->name, offset); return -1; } @@ -661,26 +663,28 @@ static int add_dead_ends(struct objtool_file *file) for_each_reloc(rsec, reloc) { - if (reloc->sym->type != STT_SECTION) { + if (reloc->sym->type == STT_SECTION) { + offset = reloc_addend(reloc); + } else if (reloc->sym->local_label) { + offset = reloc->sym->offset; + } else { WARN("unexpected relocation symbol type in %s", rsec->name); return -1; } - addend = reloc_addend(reloc); - - insn = find_insn(file, reloc->sym->sec, addend); + insn = find_insn(file, reloc->sym->sec, offset); if (insn) insn = prev_insn_same_sec(file, insn); - else if (addend == reloc->sym->sec->sh.sh_size) { + else if (offset == reloc->sym->sec->sh.sh_size) { insn = find_last_insn(file, reloc->sym->sec); if (!insn) { WARN("can't find reachable insn at %s+0x%" PRIx64, - reloc->sym->sec->name, addend); + reloc->sym->sec->name, offset); return -1; } } else { WARN("can't find reachable insn at %s+0x%" PRIx64, - reloc->sym->sec->name, addend); + reloc->sym->sec->name, offset); return -1; } -- 2.42.0