^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) #!/bin/sh
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) # SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) # Create an autoksyms.h header file from the list of all module's needed symbols
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) # as recorded on the second line of *.mod files and the user-provided symbol
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) # whitelist.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) set -e
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) output_file="$1"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) # Use "make V=1" to debug this script.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) case "$KBUILD_VERBOSE" in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) *1*)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) set -x
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) ;;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) esac
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) # We need access to CONFIG_ symbols
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) . include/config/auto.conf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) needed_symbols=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) # Special case for modversions (see modpost.c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) if [ -n "$CONFIG_MODVERSIONS" ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) needed_symbols="$needed_symbols module_layout"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) # With CONFIG_LTO_CLANG, LLVM bitcode has not yet been compiled into a binary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) # when the .mod files are generated, which means they don't yet contain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) # references to certain symbols that will be present in the final binaries.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) if [ -n "$CONFIG_LTO_CLANG" ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) # intrinsic functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) needed_symbols="$needed_symbols memcpy memmove memset"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) # ftrace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) needed_symbols="$needed_symbols _mcount"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) # stack protector symbols
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) needed_symbols="$needed_symbols __stack_chk_fail __stack_chk_guard"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) ksym_wl=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) if [ -n "$CONFIG_UNUSED_KSYMS_WHITELIST" ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) # Use 'eval' to expand the whitelist path and check if it is relative
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) eval ksym_wl="$CONFIG_UNUSED_KSYMS_WHITELIST"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) [ "${ksym_wl}" != "${ksym_wl#/}" ] || ksym_wl="$abs_srctree/$ksym_wl"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) if [ ! -f "$ksym_wl" ] || [ ! -r "$ksym_wl" ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) echo "ERROR: '$ksym_wl' whitelist file not found" >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) exit 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) # Generate a new ksym list file with symbols needed by the current
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) # set of modules.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) cat > "$output_file" << EOT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * Automatically generated file; DO NOT EDIT.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) EOT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) [ -f modules.order ] && modlist=modules.order || modlist=/dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) sed 's/ko$/mod/' $modlist | xargs -n1 sed -n -e '2p'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) echo "$needed_symbols"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) [ -n "$ksym_wl" ] && cat "$ksym_wl"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) } | sed -e 's/ /\n/g' | sed -n -e '/^$/!p' |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) # Remove the dot prefix for ppc64; symbol names with a dot (.) hold entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) # point addresses.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) sed -e 's/^\.//' |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) sort -u |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) sed -e 's/\(.*\)/#define __KSYM_\1 1/' >> "$output_file"