From nobody Sat Jun 13 23:58:03 2026 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 726E636165A; Tue, 5 May 2026 08:47:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777970867; cv=none; b=GGffRaLnQxoyjXL7Worxr3gW42qDihW+0+XxYDpXhsOKJi7KT42UiD9Vv5LwI8CmFxkVZ6obJ1MovYzsh3FqsInUmnVviHW7QiKxELOrv5P3g3xqZqYOtatKhmuXJOFRdjTZzONdR7GiH5lakwbXzt//0jzkkiZ4z3PR5U3A7jE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777970867; c=relaxed/simple; bh=/N//trj709H4QqHLbpgBuIpvzN+zQx6SDqgOTz1z3Uc=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UfqHr5T49IUU77AnC6b+KxqjnuEB/2MDbmDGJLRHy7T/GiNXAA6ey77srStcPh4q5CvEQJ+tcF+h37wCsbMdeO+4z1tBSn9TqLwBUbQBz6MfrbGp3my9eC6ltplgDR0YMiNCC/PnGPMFaM5knlLM8teR8eGsC2Cz/NdCP53wqyM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=V1YCmaKG; arc=none smtp.client-ip=148.163.158.5 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.b="V1YCmaKG" Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 64583SNB3012905; Tue, 5 May 2026 08:46:51 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h= content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=ldEaI3/NxF2VB410A U5fZYV6Tmr5i8LAzGkBmKI8gYU=; b=V1YCmaKGgb27iLCj2QTnIk2JbaNfXPQDh jcsH0quwyvqEFiFxCV57xKNq4HIvne9PO9F4WGc1C/O8FkCm6tOeuCObg+ZrWw8V /YYrDLug63ADdFCQCppipY3h+odlFNpfTIU4P/UAWMkxj9S+uc9qolBdw0aFMJQP toYwjnFSQwVaT9AA3DwF9aY6cNM9yMktlqv+6Nuji59YvP6h389grZlGG5oBU/i0 6u558AXm8BGfT3NnzB6Fgc4JVCB0mQvPlOSGBFt0U5oMobXL9WEzXnvqUf+Be46j 7nQtvDncgmhSaLCRFtzJc4rD8BkLilD4clzdmzqgBwm24XaC1Rdmw== Received: from ppma13.dal12v.mail.ibm.com (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4dw9y4jf9y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 05 May 2026 08:46:51 +0000 (GMT) Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.18.1.7/8.18.1.7) with ESMTP id 6458dQQN032036; Tue, 5 May 2026 08:46:50 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 4dwwtg8mrw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 05 May 2026 08:46:49 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6458kktr51839472 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 5 May 2026 08:46:46 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DF84C2004F; Tue, 5 May 2026 08:46:45 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A18C620043; Tue, 5 May 2026 08:46:39 +0000 (GMT) Received: from li-2fa77bcc-2701-11b2-a85c-cd621c23b6bd.bl1-in.ibm.com (unknown [9.123.13.4]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 5 May 2026 08:46:39 +0000 (GMT) From: Sathvika Vasireddy To: nathan@kernel.org, nsc@kernel.org, maddy@linux.ibm.com, mpe@ellerman.id.au, npiggin@gmail.com, chleroy@kernel.org, jpoimboe@kernel.org, peterz@infradead.org, ojeda@kernel.org, masahiroy@kernel.org, lossin@kernel.org, tamird@kernel.org, thomas.weissschuh@linutronix.de, rostedt@goodmis.org, ihor.solodrai@linux.dev, thuth@redhat.com, pmladek@suse.com, aliceryhl@google.com, elver@google.com, kees@kernel.org, legion@kernel.org, ardb@kernel.org, yuxuan.zuo@outlook.com, alexghiti@rivosinc.com, alexandre.chartre@oracle.com, bp@alien8.de, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, sv@linux.ibm.com Subject: [PATCH v1 1/6] objtool/powerpc: Add build-time fixup of alternate feature branch targets Date: Tue, 5 May 2026 14:16:23 +0530 Message-ID: <20260505084628.17940-2-sv@linux.ibm.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260505084628.17940-1-sv@linux.ibm.com> References: <20260505084628.17940-1-sv@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNTA1MDA3OSBTYWx0ZWRfXyfKJ7yInZmR/ 3tl88Qhc+4XvCePHUIEl2BMSg5sbQgYzwyH/uvDifF7bFBrmU0u0FIquZaF/RLdpMkGkFIVFvC/ EQ52YvZr0lN0ExGt/devXLHIBR9FbmGjnNo1BUONrmV42v/6uQdHvs21rpugB5tmTmsVU7tKQQ1 z6Vf72ax9rIzSbLqejRqh54SUsMZO//SwDosb8R3gab9ubhQN6+x4cSvr3JVZztJt6KfTkzNt/1 romWHvNXNgw87mPKDq4GXp71JlycPtGbngpEn+XzQS0hsXdRUNsUQMmoOJTbJDzVPznGEFSO37v 9l8VY7aC8IQCctjAhVtEr3jfjL5yDByqcUQnV0D99pNW/Q/jpsj/gsRNVO28ok2ZJui7sSJLd9X 0HZXDFh5VUX2/gLqc19MWSYymEyz4fjq/pd837Sj9D2fovhJnILNqsbSRYrmpxxC4TFcoAD+S9F jISgyBGFyZKPNlWsfIQ== X-Authority-Analysis: v=2.4 cv=J4GaKgnS c=1 sm=1 tr=0 ts=69f9ae7b cx=c_pps a=AfN7/Ok6k8XGzOShvHwTGQ==:117 a=AfN7/Ok6k8XGzOShvHwTGQ==:17 a=NGcC8JguVDcA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=RzCfie-kr_QcCd8fBx8p:22 a=VwQbUJbxAAAA:8 a=pGLkceISAAAA:8 a=VnNF1IyMAAAA:8 a=Bgn1OAOv2882JTcyVjQA:9 X-Proofpoint-GUID: 267gpyc1wiufNxZXHhD2pVq8M8N7wFju X-Proofpoint-ORIG-GUID: xN9asAEjZ5_U4KaxRqsh90CYKrm1Ch7L X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-05-05_02,2026-04-30_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 clxscore=1015 malwarescore=0 bulkscore=0 suspectscore=0 priorityscore=1501 spamscore=0 phishscore=0 adultscore=0 lowpriorityscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2604200000 definitions=main-2605050079 Content-Type: text/plain; charset="utf-8" PowerPC __ftr_alt* sections must currently be placed near .text because they lack the executable attribute, preventing the linker from inserting stubs. Branches in the alternate code must reach their targets directly. This can cause build failures as the kernel grows. Fix this by processing alternate feature relocations at build time with objtool. Link with --emit-relocs to preserve relocation information, mark __ftr_alt* sections executable ("ax") so the linker can insert stubs, then use objtool --ftr-fixup to recompute branch offsets based on their runtime locations. objtool already has ELF parsing and instruction patching infrastructure, so this avoids introducing a separate tool as was originally proposed [1]. [1] https://lore.kernel.org/linuxppc-dev/20170521010130.13552-1-npiggin@gma= il.com/ Co-developed-by: Nicholas Piggin Signed-off-by: Nicholas Piggin Signed-off-by: Sathvika Vasireddy --- tools/objtool/arch/powerpc/decode.c | 15 +- tools/objtool/arch/powerpc/special.c | 451 ++++++++++++++++++++++++ tools/objtool/builtin-check.c | 2 + tools/objtool/check.c | 29 +- tools/objtool/elf.c | 1 + tools/objtool/include/objtool/builtin.h | 1 + tools/objtool/include/objtool/special.h | 56 +++ tools/objtool/special.c | 29 ++ 8 files changed, 582 insertions(+), 2 deletions(-) diff --git a/tools/objtool/arch/powerpc/decode.c b/tools/objtool/arch/power= pc/decode.c index e534ac1123b3..f6e69d074f28 100644 --- a/tools/objtool/arch/powerpc/decode.c +++ b/tools/objtool/arch/powerpc/decode.c @@ -59,13 +59,26 @@ int arch_decode_instruction(struct objtool_file *file, = const struct section *sec enum insn_type typ; unsigned long imm; u32 ins; + unsigned int aa; =20 ins =3D bswap_if_needed(file->elf, *(u32 *)(sec->data->d_buf + offset)); opcode =3D ins >> 26; typ =3D INSN_OTHER; imm =3D 0; + aa =3D ins & 2; =20 switch (opcode) { + case 16: + if (ins & 1) + typ =3D INSN_OTHER; + else + typ =3D INSN_JUMP_CONDITIONAL; + imm =3D ins & 0xfffc; + if (imm & 0x8000) + imm -=3D 0x10000; + insn->immediate =3D imm | aa; + break; + case 18: /* b[l][a] */ if (ins =3D=3D 0x48000005) /* bl .+4 */ typ =3D INSN_OTHER; @@ -77,7 +90,7 @@ int arch_decode_instruction(struct objtool_file *file, co= nst struct section *sec imm =3D ins & 0x3fffffc; if (imm & 0x2000000) imm -=3D 0x4000000; - imm |=3D ins & 2; /* AA flag */ + insn->immediate =3D imm | aa; break; } =20 diff --git a/tools/objtool/arch/powerpc/special.c b/tools/objtool/arch/powe= rpc/special.c index 8f9bf61ca089..deb248c63bca 100644 --- a/tools/objtool/arch/powerpc/special.c +++ b/tools/objtool/arch/powerpc/special.c @@ -3,7 +3,17 @@ #include #include #include +#include +#include +#include =20 +struct section *ftr_alt; + +struct fixup_entry *fes; +unsigned int nr_fes; + +uint64_t fe_alt_start =3D -1; +uint64_t fe_alt_end; =20 bool arch_support_alt_relocation(struct special_alt *special_alt, struct instruction *insn, @@ -23,3 +33,444 @@ const char *arch_cpu_feature_name(int feature_number) { return NULL; } + + +int process_alt_data(struct objtool_file *file) +{ + struct section *section; + + section =3D find_section_by_name(file->elf, ".__ftr_alternates.text"); + ftr_alt =3D section; + + if (!ftr_alt) { + if (opts.link) + WARN(".__ftr_alternates.text section not found in vmlinux\n"); + return opts.link ? -1 : 0; + } + + fe_alt_start =3D ftr_alt->sh.sh_addr; + fe_alt_end =3D ftr_alt->sh.sh_addr + ftr_alt->sh.sh_size; + + return 0; + +} + +static int is_le(struct objtool_file *file) +{ + return file->elf->ehdr.e_ident[EI_DATA] =3D=3D ELFDATA2LSB; +} + +static int is_64bit(struct objtool_file *file) +{ + return file->elf->ehdr.e_ident[EI_CLASS] =3D=3D ELFCLASS64; +} + +static uint32_t f32_to_cpu(struct objtool_file *file, uint32_t val) +{ + if (is_le(file)) + return __le32_to_cpu(val); + else + return __be32_to_cpu(val); +} + +static uint64_t f64_to_cpu(struct objtool_file *file, uint64_t val) +{ + if (is_le(file)) + return __le64_to_cpu(val); + else + return __be64_to_cpu(val); +} + +static uint32_t cpu_to_f32(struct objtool_file *file, uint32_t val) +{ + if (is_le(file)) + return __cpu_to_le32(val); + else + return __cpu_to_be32(val); +} + +int process_fixup_entries(struct objtool_file *file) +{ + struct section *sec; + int i; + + for_each_sec(file->elf, sec) { + Elf_Data *data; + unsigned int nr; + + if (strstr(sec->name, "_ftr_fixup") =3D=3D NULL) + continue; + + if (strstr(sec->name, ".rela") !=3D NULL) + continue; + + data =3D sec->data; + if (!data || data->d_size =3D=3D 0) + continue; + + if (is_64bit(file)) + nr =3D data->d_size / sizeof(struct fixup_entry_64); + else + nr =3D data->d_size / sizeof(struct fixup_entry_32); + + for (i =3D 0; i < nr; i++) { + unsigned long idx; + unsigned long long off; + struct fixup_entry *dst; + + if (is_64bit(file)) { + struct fixup_entry_64 *src; + + idx =3D i * sizeof(struct fixup_entry_64); + off =3D sec->sh.sh_addr + data->d_off + idx; + src =3D data->d_buf + idx; + + if (src->alt_start_off =3D=3D src->alt_end_off) + continue; + + struct fixup_entry *tmp =3D realloc(fes, (nr_fes + 1) + * sizeof(struct fixup_entry)); + + if (!tmp) { + free(fes); + fes =3D NULL; + return -1; + } + fes =3D tmp; + dst =3D &fes[nr_fes++]; + + dst->mask =3D f64_to_cpu(file, src->mask); + dst->value =3D f64_to_cpu(file, src->value); + dst->start_off =3D f64_to_cpu(file, src->start_off) + off; + dst->end_off =3D f64_to_cpu(file, src->end_off) + off; + dst->alt_start_off =3D f64_to_cpu(file, src->alt_start_off) + off; + dst->alt_end_off =3D f64_to_cpu(file, src->alt_end_off) + off; + } else { + struct fixup_entry_32 *src; + + idx =3D i * sizeof(struct fixup_entry_32); + off =3D sec->sh.sh_addr + data->d_off + idx; + src =3D data->d_buf + idx; + + if (src->alt_start_off =3D=3D src->alt_end_off) + continue; + + struct fixup_entry *tmp =3D realloc(fes, (nr_fes + 1) + * sizeof(struct fixup_entry)); + + if (!tmp) { + free(fes); + fes =3D NULL; + return -1; + } + fes =3D tmp; + dst =3D &fes[nr_fes++]; + + dst->mask =3D f32_to_cpu(file, src->mask); + dst->value =3D f32_to_cpu(file, src->value); + dst->start_off =3D (int32_t)f32_to_cpu(file, src->start_off) + off; + dst->end_off =3D (int32_t)f32_to_cpu(file, src->end_off) + off; + dst->alt_start_off =3D (int32_t)f32_to_cpu(file, + src->alt_start_off) + off; + dst->alt_end_off =3D (int32_t)f32_to_cpu(file, + src->alt_end_off) + off; + } + } + } + return 0; +} + +struct fixup_entry *find_fe_altaddr(uint64_t addr) +{ + unsigned int i; + + if (addr < fe_alt_start) + return NULL; + if (addr >=3D fe_alt_end) + return NULL; + + for (i =3D 0; i < nr_fes; i++) { + if (addr >=3D fes[i].alt_start_off && addr < fes[i].alt_end_off) + return &fes[i]; + } + return NULL; +} + +int set_uncond_branch_target(uint32_t *insn, + const uint64_t addr, uint64_t target) +{ + uint32_t i =3D *insn; + int64_t offset; + + offset =3D target; + if (!(i & BRANCH_ABSOLUTE)) + offset =3D offset - addr; + + /* Check we can represent the target in the instruction format */ + if (offset < -0x2000000 || offset > 0x1fffffc || offset & 0x3) + return -EOVERFLOW; + + /* Mask out the flags and target, so they don't step on each other. */ + *insn =3D 0x48000000 | (i & 0x3) | (offset & 0x03FFFFFC); + + return 0; +} + +int set_cond_branch_target(uint32_t *insn, + const uint64_t addr, uint64_t target) +{ + uint32_t i =3D *insn; + int64_t offset; + + offset =3D target; + + if (!(i & BRANCH_ABSOLUTE)) + offset =3D offset - addr; + + /* Check we can represent the target in the instruction format */ + if (offset < -0x8000 || offset > 0x7FFF || offset & 0x3) + return -EOVERFLOW; + + /* Mask out the flags and target, so they don't step on each other. */ + *insn =3D 0x40000000 | (i & 0x3FF0003) | (offset & 0xFFFC); + + return 0; +} + +void check_and_flatten_fixup_entries(void) +{ + static struct fixup_entry *fe; + unsigned int i; + + for (i =3D 0; i < nr_fes; i++) { + struct fixup_entry *parent; + uint64_t nested_off; + uint64_t size; + + fe =3D &fes[i]; + + parent =3D find_fe_altaddr(fe->start_off); + if (!parent) + continue; + + size =3D fe->end_off - fe->start_off; + nested_off =3D fe->start_off - parent->alt_start_off; + + fe->start_off =3D parent->start_off + nested_off; + fe->end_off =3D fe->start_off + size; + } +} + + +static struct symbol *find_symbol_at_address_within_section(struct section= *sec, + unsigned long address) +{ + struct symbol *sym; + + sec_for_each_sym(sec, sym) { + if (sym->sym.st_value <=3D address && address < sym->sym.st_value + sym-= >len) + return sym; + } + + return NULL; +} + +static int is_local_symbol(uint8_t st_other) +{ + /* STO_PPC64_LOCAL_MASK: bits [7:5] encode the local entry point offset */ + return (st_other & (7 << 5)) =3D=3D 0; +} + +static struct symbol *find_symbol_at_address(struct objtool_file *file, + unsigned long address) +{ + struct section *sec; + struct symbol *sym; + + list_for_each_entry(sec, &file->elf->sections, list) { + sym =3D find_symbol_at_address_within_section(sec, address); + if (sym) + return sym; + } + return NULL; +} + +int process_alt_relocations(struct objtool_file *file) +{ + struct section *section; + size_t n =3D 0; + struct reloc *relocation; + struct symbol *sym; + struct fixup_entry *fe; + uint64_t addr; + uint64_t scn_delta; + uint64_t dst_addr; + const char *insn_ptr; + unsigned long target; + struct symbol *symbol; + int is_local; + int j; + uint32_t new_insn; + uint32_t file_insn; + struct instruction decoded_insn =3D {0}; + uint32_t *insn_ptr_raw; + uint32_t insn; + + section =3D find_section_by_name(file->elf, ".rela.__ftr_alternates.text"= ); + if (!section) { + printf(".rela.__ftr_alternates.text section not found.\n"); + return 0; + } + + for (j =3D 0; j < sec_num_entries(section); j++) { + + relocation =3D §ion->relocs[j]; + sym =3D relocation->sym; + + addr =3D reloc_offset(relocation); + target =3D sym->sym.st_value + reloc_addend(relocation); + symbol =3D find_symbol_at_address(file, target); + + if (symbol) { + is_local =3D is_local_symbol(symbol->sym.st_other); + if (!is_local) + target =3D target + 0x8; + } + + n++; + fe =3D find_fe_altaddr(addr); + if (!fe) + continue; + + if (target >=3D fe->alt_start_off && target < fe->alt_end_off) + continue; + + if (target >=3D ftr_alt->sh.sh_addr && + target < ftr_alt->sh.sh_addr + ftr_alt->sh.sh_size) + return -1; + + scn_delta =3D addr - ftr_alt->sh.sh_addr; + dst_addr =3D addr - fe->alt_start_off + fe->start_off; + + if (!ftr_alt->data || !ftr_alt->data->d_buf) + continue; + + if (arch_decode_instruction(file, ftr_alt, scn_delta, 4, &decoded_insn) = < 0) + continue; + + insn_ptr_raw =3D (uint32_t *)(ftr_alt->data->d_buf + scn_delta); + + insn =3D f32_to_cpu(file, *insn_ptr_raw); + new_insn =3D insn; + + switch (decoded_insn.type) { + case INSN_JUMP_CONDITIONAL: + if (set_cond_branch_target(&new_insn, dst_addr, target) !=3D 0) + continue; + break; + + case INSN_JUMP_UNCONDITIONAL: + if (set_uncond_branch_target(&new_insn, dst_addr, target) !=3D 0) + continue; + break; + + case INSN_CALL: + if (set_uncond_branch_target(&new_insn, dst_addr, target) !=3D 0) + continue; + break; + default: + continue; + } + + if (new_insn =3D=3D insn) + continue; + + file_insn =3D cpu_to_f32(file, new_insn); + insn_ptr =3D (const char *)&file_insn; + elf_write_insn(file->elf, ftr_alt, scn_delta, sizeof(file_insn), insn_pt= r); + } + return 0; +} + +int process_exception_entries(struct objtool_file *file) +{ + struct section *section; + Elf_Data *data; + unsigned int nr, i; + + section =3D find_section_by_name(file->elf, "__ex_table"); + if (!section) { + printf("__ex_table section not found\n"); + return 0; + } + + data =3D section->data; + if (!data || data->d_size =3D=3D 0) + return 0; + + nr =3D data->d_size / sizeof(struct exception_entry); + + for (i =3D 0; i < nr; i++) { + struct exception_entry *ex; + unsigned long idx; + uint64_t exaddr; + unsigned long long off; + + idx =3D i * sizeof(struct exception_entry); + off =3D section->sh.sh_addr + data->d_off + idx; + ex =3D data->d_buf + idx; + + exaddr =3D off + (int32_t)f32_to_cpu(file, ex->insn); + + if (exaddr < fe_alt_start) + continue; + if (exaddr >=3D fe_alt_end) + continue; + + return -1; + } + return 0; +} + +int process_bug_entries(struct objtool_file *file) +{ + struct section *section; + Elf_Data *data; + unsigned int nr, i; + + section =3D find_section_by_name(file->elf, "__bug_table"); + if (!section) { + printf("__bug_table section not found\n"); + return 0; + } + + data =3D section->data; + if (!data || data->d_size =3D=3D 0) + return 0; + + if (data->d_size % sizeof(struct bug_entry) !=3D 0) + return -1; + + nr =3D data->d_size / sizeof(struct bug_entry); + for (i =3D 0; i < nr; i++) { + struct bug_entry *bug; + unsigned long idx; + uint64_t entry_addr; + uint64_t bugaddr; + int32_t bug_disp; + + idx =3D i * sizeof(struct bug_entry); + entry_addr =3D section->sh.sh_addr + data->d_off + idx; + bug =3D (struct bug_entry *)(data->d_buf + idx); + bug_disp =3D f32_to_cpu(file, bug->bug_addr_disp); + bugaddr =3D entry_addr + bug_disp; + + if (bugaddr < fe_alt_start) + continue; + if (bugaddr >=3D fe_alt_end) + continue; + + return -1; + } + return 0; +} diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c index b780df513715..5ee0880baec5 100644 --- a/tools/objtool/builtin-check.c +++ b/tools/objtool/builtin-check.c @@ -78,6 +78,7 @@ static const struct option check_options[] =3D { OPT_STRING_OPTARG('d', "disas", &opts.disas, "function-pattern", "disass= emble functions", "*"), OPT_CALLBACK_OPTARG('h', "hacks", NULL, NULL, "jump_label,noinstr,skylake= ", "patch toolchain bugs/limitations", parse_hacks), OPT_BOOLEAN('i', "ibt", &opts.ibt, "validate and annotate IBT"), + OPT_BOOLEAN('f', "ftr-fixup", &opts.ftr_fixup, "feature fixup"), OPT_BOOLEAN('m', "mcount", &opts.mcount, "annotate mcount/fentry calls f= or ftrace"), OPT_BOOLEAN(0, "noabs", &opts.noabs, "reject absolute references in all= ocatable sections"), OPT_BOOLEAN('n', "noinstr", &opts.noinstr, "validate noinstr rules"), @@ -181,6 +182,7 @@ static bool opts_valid(void) opts.disas || opts.hack_jump_label || opts.hack_noinstr || + opts.ftr_fixup || opts.ibt || opts.mcount || opts.noabs || diff --git a/tools/objtool/check.c b/tools/objtool/check.c index b6765e876507..8cb55fe6e1dc 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -1636,9 +1636,11 @@ static int add_jump_destinations(struct objtool_file= *file) dest_off =3D=3D func->offset + func->len) continue; =20 + ERROR_INSN(insn, "can't find jump dest instruction at %s", - offstr(dest_sec, dest_off)); + offstr(dest_sec, dest_off)); return -1; + } =20 if (!dest_sym || is_sec_sym(dest_sym)) { @@ -5021,6 +5023,31 @@ int check(struct objtool_file *file) if (!nr_insns) goto out; =20 + if (opts.ftr_fixup) { + ret =3D process_alt_data(file); + if (ret < 0) + return ret; + + ret =3D process_fixup_entries(file); + if (ret < 0) + return ret; + + check_and_flatten_fixup_entries(); + + ret =3D process_exception_entries(file); + if (ret < 0) + return ret; + + ret =3D process_bug_entries(file); + if (ret < 0) + return ret; + + ret =3D process_alt_relocations(file); + if (ret < 0) + return ret; + } + + if (opts.retpoline) warnings +=3D validate_retpoline(file); =20 diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index 2ffe3ebfbe37..2ca2a4e4b92e 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -1156,6 +1156,7 @@ struct elf *elf_open_read(const char *name, int flags) cmd =3D ELF_C_WRITE; =20 elf->elf =3D elf_begin(elf->fd, cmd, NULL); + if (!elf->elf) { ERROR_ELF("elf_begin"); goto err; diff --git a/tools/objtool/include/objtool/builtin.h b/tools/objtool/includ= e/objtool/builtin.h index b9e229ed4dc0..3578ec174a59 100644 --- a/tools/objtool/include/objtool/builtin.h +++ b/tools/objtool/include/objtool/builtin.h @@ -13,6 +13,7 @@ struct opts { bool checksum; bool dump_orc; bool hack_jump_label; + bool ftr_fixup; bool hack_noinstr; bool hack_skylake; bool ibt; diff --git a/tools/objtool/include/objtool/special.h b/tools/objtool/includ= e/objtool/special.h index 121c3761899c..0a5efbfa29d0 100644 --- a/tools/objtool/include/objtool/special.h +++ b/tools/objtool/include/objtool/special.h @@ -12,6 +12,41 @@ =20 #define C_JUMP_TABLE_SECTION ".data.rel.ro.c_jump_table" =20 +#define BRANCH_SET_LINK 0x1 +#define BRANCH_ABSOLUTE 0x2 + +struct bug_entry { + int32_t bug_addr_disp; + int32_t file_disp; + uint16_t line; + uint16_t flags; +}; + +struct exception_entry { + int32_t insn; + int32_t fixup; +}; + +struct fixup_entry_64 { + uint64_t mask; + uint64_t value; + uint64_t start_off; + uint64_t end_off; + uint64_t alt_start_off; + uint64_t alt_end_off; +}; + +#define fixup_entry fixup_entry_64 + +struct fixup_entry_32 { + uint32_t mask; + uint32_t value; + uint32_t start_off; + uint32_t end_off; + uint32_t alt_start_off; + uint32_t alt_end_off; +}; + struct special_alt { struct list_head list; =20 @@ -28,6 +63,8 @@ struct special_alt { unsigned int orig_len, new_len, feature; /* group only */ }; =20 +int process_alt_data(struct objtool_file *file); + int special_get_alts(struct elf *elf, struct list_head *alts); =20 void arch_handle_alternative(struct special_alt *alt); @@ -40,4 +77,23 @@ struct reloc *arch_find_switch_table(struct objtool_file= *file, unsigned long *table_size); const char *arch_cpu_feature_name(int feature_number); =20 +int process_fixup_entries(struct objtool_file *file); + +void check_and_flatten_fixup_entries(void); + +int process_exception_entries(struct objtool_file *file); + +int process_bug_entries(struct objtool_file *file); + +int process_alt_relocations(struct objtool_file *file); + +struct fixup_entry *find_fe_altaddr(uint64_t addr); + +int set_uncond_branch_target(uint32_t *insn, + const uint64_t addr, uint64_t target); + +int set_cond_branch_target(uint32_t *insn, + const uint64_t addr, uint64_t target); + + #endif /* _SPECIAL_H */ diff --git a/tools/objtool/special.c b/tools/objtool/special.c index 2a533afbc69a..43b60bf789dd 100644 --- a/tools/objtool/special.c +++ b/tools/objtool/special.c @@ -167,3 +167,32 @@ int special_get_alts(struct elf *elf, struct list_head= *alts) =20 return 0; } + +int __weak process_alt_data(struct objtool_file *file) +{ + return 0; +} + +int __weak process_fixup_entries(struct objtool_file *file) +{ + return 0; +} + +void __weak check_and_flatten_fixup_entries(void) +{ +} + +int __weak process_exception_entries(struct objtool_file *file) +{ + return 0; +} + +int __weak process_bug_entries(struct objtool_file *file) +{ + return 0; +} + +int __weak process_alt_relocations(struct objtool_file *file) +{ + return 0; +} --=20 2.43.0 From nobody Sat Jun 13 23:58:03 2026 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BD73B30C632; Tue, 5 May 2026 08:47:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.156.1 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777970850; cv=none; b=kNb08k1VnGDTnykw98KSqBoNuTCPSsXHrECuSKKtSXLJnq2xYjPNubFPd/RNm1JjgyLPL3q9dh09R8ZcNlbgoKgde1mh+1mj5dbH/y6XsAkmoMX/XeljtW0yT9ivnmbMEPCL3LA4sd97WuROsClawo6y2r2wos2uGFlNUmjVYMk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777970850; c=relaxed/simple; bh=fPKKzU9vG1Nvp7bbrzXYHRuFZ9Acv+Gz0u0Vy/TYz5w=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=X7/ARIYyPHvrk+b4O67jn8jrpdStofTtS5jp1iAQKUY3eJ+32ZdrnhZ50LrUWry++Jyig4oadENQp0+Qx5x2fZspOp3lurcDtSEYqEEur0FAZc+tmQZBVV5DJN6HJyNf2SXx1MouGzpCnMlzpmaJ7tAif1SawhvMamOlwz121I4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=g3eI3KOR; arc=none smtp.client-ip=148.163.156.1 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.b="g3eI3KOR" 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 645681dc2606962; Tue, 5 May 2026 08:46:58 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h= content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=BjlYOPVSncnM2b0yF WrLhG8f6G8kzasvWSJy/dQk/dA=; b=g3eI3KORvjcquC5V+tDgVHeMVNw6mkFl9 VpkEtC0JOZXbEDvaKj66DT4n3DYKhGv86OGREUrIgQJ+m32Ol9oR/D5SitkvmwTm Sy1U06fPeQ7iHH42egcjUP2Y+aDy4Hr3nFywrbijbl8uuZ++PYt8Gr6H4GKrLaJd pJlVOu7wiy6PF1/oODo+8rN3nMWEEAr/ZPy4oniXJ9C8lED/MlkC3B3hkYvOeqbX tF7YYJQWiwj+kPI8olonnoahORiliFufmqWio+Zb21LmoGpCJToFQpnH07apFMnN qQLiFn2E4MXXPqKUsL06vqElC9ZxyN+v8DvSvgKnxDd094/WBDwNA== Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4dw9v7asc6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 05 May 2026 08:46:57 +0000 (GMT) Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.18.1.7/8.18.1.7) with ESMTP id 6458dUDT018333; Tue, 5 May 2026 08:46:56 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 4dwx9y8hhg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 05 May 2026 08:46:56 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6458kr9g51839240 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 5 May 2026 08:46:53 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0A2232004E; Tue, 5 May 2026 08:46:53 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C187520043; Tue, 5 May 2026 08:46:46 +0000 (GMT) Received: from li-2fa77bcc-2701-11b2-a85c-cd621c23b6bd.bl1-in.ibm.com (unknown [9.123.13.4]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 5 May 2026 08:46:46 +0000 (GMT) From: Sathvika Vasireddy To: nathan@kernel.org, nsc@kernel.org, maddy@linux.ibm.com, mpe@ellerman.id.au, npiggin@gmail.com, chleroy@kernel.org, jpoimboe@kernel.org, peterz@infradead.org, ojeda@kernel.org, masahiroy@kernel.org, lossin@kernel.org, tamird@kernel.org, thomas.weissschuh@linutronix.de, rostedt@goodmis.org, ihor.solodrai@linux.dev, thuth@redhat.com, pmladek@suse.com, aliceryhl@google.com, elver@google.com, kees@kernel.org, legion@kernel.org, ardb@kernel.org, yuxuan.zuo@outlook.com, alexghiti@rivosinc.com, alexandre.chartre@oracle.com, bp@alien8.de, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, sv@linux.ibm.com Subject: [PATCH v1 2/6] objtool: Set ELF_F_LAYOUT flag to preserve vmlinux segment layout Date: Tue, 5 May 2026 14:16:24 +0530 Message-ID: <20260505084628.17940-3-sv@linux.ibm.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260505084628.17940-1-sv@linux.ibm.com> References: <20260505084628.17940-1-sv@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNTA1MDA3OSBTYWx0ZWRfX4WjxiSb3gXtV T6XkrVuhnTwldORwUXn9tY9wcOajEDd6B0cRceHQvNGGTiqaoh8N1wu17o3rziIR+yCAe9lO5nV iO2Ky0m7j1S8DzHTDQ+zUnte0bocj/Zt7zB+VJN0NOAL4eF3Mr3srEhd14/Rrni+me1zz23H4/i zAiDST+0fHXzvfQomd9UMk+MrtwAPnOp26TN0p0QAsLEhXM2Nz80pcB003L48kQPnXAORlNIDkP tM6XGPFOYY0rd7jS4QbeA1kMUEFwJp5W+n19RMjfhzcGnvQk7hetF2crFP3cN3sQfE23sfH2bh9 msHWZt37eQ1RX1/uELBfWKbPbV5XiFebrRd4e18vtuTgnLUSOxD6ISxE7tRGQosyndVaVr6T/ns PVNpNJTSM5bAEkelM8FAw6T+Uq6eCCC/rMZ/3h+WKnGH4GYmJKLmOaWaVoutRhsVYDAkrTlZcy7 gwNmJTfm1jRWMFKFWpQ== X-Proofpoint-GUID: FbpAoVpZbO6Me2AALh09RV_gioLPNohg X-Proofpoint-ORIG-GUID: ukP5QapWDPuwWKRAvCoMZDxpgrMzUfCG X-Authority-Analysis: v=2.4 cv=eu/vCIpX c=1 sm=1 tr=0 ts=69f9ae82 cx=c_pps a=aDMHemPKRhS1OARIsFnwRA==:117 a=aDMHemPKRhS1OARIsFnwRA==:17 a=NGcC8JguVDcA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=iQ6ETzBq9ecOQQE5vZCe:22 a=VnNF1IyMAAAA:8 a=dGyo4u3eiptz4-Zsc8UA:9 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-05-05_02,2026-04-30_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 phishscore=0 lowpriorityscore=0 clxscore=1015 adultscore=0 suspectscore=0 malwarescore=0 bulkscore=0 impostorscore=0 spamscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2604200000 definitions=main-2605050079 Content-Type: text/plain; charset="utf-8" When objtool writes changes back to vmlinux with --ftr-fixup --link, libelf recalculates the file layout and inserts padding between sections. This corrupts the ELF segment structure, causing kexec to fail with: ELF Note corrupted ! Cannot determine the file type of vmlinux This happens because libelf's default behavior assumes it can freely rearrange section offsets when writing, which breaks the carefully constructed vmlinux layout produced by the linker. Set ELF_F_LAYOUT after elf_begin() to instruct libelf that the application is responsible for the file layout. This prevents libelf from inserting padding or repositioning sections while still allowing data modifications to be written back. Signed-off-by: Sathvika Vasireddy --- tools/objtool/elf.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index 2ca2a4e4b92e..8752cec5e818 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -1162,6 +1162,9 @@ struct elf *elf_open_read(const char *name, int flags) goto err; } =20 + if (opts.ftr_fixup) + elf_flagelf(elf->elf, ELF_C_SET, ELF_F_LAYOUT); + if (!gelf_getehdr(elf->elf, &elf->ehdr)) { ERROR_ELF("gelf_getehdr"); goto err; --=20 2.43.0 From nobody Sat Jun 13 23:58:03 2026 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8D1D726F476; Tue, 5 May 2026 08:47:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777970864; cv=none; b=ip42udjXlE+/2VJs1V3CQFWvfOUoe8bo8JljAJLh7lmLWlSFBX5iG42WCWnSxUMxG4QazdtkpfRkxKob7B5EzfsQ7rSM7D1pl6HvKOwpL1TYt04GBnC6vNH25GI6AuDdiho5H5Ryv8/jjg8Kow6bc2ldtI1a/nBbMSQQ2efdkTk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777970864; c=relaxed/simple; bh=MR30btQ1qvhndTWwiWd7A6CfyvtCTBZZas3qPiG9ugw=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Cra3KKOHwUQy+jkwN5v3XWSUmClGmSomiTjfHNzMRmHs06vjM4hUbt13UsI6M19BI9rGCXY3Wt9bO0z4qbw4OPwlUsvv7llnI6elQCm6QQ2rHZG9V211qGVblM3w1Q3dfEc6vbzHtEnm8zaSiON9rRWc02a0JgFTjgtWvx22Uaw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=TWiD9N/P; arc=none smtp.client-ip=148.163.158.5 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.b="TWiD9N/P" Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 644JpBdb1430407; Tue, 5 May 2026 08:47:06 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h= content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=hGJh2f4c0LNFYVx89 4cgxHv+USKOgC1gectplGa8nBc=; b=TWiD9N/Pn0Zm3VDNJ8Fn/okMnfvB1ihGg LCTylcO9z92uHZYzPwrtPhtzj4QsRZTUjxA4XgNghhcF0f5nNPK4S4truf6/h3oa rY710tU4nml6a7UE9wyC8zTWsW/Tkw4WI1ZnXT7Qhb9/vlMS9n+jEKNRaZHPkD8e 6pjklGHQEmyexhCSEdhfFvgytCH2W6dM+w37G+pgCWHHmRc23wfWO9abBWtIBJeW mpV3zT5DE6EiAgrZeTWovgBcc7HW+gYkTwn1Sn3L9ea+zmsrCzBupaULB2lqyBYh m4hSUPnbcPX8kExB/4uMnq57oBzcA03Nf00llkC8iH6QiXgEFONdA== Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4dw9xxjdf4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 05 May 2026 08:47:05 +0000 (GMT) Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.18.1.7/8.18.1.7) with ESMTP id 6458OaL3020973; Tue, 5 May 2026 08:47:04 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4dwvkjrrvk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 05 May 2026 08:47:04 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6458l0dg52625690 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 5 May 2026 08:47:00 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 973A82005A; Tue, 5 May 2026 08:47:00 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D79682004B; Tue, 5 May 2026 08:46:54 +0000 (GMT) Received: from li-2fa77bcc-2701-11b2-a85c-cd621c23b6bd.bl1-in.ibm.com (unknown [9.123.13.4]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 5 May 2026 08:46:54 +0000 (GMT) From: Sathvika Vasireddy To: nathan@kernel.org, nsc@kernel.org, maddy@linux.ibm.com, mpe@ellerman.id.au, npiggin@gmail.com, chleroy@kernel.org, jpoimboe@kernel.org, peterz@infradead.org, ojeda@kernel.org, masahiroy@kernel.org, lossin@kernel.org, tamird@kernel.org, thomas.weissschuh@linutronix.de, rostedt@goodmis.org, ihor.solodrai@linux.dev, thuth@redhat.com, pmladek@suse.com, aliceryhl@google.com, elver@google.com, kees@kernel.org, legion@kernel.org, ardb@kernel.org, yuxuan.zuo@outlook.com, alexghiti@rivosinc.com, alexandre.chartre@oracle.com, bp@alien8.de, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, sv@linux.ibm.com Subject: [PATCH v1 3/6] objtool: Fix "can't find starting instruction" warnings on vmlinux Date: Tue, 5 May 2026 14:16:25 +0530 Message-ID: <20260505084628.17940-4-sv@linux.ibm.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260505084628.17940-1-sv@linux.ibm.com> References: <20260505084628.17940-1-sv@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNTA1MDA3OSBTYWx0ZWRfX7vQaoCu9debt 16/NsQoQpYxjxaGQsnkT8wgPhfMGrWrEu+uDtT21yOz01mQY259DSIQZqNzT+941jrHFT8+3kP6 VXIkTBOvMyRoAjKhwUhBmaisnRS0JwCQLI1M8RPA4IdgbJqGUpY1nn/beQJipJ+COq9UvblyeaH 2u3wPn5jlMOEkbzW+oGiSa5QBC1lMA/DIOyzI8nhPIss1s7KdVOSt0qsB6ba9xV2wneM5JdI3dM x937HTSFfp4ue9385IFCsEMDxrupR3lTZCdBrjEt/vPGu3pcLkOU/R2Ht39zX9NaL8/A+tGMdgp 4YTSOXtoi7OxIVr3gp/Yz6s4KKTFh/WNUnUsQzg67LCphNIHZbBnr80wXZ3XPzweR6vD27GyluE 3IiBl127mjYq92tQsoX2RLtDp0yXYD98f8svHSAHO3fCYpzYixup6Df/aAB22MaMHUFnAxbKg35 Qdr1ly9AKD5Btv59eyQ== X-Proofpoint-ORIG-GUID: HBXI0MPVD3JpW_3ioLPeEBYqDKWCjLBo X-Proofpoint-GUID: R61SQUfzhjeWGwAFZqAdlgwYkUYuwUG9 X-Authority-Analysis: v=2.4 cv=ctWrVV4i c=1 sm=1 tr=0 ts=69f9ae89 cx=c_pps a=GFwsV6G8L6GxiO2Y/PsHdQ==:117 a=GFwsV6G8L6GxiO2Y/PsHdQ==:17 a=NGcC8JguVDcA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=V8glGbnc2Ofi9Qvn3v5h:22 a=VnNF1IyMAAAA:8 a=0ZCZ8pRhY7ETOmrAYN0A:9 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-05-05_02,2026-04-30_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 lowpriorityscore=0 adultscore=0 clxscore=1015 suspectscore=0 impostorscore=0 spamscore=0 malwarescore=0 phishscore=0 bulkscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2604200000 definitions=main-2605050079 Content-Type: text/plain; charset="utf-8" Objtool throws a lot of can't find starting instruction warnings when run on vmlinux with --ftr-fixup option. These warnings are seen because find_insn() function looks for instructions at offsets that are relative to the start of the section. In case of individual object files (.o), there are no can't find starting instruction warnings seen because the actual offset associated with an instruction is itself a relative offset since the sections start at offset 0x0. However, in case of vmlinux, find_insn() function fails to find instructions at the actual offset associated with an instruction since the sections in vmlinux do not start at offset 0x0. Due to this, find_insn() will look for absolute offset and not the relative offset. This is resulting in a lot of can't find starting instruction warnings when objtool is run on vmlinux. To fix this, pass offset that is relative to the start of the section to find_insn(). find_insn() is also looking for symbols of size 0. But, objtool does not store empty STT_NOTYPE symbols in the rbtree. Due to this, for empty symbols, objtool is throwing can't find starting instruction warnings. Fix this by ignoring symbols that are of size 0 since objtool does not add them to the rbtree. Signed-off-by: Sathvika Vasireddy --- tools/objtool/check.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 8cb55fe6e1dc..f3501b149829 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -412,7 +412,7 @@ static int decode_instructions(struct objtool_file *fil= e) { struct section *sec; struct symbol *func; - unsigned long offset; + unsigned long offset, func_off; struct instruction *insn; =20 for_each_sec(file->elf, sec) { @@ -494,17 +494,25 @@ static int decode_instructions(struct objtool_file *f= ile) if (func->embedded_insn || func->alias !=3D func) continue; =20 - if (!find_insn(file, sec, func->offset)) { + if (func->len =3D=3D 0 && is_notype_sym(func)) + continue; + + func_off =3D opts.ftr_fixup ? + func->offset - sec->sh.sh_addr : func->offset; + + if (!find_insn(file, sec, func_off)) { ERROR("%s(): can't find starting instruction", func->name); return -1; } =20 - sym_for_each_insn(file, func, insn) { + for (insn =3D find_insn(file, sec, func_off); + insn && insn->offset < func_off + func->len; + insn =3D next_insn_same_sec(file, insn)) { insn->sym =3D func; if (is_func_sym(func) && insn->type =3D=3D INSN_ENDBR && list_empty(&insn->call_node)) { - if (insn->offset =3D=3D func->offset) { + if (insn->offset =3D=3D func_off) { list_add_tail(&insn->call_node, &file->endbr_list); file->nr_endbr++; } else { --=20 2.43.0 From nobody Sat Jun 13 23:58:03 2026 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B3D4F3C6A39; Tue, 5 May 2026 08:47:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777970888; cv=none; b=hqMB5AU/g7WL9e3hwezEtB89Zainu9B47hpZs2AMeZrNXw7kuhnhIl38S+RthFWnNVFPPlekD0nCJBIZkNWGhFbvmpLHC5fNUloyX3WqkzdOmmaJyAWhjwp5/QStYdbO2206CS2UIfFvvZHU6sSi6ty9QRXqSnj5IqwA4neHtHM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777970888; c=relaxed/simple; bh=3rktnoIkXXya+u/8GoNZoQLYEyGo8U+1c1ku44KBkUE=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=o/3R92BFX74u7VHjtg5ZRkKeKaNvMHeLUekUMPVlmvDLAV4X4Pi3nqjmcGJ1z+s7rCNu4Scod20ysNZwTgdCOOIMnCY9TVu2PuoR0IKSZPNVm4uEAw6Hcq+n5fW4SsfWTsB3esppzrrgXHCe2NkYbi5wlSc6QaJJhWCSnvCDqaE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=OknEysb3; arc=none smtp.client-ip=148.163.158.5 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.b="OknEysb3" Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 644Fu4Qr3001038; Tue, 5 May 2026 08:47:13 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h= content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=k+DJ/QKgnsJRWP5aa 3/5HeOk4bQEztdyefO8B9y+e94=; b=OknEysb3PN/f4lhNgazWJGAAsz4GamKkh SJ4NeJnI4VgeYLikfEAbPatwlSSRSd66wRb6g001QJkZW1Hy6OVu9qavb05l2i0g zvylTQdTEATewQ/ZJkpKR0CVYOCRKcu0DOunKnD0K4LE0CdE4MERwM7SbLy4llNh meoVV/tRY9w+dHhFiuezvE84ag/DeJs/jOPcUr7z/ki+8bXEJP9gBp4sji6YlKfQ jI4RVf2GhRW2FqmQUqeQ6E5leFu2G1HhcI1aTx31pNNV2DUE+Smc6c5gZ1A2NlDS FOyCBZWvs9pKqs2TDRuLeu2L9elKA19JX9EFgLlegubr48kfPwbYA== Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4dw9y4jfb6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 05 May 2026 08:47:12 +0000 (GMT) Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.18.1.7/8.18.1.7) with ESMTP id 6458dson030084; Tue, 5 May 2026 08:47:11 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4dww3h0qk7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 05 May 2026 08:47:11 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6458l7ZX51839262 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 5 May 2026 08:47:07 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 759122004B; Tue, 5 May 2026 08:47:07 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9C3DE2004E; Tue, 5 May 2026 08:47:01 +0000 (GMT) Received: from li-2fa77bcc-2701-11b2-a85c-cd621c23b6bd.bl1-in.ibm.com (unknown [9.123.13.4]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 5 May 2026 08:47:01 +0000 (GMT) From: Sathvika Vasireddy To: nathan@kernel.org, nsc@kernel.org, maddy@linux.ibm.com, mpe@ellerman.id.au, npiggin@gmail.com, chleroy@kernel.org, jpoimboe@kernel.org, peterz@infradead.org, ojeda@kernel.org, masahiroy@kernel.org, lossin@kernel.org, tamird@kernel.org, thomas.weissschuh@linutronix.de, rostedt@goodmis.org, ihor.solodrai@linux.dev, thuth@redhat.com, pmladek@suse.com, aliceryhl@google.com, elver@google.com, kees@kernel.org, legion@kernel.org, ardb@kernel.org, yuxuan.zuo@outlook.com, alexghiti@rivosinc.com, alexandre.chartre@oracle.com, bp@alien8.de, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, sv@linux.ibm.com Subject: [PATCH v1 4/6] objtool/powerpc: Skip jump destination analysis and unnanotated intra-function call warnings for --ftr-fixup Date: Tue, 5 May 2026 14:16:26 +0530 Message-ID: <20260505084628.17940-5-sv@linux.ibm.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260505084628.17940-1-sv@linux.ibm.com> References: <20260505084628.17940-1-sv@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNTA1MDA3OSBTYWx0ZWRfX6qvbi3Gfi4tO 2Q1e/6qX0hywOVz01hfLDmgNYwvWMBYFkbRAmn+X6zqN6sI/GTGrml+X6hNNLEzsUyX0e3m31+c nX807DfHGfdKtx4mjjF9/V/wRzVfZ5So8vpFyjg04H1k/zRXV2nBKKVogx/P26si2hOyvAmgsvN 6KwI26ivTbRjA3XqiE1yzGf3V1HIH+bjtJWvBP+IYtM9CzVbjZbxz8fc8DCiSTSDHJaCpkTANKw t551eHkVsYPBJO/d0GI09IToJh3D54NyiDUMHHdoKOMwxmixR116KO156PwKmCd1vmFfVjQg5gb EQfzhic/c6+Y/cVQGJgZITkQwSUF/ty4Nk1KwbxF6OVXtEWMoQVZKgcdLOMKCMG1L0xJZPvPVnA xgREkSjNBGJNRQVPHlnqdc6eXVHpCEuTp2i8P3krMa+/u/Pkk/xHJSQCWrsBThh/Py+YiKhYiJ/ HkSkf2qCJpEKJriGTSg== X-Authority-Analysis: v=2.4 cv=J4GaKgnS c=1 sm=1 tr=0 ts=69f9ae90 cx=c_pps a=3Bg1Hr4SwmMryq2xdFQyZA==:117 a=3Bg1Hr4SwmMryq2xdFQyZA==:17 a=NGcC8JguVDcA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=RzCfie-kr_QcCd8fBx8p:22 a=VnNF1IyMAAAA:8 a=8-sZ6GPjQPUUxCpKAYwA:9 X-Proofpoint-GUID: Vz2DgZck83xZqSxidr6EDdXScLdcBd5h X-Proofpoint-ORIG-GUID: 18Uy7SmtzprzGPQbqVRJ2gJ5ZJcGmxA7 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-05-05_02,2026-04-30_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 clxscore=1015 malwarescore=0 bulkscore=0 suspectscore=0 priorityscore=1501 spamscore=0 phishscore=0 adultscore=0 lowpriorityscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2604200000 definitions=main-2605050079 Content-Type: text/plain; charset="utf-8" Objtool is throwing unannotated intra-function call warnings when run on vmlinux with --ftr-fixup option. One such example: vmlinux: warning: objtool: .text+0x3d94: unannotated intra-function call .text + 0x3d94 =3D c000000000008000 + 3d94 =3D c0000000000081d4 c0000000000081d4: 45 24 02 48 bl c00000000002a618 c00000000002a610 : c00000000002a610: 0e 01 4c 3c addis r2,r12,270 c00000000002a610: R_PPC64_REL16_HA .TOC. c00000000002a614: f0 6c 42 38 addi r2,r2,27888 c00000000002a614: R_PPC64_REL16_LO .TOC.+0x4 c00000000002a618: a6 02 08 7c mflr r0 This is happening because we should be looking for destination symbols that are at absolute offsets instead of relative offsets. After fixing dest_off to point to absolute offset, there are still a lot of these warnings shown. In the above example, objtool is computing the destination offset to be c00000000002a618, which points to a completely different instruction. find_call_destination() is looking for this offset and failing. Instead, we should be looking for destination offset c00000000002a610 which points to system_reset_exception function. Even after fixing the way destination offset is computed, and after looking for dest_off - 0x8 in cases where the original offset is not found, there are still a lot of unannotated intra-function call warnings generated. This is due to symbols that are not properly annotated. So, for now, as a hack to curb these warnings, do not emit unannotated intra-function call warnings when objtool is run with --ftr-fixup option. Skip add_jump_destinations() and suppress intra-function call errors in --ftr-fixup mode. The feature fixup pass only needs fixup entry tables, relocation entries from .__ftr_alternates.text, and elf_write_insn() to patch branch offsets. Signed-off-by: Sathvika Vasireddy --- tools/objtool/check.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index f3501b149829..14644ca36d73 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -1644,7 +1644,6 @@ static int add_jump_destinations(struct objtool_file = *file) dest_off =3D=3D func->offset + func->len) continue; =20 - ERROR_INSN(insn, "can't find jump dest instruction at %s", offstr(dest_sec, dest_off)); return -1; @@ -1727,8 +1726,11 @@ static int add_call_destinations(struct objtool_file= *file) continue; =20 if (!insn_call_dest(insn)) { - ERROR_INSN(insn, "unannotated intra-function call"); - return -1; + if (!opts.ftr_fixup) { + ERROR_INSN(insn, "unannotated intra-function call"); + return -1; + } + continue; } =20 if (func && !is_func_sym(insn_call_dest(insn))) { @@ -2681,8 +2683,10 @@ static int decode_sections(struct objtool_file *file) return -1; } =20 - if (add_jump_destinations(file)) - return -1; + if (!opts.ftr_fixup) { + if (add_jump_destinations(file)) + return -1; + } =20 /* * Must be before add_call_destination(); it changes INSN_CALL to --=20 2.43.0 From nobody Sat Jun 13 23:58:03 2026 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C98E8362120; Tue, 5 May 2026 08:47:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777970873; cv=none; b=taaCaOgYA1fHPP1NZJaG3VdRl8P0YMmDfbPdNi+uEI5p8m+H14obebaeL36kJk2jieSjKnZOxNVCqJiMqX2FSTs9mHRDORgKfJTQulIhxfbYT+mNCraCh7bOAturricRUcmP9ujAuSbGSoA/KavJI4nHbNqy4fx6q5Mk9Wt+jc4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777970873; c=relaxed/simple; bh=AdvkRDt5s54uVgAjz87SQAq4sT62kN7HUSUQtCj9CqM=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FvG3kIuMqDmU6/5Ue0J025DrMzWWCi0AsusSFrkA8jMBXTWs3tzapdBjlgTWQQMdgZjpQuFMWsQ+A8knrFWe24NKZtcA1Yx9BAbXYCRDv/g3ZpufvfVBFtvh4g7iZLQo7vi1MhITtYeu+VyYLRhXzQxZyRl5Je+lbNJc8JQYaEU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=K7LpyZe2; arc=none smtp.client-ip=148.163.158.5 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.b="K7LpyZe2" Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 644NDIGT2080466; Tue, 5 May 2026 08:47:19 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h= content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=4spkt1jg5/bU5I7bc LaEF/hABIhrs79MmG3fYK+3pnw=; b=K7LpyZe2BgmZvtXdFXxjGw/stPzla9VpF veuq7mOe8lV1rN3BS5KzEFg+5U3XHZCQef6vmeyu0AqVb2ZkZkCn9k6HekdhJMTQ bSCtR0mCfgd3QLIBspYwVT0vhwiwl6wWIGGBisbzJmRE1YPUq9equ1UqtXQisEX8 QLWKOzXne5Ir0XAseCm89V1eV4b2qg39d/kgq+e8Rqv3aOo8XCgJIelC9SQhYyTL l7E2YPMky1InH0TOb+kEo+FSuCFf33+438uZzSmUSCwMRl0s7FLkQt6kZuNuNbeF o+KFpmAAhzCJf9Cds3j5RDkSluJzRzTYwHnqBpG18YuEj+NXfD4ZQ== Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4dw9xxjdg1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 05 May 2026 08:47:19 +0000 (GMT) Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.18.1.7/8.18.1.7) with ESMTP id 6458dPUV030500; Tue, 5 May 2026 08:47:18 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4dwuyw0vye-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 05 May 2026 08:47:18 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6458lEF342533334 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 5 May 2026 08:47:14 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 39F8C2004F; Tue, 5 May 2026 08:47:14 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 615ED2004B; Tue, 5 May 2026 08:47:08 +0000 (GMT) Received: from li-2fa77bcc-2701-11b2-a85c-cd621c23b6bd.bl1-in.ibm.com (unknown [9.123.13.4]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 5 May 2026 08:47:08 +0000 (GMT) From: Sathvika Vasireddy To: nathan@kernel.org, nsc@kernel.org, maddy@linux.ibm.com, mpe@ellerman.id.au, npiggin@gmail.com, chleroy@kernel.org, jpoimboe@kernel.org, peterz@infradead.org, ojeda@kernel.org, masahiroy@kernel.org, lossin@kernel.org, tamird@kernel.org, thomas.weissschuh@linutronix.de, rostedt@goodmis.org, ihor.solodrai@linux.dev, thuth@redhat.com, pmladek@suse.com, aliceryhl@google.com, elver@google.com, kees@kernel.org, legion@kernel.org, ardb@kernel.org, yuxuan.zuo@outlook.com, alexghiti@rivosinc.com, alexandre.chartre@oracle.com, bp@alien8.de, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, sv@linux.ibm.com Subject: [PATCH v1 5/6] kbuild: Add objtool integration for PowerPC feature fixups Date: Tue, 5 May 2026 14:16:27 +0530 Message-ID: <20260505084628.17940-6-sv@linux.ibm.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260505084628.17940-1-sv@linux.ibm.com> References: <20260505084628.17940-1-sv@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNTA1MDA3OSBTYWx0ZWRfXw4clIekf2zU5 tl2yuTx8xdFPTcA2m968eoLvCFIDNZn/yAG1ldEB79sTgJfrNCr0rOGM0cjTTQa6Os4vf1Qgx+j VjnaRpmCtszxqitq4HV51hPV9ejZpxJagDtaLzOSwczH8RYSNyuZ44uoO+oIJXmumJPLH6T86e2 RZ9m8hdyZ6BmJmMd6UCtWQqSzecYQoaNZkVSYjwSyOOIxdROihI5yyyhDg+KMNXcJlZ1RkfnE5Q x1vetrp8BacC5REkP3HEl+Bsy34FBmkovWm7YvL68INZC+ifkK4wk1QNr4ViyBxm+uPcnVwJS5z aQ/pahTFkkX7JZoddAkHZ71qA9eHzfJRTQwErWajDyvQzCX3GgCcmVfl0BScMd9RITPIfYc0yij Jgm22zXOcobCGfINGKKxW/1GCYnN9JEfNKfdXNzEArr5zQS+v4ZUA5cHfKuG7Anyv9zmDinJv/U r3tGYgICEP/gpvRwM8g== X-Proofpoint-ORIG-GUID: Z7cqhmyMOoiJMxjm3OfMv1vC4h2CzN55 X-Proofpoint-GUID: 3t84d6iLD2PUGGdH1yCve10RJv9vnqYC X-Authority-Analysis: v=2.4 cv=ctWrVV4i c=1 sm=1 tr=0 ts=69f9ae97 cx=c_pps a=5BHTudwdYE3Te8bg5FgnPg==:117 a=5BHTudwdYE3Te8bg5FgnPg==:17 a=NGcC8JguVDcA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=V8glGbnc2Ofi9Qvn3v5h:22 a=VwQbUJbxAAAA:8 a=VnNF1IyMAAAA:8 a=k1iL6ZPSiERSBASioQUA:9 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-05-05_02,2026-04-30_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 lowpriorityscore=0 adultscore=0 clxscore=1015 suspectscore=0 impostorscore=0 spamscore=0 malwarescore=0 phishscore=0 bulkscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2604200000 definitions=main-2605050079 Content-Type: text/plain; charset="utf-8" Add build system support for PowerPC feature fixup processing: - Add HAVE_OBJTOOL_FTR_FIXUP config option for architectures that support build-time feature fixup processing - Integrate objtool feature fixup processing into vmlinux build Suggested-by: Masahiro Yamada Signed-off-by: Sathvika Vasireddy Acked-by: Nicolas Schier # kbuild --- Makefile | 7 +++++++ scripts/Makefile.lib | 4 ++-- scripts/Makefile.vmlinux | 3 ++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 6b1d9fb1a6b4..f9a990036f3f 100644 --- a/Makefile +++ b/Makefile @@ -1478,6 +1478,13 @@ ifdef CONFIG_OBJTOOL prepare: tools/objtool endif =20 +# CONFIG_OBJTOOL and CONFIG_HAVE_OBJTOOL_FTR_FIXUP are unrelated, separate +# options. It was integrated in objtool in order to borrow the elf parser, +# but this is different from how the other objtool commands are used. +ifdef CONFIG_HAVE_OBJTOOL_FTR_FIXUP +prepare: tools/objtool +endif + ifdef CONFIG_BPF ifdef CONFIG_DEBUG_INFO_BTF prepare: tools/bpf/resolve_btfids diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index 0718e39cedda..fa72619e5bb0 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -179,10 +179,10 @@ cpp_flags =3D -Wp,-MMD,$(depfile) $(NOSTDINC_FLA= GS) $(LINUXINCLUDE) \ =20 ld_flags =3D $(KBUILD_LDFLAGS) $(ldflags-y) $(LDFLAGS_$(@F)) =20 -ifdef CONFIG_OBJTOOL - objtool :=3D $(objtree)/tools/objtool/objtool =20 +ifdef CONFIG_OBJTOOL + objtool-args-$(CONFIG_HAVE_JUMP_LABEL_HACK) +=3D --hacks=3Djump_label objtool-args-$(CONFIG_HAVE_NOINSTR_HACK) +=3D --hacks=3Dnoinstr objtool-args-$(CONFIG_MITIGATION_CALL_DEPTH_TRACKING) +=3D --hacks=3Dskyla= ke diff --git a/scripts/Makefile.vmlinux b/scripts/Makefile.vmlinux index fcae1e432d9a..a1bef0638ecb 100644 --- a/scripts/Makefile.vmlinux +++ b/scripts/Makefile.vmlinux @@ -65,7 +65,8 @@ ARCH_POSTLINK :=3D $(wildcard $(srctree)/arch/$(SRCARCH)/= Makefile.postlink) # Final link of vmlinux with optional arch pass after final link cmd_link_vmlinux =3D \ $< "$(LD)" "$(KBUILD_LDFLAGS)" "$(LDFLAGS_vmlinux)" "$@"; \ - $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true) + $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true); \ + $(if $(CONFIG_HAVE_OBJTOOL_FTR_FIXUP), $(objtool) --ftr-fixup --link $@, = true) =20 targets +=3D vmlinux.unstripped .vmlinux.export.o vmlinux.unstripped: scripts/link-vmlinux.sh vmlinux.o .vmlinux.export.o $(= KBUILD_LDS) FORCE --=20 2.43.0 From nobody Sat Jun 13 23:58:03 2026 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1CC473A2553; Tue, 5 May 2026 08:47:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777970875; cv=none; b=YHxPf0mX1RnwfZUIYdaw4jlm8dZRTAEx9EZZEd1Tcya22+U8Ee8rV9cwqBg8e7vonudwiPy4ZEORCYZidIRVKA9OyY9r3ROTsdW4wjL1t77LZrwwSXWXV9BhrGnavrDsrQ0um2aloRvvpuM9vtweOm5QsXTVtAa5bQNcBUc79wM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777970875; c=relaxed/simple; bh=a0zdWsXYrpxcV06UP0Vo7QMqva2l+TrCu9XkHlVtNP4=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g3qsMJxD2V3m5LhSwL5572mpaAXxZPgO4sk30w2IRbNvdChBmHX4N+kwXl3HaaWcRBjHSy3GwJmY4C9kPtlKN2ALfT78uSRmwRAOm0gBrCoCbmaqTsVf9D9rKhmXsMTvEEEoxNIkgZGB4QWvqGIL9h6FVWBrYX9W+BshPuT298w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=mOjQRGVk; arc=none smtp.client-ip=148.163.158.5 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.b="mOjQRGVk" Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6450eohI2062528; Tue, 5 May 2026 08:47:26 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h= content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=e5ifK/It/v+dYOWMp DHgwdUgvz/hsigtd85AqACBUto=; b=mOjQRGVkLc/5AbA34NliUi38SQpjCHW0z tL5vC9aHszMe1R/OlSpPEw+vZ5JH/8sYLVuBLRLmCgU49uaEttd4gqzGW/tc5pr+ BG4DfIAEHRLsNdI66Kw7j4telybVpcv7m1awENPQLHcPQ0lp9LrNxRv1KkTEgche UAOAl2piaAChj655RY79R22OY32kk6qv1XwsKRyl61wChVA70aYoeZ8Q86B7l1zf Pa3OHiZfY39GTQxk5haEuM3wGsl7XwL0MgqlGILCa0sYnI5Dk9RMGdEXsyfJUbKI qCnHXaMByc8MBDpkD4GAVNA++Op2JxAYG7fCtA3NUM02DBR0GLUsA== 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 4dw9w6af7f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 05 May 2026 08:47:25 +0000 (GMT) Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.18.1.7/8.18.1.7) with ESMTP id 6458dSZL001389; Tue, 5 May 2026 08:47:24 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 4dwukq8xuw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 05 May 2026 08:47:24 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6458lLGe52625714 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 5 May 2026 08:47:21 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3B34320043; Tue, 5 May 2026 08:47:21 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8A6A92004E; Tue, 5 May 2026 08:47:15 +0000 (GMT) Received: from li-2fa77bcc-2701-11b2-a85c-cd621c23b6bd.bl1-in.ibm.com (unknown [9.123.13.4]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 5 May 2026 08:47:15 +0000 (GMT) From: Sathvika Vasireddy To: nathan@kernel.org, nsc@kernel.org, maddy@linux.ibm.com, mpe@ellerman.id.au, npiggin@gmail.com, chleroy@kernel.org, jpoimboe@kernel.org, peterz@infradead.org, ojeda@kernel.org, masahiroy@kernel.org, lossin@kernel.org, tamird@kernel.org, thomas.weissschuh@linutronix.de, rostedt@goodmis.org, ihor.solodrai@linux.dev, thuth@redhat.com, pmladek@suse.com, aliceryhl@google.com, elver@google.com, kees@kernel.org, legion@kernel.org, ardb@kernel.org, yuxuan.zuo@outlook.com, alexghiti@rivosinc.com, alexandre.chartre@oracle.com, bp@alien8.de, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, sv@linux.ibm.com Subject: [PATCH v1 6/6] powerpc: Enable build-time feature fixup processing by default Date: Tue, 5 May 2026 14:16:28 +0530 Message-ID: <20260505084628.17940-7-sv@linux.ibm.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260505084628.17940-1-sv@linux.ibm.com> References: <20260505084628.17940-1-sv@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Authority-Analysis: v=2.4 cv=XPQAjwhE c=1 sm=1 tr=0 ts=69f9ae9e cx=c_pps a=bLidbwmWQ0KltjZqbj+ezA==:117 a=bLidbwmWQ0KltjZqbj+ezA==:17 a=NGcC8JguVDcA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=Y2IxJ9c9Rs8Kov3niI8_:22 a=CCpqsmhAAAAA:8 a=pGLkceISAAAA:8 a=VnNF1IyMAAAA:8 a=-G-hYi3DffSlC2uomIIA:9 a=O8hF6Hzn-FEA:10 a=ul9cdbp4aOFLsgKbc677:22 X-Proofpoint-ORIG-GUID: DlNH4ux-SCL4XmeyOW_AaBaIfUfhvfa- X-Proofpoint-GUID: yfRL53VgHSJeULy5jQR2p1q42CQHfQSD X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNTA1MDA3OSBTYWx0ZWRfX24wF2iXUa6nD wd1MYPRLKPFTFTYBKhinAzT9rWpFDQhfZkPcLZSnefk6s1DcWxOKuN/jkLbIP/FoOg/9V9/Jf// sVy5TsZq1P+jxkAiLjl3YZdqk6DUH2dtKD47xPjVKikzD6u5RQd+khEUnAgcXgHPBsvuRereWZf b+a3dGUUXmopM+XUJ5Z+QyyALrG7goT2hJXQhfaksnoe3uXwZyxrLkfBedciIlH4dwLcUby4XZ3 YT2bHmGM5hLntvdRvtx9AntyVkvG5SBz+Iv8ghHKHFIEzjAC1cxN/W5JCNijEhmmp48Gw8nYXHS iNxoM8OGc+ErGa0Bsujv29h/MfknodupT0YjVz68UuG2VmtH+PVzf/BjWDFOvEn5q8R0OMG0puV FHfGvdNOcCIUgzpUrFUuLK7YXFualnOCLy4i/un7rdJTbKcMwAheFqjKP3hjpdk1mgw9HAlR2xV h6NtaYoLy3ULpjeHOJw== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-05-05_02,2026-04-30_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 lowpriorityscore=0 suspectscore=0 adultscore=0 spamscore=0 priorityscore=1501 impostorscore=0 phishscore=0 malwarescore=0 clxscore=1015 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2604200000 definitions=main-2605050079 Content-Type: text/plain; charset="utf-8" Enable HAVE_OBJTOOL_FTR_FIXUP by default on PowerPC architecture. - Remove runtime branch translation logic from patch_alt_instruction() - Add --emit-relocs linker flags for post-link fixup processing - Update ftr_alt section attributes to include executable flag - Strip the --emit-relocs relocation sections (.rel*) from the final vmlinux after processing Co-developed-by: Nicholas Piggin Signed-off-by: Nicholas Piggin Signed-off-by: Sathvika Vasireddy --- arch/powerpc/Kconfig | 3 +++ arch/powerpc/Makefile | 5 +++++ arch/powerpc/include/asm/feature-fixups.h | 2 +- arch/powerpc/kernel/vmlinux.lds.S | 8 ++++++-- arch/powerpc/lib/feature-fixups.c | 12 ------------ scripts/Makefile.vmlinux | 8 ++++++-- 6 files changed, 21 insertions(+), 17 deletions(-) diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig index 10240cb80904..6cc10927730d 100644 --- a/arch/powerpc/Kconfig +++ b/arch/powerpc/Kconfig @@ -23,6 +23,9 @@ config 64BIT bool default y if PPC64 =20 +config HAVE_OBJTOOL_FTR_FIXUP + def_bool y + config LIVEPATCH_64 def_bool PPC64 depends on LIVEPATCH diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile index a58b1029592c..8e1dab5f3c9a 100644 --- a/arch/powerpc/Makefile +++ b/arch/powerpc/Makefile @@ -105,6 +105,11 @@ LDFLAGS_vmlinux-$(CONFIG_RELOCATABLE) :=3D -pie --no-d= ynamic-linker LDFLAGS_vmlinux-$(CONFIG_RELOCATABLE) +=3D -z notext LDFLAGS_vmlinux :=3D $(LDFLAGS_vmlinux-y) =20 +# --emit-relocs required for post-link fixup of alternate feature +# text section relocations. +LDFLAGS_vmlinux +=3D --emit-relocs +KBUILD_LDFLAGS_MODULE +=3D --emit-relocs + ifdef CONFIG_PPC64 ifndef CONFIG_PPC_KERNEL_PCREL # -mcmodel=3Dmedium breaks modules because it uses 32bit offsets from diff --git a/arch/powerpc/include/asm/feature-fixups.h b/arch/powerpc/inclu= de/asm/feature-fixups.h index 756a6c694018..d6ae92a292ec 100644 --- a/arch/powerpc/include/asm/feature-fixups.h +++ b/arch/powerpc/include/asm/feature-fixups.h @@ -32,7 +32,7 @@ =20 #define FTR_SECTION_ELSE_NESTED(label) \ label##2: \ - .pushsection __ftr_alt_##label,"a"; \ + .pushsection __ftr_alt_##label, "ax"; \ .align 2; \ label##3: =20 diff --git a/arch/powerpc/kernel/vmlinux.lds.S b/arch/powerpc/kernel/vmlinu= x.lds.S index 8fc11d6565bf..1a2d7c2d32f1 100644 --- a/arch/powerpc/kernel/vmlinux.lds.S +++ b/arch/powerpc/kernel/vmlinux.lds.S @@ -99,8 +99,8 @@ SECTIONS .text : AT(ADDR(.text) - LOAD_OFFSET) { ALIGN_FUNCTION(); #endif - /* careful! __ftr_alt_* sections need to be close to .text */ - *(.text.hot .text.hot.* TEXT_MAIN .text.fixup .text.unlikely .text.unlik= ely.* .fixup __ftr_alt_* .ref.text); + *(.text.hot .text.hot.* TEXT_MAIN .text.fixup .text.unlikely + .text.unlikely.* .fixup .ref.text); *(.tramp.ftrace.text); NOINSTR_TEXT SCHED_TEXT @@ -267,6 +267,10 @@ SECTIONS _einittext =3D .; } :text =20 + .__ftr_alternates.text : AT(ADDR(.__ftr_alternates.text) - LOAD_OFFSET) { + *(__ftr_alt*); + } + /* .exit.text is discarded at runtime, not link time, * to deal with references from __bug_table */ diff --git a/arch/powerpc/lib/feature-fixups.c b/arch/powerpc/lib/feature-f= ixups.c index 587c8cf1230f..269e992b1631 100644 --- a/arch/powerpc/lib/feature-fixups.c +++ b/arch/powerpc/lib/feature-fixups.c @@ -53,22 +53,10 @@ static u32 *calc_addr(struct fixup_entry *fcur, long of= fset) =20 static int patch_alt_instruction(u32 *src, u32 *dest, u32 *alt_start, u32 = *alt_end) { - int err; ppc_inst_t instr; =20 instr =3D ppc_inst_read(src); =20 - if (instr_is_relative_branch(ppc_inst_read(src))) { - u32 *target =3D (u32 *)branch_target(src); - - /* Branch within the section doesn't need translating */ - if (target < alt_start || target > alt_end) { - err =3D translate_branch(&instr, dest, src); - if (err) - return 1; - } - } - raw_patch_instruction(dest, instr); =20 return 0; diff --git a/scripts/Makefile.vmlinux b/scripts/Makefile.vmlinux index a1bef0638ecb..66e5d58a6ce8 100644 --- a/scripts/Makefile.vmlinux +++ b/scripts/Makefile.vmlinux @@ -82,11 +82,15 @@ endif # vmlinux # ------------------------------------------------------------------------= --- =20 +# These configurations require vmlinux.unstripped to be linked with +# '--emit-relocs', which need to be stripped from the final vmlinux. +uses-emit-relocs :=3D $(or $(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS),$(CONFIG_HA= VE_OBJTOOL_FTR_FIXUP)) + remove-section-y :=3D .modinfo -remove-section-$(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS) +=3D '.rel*' '!.rel*.dy= n' +remove-section-$(uses-emit-relocs) +=3D '.rel*' '!.rel*.dy= n' # for compatibility with binutils < 2.32 # https://sourceware.org/git/?p=3Dbinutils-gdb.git;a=3Dcommit;h=3Dc12d9fa2= afe7abcbe407a00e15719e1a1350c2a7 -remove-section-$(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS) +=3D '.rel.*' +remove-section-$(uses-emit-relocs) +=3D '.rel.*' =20 remove-symbols :=3D -w --strip-unneeded-symbol=3D'__mod_device_table__*' =20 --=20 2.43.0