File: dynamic_dependency_test.sh

package info (click to toggle)
cfengine3 3.24.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 37,552 kB
  • sloc: ansic: 163,161; sh: 10,296; python: 2,950; makefile: 1,744; lex: 784; yacc: 633; perl: 211; pascal: 157; xml: 21; sed: 13
file content (83 lines) | stat: -rwxr-xr-x 3,026 bytes parent folder | download | duplicates (5)
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
#!/bin/sh

# Tests that the symbols in our static libraries do not occur twice in the
# output binaries. Most platforms don't warn about this, but it has potential
# ill effects.
#
# How it can happen: It can happen if we list a static library as a dependency
# for libpromises, and then we list the same static library as a dependency for
# a binary that depends on libpromises. Then the symbol will be included both
# in the library and in the binary.
#
# What effects does it have: Exactly how the symbols are resolved appears to be
# platform dependent, but what can happen is this: At any point, when you call
# a duplicate symbol, depending on where you call it from, you will either call
# the version in the binary or in the library. This is fine, since they both
# contain exactly the same code. However, they do not refer to the same global
# symbols. They each have their own set. This means that something that was
# initialized in the binary may not be initialized in the library, even though
# the symbol name is the same. This has weird effects, like a symbol suddenly
# switching from a valid value to zero when the stack trace crosses a library
# boundary.
#
# The problem has been observed on AIX, where the log level randomly switches
# between verbose and non-verbose, depending on where the Log() function was
# called from. It has also been observed on certain Linux versions (Ubuntu
# 12.04).
#
# How do we test for it: By making sure that functions that are known to be in
# the static libraries are undefined in the binaries, which means that they
# will link to the shared library version, instead of using their own version.

#
# Detect and replace non-POSIX shell
#
try_exec() {
    type "$1" > /dev/null 2>&1 && exec "$@"
}

broken_posix_shell()
{
    unset foo
    local foo=1
    test "$foo" != "1"
}

if broken_posix_shell >/dev/null 2>&1; then
    try_exec /usr/xpg4/bin/sh "$0" "$@"
    echo "No compatible shell script interpreter found."
    echo "Please find a POSIX shell for your system."
    exit 42
fi


cd ../..

# Sanity check that nm works.
if ! which nm | grep '^/' >/dev/null; then
    echo "Could not find nm"
    exit 2
fi

#                libutils.a         libenv.a         libcfnet.a
#                    v                 v                 v
for symbol in LogSetGlobalLevel GetInterfacesInfo ConnectionInfoNew; do
    for binary in cf-*; do
        if test "$binary" = "cf-check" ; then
            continue
        fi
        if test -e "$binary/.libs/$binary"; then
            LOC="$binary/.libs/$binary"
        else
            LOC="$binary/$binary"
        fi
        if nm "$LOC" | grep "$symbol" >/dev/null 2>&1 && ! nm -u "$LOC" | grep "$symbol" >/dev/null 2>&1; then
            echo "$symbol is defined in $binary, but should be undefined."
            echo "Most likely a static library is listed in the Makefile.am which shouldn't be."
            echo "Check the *_LDADD statements in $binary/Makefile.am."
            exit 1
        fi
    done
done

exit 0