Manuel Pégourié-Gonnard | 0d0a104 | 2021-09-22 12:15:27 +0200 | [diff] [blame] | 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 | |
| 28 | set -eu |
| 29 | |
| 30 | # list mbedtls_ symbols of a given type in a static library |
| 31 | syms() { |
| 32 | TYPE="$1" |
| 33 | FILE="$2" |
| 34 | |
| 35 | nm "$FILE" | sed -n "s/[0-9a-f ]*${TYPE} \(mbedtls_.*\)/\1/p" | sort -u |
| 36 | } |
| 37 | |
| 38 | # create listings for the given library |
| 39 | list() { |
| 40 | NAME="$1" |
| 41 | FILE="library/libmbed${NAME}.a" |
| 42 | PREF="${CONFIG}-$NAME" |
| 43 | |
| 44 | syms '[TRrD]' $FILE > ${PREF}-defined |
| 45 | syms U $FILE > ${PREF}-unresolved |
| 46 | |
| 47 | diff ${PREF}-defined ${PREF}-unresolved \ |
| 48 | | sed -n 's/^> //p' > ${PREF}-external |
| 49 | sed 's/mbedtls_\([^_]*\).*/\1/' ${PREF}-external \ |
| 50 | | uniq -c | sort -rn > ${PREF}-modules |
| 51 | |
| 52 | rm ${PREF}-defined ${PREF}-unresolved |
| 53 | } |
| 54 | |
| 55 | CONFIG="${1:-unknown}" |
| 56 | |
| 57 | list x509 |
| 58 | list tls |