File size: 2,936 Bytes
864071c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#! /bin/sh

# Script to test that all the symbols of a shared object are as expected.

set -e

# Ensure stable ordering of `sort` output
LANG=C
LC_ALL=C
export LANG LC_ALL

if [ "$1" = "" -o "$2" = "" ] ; then
  echo "Usage: $0 <so_dir> <manifest_dir>" >&2
  exit 1
fi

input_dir="$1"
manifest_dir="$2"

sed=sed
grep=grep
# Helpers for Solaris
if [ -f /usr/bin/gsed ] ; then
  sed=/usr/bin/gsed
fi
if [ -f /usr/bin/ggrep ] ; then
  grep=/usr/bin/ggrep
fi

nm="nm -B -D"
if [ "`uname -s`" = "Linux" ]; then
  nm="$nm --with-symbol-versions"
elif [ "`uname -s`" = "FreeBSD" ]; then
  # Use llvm-nm to get symbol version information
  nm="llvm-nm -B -D"
elif [ "`uname -s`" = "SunOS" ]; then
  # Highly annoyingly, Solaris' nm doesn't show symbol versions, so here is a
  # laborious way to reformat the output of elfdump to be as we require.
  #nm="nm -p -h -D -g"
  nm=emulated_nm
  emulated_nm()
    {
    # Grab the versions from the version table, and convert into a sed script.
    VERSUB=`elfdump -v "$1" | \
      $grep -E '^\s*\[[0-9]+\]' | \
      $sed -E -e 's/\s+/,/g' | \
      tr -d '\[\]' | \
      cut -d',' -f 2,3 | \
      $sed -E -e 's/([0-9]+),(.*)/s\/@@\1\/@@\2\/;/'`

    # Then grab the symbols and heavily reformat the output to match nm.
    elfdump -T SHT_DYNSYM "$1" | \
      $grep -E '^\s*\[[0-9]+\]' | \
      $sed -E -e 's/\s+/ /g' | \
      cut -d' ' -f 3,8,9,10 | \
      $sed -E -e 's/^0x//;s/([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*)/\1 \3 \4@@\2/;' | \
      $sed -E -e 's/^([^ ]*) .text /\1 T /' | \
      $sed -E -e 's/^([^ ]*) ([UA])(NDEF|BS) /\1 \2 /' | \
      $sed -E -e "$VERSUB"
    }
elif [ "`uname -s`" = "Darwin" ]; then
  nm="nm -B -g"
fi

supports_versions=1
if [ "`uname -s`" = "Darwin" ]; then
  supports_versions=0
fi

so_ext=so
so_mangling() { cat; }
if [ "`uname -s`" = "Darwin" ]; then
  so_ext=dylib
  so_mangling()
    {
    $sed -E -e 's/_([_0-9a-zA-Z]+)$/\1/g'
    }
fi

for so_name in "libpcre2-8" "libpcre2-16" "libpcre2-32" "libpcre2-posix"; do
  expected_file="$manifest_dir/manifest-$so_name.so"
  so_file="$input_dir/$so_name.$so_ext"
  base=`basename $expected_file`

  $nm "$so_file" | \
    $sed -E -e 's/^[0-9a-fA-F]* *//g' | \
    $grep -E -v '^[Uw] ' | \
    $grep -E -v '^A PCRE2_' | \
    $grep -E -v ' (_init|_fini)($|@)' | \
    $grep -E -v ' (__bss_start|_end|_DYNAMIC|_GLOBAL_OFFSET_TABLE_|_PROCEDURE_LINKAGE_TABLE_|_edata|_etext)($|@)' | \
    so_mangling | \
    sort \
    > "$base.actual"

  if [ $supports_versions -eq 0 ]; then
    $sed -E -e 's/@.*$//' "$expected_file" \
      > "$base.expected"
  else
    cp "$expected_file" "$base.expected"
  fi

  if ! diff -u "$base.expected" "$base.actual"; then
    echo "Shared object contents for $so_file differ from expected"

    echo "===Actual==="
    cat "$base.actual"
    echo "===End==="

    exit 1
  fi

  echo "Shared object contents for $so_file match expected"
  rm -f "$base.expected" "$base.actual"

done