check_blobs.sh 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. if [ -z "${IDF_PATH:-}" ]; then
  4. echo "IDF_PATH must be set before running this script"
  5. exit 1
  6. fi
  7. failed=""
  8. # check_lib_symbols <libraray path> <symbols to look for...>
  9. #
  10. # If the given library contains references to the listed symbols, prints
  11. # a message and adds the library to "failed" list.
  12. function check_lib_symbols {
  13. lib="$1"
  14. symbols="${@:2}"
  15. syms_file="$(mktemp)"
  16. # for symbols="foo bar" create grep search argument "foo\|bar"
  17. symbols_args="${symbols// /\\|}"
  18. errors=0
  19. nm -A $lib 2>/dev/null | { grep -w "${symbols_args}" > ${syms_file} || true; }
  20. if [ $(wc -l <${syms_file}) != 0 ]; then
  21. echo "${lib}: found illegal symbol references:"
  22. cat ${syms_file} | sed 's/^/\t/'
  23. failed="${failed} ${lib}"
  24. errors=1
  25. fi
  26. if [ $errors == 0 ]; then
  27. echo "${lib}: OK"
  28. fi
  29. rm -f ${syms_file}
  30. }
  31. # Check Wi-Fi, PHY libraries for references to "printf"-like functions:
  32. illegal_symbols="printf ets_printf"
  33. pushd ${IDF_PATH}/components/esp_wifi/lib > /dev/null
  34. wifi_targets=$(find . -type d -name 'esp*' -exec basename {} \; | sort)
  35. for target in ${wifi_targets}; do
  36. for library in ${target}/*.a; do
  37. check_lib_symbols ${library} ${illegal_symbols}
  38. done
  39. done
  40. popd > /dev/null
  41. pushd ${IDF_PATH}/components/esp_phy/lib > /dev/null
  42. phy_targets=$(find . -type d -name 'esp*' -exec basename {} \; | sort)
  43. for target in ${phy_targets}; do
  44. libraries=$(find ${target} -name '*.a')
  45. for library in ${libraries}; do
  46. check_lib_symbols ${library} ${illegal_symbols}
  47. done
  48. done
  49. popd > /dev/null
  50. # Print summary
  51. if [ -n "${failed}" ]; then
  52. echo "Issues found in the following libraries:"
  53. for lib in $failed; do
  54. echo "- $lib"
  55. done
  56. exit 1
  57. fi