]> git.cworth.org Git - fips/blob - extract-wrapped-symbols
Makefile: Automatically generate libfips.sym symbol map
[fips] / extract-wrapped-symbols
1 #!/bin/sh
2
3 # Extract symbols from the fips source code for functions that are wrapped.
4
5 # Output is a version script, (suitable to be passed to the linker
6 # through a compiler flag -f -Wl,--version-script=<foo>), which
7 # indicates that the extracted symbols should be exported from
8 # libfips, while all other symbols are private.
9
10 # We have two different patterns for identifying wrapped
11 # functions. The first is a call to a macro ending in "DEFER" (such as
12 # DEFER or TIMED_DEFER). In this case, the first argument to the macro
13 # is the name of the wrapped function.
14
15 deferred=`grep 'DEFER[ (]*e*gl' $@ | sed -s 's/.*DEFER *(\([^,)]*\).*/\1/'`
16
17 # The second-case is functions for which we either implement or call
18 # the underlying "real" function. In these cases, the code uses the
19 # convention of having a function or a function-pointer with a name of
20 # the form *wrap_real_<function>
21
22 wrapped=`grep wrap_real_ $@ | sed -e 's/.*wrap_real_\([a-zA-Z0-9_]*\).*/\1/'`
23
24 # With those two lists collected, all we need is a simple template for
25 # a version script, along with alphabetic sorting and uniquifying of
26 # the list, (and adding tabs for nice-looking indentation and ';'
27 # separators).
28
29 cat <<EOF
30 {
31 global:
32 EOF
33
34 echo "$deferred
35 $wrapped" | sort | uniq | sed -e 's/\(.*\)/     \1;/'
36
37 cat <<EOF
38 local:
39         *;
40 };
41 EOF