Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1072229rda; Mon, 23 Oct 2023 01:12:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHsUSitRcnAKboZdUXNYzIChOawMzIEw2FksCbYgheShfjjQ7CTf1ix1bSEoYBsERuTv49x X-Received: by 2002:a05:6830:7181:b0:6c0:ef3c:5ab4 with SMTP id el1-20020a056830718100b006c0ef3c5ab4mr10753479otb.0.1698048752964; Mon, 23 Oct 2023 01:12:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698048752; cv=none; d=google.com; s=arc-20160816; b=chLFKslDi/3TEksyRxbmFP0zclVSL+KKbbYJHwurH5Mrs+Bk/cb/SfEU/moIEDo3vd 2y7l1glE+VTHwEnIeGmA1IG4J7TjbHN+XI3lv8V6/W6weFiuX+Ai5sH5aCPsstIfIso4 vOP1OcCywi2meGMo2hbTduotNlgYWQe/H6ZTO+XemfRuuECmR74jGdSr2zC8Rt8rEXG9 5jOznjXyHXjeVI7CRIgaEbjNhQWRXC9IfM6f7Xuuh4Wm31nGN52Ge2IX4xGcfMtESQmx bn0uqqVobu12Nl+404Re0pDhheYd/IKE/6Fw3KfWoTMLe8WrAvW02jzEutxUCQfjHtBu WOYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=9cgiXN3WP3czHR85jfE67ypjC/4lXnMt2dWKvXYOR7I=; fh=3j/20F2LKXrdRGvNzW5us/B/H+CmIg1AkSVATQRCgiM=; b=nv0rtkki1Nbf1F7TjczKrG8B8xE2CZ05Il+6YTPdyoVn/fe4Atj6m/+TtJHzGJJYwC pwjcPSVwKzd8GlkLa2EfC5ICzL0hp36w7qUMBDHYzknQo1FBqe58jWRm85rmS6niySlq 7kKh1j8msp3kEV4uoSm77rtcuLsGYYAf0yuRHO6ENK3RH6bw16Wjyk0mfdrF+0aip1fc FjFRqx9yOm0YSqD4c0jJmy/LqHRH3q9vLs0GXhNs+899byiC+GqkE2T3OEr8gszAJXpJ yGlD6AbTxfl9v2ObxBRnn3vxnOoqUO4KPwTiydNNsInTc5+KB39g6SM7BoNjUGGUsmnM YtzQ== 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 i10-20020a63bf4a000000b005ab6142f1besi5858953pgo.169.2023.10.23.01.12.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 01:12:32 -0700 (PDT) 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 30D1A8062369; Mon, 23 Oct 2023 01:12:28 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231868AbjJWIMC (ORCPT + 99 others); Mon, 23 Oct 2023 04:12:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229793AbjJWILs (ORCPT ); Mon, 23 Oct 2023 04:11:48 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 11759D6B for ; Mon, 23 Oct 2023 01:11:43 -0700 (PDT) Received: from loongson.cn (unknown [113.200.148.30]) by gateway (Coremail) with SMTP id _____8AxTeu7KjZlfuYzAA--.29979S3; Mon, 23 Oct 2023 16:11:39 +0800 (CST) Received: from linux.localdomain (unknown [113.200.148.30]) by localhost.localdomain (Coremail) with SMTP id AQAAf8AxG9y0KjZlQRAvAA--.34174S8; Mon, 23 Oct 2023 16:11:38 +0800 (CST) From: Tiezhu Yang To: Josh Poimboeuf , Peter Zijlstra , Huacai Chen Cc: loongarch@lists.linux.dev, linux-kernel@vger.kernel.org, loongson-kernel@lists.loongnix.cn Subject: [PATCH v4 6/8] objtool: Check local label in add_dead_ends() Date: Mon, 23 Oct 2023 16:11:29 +0800 Message-Id: <1698048691-19521-7-git-send-email-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1698048691-19521-1-git-send-email-yangtiezhu@loongson.cn> References: <1698048691-19521-1-git-send-email-yangtiezhu@loongson.cn> X-CM-TRANSID: AQAAf8AxG9y0KjZlQRAvAA--.34174S8 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBj93XoWxWryUXryUtryDKF1DCw48GrX_yoWrXr4UpF 43C343Kr42yr13uw47tF1kWasxWws7WFnrJ39rGFyrAr9FvFs8KwnFyr15uas8Gr12vw45 Xay5Kay3CryDAwcCm3ZEXasCq-sJn29KB7ZKAUJUUUU7529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUBab4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1a6r1DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Cr0_Gr1UM28EF7xvwVC2z280aVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIEc7CjxVAF wI0_Gr1j6F4UJwAaw2AFwI0_Jrv_JF1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2 xF0cIa020Ex4CE44I27wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_ Wrv_ZF1lYx0Ex4A2jsIE14v26r4j6F4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x 0EwIxGrwCY1x0262kKe7AKxVWUAVWUtwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkE bVWUJVW8JwCFI7km07C267AKxVWUXVWUAwC20s026c02F40E14v26r1j6r18MI8I3I0E74 80Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIxkGc2Ij64vIr41lIxAIcVC0 I7IYx2IY67AKxVW5JVW7JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04 k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2jsIEc7Cj xVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x07jF4EiUUUUU= X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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]); Mon, 23 Oct 2023 01:12:28 -0700 (PDT) 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.6.test]$ gcc --version gcc (GCC) 14.0.0 20231009 (experimental) [fedora@linux 6.6.test]$ as --version GNU assembler (GNU Binutils) 2.41.50.20231009 [fedora@linux 6.6.test]$ readelf -r init/main.o | grep -A 2 "rela.discard.unreachable" Relocation section '.rela.discard.unreachable' at offset 0x4b70 contains 1 entry: Offset Info Type Sym. Value Sym. Name + Addend 000000000000 00de00000063 R_LARCH_32_PCREL 0000000000000228 .L466^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 1b40639..8ddf02f 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.1.0