syms.sh 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/bin/sh
  2. #
  3. # Copyright The Mbed TLS Contributors
  4. # SPDX-License-Identifier: Apache-2.0
  5. #
  6. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  7. # not use this file except in compliance with the License.
  8. # You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  14. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. #
  18. # Purpose
  19. #
  20. # Show symbols in the X.509 and TLS libraries that are defined in another
  21. # libmbedtlsXXX.a library. This is usually done to list Crypto dependencies.
  22. #
  23. # Usage:
  24. # - build the library with debug symbols and the config you're interested in
  25. # (default, full minus MBEDTLS_USE_PSA_CRYPTO, full, etc.)
  26. # - run this script with the name of your config as the only argument
  27. set -eu
  28. # list mbedtls_ symbols of a given type in a static library
  29. syms() {
  30. TYPE="$1"
  31. FILE="$2"
  32. nm "$FILE" | sed -n "s/[0-9a-f ]*${TYPE} \(mbedtls_.*\)/\1/p" | sort -u
  33. }
  34. # create listings for the given library
  35. list() {
  36. NAME="$1"
  37. FILE="library/libmbed${NAME}.a"
  38. PREF="${CONFIG}-$NAME"
  39. syms '[TRrD]' $FILE > ${PREF}-defined
  40. syms U $FILE > ${PREF}-unresolved
  41. diff ${PREF}-defined ${PREF}-unresolved \
  42. | sed -n 's/^> //p' > ${PREF}-external
  43. sed 's/mbedtls_\([^_]*\).*/\1/' ${PREF}-external \
  44. | uniq -c | sort -rn > ${PREF}-modules
  45. rm ${PREF}-defined ${PREF}-unresolved
  46. }
  47. CONFIG="${1:-unknown}"
  48. list x509
  49. list tls