From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4013C606A337 for ; Wed, 2 Dec 2026 07:42:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=YEwbQcPg Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4jfV8d71fwz2xsW; Wed, 02 Dec 2026 18:42:25 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip=148.163.156.1 ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1796197345; cv=none; b=LwmNiksISCiHDQVMzeyBrHrcUiOOfGLxAcAasZa0sY4DoTfoC1WgsgB5+kMUzPEoA/U9O+6gtyKyCLOppqQ0uVi3aGTrG7T6vcwWcQ5u3i6YLwiNFbYnyV4ycKo37MTuGM8u6DDNAfjjC7j5xAivHTEVaaosHrXmLh9tKgVSsyKKli/TIgGQ3/PgdWB3e6grhzexJH3O7Rm6PxCrytz1b06gDuuyw7xpNBHJTNE3HTRKKa4PL91LKRHaDILCfY5wfov0IRRVjDFPfrkbqSvXSXSP+HD0erB+KrV4uaYb6A9ALTjKNerPAGT18kHviYqwvRdX8OMdO9MzdY7SWEfCBw== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1796197345; c=relaxed/relaxed; bh=zHOEhiltD+yB5eZmgYEz8u13s2UrD2mVgD3fVPNe47o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=R5vm/IwV9jn1z/04gzi1jeFXEEbqzmJfIXBdZEXLX34w5XMp5KffS0HsRxzmQ7ljI1oY77vbfWTyixa9unjLNU8QJVhPtWh7kYrHK4UgYAVKeE6HP5lVfwvsJfTTAdS1oj438TT5QEJkUXaCjFCAZQrMcDgjA8SCK/jzZDZ7+sXhbEM/DHzSubsQfpD0lG9lgsREYzhbon3o//zgNKri+bzz3vhdvxre19Ztdjdr6QA7l80eqsPbfyQc9wgXgrH04dG0PAwYyh/+Blgi5x9YUiEOrsKPKeEOON8NnktF0c7CUTKx+oGyVr6JzsTZ97k3lVq6WNPECH9kyzSD6VWORQ== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=YEwbQcPg; dkim-atps=neutral; spf=pass (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=shivangu@linux.ibm.com; receiver=lists.ozlabs.org) smtp.mailfrom=linux.ibm.com Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=YEwbQcPg; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=shivangu@linux.ibm.com; receiver=lists.ozlabs.org) Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4jfV8d1qRQz2xrC for ; Wed, 02 Dec 2026 18:42:25 +1100 (AEDT) Received: from pps.filterd (m0360083.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6B274hZ04177152; Wed, 2 Dec 2026 07:42:11 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=zHOEhiltD+yB5eZmg YEz8u13s2UrD2mVgD3fVPNe47o=; b=YEwbQcPgiL0mkmF3wpxcSkGlkCynl3ygK ssKalQX++OV56caGLQbnpME52PGV0aKMZRzo/eUb3FbQiCLVUUDSJdEI+Mz1u0EV FZw11SWXTIBbE9majonDbRIffMqk6DWxnvu5a/7O8viDmJZrY6yjR77igdlXh7+0 tNPmS1O5c0NPn2zCv6t9AVLnqNTYmr+AdCi1qPb5rqaw6mRL1WHp6h48SZW/63Kg Ct7Lc1jGiPP6vgRl9xqI1A8uw4HD1B/TQ/rW2hbp6mgsT5iWEka+8b9SSK5RSWW6 7Bh7FmL5ncA0W+IwisKFR6kGubYqCUTar4El49At7Fv37SunMweaw== Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4j7pf40pfg-1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 02 Dec 2026 07:42:10 +0000 (GMT) Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.18.1.11/8.18.1.11) with ESMTP id 6B26nK1Q2682976; Wed, 2 Dec 2026 07:42:09 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 4j9ujnm64y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 02 Dec 2026 07:42:09 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6B27g3pm42926436 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 2 Dec 2026 07:42:03 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3465A2004F; Wed, 2 Dec 2026 07:42:03 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 13A1C20043; Wed, 2 Dec 2026 07:41:56 +0000 (GMT) Received: from shivang.com (unknown [9.67.68.246]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 2 Dec 2026 07:41:55 +0000 (GMT) From: Shivang Upadhyay To: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Cc: maddy@linux.ibm.com, mpe@ellerman.id.au, npiggin@gmail.com, chleroy@kernel.org, ritesh.list@gmail.com, sshegde@linux.ibm.com, jpoimboe@kernel.org, peterz@infradead.org, shivangu@linux.ibm.com, ardb@kernel.org, will@kernel.org, sv@linux.ibm.com, joe.lawrence@redhat.com, song@kernel.org, mingo@kernel.org, mbenes@suse.cz Subject: [PATCH v3 06/11] objtool: Describe special_entry parsing for --alt-fixup Date: Wed, 2 Dec 2026 13:10:53 +0530 Message-ID: <20261202074059.899491-7-shivangu@linux.ibm.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261202074059.899491-1-shivangu@linux.ibm.com> References: <20261202074059.899491-1-shivangu@linux.ibm.com> X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Owner: List-Post: List-Archive: , List-Subscribe: , , Precedence: list X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Proofpoint-Spam-Info: AW1haW4tMjYxMjAyMDAzMCBTYWx0ZWRfX43UDoPgOS9SK GgvqeKuztjTGyBt8JWNfw1p0VXOPuiy8i5jPEtb2lsUdbxDhWylQPg9Pm6blwP4sj4V0LF0RmZb MXt5pLXhCquSdvnozsY1nJsImLaGM60= X-Proofpoint-ORIG-GUID: QGP0UGl_dqsSTSbp_ofE3LAdhXxTeW2B X-Proofpoint-GUID: mW9uaSkQK6eHYZ84EFuKBP96Tb_ozcEL X-Authority-Analysis: v=2.4 cv=R6eWitRX c=1 sm=1 tr=0 ts=6b0fcbd3 cx=c_pps a=bLidbwmWQ0KltjZqbj+ezA==:117 a=bLidbwmWQ0KltjZqbj+ezA==:17 a=pUM-KoujPXoA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=iQ6ETzBq9ecOQQE5vZCe:22 a=VnNF1IyMAAAA:8 a=FAM3tMn-m3-vgn4F6LkA:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMjAyMDAzMCBTYWx0ZWRfXznPp3sbHXpIN v3GokAeR0+U41kGmGrsPPSN2CWlUUwQz5AkpbC6jvnRrIeMjO21LJspjg9atkPKfoBO0wUmGTTi 1jN/Rn7oBHr6+Rlh7Zz44Q+SP5d/7beSLvsbHloEo8BzCZRKkb5c4S3B3hR1NUGB/OzK+SBkYu5 jPdJFLmva2QAuKhLH64lAKDXjxyvlyNfbZjlMkCJODaVFmIUY/TsYeK0+XRybl4hWe9bItf9U4z PN9Ylh4MBPpfNwaKG64k6Cv5+pPn26eyPwvVD2MA0U3S4jck19p8ifBv7uCfpfoCrr6Pmat0qWM dmvRDDpn8/2jkW7tnecKp/kTTVPfPFbrb3ZXqNVx0fP2BZFiIFwRKGCH1cnRwZXxaYBqj/Fwh6T RSOQeWSmxogQk/ctbc0Te40v6/PXgjVJQPwTx1XSux9zV+qCHTZXPt0Otw1DpZX4AeBiYwTepPd QUiEmgL/W1MUdSHwVnA== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-12-02_02,2026-12-01_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 priorityscore=1501 adultscore=0 spamscore=0 bulkscore=0 phishscore=0 suspectscore=0 malwarescore=0 clxscore=1015 impostorscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2612020030 X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 struct special_entry describes a special section entry with a length of the original and of the replacement code, in bytes. Powerpc tables store where the code ends instead, as a relocation against the end label. For these entries, we compute orig_len and new_len, with help of find_reloc_by_dest and reloc_to_sec_off function. Parse these entries when --alt-fixup is provided. BEGIN_FTR_SECTION/END_FTR_SECTION and friends record, for each pair of original and replacement code, an entry in __ftr_fixup, __mmu_ftr_fixup or __fw_ftr_fixup (see MAKE_FTR_SECTION_ENTRY()): word mask, value, start, end, alt_start, alt_end; Add these sections to special_entries, so they can be parsed. Signed-off-by: Shivang Upadhyay --- .../arch/powerpc/include/arch/special.h | 16 ++++ tools/objtool/special.c | 80 ++++++++++++++++++- 2 files changed, 93 insertions(+), 3 deletions(-) diff --git a/tools/objtool/arch/powerpc/include/arch/special.h b/tools/objtool/arch/powerpc/include/arch/special.h index ffef9ada7133..5667a476fd16 100644 --- a/tools/objtool/arch/powerpc/include/arch/special.h +++ b/tools/objtool/arch/powerpc/include/arch/special.h @@ -18,4 +18,20 @@ #define ALT_ORIG_LEN_OFFSET 10 #define ALT_NEW_LEN_OFFSET 11 +/* + * Feature fixup entries (__ftr_fixup, __mmu_ftr_fixup, __fw_ftr_fixup), see + * MAKE_FTR_SECTION_ENTRY() in asm/feature-fixups.h: + * + * word mask, value; + * word start, end, alt_start, alt_end; + * + * The sizes below are in words, objtool multiplies them by the ELF word size. + */ + +#define FTR_ENTRY_SIZE 6 +#define FTR_ORIG_OFFSET 2 +#define FTR_ORIG_END_OFFSET 3 +#define FTR_NEW_OFFSET 4 +#define FTR_NEW_END_OFFSET 5 + #endif /* _PPC_ARCH_SPECIAL_H */ diff --git a/tools/objtool/special.c b/tools/objtool/special.c index 2a533afbc69a..31420134d77e 100644 --- a/tools/objtool/special.c +++ b/tools/objtool/special.c @@ -23,9 +23,26 @@ struct special_entry { unsigned char orig_len, new_len; /* group only */ unsigned char feature; /* ALTERNATIVE macro CPU feature */ unsigned char key; /* jump_label key */ + + // --alt-fixup entries, read by nothing else. + bool fixup; + int orig_end, new_end; }; -static const struct special_entry entries[] = { +/* powerpc feature fixups, see arch/powerpc/include/asm/feature-fixups.h */ +#define FTR_FIXUP_ENTRY(name) \ + { \ + .sec = name, \ + .group = true, \ + .size = FTR_ENTRY_SIZE, \ + .orig = FTR_ORIG_OFFSET, \ + .new = FTR_NEW_OFFSET, \ + .fixup = true, \ + .orig_end = FTR_ORIG_END_OFFSET,\ + .new_end = FTR_NEW_END_OFFSET, \ + } + +static struct special_entry entries[] = { { .sec = ".altinstructions", .group = true, @@ -50,6 +67,11 @@ static const struct special_entry entries[] = { .orig = EX_ORIG_OFFSET, .new = EX_NEW_OFFSET, }, +#ifdef FTR_ENTRY_SIZE + FTR_FIXUP_ENTRY("__ftr_fixup"), + FTR_FIXUP_ENTRY("__mmu_ftr_fixup"), + FTR_FIXUP_ENTRY("__fw_ftr_fixup"), +#endif {}, }; @@ -93,9 +115,25 @@ static int get_alt_entry(struct elf *elf, const struct special_entry *entry, reloc_to_sec_off(orig_reloc, &alt->orig_sec, &alt->orig_off); + if (entry->fixup) { + struct section *end_sec; + unsigned long end_off; + + alt->orig_off -= entry->orig; + struct reloc *end_reloc = find_reloc_by_dest(elf, sec, idx * entry->size + entry->orig_end); + if (!end_reloc) { + ERROR_FUNC(sec, idx * entry->size + entry->orig_end, "can't find reloc"); + return -1; + } + reloc_to_sec_off(end_reloc, &end_sec, &end_off); + end_off -= entry->orig_end; + + alt->orig_len = end_off - alt->orig_off; + } + arch_handle_alternative(alt); - if (!entry->group || alt->new_len) { + if (!entry->group || alt->new_len || entry->fixup) { new_reloc = find_reloc_by_dest(elf, sec, offset + entry->new); if (!new_reloc) { ERROR_FUNC(sec, offset + entry->new, "can't find new reloc"); @@ -104,6 +142,22 @@ static int get_alt_entry(struct elf *elf, const struct special_entry *entry, reloc_to_sec_off(new_reloc, &alt->new_sec, &alt->new_off); + if (entry->fixup) { + struct section *end_sec; + unsigned long end_off; + + alt->new_off -= entry->new; + struct reloc *end_reloc = find_reloc_by_dest(elf, sec, idx * entry->size + entry->new_end); + if (!end_reloc) { + ERROR_FUNC(sec, idx * entry->size + entry->new_end, "can't find reloc"); + return -1; + } + reloc_to_sec_off(end_reloc, &end_sec, &end_off); + end_off -= entry->new_end; + + alt->new_len = end_off - alt->new_off; + } + /* _ASM_EXTABLE_EX hack */ if (alt->new_off >= 0x7ffffff0) alt->new_off -= 0x7ffffff0; @@ -130,7 +184,7 @@ static int get_alt_entry(struct elf *elf, const struct special_entry *entry, */ int special_get_alts(struct elf *elf, struct list_head *alts) { - const struct special_entry *entry; + struct special_entry *entry; struct section *sec; unsigned int nr_entries; struct special_alt *alt; @@ -139,6 +193,17 @@ int special_get_alts(struct elf *elf, struct list_head *alts) INIT_LIST_HEAD(alts); for (entry = entries; entry->sec; entry++) { + /* The fixup layout is given in words, scale it to the ELF word size */ + if (entry->fixup) { + size_t word = elf_addr_size(elf); + + entry->size *= word; + entry->orig *= word; + entry->new *= word; + entry->orig_end *= word; + entry->new_end *= word; + } + sec = find_section_by_name(elf, entry->sec); if (!sec) continue; @@ -161,6 +226,15 @@ int special_get_alts(struct elf *elf, struct list_head *alts) if (get_alt_entry(elf, entry, sec, idx, alt)) return -1; + /* + * Nothing to copy and fix up if the original is just + * nopped. Such an entry can overlap other ones. + */ + if (entry->fixup && !alt->new_len) { + free(alt); + continue; + } + list_add_tail(&alt->list, alts); } } -- 2.56.1