* [PATCH] scripts: check-function-names: propagate nm failures
@ 2026-11-03 10:58 Hamdy Abou El Anein
2026-11-04 10:58 ` sashiko-bot
2026-11-04 12:03 ` [PATCH v2] " Hamdy Abou El Anein
0 siblings, 2 replies; 6+ messages in thread
From: Hamdy Abou El Anein @ 2026-11-03 10:58 UTC (permalink / raw)
To: nathan; +Cc: nsc, linux-kbuild, linux-kernel, hamdy.aea
From: Hamdy Abou El Anein <hamdy.aea@protonmail.com>
The symbol-name check pipes nm through awk and grep. If nm cannot read
an object file, its failure status is lost and the script reports
success without checking any symbols.
Capture nm output before filtering it and fail when nm fails. This
keeps the existing forbidden-name detection unchanged.
Tested with a malformed object (failure), a valid object (success),
and an object defining startup (failure).
Signed-off-by: Hamdy Abou El Anein <hamdy.aea@protonmail.com>
---
scripts/check-function-names.sh | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/scripts/check-function-names.sh b/scripts/check-function-names.sh
index 94883e6..f07a0e1 100755
--- a/scripts/check-function-names.sh
+++ b/scripts/check-function-names.sh
@@ -13,7 +13,8 @@ if [ ! -f "$objfile" ]; then
exit 1
fi
-bad_symbols=$(${NM:-nm} -p "$objfile" | awk '$2 ~ /^[TtWw]$/ {print $3}' |
+symbols=$(${NM:-nm} -p "$objfile") || exit 1
+bad_symbols=$(printf '%s\n' "$symbols" | awk '$2 ~ /^[TtWw]$/ {print $3}' |
grep -E '^(startup|exit|split|unlikely|hot|unknown)(\.|$)')
if [ -n "$bad_symbols" ]; then
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
--
2.56.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] scripts: check-function-names: propagate nm failures
2026-11-03 10:58 [PATCH] scripts: check-function-names: propagate nm failures Hamdy Abou El Anein
@ 2026-11-04 10:58 ` sashiko-bot
2026-11-04 12:03 ` [PATCH v2] " Hamdy Abou El Anein
1 sibling, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-11-04 10:58 UTC (permalink / raw)
To: Hamdy Abou El Anein, nathan; +Cc: nsc, linux-kbuild, hamdy.aea
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] scripts: check-function-names: buffering full vmlinux.o nm output in shell
--
commit 329efcc5adb68fe0ddbe8ccd5ee716b893c4188e
Author: Hamdy Abou El Anein <hamdy.aea@protonmail.com>
scripts: check-function-names: propagate nm failures
This commit captures the output of nm in a shell variable before piping it
to awk and grep so that check-function-names.sh exits with an error if nm
fails on the input object file.
> diff --git a/scripts/check-function-names.sh b/scripts/check-function-names.sh
> index 94883e690627d..f07a0e1cf3394 100755
> --- a/scripts/check-function-names.sh
> +++ b/scripts/check-function-names.sh
> @@ -13,7 +13,8 @@ if [ ! -f "$objfile" ]; then
> exit 1
> fi
>
> -bad_symbols=$(${NM:-nm} -p "$objfile" | awk '$2 ~ /^[TtWw]$/ {print $3}' |
> +symbols=$(${NM:-nm} -p "$objfile") || exit 1
> +bad_symbols=$(printf '%s\n' "$symbols" | awk '$2 ~ /^[TtWw]$/ {print $3}' |
> grep -E '^(startup|exit|split|unlikely|hot|unknown)(\.|$)')
[Severity: Medium]
Does capturing the entire nm output into symbols and expanding it into
printf introduce a build-time performance and memory regression when linking
vmlinux.o?
In scripts/Makefile.vmlinux_o, rule_ld_vmlinux.o runs this script on
vmlinux.o in the serial path of the kernel link:
scripts/Makefile.vmlinux_o:
cmd_check_function_names = $(srctree)/scripts/check-function-names.sh $@
define rule_ld_vmlinux.o
$(call cmd_and_savecmd,ld_vmlinux.o)
$(call cmd,gen_objtooldep)
$(call cmd,check_function_names)
endef
Because vmlinux.o contains the full built-in kernel symbol table (spanning
many megabytes and hundreds of thousands of symbols, especially on
allmodconfig or allyesconfig builds), previously nm -p streamed directly
into awk in parallel and command substitution only buffered the matching
bad_symbols output (which is empty in the normal case).
With this change, the shell waits for nm to finish while buffering the
entire multi-megabyte symbol table in the symbols variable, and then forks a
subshell that expands and copies the entire string as an argument to printf
before piping it to awk, working against the serial link optimization in
commit c2970d8b52d1 ("kbuild: do not sort nm output where the order is
irrelevant").
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261103105829.10511-1-info@daylightlinux.ch?part=1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2] scripts: check-function-names: propagate nm failures
2026-11-03 10:58 [PATCH] scripts: check-function-names: propagate nm failures Hamdy Abou El Anein
2026-11-04 10:58 ` sashiko-bot
@ 2026-11-04 12:03 ` Hamdy Abou El Anein
2026-11-04 12:07 ` [PATCH v3] " Hamdy Abou El Anein
1 sibling, 1 reply; 6+ messages in thread
From: Hamdy Abou El Anein @ 2026-11-04 12:03 UTC (permalink / raw)
To: nathan; +Cc: nsc, linux-kbuild, linux-kernel, hamdy.aea
From: Hamdy Abou El Anein <hamdy.aea@protonmail.com>
The symbol-name check pipes nm through awk and grep. If nm cannot read
an object file, its failure status is lost and the script reports
success without checking any symbols.
Keep nm output streaming while carrying its exit status through the
filter. This avoids buffering the full vmlinux.o symbol table in a
shell variable during the serial kernel link.
Tested with a malformed object (failure), a valid object (success), an
object defining startup (failure), and a synthetic large nm stream
(success).
AI assistance: ChatGPT/Codex identified the issue and prepared the
change, commit message and executable regression tests.
Signed-off-by: Hamdy Abou El Anein <hamdy.aea@protonmail.com>
---
scripts/check-function-names.sh | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/scripts/check-function-names.sh b/scripts/check-function-names.sh
index 94883e690627..f07a0e1cf339 100755
--- a/scripts/check-function-names.sh
+++ b/scripts/check-function-names.sh
@@ -13,7 +13,8 @@ if [ ! -f "$objfile" ]; then
exit 1
fi
-bad_symbols=$(${NM:-nm} -p "$objfile" | awk '$2 ~ /^[TtWw]$/ {print $3}' |
+symbols=$(${NM:-nm} -p "$objfile") || exit 1
+bad_symbols=$(printf '%s\n' "$symbols" | awk '$2 ~ /^[TtWw]$/ {print $3}' |
grep -E '^(startup|exit|split|unlikely|hot|unknown)(\.|$)')
if [ -n "$bad_symbols" ]; then
--
2.56.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v3] scripts: check-function-names: propagate nm failures
2026-11-04 12:03 ` [PATCH v2] " Hamdy Abou El Anein
@ 2026-11-04 12:07 ` Hamdy Abou El Anein
2026-11-04 23:26 ` Nathan Chancellor
0 siblings, 1 reply; 6+ messages in thread
From: Hamdy Abou El Anein @ 2026-11-04 12:07 UTC (permalink / raw)
To: nathan; +Cc: nsc, linux-kbuild, linux-kernel, hamdy.aea
From: Hamdy Abou El Anein <hamdy.aea@protonmail.com>
The symbol-name check pipes nm through awk and grep. If nm cannot read
an object file, its failure status is lost and the script reports
success without checking any symbols.
Keep nm output streaming while carrying its exit status through the
filter. This avoids buffering the full vmlinux.o symbol table in a
shell variable during the serial kernel link, as the v2 did.
Tested with a malformed object (failure), a valid object (success), an
object defining startup (failure), and a synthetic large nm stream
(success).
AI assistance: ChatGPT/Codex identified the issue and prepared the
change, commit message and executable regression tests.
Signed-off-by: Hamdy Abou El Anein <hamdy.aea@protonmail.com>
---
scripts/check-function-names.sh | 25 ++++++++++++++++++++++---
1 file changed, 22 insertions(+), 3 deletions(-)
diff --git a/scripts/check-function-names.sh b/scripts/check-function-names.sh
index 94883e690627..b25e630cc594 100755
--- a/scripts/check-function-names.sh
+++ b/scripts/check-function-names.sh
@@ -13,9 +13,28 @@ if [ ! -f "$objfile" ]; then
exit 1
fi
-bad_symbols=$(${NM:-nm} -p "$objfile" | awk '$2 ~ /^[TtWw]$/ {print $3}' |
- grep -E '^(startup|exit|split|unlikely|hot|unknown)(\.|$)')
-
+# Keep nm output streaming while preserving its exit status.
+bad_symbols=$(
+ {
+ ${NM:-nm} -p "$objfile"
+ nm_status=$?
+ printf '\n#nm_status %s\n' "$nm_status"
+ } |
+ awk '
+ $1 == "#nm_status" {
+ if ($2 != 0)
+ nm_failed = 1
+ next
+ }
+ $2 ~ /^[TtWw]$/ && $3 ~ /^(startup|exit|split|unlikely|hot|unknown)(\.|$)/ {
+ print $3
+ }
+ END {
+ if (nm_failed)
+ exit 1
+ }
+ '
+) || exit 1
if [ -n "$bad_symbols" ]; then
echo "$bad_symbols" | while read -r sym; do
echo "$objfile: error: $sym() function name creates ambiguity with -ffunction-sections" >&2
--
2.56.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v3] scripts: check-function-names: propagate nm failures
2026-11-04 12:07 ` [PATCH v3] " Hamdy Abou El Anein
@ 2026-11-04 23:26 ` Nathan Chancellor
2026-11-05 13:02 ` Hamdy Abou El Anein
0 siblings, 1 reply; 6+ messages in thread
From: Nathan Chancellor @ 2026-11-04 23:26 UTC (permalink / raw)
To: Hamdy Abou El Anein; +Cc: nsc, linux-kbuild, linux-kernel, hamdy.aea
Hi Hamdy,
On Wed, Nov 04, 2026 at 01:07:33PM +0100, Hamdy Abou El Anein wrote:
> From: Hamdy Abou El Anein <hamdy.aea@protonmail.com>
>
> The symbol-name check pipes nm through awk and grep. If nm cannot read
> an object file, its failure status is lost and the script reports
> success without checking any symbols.
If nm fails because vmlinux.o is malformed, surely that means that $(LD)
is going to choke on it too? This feels like unnecessary complication
and hardening for little gain. Were you able to reproduce a situation
where $(NM) failed but the rest of the build succeeded?
> Keep nm output streaming while carrying its exit status through the
> filter. This avoids buffering the full vmlinux.o symbol table in a
> shell variable during the serial kernel link, as the v2 did.
Just a work of advice for the future, avoid mentioning revisions within
the commit message, they won't make sense once the patch is applied.
Place differential notes below the '---' after your signoff and make
sure the commit message makes sense on its own.
> Tested with a malformed object (failure), a valid object (success), an
> object defining startup (failure), and a synthetic large nm stream
> (success).
>
> AI assistance: ChatGPT/Codex identified the issue and prepared the
> change, commit message and executable regression tests.
>
> Signed-off-by: Hamdy Abou El Anein <hamdy.aea@protonmail.com>
> ---
> scripts/check-function-names.sh | 25 ++++++++++++++++++++++---
> 1 file changed, 22 insertions(+), 3 deletions(-)
>
> diff --git a/scripts/check-function-names.sh b/scripts/check-function-names.sh
> index 94883e690627..b25e630cc594 100755
> --- a/scripts/check-function-names.sh
> +++ b/scripts/check-function-names.sh
> @@ -13,9 +13,28 @@ if [ ! -f "$objfile" ]; then
> exit 1
> fi
>
> -bad_symbols=$(${NM:-nm} -p "$objfile" | awk '$2 ~ /^[TtWw]$/ {print $3}' |
> - grep -E '^(startup|exit|split|unlikely|hot|unknown)(\.|$)')
> -
> +# Keep nm output streaming while preserving its exit status.
> +bad_symbols=$(
> + {
> + ${NM:-nm} -p "$objfile"
> + nm_status=$?
> + printf '\n#nm_status %s\n' "$nm_status"
> + } |
> + awk '
> + $1 == "#nm_status" {
> + if ($2 != 0)
> + nm_failed = 1
> + next
> + }
> + $2 ~ /^[TtWw]$/ && $3 ~ /^(startup|exit|split|unlikely|hot|unknown)(\.|$)/ {
> + print $3
> + }
> + END {
> + if (nm_failed)
> + exit 1
> + }
> + '
> +) || exit 1
> if [ -n "$bad_symbols" ]; then
> echo "$bad_symbols" | while read -r sym; do
> echo "$objfile: error: $sym() function name creates ambiguity with -ffunction-sections" >&2
> --
> 2.56.0
>
--
Cheers,
Nathan
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v3] scripts: check-function-names: propagate nm failures
2026-11-04 23:26 ` Nathan Chancellor
@ 2026-11-05 13:02 ` Hamdy Abou El Anein
0 siblings, 0 replies; 6+ messages in thread
From: Hamdy Abou El Anein @ 2026-11-05 13:02 UTC (permalink / raw)
To: nathan; +Cc: nsc, linux-kbuild, linux-kernel, hamdy.aea
Hi Nathan,
Thanks for the review. I checked the vmlinux.o rule and tested with GNU binutils 2.47.
A valid object linked successfully with ld -r and was read successfully by nm. For malformed and truncated objects, I could not reproduce nm failing while ld accepted the same input: bad-format and malformed symbol-table objects failed in both tools, while truncated objects were rejected by ld.
I also tested a wrapper that runs nm successfully and then returns an error. That confirms the shell pipeline masks a failing command status, but it does not reproduce a real nm failure on a valid vmlinux.o.
I have not found the build scenario you asked for, so I am withdrawing this patch.
Regards,
Hamdy
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-05 13:02 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-03 10:58 [PATCH] scripts: check-function-names: propagate nm failures Hamdy Abou El Anein
2026-11-04 10:58 ` sashiko-bot
2026-11-04 12:03 ` [PATCH v2] " Hamdy Abou El Anein
2026-11-04 12:07 ` [PATCH v3] " Hamdy Abou El Anein
2026-11-04 23:26 ` Nathan Chancellor
2026-11-05 13:02 ` Hamdy Abou El Anein
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox