From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=148.163.156.1 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796197351; b=UWaAIoKJtMR+Gtig472PweRZql+chphyr6ZQHbSdsqiQf5flWylsUxLrQhYCbQVSNrif ixLnQOoFMLe+ayQlt3zsCJ0aIM4Z9EDPFO4lHPuw2Fz2PgCPtc4pu63gCCtmEh2mIRnSr 9Mw0WyMN8MG5KZBXomoqebdslLO63N3aR2HyrcH5BLDz1VIdHYpMr6vOQ0PDldodKKuPq 54CXhaOJeX+08bcBFV+5xKoqU6RuRW1zrgy0gELlWQo1HyhjXQ75RrxiANJehsNu5znsA lQreBrj0NO4ENCOQgn200E+BDTauOAoT61R99m/NAYih+rKMqBsVcS/sz5+2AY6pA+A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796197351; h=DMARC-Filter:Received:DKIM-Signature:Received:Received:Received: Received:Received:Received:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-TM-AS-GCONF:X-Proofpoint-Reinject: X-Proofpoint-Spam-Info:X-Proofpoint-ORIG-GUID:X-Proofpoint-GUID: X-Authority-Analysis:X-Proofpoint-Spam-Details-Enc: X-Proofpoint-Virus-Version:X-Proofpoint-Spam-Details; bh=zHOEhiltD+yB5eZmgYEz8u13s2UrD2mVgD3fVPNe47o=; b=swkaCtwcSWHOH8Lrt4aqWo2yzb7XlwSi1A3MgqTLZKT/6ke4ulLCY/p5Hw/j738gvGdg 6Zz6pszbzRlxMRDQwSsy/ujLyvVJOx/gu+LJwuCsdbnI4guitfF7TcF1xcmSiFN1XYTP4 Bi6eWEX76sHeBu0a8Ol6IF/BLe/FqLpkwakgvbJlPdnC8phaB5SE9dLqaSMQ6VYv0x79X zIIDA0m58elXDVHAVzffb6cQg+j4P1DrQ3gpLR6vzkKH78HW9PyRubvtrT2vUqsKU4rro xAcssQI2o4BYtwUhLzBVs+EVGtKbt/Cx1vmTf8Ka+LYMwjdsy9/6UeMqtKLTNx7M//A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=YEwbQcPg; arc=none smtp.remote-ip=148.163.156.1 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 ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1034F606A32C for ; Wed, 2 Dec 2026 07:42:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1034F606A32C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com 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 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: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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