From nobody Wed Feb 5 15:54:29 2025 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8FBD61DED49 for ; Wed, 15 Jan 2025 22:50:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=93.17.235.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736981457; cv=none; b=PbZnAlmVo2Z7FEIOjWMDqvO643NyQ1cHo0lpRVGPC8I69WILQGASDl7wi7ulPpPrP22riPJDXQbDinmm44Z/LD+ATTTfuV+OjMK3GBwQB3XPEJSaURqs1TlJVtJNUbLK5Gdf3DdWhk0y68PGqY9MarFq7KR1KyFNY+I0yaoh1wA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736981457; c=relaxed/simple; bh=fqttkCOH/DPr21Jy9pk9KHcyBNc9VVe/REU9Zsv+9Qk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RNe/LCHDvuHR6Ajm+UcdrVZOiZB770vlbAX+c9uEL25l6acAoqdfCikq1PlYQyu+yAndCL+QWogsYnLYg8s2sH+uDmYDvAD4m/YfuTqtsL535eNsuu3DrMigzsQdU6enqZVvSd5VpQXTstEv47IBEF6PWjRXOde3MMnqc/giNXQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=csgroup.eu; spf=pass smtp.mailfrom=csgroup.eu; arc=none smtp.client-ip=93.17.235.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=csgroup.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=csgroup.eu Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4YYLcT5fpGz9sSR; Wed, 15 Jan 2025 23:43:05 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id CGI684IZnpuz; Wed, 15 Jan 2025 23:43:05 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4YYLcT4rZ8z9sSN; Wed, 15 Jan 2025 23:43:05 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 965228B77A; Wed, 15 Jan 2025 23:43:05 +0100 (CET) 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 jnXJZo8I46BV; Wed, 15 Jan 2025 23:43:05 +0100 (CET) Received: from PO20335.idsi0.si.c-s.fr (unknown [192.168.202.221]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 09BDD8B774; Wed, 15 Jan 2025 23:43:02 +0100 (CET) From: Christophe Leroy To: Josh Poimboeuf , Peter Zijlstra , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Julien Thierry , Miroslav Benes , Raphael Gault , Michael Ellerman , Nicholas Piggin , Naveen N Rao , Madhavan Srinivasan Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, llvm@lists.linux.dev Subject: [PATCH v5 06/15] objtool: Add support for relative switch tables Date: Wed, 15 Jan 2025 23:42:46 +0100 Message-ID: <3b380e5e0cf3e54304d52c45a551fb7a6c9627bb.1736955567.git.christophe.leroy@csgroup.eu> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1736980963; l=3463; i=christophe.leroy@csgroup.eu; s=20211009; h=from:subject:message-id; bh=fqttkCOH/DPr21Jy9pk9KHcyBNc9VVe/REU9Zsv+9Qk=; b=LSTIL6frG7RFbeahKwa9DSgA5iHcfOsT5UT1LBv1jKoVYMhtlqEAlpQ79RgFph57SAcqPHakA HQg/1M/i9PRCRCSSTD6yf4l8b8Mja8Pyf0Hr5TyVJZwDlTzgvcxU+7c X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= Content-Transfer-Encoding: quoted-printable 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 10979d68103d..4495e7823b29 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -1950,7 +1950,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 @@ -1967,7 +1967,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: */ @@ -1975,7 +1975,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.47.0