gen_autoksyms.sh 2.0 KB

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