summaryrefslogtreecommitdiff
path: root/scripts/check-local-export
diff options
context:
space:
mode:
authorSughosh Ganu <[email protected]>2025-12-16 11:16:24 +0200
committerTom Rini <[email protected]>2026-01-02 10:28:14 -0600
commitbd3f9ee679b4d1456d0d3c261ab76788950e6096 (patch)
treea50e5ddfb4b5116903ad59753af910a76874705e /scripts/check-local-export
parent56ae3c2a44fcd8e2f680c51620011273727ae9db (diff)
kbuild: Bump the build system to 6.1
Our last sync with the kernel was 5.1. We are so out of sync now, that tracking the patches and backporting them one by one makes little sense and it's going to take ages. This is an attempt to sync up Makefiles to 6.1. Unfortunately due to sheer amount of patches this is not easy to review, but that's what we decided during a community call for the bump to 5.1, so we are following the same guidelines here. Signed-off-by: Sughosh Ganu <[email protected]> Signed-off-by: Ilias Apalodimas <[email protected]>a #rebased on -next
Diffstat (limited to 'scripts/check-local-export')
-rwxr-xr-xscripts/check-local-export71
1 files changed, 71 insertions, 0 deletions
diff --git a/scripts/check-local-export b/scripts/check-local-export
new file mode 100755
index 00000000000..6ccc2f46741
--- /dev/null
+++ b/scripts/check-local-export
@@ -0,0 +1,71 @@
+#!/usr/bin/env bash
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# Copyright (C) 2022 Masahiro Yamada <[email protected]>
+#
+# Exit with error if a local exported symbol is found.
+# EXPORT_SYMBOL should be used for global symbols.
+
+set -e
+
+# catch errors from ${NM}
+set -o pipefail
+
+# Run the last element of a pipeline in the current shell.
+# Without this, the while-loop would be executed in a subshell, and
+# the changes made to 'symbol_types' and 'export_symbols' would be lost.
+shopt -s lastpipe
+
+declare -A symbol_types
+declare -a export_symbols
+
+exit_code=0
+
+# If there is no symbol in the object, ${NM} (both GNU nm and llvm-nm) shows
+# 'no symbols' diagnostic (but exits with 0). It is harmless and hidden by
+# '2>/dev/null'. However, it suppresses real error messages as well. Add a
+# hand-crafted error message here.
+#
+# TODO:
+# Use --quiet instead of 2>/dev/null when we upgrade the minimum version of
+# binutils to 2.37, llvm to 13.0.0.
+# Then, the following line will be really simple:
+# ${NM} --quiet ${1} |
+
+{ ${NM} ${1} 2>/dev/null || { echo "${0}: ${NM} failed" >&2; false; } } |
+while read value type name
+do
+ # Skip the line if the number of fields is less than 3.
+ #
+ # case 1)
+ # For undefined symbols, the first field (value) is empty.
+ # The outout looks like this:
+ # " U _printk"
+ # It is unneeded to record undefined symbols.
+ #
+ # case 2)
+ # For Clang LTO, llvm-nm outputs a line with type 't' but empty name:
+ # "---------------- t"
+ if [[ -z ${name} ]]; then
+ continue
+ fi
+
+ # save (name, type) in the associative array
+ symbol_types[${name}]=${type}
+
+ # append the exported symbol to the array
+ if [[ ${name} == __ksymtab_* ]]; then
+ export_symbols+=(${name#__ksymtab_})
+ fi
+done
+
+for name in "${export_symbols[@]}"
+do
+ # nm(3) says "If lowercase, the symbol is usually local"
+ if [[ ${symbol_types[$name]} =~ [a-z] ]]; then
+ echo "$@: error: local symbol '${name}' was exported" >&2
+ exit_code=1
+ fi
+done
+
+exit ${exit_code}