From nobody Mon Feb 9 20:37:00 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DBF81EB64DD for ; Tue, 11 Jul 2023 16:09:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232957AbjGKQJq (ORCPT ); Tue, 11 Jul 2023 12:09:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232530AbjGKQJn (ORCPT ); Tue, 11 Jul 2023 12:09:43 -0400 Received: from pegase1.c-s.fr (pegase1.c-s.fr [93.17.236.30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8AB35170E for ; Tue, 11 Jul 2023 09:09:25 -0700 (PDT) Received: from localhost (mailhub3.si.c-s.fr [192.168.12.233]) by localhost (Postfix) with ESMTP id 4R0m5N1NLtz9sFL; Tue, 11 Jul 2023 18:08:56 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id wsyMecsaoy7o; Tue, 11 Jul 2023 18:08:56 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 4R0m5C4tMLz9sFM; Tue, 11 Jul 2023 18:08:47 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id A3DA58B763; Tue, 11 Jul 2023 18:08:47 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id VI7KivWCYD5v; Tue, 11 Jul 2023 18:08:47 +0200 (CEST) Received: from PO20335.IDSI0.si.c-s.fr (unknown [192.168.233.184]) by messagerie.si.c-s.fr (Postfix) with ESMTP id DF6BB8B780; Tue, 11 Jul 2023 18:08:46 +0200 (CEST) Received: from PO20335.IDSI0.si.c-s.fr (localhost [127.0.0.1]) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.16.1) with ESMTPS id 36BG8jIJ3696824 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 11 Jul 2023 18:08:45 +0200 Received: (from chleroy@localhost) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.17.1/Submit) id 36BG8ifY3696823; Tue, 11 Jul 2023 18:08:44 +0200 X-Authentication-Warning: PO20335.IDSI0.si.c-s.fr: chleroy set sender to christophe.leroy@csgroup.eu using -f From: Christophe Leroy To: Michael Ellerman , Nicholas Piggin , Josh Poimboeuf , Peter Zijlstra , Sathvika Vasireddy , Naveen N Rao Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v4 06/15] objtool: Add support for relative switch tables Date: Tue, 11 Jul 2023 18:08:32 +0200 Message-ID: <4af87597cf2c260493ebf8c9b85420d87de1c189.1689091394.git.christophe.leroy@csgroup.eu> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1689091705; l=3463; i=christophe.leroy@csgroup.eu; s=20211009; h=from:subject:message-id; bh=ETgTsYTnSlaUTHNPciowRw4KEMC/5ipB4+rmwgj2QXE=; b=aWAWWefIXBV6kTZ3N/7ZsUGYGOT1fLWwXJ7T0eLWj5qYU9xp/MnjKJ3WnKtvD6+OBySic5z05 jyPimcRP5N/AooQfqNONOw2j7PooxuI2VD1DbpBuSYLKJZMnLa7y7xK X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" On powerpc, switch tables are relative, than means the address of the table is added to the value of the entry in order to get the pointed address: (r10 is the table address, r4 the index in the table) lis r10,0 <=3D=3D Load r10 with upper part of .rodata address R_PPC_ADDR16_HA .rodata addi r10,r10,0 <=3D=3D Add lower part of .rodata address R_PPC_ADDR16_LO .rodata lwzx r8,r10,r4 <=3D=3D Read table entry at r10 + r4 into r8 add r10,r8,r10 <=3D=3D Add table address to read value mtctr r10 <=3D=3D Save calculated address in CTR bctr <=3D=3D Branch to address in CTR RELOCATION RECORDS FOR [.rodata]: OFFSET TYPE VALUE 00000000 R_PPC_REL32 .text+0x0000054c 00000004 R_PPC_REL32 .text+0x000003d0 ... But for c_jump_tables it is not the case, they contain the pointed address directly: lis r28,0 <=3D=3D Load r28 with upper .rodata..c_jump_table R_PPC_ADDR16_HA .rodata..c_jump_table addi r28,r28,0 <=3D=3D Add lower part of .rodata..c_jump_table R_PPC_ADDR16_LO .rodata..c_jump_table lwzx r10,r28,r10 <=3D=3D Read table entry at r10 + r28 into r10 mtctr r10 <=3D=3D Save read value in CTR bctr <=3D=3D Branch to address in CTR RELOCATION RECORDS FOR [.rodata..c_jump_table]: OFFSET TYPE VALUE 00000000 R_PPC_ADDR32 .text+0x00000dc8 00000004 R_PPC_ADDR32 .text+0x00000dc8 ... Add support to objtool for relative tables, based on the relocation type which is R_PPC_REL32 for switch tables and R_PPC_ADDR32 for C jump tables. Do the comparison using R_ABS32 and R_ABS64 which are architecture agnostic. And use correct size for 'long' instead of hard coding a size of '8'. Signed-off-by: Christophe Leroy --- tools/objtool/check.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index ae0019412123..5a6a87ddbf27 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -1988,7 +1988,7 @@ static int add_jump_table(struct objtool_file *file, = struct instruction *insn, struct symbol *pfunc =3D insn_func(insn)->pfunc; struct reloc *table =3D insn_jump_table(insn); struct instruction *dest_insn; - unsigned int prev_offset =3D 0; + unsigned int offset, prev_offset =3D 0; struct reloc *reloc =3D table; struct alternative *alt; =20 @@ -2003,7 +2003,7 @@ static int add_jump_table(struct objtool_file *file, = struct instruction *insn, break; =20 /* Make sure the table entries are consecutive: */ - if (prev_offset && reloc_offset(reloc) !=3D prev_offset + 8) + if (prev_offset && reloc_offset(reloc) !=3D prev_offset + elf_addr_size(= file->elf)) break; =20 /* Detect function pointers from contiguous objects: */ @@ -2011,7 +2011,12 @@ static int add_jump_table(struct objtool_file *file,= struct instruction *insn, reloc_addend(reloc) =3D=3D pfunc->offset) break; =20 - dest_insn =3D find_insn(file, reloc->sym->sec, reloc_addend(reloc)); + if (reloc_type(reloc) =3D=3D R_ABS32 || reloc_type(reloc) =3D=3D R_ABS64) + offset =3D reloc_addend(reloc); + else + offset =3D reloc_addend(reloc) + reloc_offset(table) - reloc_offset(rel= oc); + + dest_insn =3D find_insn(file, reloc->sym->sec, offset); if (!dest_insn) break; =20 --=20 2.41.0