Behdad Esfahbod | a02d864 | 2012-08-08 18:04:29 -0400 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | LC_ALL=C |
| 4 | export LC_ALL |
| 5 | |
| 6 | test -z "$srcdir" && srcdir=. |
Ebrahim Byagowi | 72bec1c | 2018-01-05 12:42:20 +0330 | [diff] [blame] | 7 | test -z "$libs" && libs=.libs |
Behdad Esfahbod | a02d864 | 2012-08-08 18:04:29 -0400 | [diff] [blame] | 8 | stat=0 |
| 9 | |
Behdad Esfahbod | e0939d8 | 2018-02-23 13:19:34 -0800 | [diff] [blame] | 10 | IGNORED_SYMBOLS='_fini\|_init\|_fdata\|_ftext\|_fbss\|__bss_start\|__bss_start__\|__bss_end__\|_edata\|_end\|_bss_end__\|__end__\|__gcov_flush\|llvm_.*' |
Behdad Esfahbod | 2af8262 | 2013-09-16 21:49:56 -0400 | [diff] [blame] | 11 | |
Behdad Esfahbod | a02d864 | 2012-08-08 18:04:29 -0400 | [diff] [blame] | 12 | if which nm 2>/dev/null >/dev/null; then |
| 13 | : |
| 14 | else |
Behdad Esfahbod | bafdf3d | 2013-02-04 23:06:50 -0500 | [diff] [blame] | 15 | echo "check-symbols.sh: 'nm' not found; skipping test" |
Behdad Esfahbod | a02d864 | 2012-08-08 18:04:29 -0400 | [diff] [blame] | 16 | exit 77 |
| 17 | fi |
| 18 | |
Behdad Esfahbod | a02d864 | 2012-08-08 18:04:29 -0400 | [diff] [blame] | 19 | tested=false |
Behdad Esfahbod | a981d79 | 2018-02-10 15:17:28 -0600 | [diff] [blame] | 20 | for soname in harfbuzz harfbuzz-subset harfbuzz-icu harfbuzz-gobject; do |
Ebrahim Byagowi | 844f48e | 2018-02-10 23:13:12 +0330 | [diff] [blame] | 21 | for suffix in so dylib; do |
| 22 | so=$libs/lib$soname.$suffix |
| 23 | if ! test -f "$so"; then continue; fi |
Ebrahim Byagowi | bef240b | 2016-10-10 17:27:52 +0330 | [diff] [blame] | 24 | |
Ebrahim Byagowi | 844f48e | 2018-02-10 23:13:12 +0330 | [diff] [blame] | 25 | # On macOS, C symbols are prefixed with _ |
Behdad Esfahbod | e0939d8 | 2018-02-23 13:19:34 -0800 | [diff] [blame] | 26 | symprefix= |
| 27 | if test $suffix = dylib; then symprefix=_; fi |
Behdad Esfahbod | 8c6bd34 | 2014-08-14 13:33:37 -0400 | [diff] [blame] | 28 | |
Behdad Esfahbod | e0939d8 | 2018-02-23 13:19:34 -0800 | [diff] [blame] | 29 | EXPORTED_SYMBOLS="`nm "$so" | grep ' [BCDGINRSTVW] .' | grep -v " $symprefix\\($IGNORED_SYMBOLS\\>\\)" | cut -d' ' -f3 | c++filt`" |
| 30 | |
| 31 | prefix=$symprefix`basename "$so" | sed 's/libharfbuzz/hb/; s/-/_/g; s/[.].*//'` |
| 32 | |
Behdad Esfahbod | e0939d8 | 2018-02-23 13:19:34 -0800 | [diff] [blame] | 33 | echo "Checking that $so does not expose internal symbols" |
Ebrahim Byagowi | 844f48e | 2018-02-10 23:13:12 +0330 | [diff] [blame] | 34 | if echo "$EXPORTED_SYMBOLS" | grep -v "^${prefix}\(_\|$\)"; then |
| 35 | echo "Ouch, internal symbols exposed" |
| 36 | stat=1 |
| 37 | fi |
Behdad Esfahbod | 2af8262 | 2013-09-16 21:49:56 -0400 | [diff] [blame] | 38 | |
Behdad Esfahbod | e0939d8 | 2018-02-23 13:19:34 -0800 | [diff] [blame] | 39 | def=$soname.def |
| 40 | if ! test -f "$def"; then |
| 41 | echo "'$def' not found; skipping" |
| 42 | else |
Behdad Esfahbod | e0939d8 | 2018-02-23 13:19:34 -0800 | [diff] [blame] | 43 | echo "Checking that $so has the same symbol list as $def" |
| 44 | { |
| 45 | echo EXPORTS |
| 46 | echo "$EXPORTED_SYMBOLS" | sed -e "s/^${symprefix}hb/hb/g" |
| 47 | # cheat: copy the last line from the def file! |
| 48 | tail -n1 "$def" |
| 49 | } | c++filt | diff "$def" - >&2 || stat=1 |
| 50 | fi |
| 51 | |
Ebrahim Byagowi | 844f48e | 2018-02-10 23:13:12 +0330 | [diff] [blame] | 52 | tested=true |
| 53 | done |
Behdad Esfahbod | a02d864 | 2012-08-08 18:04:29 -0400 | [diff] [blame] | 54 | done |
| 55 | if ! $tested; then |
Behdad Esfahbod | e0939d8 | 2018-02-23 13:19:34 -0800 | [diff] [blame] | 56 | echo "check-symbols.sh: no shared libraries found; skipping test" |
Behdad Esfahbod | a02d864 | 2012-08-08 18:04:29 -0400 | [diff] [blame] | 57 | exit 77 |
| 58 | fi |
| 59 | |
| 60 | exit $stat |