From nobody Thu Apr 2 09:33:38 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 9183921E091; Mon, 16 Mar 2026 06:26:07 +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=1773642369; cv=none; b=XFdsHPhtD6pOtW0X7opO4Lc0ipQ4mmkPekWtEBL3fS366oC91vozrhNbM2SPNtDoAmBMn+pprZibpnJO0XKOGUq7lMewJLy77Fx8iDw7dhy8fqoqRuIyO56FF8LcxJOOC/RTYthY93IgEJsUcUZ0xbvjsoFaf4az7PuIvV8qgm4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773642369; c=relaxed/simple; bh=edMPyNZLVz3yRp3FqI8rXaomDY1JV83h5VLpzVg/gZI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FY3LbagUEyQ6sFuhHWKTvbIOr486+Ju9H+1LY0YA9fkRA2reHpyUJ/dNWGUYOiwGkvnGPd+XWv/3FiHUhX/LAg2lAYBKUEvKgnFzQQsFyX9LUt58fbgdYWoWQiJXO9F7YTFe7ZpnKybwyHSym6GP5E5t9B5tpdCzQaI9WFP9I3M= 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=TC6/YieA; 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="TC6/YieA" 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 62FFEgPC412294; Mon, 16 Mar 2026 06:25:44 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=Az7Lntm9S4jpjMq7i E1sFMFcNGRY+CSXdTw9wRxxGGk=; b=TC6/YieAXu+IcGvPcR3vHadBD4oZU6RqD BxxuFX3cesZ4EQPQJ208kFWCMKOKlMXazjGnj9BTalx5bGHZojTzlDkiHTjDtDS4 Vd1Gm0W1wOUtCw/Zd98DMMFV8yaQFIPHy9gv3ArSXBXgTgZSJ822K3jD38HjGWha iDrJxY48iiT1O8Iik43rDDsadMt15FKJdYSimUDouhm3PyavuVNAWmceIpJyJCFl 4AwRiq1G/VDblU0GhNVrJb0bJl1Pdt4BJMSVQQnverse0WMGfu+5c5bYQihrL5AK MNso5vzldqnmYiIFUVCi94S9Cp5Ss9R2zsUiolDQUFEXtDk4TE12g== 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 4cvy64ej4j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 16 Mar 2026 06:25:43 +0000 (GMT) Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 62G0WqJs028501; Mon, 16 Mar 2026 06:25:42 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 4cwmq13frw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 16 Mar 2026 06:25:42 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 62G6Pcm956689018 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 16 Mar 2026 06:25:38 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6015B2004B; Mon, 16 Mar 2026 06:25:38 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BC7B220049; Mon, 16 Mar 2026 06:25:34 +0000 (GMT) Received: from li-2fa77bcc-2701-11b2-a85c-cd621c23b6bd.bl1-in.ibm.com (unknown [9.123.13.4]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 16 Mar 2026 06:25:34 +0000 (GMT) From: Sathvika Vasireddy To: linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Cc: nathan@kernel.org, masahiroy@kernel.org, kees@kernel.org, naveen@kernel.org, jpoimboe@kernel.org, peterz@infradead.org, npiggin@gmail.com, maddy@linux.ibm.com, segher@kernel.crashing.org, christophe.leroy@csgroup.eu, mingo@kernel.org, mpe@ellerman.id.au, sv@linux.ibm.com, nsc@kernel.org Subject: [RFC PATCH v4 1/6] objtool/powerpc: Add build-time fixup of alternate feature branch targets Date: Mon, 16 Mar 2026 11:52:32 +0530 Message-ID: <20260316062237.30948-2-sv@linux.ibm.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260316062237.30948-1-sv@linux.ibm.com> References: <20260316062237.30948-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-ORIG-GUID: QykxEjtKnVeG6HyNY2lofJYbQZ0tqXds X-Proofpoint-GUID: Q6yMVLsNWJTeVZkSeKb5vAqNwcnRG4u4 X-Authority-Analysis: v=2.4 cv=KYnfcAYD c=1 sm=1 tr=0 ts=69b7a267 cx=c_pps a=aDMHemPKRhS1OARIsFnwRA==:117 a=aDMHemPKRhS1OARIsFnwRA==:17 a=Yq5XynenixoA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=iQ6ETzBq9ecOQQE5vZCe:22 a=VwQbUJbxAAAA:8 a=pGLkceISAAAA:8 a=VnNF1IyMAAAA:8 a=5klgpdlFSnDGvnxfnF4A:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMzE2MDA0NSBTYWx0ZWRfX+kzVVMzGt32A MLrWeJSKOiaNmZ2gqFpX/LapoD7jAkibSofJbCqMEu0Q8s1/nv3cuawt3+7uv7JoS15uAgzfIzS WFVfCZ9+jgN6XMfnMhn6dEwbRLVG9Cws5a4e5VRA2XMSzq7XFpK8iCUkaWptl0jSwDM5SUCNFMF 9kkQUv14AuBGoyPMPb+zG5hhFFg4CQ62D41wDZaNn2wC9gXNkqFz8iYoePZbHfYRkXPFqprFf7K ejKMrcXINuMFWGoudB0I+/BZTX25+08oHxeCnJy5o4y+CJC3UdAmMRQC1TPKR2dduQ1hwkaTrVr PBs/bQeUPhmQgX4E9gg+100+kZ549ZsAX5wTuuHFRnBjsNB+Mwjgvfn8H+0Y3fzuYLHyniSpXQd ZeWDSVdFQw9F5Bo87whz8NnT1pDbHCIWjAIq5yQe2YrpgzMcxrex/2Fz4oQJ3pB7r6nhaVJA7s+ YZuhyvj5NOD8JLzTZsQ== 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-03-16_02,2026-03-13_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 lowpriorityscore=0 priorityscore=1501 suspectscore=0 bulkscore=0 spamscore=0 impostorscore=0 malwarescore=0 adultscore=0 clxscore=1015 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2603050001 definitions=main-2603160045 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 | 437 ++++++++++++++++++++++++ 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, 568 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..b837b8d7dfeb 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,430 @@ 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) { + WARN(".__ftr_alternates.text section not found\n"); + return -1; + } + + 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; + + fes =3D realloc(fes, (nr_fes + 1) * sizeof(struct fixup_entry)); + dst =3D &fes[nr_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; + + fes =3D realloc(fes, (nr_fes + 1) * sizeof(struct fixup_entry)); + dst =3D &fes[nr_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; + + i =3D nr_fes; + while (i) { + static struct fixup_entry *parent; + uint64_t nested_off; /* offset from start of parent */ + uint64_t size; + + i--; + fe =3D &fes[i]; + + parent =3D find_fe_altaddr(fe->start_off); + if (!parent) { + parent =3D find_fe_altaddr(fe->end_off); + 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) +{ + return (st_other & 0x3) !=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 (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); + if (!insn_ptr_raw || !ftr_alt->data->d_buf) + continue; + + 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 3fd98c5b6e1a..b8b9cb6005d7 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -1595,9 +1595,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)) { @@ -4967,6 +4969,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 2c02c7b49265..d519eb3d7fd8 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -1157,6 +1157,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 Thu Apr 2 09:33:38 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 7697C347539; Mon, 16 Mar 2026 06:26:12 +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=1773642373; cv=none; b=ghH02wve8/4fsEisTlvUcZNnpAcnFDgCy4HwNC22cP429tgNi8SuoQQ2v/aj6yMLuFqIXpKUHXE0wk28XAjWiRUn1OsRWhWaPNUdl9bfFSoJxoQSipJiGEAPxKLRchMCu817av82QJ8ZRarLhgJUU6AirqAI77YHL6kYFSZY3D4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773642373; c=relaxed/simple; bh=N3DVzIuD0nMb/rE0e9wWlFN3QKI0jOwsQ2Nz2R9MPzU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=berQLtr18uyufjIi0CutlYOKQxA+GfT1hQAxwctFjoSsa8g/chueX0+nwEwSDKO/Snce42i9y1tY+5uNb7jGrabv7u9SHamse0KZ+DlrhQxX8Ndc3REun7SaINm5qhQe5fOiuOpkcp67/5bahi4RWSvPvSlU+CZ4PSb8MUVyCIw= 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=RPsgPTCH; 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="RPsgPTCH" 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 62FNjeqX967663; Mon, 16 Mar 2026 06:25:48 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=ZZvOsDEOjQU96fYPx lcVKG8jZFe5rT/5ilS5dmBxUSE=; b=RPsgPTCHdW0bUqbDHm6rxF/rmQ9bQOcFr 9Ba1dExKYxaSIaZwEYG1kAtoHi5bOtZu8zzwWA+hUm+U2Q8EzwgmM/m/QMNoBE0N n1/6woU0yza+tBz1Glgj0mD4ltnsQuaPuyx5RMTMREF+i3K2t0o28gO2NESgADrr aklFF/SuKTIrbbo6MZzNV+6EfMwWFGr9I1e47hnY3weUgwanlj4dq5WwWQMi26LD MFfFsf3neCcue9RhFAhCPDpKhHG4bDkuuPA/r2qbCkdSG1ILtwo4f3tgGZVmvAjX UyJu8LBEl0exg7JdfdC0Kn56SWmUds4+G47rJnYmQHAbTIwRyKJ+g== 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 4cvx3cp91x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 16 Mar 2026 06:25:47 +0000 (GMT) Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 62G6EAQD032327; Mon, 16 Mar 2026 06:25:46 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 4cwm7jkhuf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 16 Mar 2026 06:25:46 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 62G6PhwO43712950 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 16 Mar 2026 06:25:43 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E524E2004B; Mon, 16 Mar 2026 06:25:42 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 284DD20049; Mon, 16 Mar 2026 06:25:39 +0000 (GMT) Received: from li-2fa77bcc-2701-11b2-a85c-cd621c23b6bd.bl1-in.ibm.com (unknown [9.123.13.4]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 16 Mar 2026 06:25:38 +0000 (GMT) From: Sathvika Vasireddy To: linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Cc: nathan@kernel.org, masahiroy@kernel.org, kees@kernel.org, naveen@kernel.org, jpoimboe@kernel.org, peterz@infradead.org, npiggin@gmail.com, maddy@linux.ibm.com, segher@kernel.crashing.org, christophe.leroy@csgroup.eu, mingo@kernel.org, mpe@ellerman.id.au, sv@linux.ibm.com, nsc@kernel.org Subject: [RFC PATCH v4 2/6] objtool: Set ELF_F_LAYOUT flag to preserve vmlinux segment layout Date: Mon, 16 Mar 2026 11:52:33 +0530 Message-ID: <20260316062237.30948-3-sv@linux.ibm.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260316062237.30948-1-sv@linux.ibm.com> References: <20260316062237.30948-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=arO/yCZV c=1 sm=1 tr=0 ts=69b7a26c cx=c_pps a=AfN7/Ok6k8XGzOShvHwTGQ==:117 a=AfN7/Ok6k8XGzOShvHwTGQ==:17 a=Yq5XynenixoA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=V8glGbnc2Ofi9Qvn3v5h:22 a=VnNF1IyMAAAA:8 a=dGyo4u3eiptz4-Zsc8UA:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMzE2MDA0NSBTYWx0ZWRfXx0KeWWLxiAkh ue0kaLhuojb+id7MA/sepUbUaducK9uNC3X5TkvPLhv6YDgTC+qpyff/kISOZBLYZNbACFrAtHq vW/b+1tyL6Jux6E1SIxDWMdPzL8L8+rR5hVq3y0yL3wNni94rteuHYbOHNgdemz0loZzeu0Ojzt llzTfnX7vPVqn9oYyHIjfeuOO3LecX++gqLIu3wfI/pFfdbMu4SQ+9oJf+UgWZtO4cwMJoJa0fu jvsbpzsJFmWPFI5lZn5yR6jlSJTzKBhC7U2pQA2+wJuYD6P0+fCrYuilt/ek2haX6sDLo1XHkMj /sdtcoQ1fqpf6YNyRLDulxEhejZsONf1qZn8kgCxbB4peEyQ9xqCaBkCD959kWzOb7r5mBj/+vr /pPEkXP9Z30ke2fDKYel4qdnJM9fvmZerNoAqboRzX5wBIujgxUavkl8OT9dtRwjMf6A1OqGyFC Q7gJCtgo5RRfR1vQgrg== X-Proofpoint-GUID: GmcYMIHmX5wXMZ3p-ZkNoFBJvJ5N2xSd X-Proofpoint-ORIG-GUID: MjNrBFtveABCS8hU7vK8mehQHNuDlOx9 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-03-16_02,2026-03-13_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 spamscore=0 lowpriorityscore=0 impostorscore=0 adultscore=0 bulkscore=0 suspectscore=0 malwarescore=0 clxscore=1015 phishscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2603050001 definitions=main-2603160045 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 d519eb3d7fd8..3c84c2713a7b 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -1158,6 +1158,9 @@ struct elf *elf_open_read(const char *name, int flags) =20 elf->elf =3D elf_begin(elf->fd, cmd, NULL); =20 + if (opts.ftr_fixup) + elf_flagelf(elf->elf, ELF_C_SET, ELF_F_LAYOUT); + if (!elf->elf) { ERROR_ELF("elf_begin"); goto err; --=20 2.43.0 From nobody Thu Apr 2 09:33:38 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 768F622CBE6; Mon, 16 Mar 2026 06:26:12 +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=1773642373; cv=none; b=Pceohkzl+8dqGQxrCy61yQhBgNoG9kH8YWpVivfuZsdy9ho5ga5prXfLI6JyKP1goF/l26IH6I4CXmuppa99rQsiyISQy6YYIwY/7l0COPFBLlXlhJ4xsOqn9tToKXZ51/EeURQF/MS2H2U5XzuuF6u4885KS6kP7Vo1ro6Plng= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773642373; c=relaxed/simple; bh=+pkMRysJ/sUVEqIAjd4WFu+hCbrF/6p5Sw0hmn79dPQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JZM+p/69CtmoeyGPcZ//p34Tako7ud/LAcLECJhiJa/N9qYmiPIzkRlYxafCnAqcB767v8ucnoUk2IQhRXA69tmqZkzPdeam0cEea4UX8YM2fYcKIm7EXD9l9qsBmpQbtD/1csdQD94iY/L9v7UowQl4cai2XzimwmLhaujioTc= 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=ddV/85Is; 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="ddV/85Is" 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 62FLo1iO871453; Mon, 16 Mar 2026 06:25:52 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=dlhqMPK7aYKEVPJdg PwwAnPB6R5T7newl+APg3UuQtI=; b=ddV/85IsF0EeHgRDIO5zYBDSDe+Op/aUa FplQR4cRznrw6k4sXxqJn9+PAMpWY0EsCf+Xr0zu/be8YfTWbT9U5JWXneld32sP FTpW+osUQx9XsaV6R2sMV3v5nQltpkRZ+gmumf6aKt+M1vPynhYDKArrFMS56Aom rlkBcBwldNygyilzt/voJfr9FyDO0OIe2ZF0NIextV/jWTL4XxNKkT6RrZ0yzVVz +PrjSm2QkDLV63PR6GbHfR5C5iyuJQAziQhigBeKpqnl4gpXEc6Pzes13RzqOc+j Xovs0PJRAKkfhNrlB2c4lJ2srnux+ldAES6CzQ0taoRMsF2tgv7JA== 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 4cvyau65h5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 16 Mar 2026 06:25: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.2/8.18.1.2) with ESMTP id 62G0Rhgx032448; Mon, 16 Mar 2026 06:25:50 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 4cwm7jkhum-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 16 Mar 2026 06:25:50 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 62G6Pllj15401378 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 16 Mar 2026 06:25:47 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EA83A2004B; Mon, 16 Mar 2026 06:25:46 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AF06D20049; Mon, 16 Mar 2026 06:25:43 +0000 (GMT) Received: from li-2fa77bcc-2701-11b2-a85c-cd621c23b6bd.bl1-in.ibm.com (unknown [9.123.13.4]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 16 Mar 2026 06:25:43 +0000 (GMT) From: Sathvika Vasireddy To: linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Cc: nathan@kernel.org, masahiroy@kernel.org, kees@kernel.org, naveen@kernel.org, jpoimboe@kernel.org, peterz@infradead.org, npiggin@gmail.com, maddy@linux.ibm.com, segher@kernel.crashing.org, christophe.leroy@csgroup.eu, mingo@kernel.org, mpe@ellerman.id.au, sv@linux.ibm.com, nsc@kernel.org Subject: [RFC PATCH v4 3/6] objtool: Fix "can't find starting instruction" warnings on vmlinux Date: Mon, 16 Mar 2026 11:52:34 +0530 Message-ID: <20260316062237.30948-4-sv@linux.ibm.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260316062237.30948-1-sv@linux.ibm.com> References: <20260316062237.30948-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: AW1haW4tMjYwMzE2MDA0NSBTYWx0ZWRfX92OXVDeXWdkI Ru5THtvM6SwRJdQkYm6mXJ4vjgN4es181q9EATkRkGScFxjOHUtpeytie8tUQ30SQUjSCuYgNSy Ai6uPxConFeL/T5i9Gyub1YG3ujL3wf42oVw5c4Hg8xlRU9JvuyrFozofLjX8QLPcOD6F2gjnwK 3o/hLGFI0T/CjVsSmL8lYfqeZGMDkP3G3tP/Wngl9qTXxehvx8Q/Zl64D+n0F9UmCliP2qZqgQY /PR7nMqKBQwkwMoNrT7nHUtbtlgCEQmiWNn56jgpFdOO/K7zmlp/6e5Vv/TLtY50HMWs0EoaAFc lValfXBel3+wGc4Wk71vt3STykaJs3LfN93t7SojSZjfHnyoVPZg1UUFy/Owflw0/wxIOh3p3fK lLH+/V1XQnxCCeVfrnS2wq/TWDwIQqb9GCyVtb/i4bj7EnhYc4cGmmU/0x9RMCXb/2s47k6j8VK yRR5cvM9dSIz62CYQlQ== X-Authority-Analysis: v=2.4 cv=GIQF0+NK c=1 sm=1 tr=0 ts=69b7a270 cx=c_pps a=AfN7/Ok6k8XGzOShvHwTGQ==:117 a=AfN7/Ok6k8XGzOShvHwTGQ==:17 a=Yq5XynenixoA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=RzCfie-kr_QcCd8fBx8p:22 a=VnNF1IyMAAAA:8 a=7w6QjbFeSYXBFb6lQ1YA:9 X-Proofpoint-ORIG-GUID: _omZ2hr6mH-Pa4AeSg8FhFsukBCioCIN X-Proofpoint-GUID: Xv0nLPkoBUC3XF6KcMVCt4deZm6BT6oN 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-03-16_02,2026-03-13_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 priorityscore=1501 bulkscore=0 lowpriorityscore=0 malwarescore=0 phishscore=0 impostorscore=0 suspectscore=0 adultscore=0 clxscore=1015 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2603050001 definitions=main-2603160045 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 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index b8b9cb6005d7..7b95ddb0460d 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -493,7 +493,11 @@ static int decode_instructions(struct objtool_file *fi= le) if (func->embedded_insn || func->alias !=3D func) continue; =20 - if (!find_insn(file, sec, func->offset)) { + if (func->len =3D=3D 0) + continue; + + if (!find_insn(file, sec, opts.ftr_fixup ? + func->offset - sec->sym->offset : func->offset)) { ERROR("%s(): can't find starting instruction", func->name); return -1; } --=20 2.43.0 From nobody Thu Apr 2 09:33:38 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 2AC0434B662; Mon, 16 Mar 2026 06:26:13 +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=1773642375; cv=none; b=bTM2XoS1FJ7nRXOB7dpOAXbhx1BVFyuRYHXz6RIVG+49rF8o0ZTjT400RYCMW7gLTALF+nC6Ko65dkIVl531uUQtUMpkl2w3gEJEFeWEybwF7/6ksSYQrMH9i/wjCFnxPMfvG/Q9L43696EqJgb0V8A2EhUN1dCWsH4NjrnYqpo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773642375; c=relaxed/simple; bh=/fzZCe9XpKrXiHMTJ/WhtkRbpoyhUJUS92iUZhswMlg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DCZiJSSmCiO04FmMEJaSq4AmDQm+FUiTpNIM7yoSYdXIYQ3vEv5Tu0xMaPv2FDbgpdQu2QC/UR+CZ3bppT7jpMeyDWaTMO+kzkCgUrnE6YQCUNrpq258TgafcqeEu/Ohi9ewzHPQVf558eJs+X9rzEYgDVJzBcAGpgBpeTBOx6Q= 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=TmtEBPrk; 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="TmtEBPrk" 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 62FNKPn31021429; Mon, 16 Mar 2026 06:25:56 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=UXhjmtqVsij/LUlly HwnJ+xDPArOzo01zjKtMLmdHTM=; b=TmtEBPrkELM2wP5T5JWeNBxmUUEMi+MPW hhSdBqfaSR/7+xlm+6nPhVez+MSpuF6Cl1oYyd85broLV6rL7ULS0xsALxGMosom wHnDWSv6C1Wz+CAkw5g7MRydkaLNILQg1lLU98jJ9us/s+cfKu48b5qdwCFVj4N+ yttXTGz8z7BUteccO2gi7sxCyITUTItZqBpRqT1WhQxR+7Eve8V2NUWNyrrgNQ+i gcJ2uqccSXOGu1bDnWpejE/ZDJg21oRP6H91/CG0dqhuTKhDnw/Pr39ejJl5Lu1U jzOM+sqEs0jJLza+OVHAuNJMzRHyhSZ9fyRlHsjvjc5RO80y5U/5A== 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 4cvw3hpdm3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 16 Mar 2026 06:25:55 +0000 (GMT) Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 62G63TxN032346; Mon, 16 Mar 2026 06:25:54 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 4cwm7jkhur-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 16 Mar 2026 06:25:54 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 62G6PpVx50266528 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 16 Mar 2026 06:25:51 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2670020049; Mon, 16 Mar 2026 06:25:51 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C158920040; Mon, 16 Mar 2026 06:25:47 +0000 (GMT) Received: from li-2fa77bcc-2701-11b2-a85c-cd621c23b6bd.bl1-in.ibm.com (unknown [9.123.13.4]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 16 Mar 2026 06:25:47 +0000 (GMT) From: Sathvika Vasireddy To: linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Cc: nathan@kernel.org, masahiroy@kernel.org, kees@kernel.org, naveen@kernel.org, jpoimboe@kernel.org, peterz@infradead.org, npiggin@gmail.com, maddy@linux.ibm.com, segher@kernel.crashing.org, christophe.leroy@csgroup.eu, mingo@kernel.org, mpe@ellerman.id.au, sv@linux.ibm.com, nsc@kernel.org Subject: [RFC PATCH v4 4/6] objtool/powerpc: Skip jump destination analysis and unnanotated intra-function call warnings for --ftr-fixup Date: Mon, 16 Mar 2026 11:52:35 +0530 Message-ID: <20260316062237.30948-5-sv@linux.ibm.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260316062237.30948-1-sv@linux.ibm.com> References: <20260316062237.30948-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-GUID: 27Zq6sbknyaviqxCBAU34fPJbi7vFMzn X-Proofpoint-ORIG-GUID: XYuYc58Qj3sFI0SeWPiHcHaOl4PIG0UF X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMzE2MDA0NSBTYWx0ZWRfX7r+UEjy4EzJp f6pFtZr48Ix+8ttY0vZNm36KKX/ywAi2IBTMsgRx3oWo+WOgDf+pyldzRt5BRYOwhlUXhVsEg4z Rev7/gv7NxWC369oIUJPqWeagB8s7l2fYPCWLG2ZNSiShFlougtfYxP2jw++rfK4xs6dZOSPXow HE6jg8W7CWCaxwoTT8t39d22dk9yU0UbBRxr8jn6obohmv7rqmsveHPdICSnGHpRTlCJkmR77vJ eAxgauVcc6dNNF9gY+KbUMag1L2TqGzAHkpV+loW+2H6aYk0cOYjfzDgV+vONnWKAGRkjEiPVgu 3pdVE/uWeDaSIBM4JLQqNtSOucQxaaBT0uBiu43Gcn7S2kqkrxMgOXFQQbIbO7qWmL9L5ZKyPq+ 8RW0NjaCjjM77cW9fOigj6rclqscjI45aekLJFNOY5kfplu4DPMZgVB0fugJsmDSc3/3WClRb5m VNa8XAmiAPYjO/ZUZPQ== X-Authority-Analysis: v=2.4 cv=Hf8ZjyE8 c=1 sm=1 tr=0 ts=69b7a274 cx=c_pps a=AfN7/Ok6k8XGzOShvHwTGQ==:117 a=AfN7/Ok6k8XGzOShvHwTGQ==:17 a=Yq5XynenixoA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=Y2IxJ9c9Rs8Kov3niI8_:22 a=VnNF1IyMAAAA:8 a=8-sZ6GPjQPUUxCpKAYwA: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-03-16_02,2026-03-13_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 malwarescore=0 lowpriorityscore=0 impostorscore=0 bulkscore=0 suspectscore=0 priorityscore=1501 spamscore=0 adultscore=0 clxscore=1015 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2603050001 definitions=main-2603160045 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 | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 7b95ddb0460d..ba194446df0a 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -1599,7 +1599,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; @@ -1681,7 +1680,7 @@ static int add_call_destinations(struct objtool_file = *file) if (func && func->ignore) continue; =20 - if (!insn_call_dest(insn)) { + if (!insn_call_dest(insn) && !opts.ftr_fixup) { ERROR_INSN(insn, "unannotated intra-function call"); return -1; } @@ -2637,8 +2636,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 Thu Apr 2 09:33:38 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 2700221B185; Mon, 16 Mar 2026 06:26:23 +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=1773642385; cv=none; b=al+iOZNIlb9z4EpZqsrFQHgv2P+oaKOjIJ4+cB+RGQe/xWilOXFkENJBNIUBuCwSKqa8I5BaD8DJMV67sg2IYq5amSQNcYPVwUpY3D2QO7F0/6qLT4ZYCJmOByc0AtSQ3QdG7IU1yDd6T3ULSHUN31LFbIQPekTMFxHpT/VTC1k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773642385; c=relaxed/simple; bh=sQXibnR9Dbu8SCpE3jt44XGnhPr/V9Km6rMA/WCXFPA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uiV6H/W7wfJYsdJMB0GW4e0d9ro5lqdRV0L9HQI0BbjQEmEEVbp6cPW09ecUge12vgvKVYCpyS+ElRFaYY4OfW5rNmgkNFTUaJ2eVH+P0W7aTcBLofx7jmY1HWeaI/s1KnyLB2jbZWyxhdxzNO1b/EjoEnQRTTaDEjMgZsYdzVI= 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=oSFLc72w; 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="oSFLc72w" Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 62G14CND1188734; Mon, 16 Mar 2026 06:26:01 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=AgqxpQVmCwUwsQP4e YZ7Z8OFdXuN/UY+6udpEMl9Tf8=; b=oSFLc72wVhEYcQgeAQVpSO8EeBxXN3AWv VaftQcxZwCMe1e9nCeawwy1Gpzz1KD9vkI4rGB8sDxBbuMgFQtbWZkjM9lKZg+qG 8lHr3OMThQM/Pq/7pNVmBjBkPZbARvEkybY9dt3ZyJIkx1DejjKc/0AQP4PkXCer RjepSvjqbArBkXKwlu/58SoJSwav7s2hnPMKC5Z0IUaNzFflgZHslanKXvLq2f4E 6UEfe1zMw8AebLujo42kh+s9j/9zsjhU1+IwLcyZ0pM2Ei7qXQPt7ILk6yHTK57I JPxLJd5lqYP15wJDdFpAXAswGSbdcmIfgBsRE0vpvQXUzaFQ2gmtQ== 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 4cx7vf8skh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 16 Mar 2026 06:26:00 +0000 (GMT) Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 62G4dTYP014011; Mon, 16 Mar 2026 06:25:59 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4cwjcxuspa-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 16 Mar 2026 06:25:59 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 62G6PtWv35717490 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 16 Mar 2026 06:25:55 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A1F3520049; Mon, 16 Mar 2026 06:25:55 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F3D8B20040; Mon, 16 Mar 2026 06:25:51 +0000 (GMT) Received: from li-2fa77bcc-2701-11b2-a85c-cd621c23b6bd.bl1-in.ibm.com (unknown [9.123.13.4]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 16 Mar 2026 06:25:51 +0000 (GMT) From: Sathvika Vasireddy To: linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Cc: nathan@kernel.org, masahiroy@kernel.org, kees@kernel.org, naveen@kernel.org, jpoimboe@kernel.org, peterz@infradead.org, npiggin@gmail.com, maddy@linux.ibm.com, segher@kernel.crashing.org, christophe.leroy@csgroup.eu, mingo@kernel.org, mpe@ellerman.id.au, sv@linux.ibm.com, nsc@kernel.org Subject: [RFC PATCH v4 5/6] kbuild: Add objtool integration for PowerPC feature fixups Date: Mon, 16 Mar 2026 11:52:36 +0530 Message-ID: <20260316062237.30948-6-sv@linux.ibm.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260316062237.30948-1-sv@linux.ibm.com> References: <20260316062237.30948-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-ORIG-GUID: hcagTk-zsqxwONzvp47iQ595Aq-776Ks X-Authority-Analysis: v=2.4 cv=KajfcAYD c=1 sm=1 tr=0 ts=69b7a279 cx=c_pps a=5BHTudwdYE3Te8bg5FgnPg==:117 a=5BHTudwdYE3Te8bg5FgnPg==:17 a=Yq5XynenixoA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=U7nrCbtTmkRpXpFmAIza:22 a=VwQbUJbxAAAA:8 a=VnNF1IyMAAAA:8 a=k1iL6ZPSiERSBASioQUA:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMzE2MDA0NSBTYWx0ZWRfX4mwLllTvZ/im Rca5hVzY6Gl+5zr1LJ/5SQ5I3AjEzZuv5P5Bq/V2tgF2kIt8clM9eGkpaHmctRONb98lg1Psxbe uVDRsKO6xF0B8Ka5V9Anv3krWQaLAlZBjibObwFqxb+SzR+1m6VW0KUrQl/56x41v5DsfgF2QPS at4ZLbo+WmN86Jc6DoikwESeKdhr/HLVI3LkPZWtr/yC+EjTh0BbQBuzzlnq6ddwYFCc8Y7+wY+ oNdn9ZUSD2QLMMFANr438/evSh7ydL8QHSy9Q9IVtUoRmVDuypnKWDspeLpecSA2KAnr11Kl36s B993qIX50OGw1v9kYj9+Z+LYBuuiLaXX7hw4AWxZ+48h3WwbcbD77DziTagvzcsYlkmQca5DlmG 5CZx8QfSwDOz6Ato5cvIiSUJf4Xpy0LHG6PhMhyVvduQjj+MKWMHUb9v1y4tNCPhBU+FwEDQGQ5 spvHzUd5N+42D682uLg== X-Proofpoint-GUID: rR38sSfWR2jvZFCMdskex73pGmE8QcPr 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-03-16_02,2026-03-13_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 adultscore=0 spamscore=0 malwarescore=0 clxscore=1015 impostorscore=0 bulkscore=0 lowpriorityscore=0 priorityscore=1501 phishscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2603050001 definitions=main-2603160045 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 83ed80595378..861f5bec655c 100644 --- a/Makefile +++ b/Makefile @@ -1467,6 +1467,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 e429d68b8594..c9478c717574 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 Thu Apr 2 09:33:38 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 5F5E73770B; Mon, 16 Mar 2026 06:26:25 +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=1773642386; cv=none; b=iD4QB6sLLTaRy/lwTkSYG1GQZJWJKfYIR7tgV54/jetmtg5fDn9S0Hp7i+hvG3LRF9aZWkAZjhaljnZqeIyJrLG4cDAqI4RuGV1MucBOCuxQ93WIBakcoScl7oZut0T7sGkdnBWXsoUhYgmmDTCBmJR+yrE6vAbFsp2p2H6kHZs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773642386; c=relaxed/simple; bh=nO36QE+SKyYAHPQq8tQVWiFyukElKpRVDaDB5Lekx2E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cIX1n2bT41LZdQjj4Mt+xjLjAacbv+nlw4UH6R8YsDWyESGquvrCJVLWZKPeMd0Rrr+QcK7OojGzTsOSakAtFoOIo41dh8jfZ8GqS43+Y7KiZhY0STrZbpniXV0iQ5dBm587cFo+0lMPZicIliNWpGCkUM/YvhVBgDdALKwGTco= 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=kZQ6RBZQ; 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="kZQ6RBZQ" 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 62G3FZ1h1474421; Mon, 16 Mar 2026 06:26:05 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=K9Ufsq6yZaiTxVyM4 mFqxaF3/reWplKG7d2h/AG6SaE=; b=kZQ6RBZQZ7P/8K6riQBGhfdyENp3rBbzY NsERE/eVArVYxoY9wrYT/N4nd1S7Pc0nXK9pIgm9E44Ap27RwCDfpZ1kqdJZlG69 UBerKiCkASTYbe61MojVCXCE95PHX7yrY8zvVAx2//8wApXvJyXeginfsB70EmIb GX2m8qhmSuNYA0NU8GHDJCofRp19Gu83dFlwFpmftueOXt24CSkt/bEBhULsnjhW CnSEuZRNBgv+DtfIpXG7ZRhcM1mmH9u2/Wo0sNO6yEXhBEtpQe04KPTXHW6s9TS8 cCqyb8B1HLkGfvRTwMgauyJANZqn2dK1NYBgUwEQNqhdva3J1lmZA== 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 4cvw3hpdmf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 16 Mar 2026 06:26:04 +0000 (GMT) Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 62G0YDha028452; Mon, 16 Mar 2026 06:26:03 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 4cwmq13fsk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 16 Mar 2026 06:26:03 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 62G6Q0g831064558 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 16 Mar 2026 06:26:00 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 103C020040; Mon, 16 Mar 2026 06:26:00 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A712C20049; Mon, 16 Mar 2026 06:25:56 +0000 (GMT) Received: from li-2fa77bcc-2701-11b2-a85c-cd621c23b6bd.bl1-in.ibm.com (unknown [9.123.13.4]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 16 Mar 2026 06:25:56 +0000 (GMT) From: Sathvika Vasireddy To: linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Cc: nathan@kernel.org, masahiroy@kernel.org, kees@kernel.org, naveen@kernel.org, jpoimboe@kernel.org, peterz@infradead.org, npiggin@gmail.com, maddy@linux.ibm.com, segher@kernel.crashing.org, christophe.leroy@csgroup.eu, mingo@kernel.org, mpe@ellerman.id.au, sv@linux.ibm.com, nsc@kernel.org Subject: [RFC PATCH v4 6/6] powerpc: Enable build-time feature fixup processing by default Date: Mon, 16 Mar 2026 11:52:37 +0530 Message-ID: <20260316062237.30948-7-sv@linux.ibm.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260316062237.30948-1-sv@linux.ibm.com> References: <20260316062237.30948-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-GUID: wbe1sxH-h5dS1mLZVfK3gXDgo-55mt4V X-Proofpoint-ORIG-GUID: onQemc1L8a_T6S4edm8Yi6o-4WVGO8I_ X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMzE2MDA0NSBTYWx0ZWRfX++SEW6gmZvyK pfHgi218xVlkoQZNKHGGumLcR/FD+R/dfqJvZ/JO7HuuYPGszLib3J+ru0upkSLTnyFqHDQdB38 7y7gFbO5bgFhkPLXrLLwQ+y31MiZdAArDrWul+BGjGuOFkT1ujJPfNxCxNauTWNHKZIbGP5MG8a SYMoQogJzxMhpckRbU9pnK4SBVic5zBt4zzTgCvuUBP0PJOjslFeysRkOxr8qvMAicBRyHu9Up0 Py1NFusxVIDu0/ADw/S1tbA4wiZrSJ4loPd3hSm2lBxVCBhGYwifXdxXh1CnGfjMtNeWw7FDO/k 88MJUkjx4kfM3MHnigi3mMqehmEXYiCzLekUbd1868qtObkBY5pX8tI/hMxewYPp5Cob3DDPvUU Eof6QR7zT0F8jDSOYoQeWfbWJ0+7NzGF/GZ7rlynvF8B8p3d9ruJ1Dx/RtfZ7ePlXuqmdXfblA4 3cGi0DSV0HFpVW5p5Fw== X-Authority-Analysis: v=2.4 cv=Hf8ZjyE8 c=1 sm=1 tr=0 ts=69b7a27d cx=c_pps a=aDMHemPKRhS1OARIsFnwRA==:117 a=aDMHemPKRhS1OARIsFnwRA==:17 a=Yq5XynenixoA: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-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-03-16_02,2026-03-13_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 malwarescore=0 lowpriorityscore=0 impostorscore=0 bulkscore=0 suspectscore=0 priorityscore=1501 spamscore=0 adultscore=0 clxscore=1015 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2603050001 definitions=main-2603160045 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 b8d36a261009..aedb11912672 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 15850296c0a9..70a4de464b34 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