From: "tip-bot2 for Josh Poimboeuf" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: Josh Poimboeuf <jpoimboe@kernel.org>,
Ingo Molnar <mingo@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
live-patching@vger.kernel.org,
Linus Torvalds <torvalds@linux-foundation.org>,
x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [tip: objtool/core] objtool: Warn on functions with ambiguous -ffunction-sections section names
Date: Thu, 13 Nov 2025 07:08:52 -0000 [thread overview]
Message-ID: <176301773269.498.5236055241779881022.tip-bot2@tip-bot2> (raw)
In-Reply-To: <65fedea974fe14be487c8867a0b8d0e4a294ce1e.1762991150.git.jpoimboe@kernel.org>
The following commit has been merged into the objtool/core branch of tip:
Commit-ID: 9c7dc1dd897a1cdcade9566ea4664b03fbabf4a4
Gitweb: https://git.kernel.org/tip/9c7dc1dd897a1cdcade9566ea4664b03fbabf4a4
Author: Josh Poimboeuf <jpoimboe@kernel.org>
AuthorDate: Wed, 12 Nov 2025 15:47:51 -08:00
Committer: Ingo Molnar <mingo@kernel.org>
CommitterDate: Thu, 13 Nov 2025 08:03:10 +01:00
objtool: Warn on functions with ambiguous -ffunction-sections section names
When compiled with -ffunction-sections, a function named startup() will
be placed in .text.startup. However, .text.startup is also used by the
compiler for functions with __attribute__((constructor)).
That creates an ambiguity for the vmlinux linker script, which needs to
differentiate those two cases.
Similar naming conflicts exist for functions named exit(), split(),
unlikely(), hot() and unknown().
One potential solution would be to use '#ifdef CC_USING_FUNCTION_SECTIONS'
to create two distinct implementations of the TEXT_MAIN macro. However,
-ffunction-sections can be (and is) enabled or disabled on a per-object
basis (for example via ccflags-y or AUTOFDO_PROFILE).
So the recently unified TEXT_MAIN macro (commit 1ba9f8979426
("vmlinux.lds: Unify TEXT_MAIN, DATA_MAIN, and related macros")) is
necessary. This means there's no way for the linker script to
disambiguate things.
Instead, use objtool to warn on any function names whose resulting
section names might create ambiguity when the kernel is compiled (in
whole or in part) with -ffunction-sections.
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: live-patching@vger.kernel.org
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: https://patch.msgid.link/65fedea974fe14be487c8867a0b8d0e4a294ce1e.1762991150.git.jpoimboe@kernel.org
---
include/asm-generic/vmlinux.lds.h | 15 +++++++++++-
tools/objtool/Documentation/objtool.txt | 7 +++++-
tools/objtool/check.c | 33 ++++++++++++++++++++++++-
3 files changed, 55 insertions(+)
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index 8f92d66..5efe1de 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -97,6 +97,21 @@
* Other .text.* sections that are typically grouped separately, such as
* .text.unlikely or .text.hot, must be matched explicitly before using
* TEXT_MAIN.
+ *
+ * NOTE: builds *with* and *without* -ffunction-sections are both supported by
+ * this single macro. Even with -ffunction-sections, there may be some objects
+ * NOT compiled with the flag due to the use of a specific Makefile override
+ * like cflags-y or AUTOFDO_PROFILE_foo.o. So this single catchall rule is
+ * needed to support mixed object builds.
+ *
+ * One implication is that functions named startup(), exit(), split(),
+ * unlikely(), hot(), and unknown() are not allowed in the kernel due to the
+ * ambiguity of their section names with -ffunction-sections. For example,
+ * .text.startup could be __attribute__((constructor)) code in a *non*
+ * ffunction-sections object, which should be placed in .init.text; or it could
+ * be an actual function named startup() in an ffunction-sections object, which
+ * should be placed in .text. Objtool will detect and complain about any such
+ * ambiguously named functions.
*/
#define TEXT_MAIN \
.text \
diff --git a/tools/objtool/Documentation/objtool.txt b/tools/objtool/Documentation/objtool.txt
index 9e97fc2..f88f8d2 100644
--- a/tools/objtool/Documentation/objtool.txt
+++ b/tools/objtool/Documentation/objtool.txt
@@ -456,6 +456,13 @@ the objtool maintainers.
these special names and does not use module_init() / module_exit()
macros to create them.
+13. file.o: warning: func() function name creates ambiguity with -ffunctions-sections
+
+ Functions named startup(), exit(), split(), unlikely(), hot(), and
+ unknown() are not allowed due to the ambiguity of their section
+ names when compiled with -ffunction-sections. For more information,
+ see the comment above TEXT_MAIN in include/asm-generic/vmlinux.lds.h.
+
If the error doesn't seem to make sense, it could be a bug in objtool.
Feel free to ask objtool maintainers for help.
diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 57fac6c..72c7f6f 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -2663,6 +2663,37 @@ static int decode_sections(struct objtool_file *file)
return 0;
}
+/*
+ * Certain function names are disallowed due to section name ambiguities
+ * introduced by -ffunction-sections.
+ *
+ * See the comment above TEXT_MAIN in include/asm-generic/vmlinux.lds.h.
+ */
+static int validate_function_names(struct objtool_file *file)
+{
+ struct symbol *func;
+ int warnings = 0;
+
+ for_each_sym(file->elf, func) {
+ if (!is_func_sym(func))
+ continue;
+
+ if (!strcmp(func->name, "startup") || strstarts(func->name, "startup.") ||
+ !strcmp(func->name, "exit") || strstarts(func->name, "exit.") ||
+ !strcmp(func->name, "split") || strstarts(func->name, "split.") ||
+ !strcmp(func->name, "unlikely") || strstarts(func->name, "unlikely.") ||
+ !strcmp(func->name, "hot") || strstarts(func->name, "hot.") ||
+ !strcmp(func->name, "unknown") || strstarts(func->name, "unknown.")) {
+
+ WARN("%s() function name creates ambiguity with -ffunction-sections",
+ func->name);
+ warnings++;
+ }
+ }
+
+ return warnings;
+}
+
static bool is_special_call(struct instruction *insn)
{
if (insn->type == INSN_CALL) {
@@ -4932,6 +4963,8 @@ int check(struct objtool_file *file)
if (!nr_insns)
goto out;
+ warnings += validate_function_names(file);
+
if (opts.retpoline)
warnings += validate_retpoline(file);
prev parent reply other threads:[~2025-11-13 7:08 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-12 23:47 [PATCH 0/4] objtool: Fix some -ffunction-sections edge cases Josh Poimboeuf
2025-11-12 23:47 ` [PATCH 1/4] vmlinux.lds: Fix TEXT_MAIN to include .text.start and friends Josh Poimboeuf
2025-11-13 7:08 ` [tip: objtool/core] " tip-bot2 for Josh Poimboeuf
2025-11-12 23:47 ` [PATCH 2/4] media: atomisp: Fix startup() section placement with -ffunction-sections Josh Poimboeuf
2025-11-13 7:08 ` [tip: objtool/core] media: atomisp: Fix namespace collision and " tip-bot2 for Josh Poimboeuf
2025-11-14 8:56 ` [PATCH 2/4] media: atomisp: Fix " Peter Zijlstra
2025-11-14 20:43 ` Josh Poimboeuf
2025-11-18 8:57 ` Peter Zijlstra
2025-11-12 23:47 ` [PATCH 3/4] drivers/xen/xenbus: Fix split() section placement with AutoFDO Josh Poimboeuf
2025-11-13 7:08 ` [tip: objtool/core] drivers/xen/xenbus: Fix namespace collision and " tip-bot2 for Josh Poimboeuf
2025-11-12 23:47 ` [PATCH 4/4] objtool: Warn on functions with ambiguous -ffunction-sections section names Josh Poimboeuf
2025-11-13 7:08 ` tip-bot2 for Josh Poimboeuf [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=176301773269.498.5236055241779881022.tip-bot2@tip-bot2 \
--to=tip-bot2@linutronix.de \
--cc=jpoimboe@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=live-patching@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=torvalds@linux-foundation.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox