summaryrefslogtreecommitdiff
path: root/qpid/cpp/src/check-abi
blob: 3e85dab8623d48ea9cc1fc660cd0bb99c3d625f7 (plain)
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
#!/usr/bin/env bash

#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
#

MKTEMP="mktemp /tmp/tmp.XXXXXXXXXX"

# Ask the compiler the implementation specific type for a standard typedeffed type
# (int64_t, size_t etc.). Operates by test compiling and using the demangling ABI call.
#
# This works for gcc and clang on Unix.
full_type_of () {
    prog=$($MKTEMP)
    trap "rm $prog" EXIT

    ${CXX:-g++} -x c++ -o $prog - <<END-FILE
#include <stdint.h>
#include <stdlib.h>
#include <cxxabi.h>
#include <iostream>
#include <typeinfo>

int main() {
  int status;
  char* printable_type =
    __cxxabiv1::__cxa_demangle(typeid($1).name(), 0, 0, &status);
  if (printable_type) {
    std::cout << printable_type;
  } else {
    std::cout << "$1";
  }
  ::free(printable_type);
}
END-FILE
$prog
}

rc=0
syms_desired=$($MKTEMP)
syms_library=$($MKTEMP)
syms_missing=$($MKTEMP)
syms_extra=$($MKTEMP)

trap 'rm $syms_desired $syms_library $syms_missing $syms_extra' EXIT

CXX=$1
export CXX

LC_ALL=C
export LC_ALL

# Extract exported symbols from library
nm -DC --defined-only -f s $2 | cut -f1 -d'|' -s | sort -u > $syms_library

# Process API syms (substitute in some typedefs etc.)
sed -e "
    s/uint64_t/$(full_type_of uint64_t)/
    s/uint32_t/unsigned int/
    s/uint16_t/unsigned short/
    s/uint8_t/unsigned char/
    s/size_t/$(full_type_of size_t)/
    s/int64_t/$(full_type_of int64_t)/
    s/int32_t/int/
    s/int16_t/short/
    s/int8_t/signed char/
    s/qpid::types::Variant::Map/std::map<std::string, qpid::types::Variant, std::less<std::string>, std::allocator<std::pair<std::string const, qpid::types::Variant> > >/
    s/qpid::types::Variant::List/std::list<qpid::types::Variant, std::allocator<qpid::types::Variant> >/
    /^\$/d
    /^#.*\$/d
" $3 | sort -u > $syms_desired

comm -23 $syms_desired $syms_library > $syms_missing
comm -13 $syms_desired $syms_library > $syms_extra

if [ -n "$(cat $syms_missing)" ] ; then
  (echo "Not exported from library (should be)"
   echo "====================================="
   cat $syms_missing ) 1>&2
   rc=1
fi


if [ -n "$(cat $syms_extra)" ]; then
  (echo "Exported by library but not in spec"
   echo "==================================="
   cat $syms_extra ) 1>&2
fi

exit $rc