From nobody Sat Jun 13 22:11:22 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 34D28383C6C; Tue, 5 May 2026 10:55:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777978556; cv=none; b=ccZyBFTZFH5qWhOON3DeBn3T9kEK+W/XO5MEXg996vbrVJhz7B3yDWNZ3HchYe4Td4g1XahL4K+Kwelt9crLukwehjhrpcVDIQ2X7GqlnbpsQMwHs+yO3kcxTsDRgyV7YY3VDYQldVPa7kAOAFw1XegvSSIlgR1EGhGjcj1YEuA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777978556; c=relaxed/simple; bh=xajjJxhxXBvpFjeKkqe1OU7h7ljDiGJ9Iyu4RpTai3Y=; h=Date:From:To:Subject:Cc:MIME-Version:Message-ID:Content-Type; b=VRCQrDUM8YUDY5Ozde3aXv/XmBgjbWKvI+G3/6148ojPb4w0KSa3fEIOXz+GpEEBafX6WfUSb47avJSGIHyWt0R3VbPgl56oZEvEvNEkccdbBZsHOCqSe7Hf68Us0CQDTTikcZ65Mxmpbwxv3IT7AC68dsub1+2VhnYhIbNwT9U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=3YVlb922; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=5PlFGzE9; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="3YVlb922"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="5PlFGzE9" Date: Tue, 05 May 2026 10:55:51 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1777978553; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=YOzchZFkmMS3nm9ObNuYmXK31PF0TIvlugN6Zco5r30=; b=3YVlb922nnM+24Vdv5Iv2fBjubEg2iChf2AWsyDpsxg28iWj8+/DmmloXqvgImEOS4bHD5 UaTYqLf/fCHoBMMAEzhOQlYP9S+EgmJw2kxAHi4OKCYsM8hsiicVJING5fI0cfVLVLz/c1 S8CtGgwMHdxMm7Po16JIcNSXULuf9TA1sBJP3SRSutHH9LdGU27Ro8wYX5Ye5MTvym/Czz eKHmQk36Zrfd7fDZVkto9DQdXyGgLOsAiKk4c4SLYcge2tZHfG5J61DfYL/BqGqzNbgq1z 4udMnO1rJ3b9z32vdJkZy+LHSGcX9YMlRvZIsSzTQ9amq2TkEgGt8DtKTQ6epA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1777978553; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=YOzchZFkmMS3nm9ObNuYmXK31PF0TIvlugN6Zco5r30=; b=5PlFGzE9eJ6oFjZp8bEx0UpVCpUT8IeqcHknBFS4Ab1uRYOCzADNiMZOn33dU2P7dKK+MA UYfCAwwqx3WKN1CQ== From: "tip-bot2 for Josh Poimboeuf" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: objtool/core] objtool: Improve and simplify prefix symbol detection Cc: Josh Poimboeuf , x86@kernel.org, linux-kernel@vger.kernel.org Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <177797855185.424702.126187460485059205.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the objtool/core branch of tip: Commit-ID: fe6a87e0abac45b20664377545760901d4537ea8 Gitweb: https://git.kernel.org/tip/fe6a87e0abac45b20664377545760901d= 4537ea8 Author: Josh Poimboeuf AuthorDate: Tue, 07 Apr 2026 20:56:48 -07:00 Committer: Josh Poimboeuf CommitterDate: Mon, 04 May 2026 21:16:07 -07:00 objtool: Improve and simplify prefix symbol detection Only create prefix symbols for functions that have __patchable_function_entries entries, since those are the only C functions where prefix NOPs are intentional. This both simplifies the detection and makes it more accurate. Note that assembly functions using SYM_TYPED_FUNC_START() can also have prefixed NOPs, but that macro already creates their __cfi_ symbols. Signed-off-by: Josh Poimboeuf --- tools/objtool/check.c | 88 +++++++++--------------------------------- 1 file changed, 20 insertions(+), 68 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 73e99bd..10b18cf 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -4296,17 +4296,6 @@ static bool ignore_unreachable_insn(struct objtool_f= ile *file, struct instructio * For FineIBT or kCFI, a certain number of bytes preceding the function m= ay be * NOPs. Those NOPs may be rewritten at runtime and executed, so give the= m a * proper function name: __pfx_. - * - * The NOPs may not exist for the following cases: - * - * - compiler cloned functions (*.cold, *.part0, etc) - * - asm functions created with inline asm or without SYM_FUNC_START() - * - * Also, the function may already have a prefix from a previous objtool run - * (livepatch extracted functions, or manually running objtool multiple ti= mes). - * - * So return 0 if the NOPs are missing or the function already has a prefix - * symbol. */ static int create_prefix_symbol(struct objtool_file *file, struct symbol *= func) { @@ -4314,10 +4303,6 @@ static int create_prefix_symbol(struct objtool_file = *file, struct symbol *func) char name[SYM_NAME_LEN]; struct cfi_state *cfi; =20 - if (!is_func_sym(func) || is_prefix_func(func) || is_cold_func(func) || - func->static_call_tramp) - return 0; - if ((strlen(func->name) + sizeof("__pfx_") > SYM_NAME_LEN)) { WARN("%s: symbol name too long, can't create __pfx_ symbol", func->name); @@ -4327,59 +4312,21 @@ static int create_prefix_symbol(struct objtool_file= *file, struct symbol *func) if (snprintf_check(name, SYM_NAME_LEN, "__pfx_%s", func->name)) return -1; =20 - if (file->klp) { - struct symbol *pfx; - - pfx =3D find_symbol_by_offset(func->sec, func->offset - opts.prefix); - if (pfx && is_prefix_func(pfx) && !strcmp(pfx->name, name)) - return 0; - } - - insn =3D find_insn(file, func->sec, func->offset); - if (!insn) { - WARN("%s: can't find starting instruction", func->name); + if (!elf_create_symbol(file->elf, name, func->sec, + GELF_ST_BIND(func->sym.st_info), + GELF_ST_TYPE(func->sym.st_info), + func->offset - opts.prefix, opts.prefix)) return -1; - } - - for (prev =3D prev_insn_same_sec(file, insn); - prev; - prev =3D prev_insn_same_sec(file, prev)) { - u64 offset; - - if (prev->type !=3D INSN_NOP) - return 0; - - offset =3D func->offset - prev->offset; - - if (offset > opts.prefix) - return 0; - - if (offset < opts.prefix) - continue; =20 - if (!elf_create_symbol(file->elf, name, func->sec, - GELF_ST_BIND(func->sym.st_info), - GELF_ST_TYPE(func->sym.st_info), - prev->offset, opts.prefix)) - return -1; - - break; - } - - if (!prev) - return 0; - - if (!insn->cfi) { - /* - * This can happen if stack validation isn't enabled or the - * function is annotated with STACK_FRAME_NON_STANDARD. - */ + /* Propagate insn->cfi to the prefix code */ + insn =3D find_insn(file, func->sec, func->offset); + if (!insn || !insn->cfi) return 0; - } =20 - /* Propagate insn->cfi to the prefix code */ cfi =3D cfi_hash_find_or_add(insn->cfi); - for (; prev !=3D insn; prev =3D next_insn_same_sec(file, prev)) + for (prev =3D find_insn(file, func->sec, func->offset - opts.prefix); + prev && prev !=3D insn; + prev =3D next_insn_same_sec(file, prev)) prev->cfi =3D cfi; =20 return 0; @@ -4387,15 +4334,20 @@ static int create_prefix_symbol(struct objtool_file= *file, struct symbol *func) =20 static int create_prefix_symbols(struct objtool_file *file) { - struct section *sec; + struct section *pfe_sec; struct symbol *func; + struct reloc *reloc; =20 - for_each_sec(file->elf, sec) { - if (!is_text_sec(sec)) + for_each_sec(file->elf, pfe_sec) { + if (strcmp(pfe_sec->name, "__patchable_function_entries")) + continue; + if (!pfe_sec->rsec) continue; =20 - sec_for_each_sym(sec, func) { - if (create_prefix_symbol(file, func)) + for_each_reloc(pfe_sec->rsec, reloc) { + func =3D find_func_by_offset(reloc->sym->sec, + reloc->sym->offset + reloc_addend(reloc) + opts.prefix); + if (func && create_prefix_symbol(file, func)) return -1; } }