check-namespace.sh.in revision ef29eade44fc2aa7e49811a8bd76e941b369b914
1#!/bin/sh
2verbose=false
3if [ "$1" = "-v" ]; then
4    verbose=true
5    shift
6fi
7
8build_plat=@build_arch@
9plat=@arch@
10os=@target_os@
11num_errors=0
12
13LIBUNWIND=../src/.libs/libunwind.so
14LIBUNWIND_GENERIC=../src/.libs/libunwind-${plat}.so
15
16fetch_symtab () {
17    filename=$1
18
19    if [ ! -r $filename ]; then
20	return
21    fi
22
23    if $verbose; then
24	echo "Checking $filename..."
25    fi
26
27    #
28    # Unfortunately, "nm --defined" is a GNU-extension.  For portability,
29    # build the list of defined symbols by hand.
30    #
31    symtab=`nm -g $filename`
32    saved_IFS="$IFS"
33    IFS=""
34    undef=`nm -g -u $filename`
35    for line in $undef; do
36	symtab=`echo "$symtab" | grep -v "^${line}"\$`
37    done;
38    IFS="$saved_IFS"
39}
40
41ignore () {
42    sym=$1
43    symtab=`echo "$symtab" | grep -v " ${sym}\$"`
44}
45
46match () {
47    sym=$1
48    if `echo "$symtab" | grep -q " ${sym}\$"`; then
49	symtab=`echo "$symtab" | grep -v " ${sym}\$"`
50    else
51	echo "  ERROR: Symbol \"$sym\" missing."
52	num_errors=`expr $num_errors + 1`
53    fi
54}
55
56#
57# Filter out miscellaneous symbols that get defined by the
58# linker for each shared object.
59#
60filter_misc () {
61    ignore _DYNAMIC
62    ignore _GLOBAL_OFFSET_TABLE_
63    ignore __bss_start
64    ignore _edata
65    ignore _end
66    ignore _Uelf32_get_proc_name
67    ignore _Uelf32_valid_object
68    ignore _Uelf64_get_proc_name
69    ignore _Uelf64_valid_object
70    ignore _U.*debug_level
71    ignore ICRT.INTERNAL	# ICC 8.x defines this
72}
73
74check_local_unw_abi () {
75    match _UL${plat}_create_addr_space
76    match _UL${plat}_destroy_addr_space
77    match _UL${plat}_get_fpreg
78    match _UL${plat}_get_proc_info
79    match _UL${plat}_get_proc_info_by_ip
80    match _UL${plat}_get_proc_name
81    match _UL${plat}_get_reg
82    match _UL${plat}_get_save_loc
83    match _UL${plat}_init_local
84    match _UL${plat}_init_remote
85    match _UL${plat}_is_signal_frame
86    match _UL${plat}_local_addr_space
87    match _UL${plat}_resume
88    match _UL${plat}_set_caching_policy
89    match _UL${plat}_set_reg
90    match _UL${plat}_set_fpreg
91    match _UL${plat}_step
92
93    match _U${plat}_flush_cache
94    match _U${plat}_get_accessors
95    match _U${plat}_getcontext
96    match _U${plat}_regname
97    match _U${plat}_strerror
98
99    match _U_dyn_cancel
100    match _U_dyn_info_list_addr
101    match _U_dyn_register
102
103    match backtrace
104
105    case ${plat} in
106	hppa)
107	    match _UL${plat}_dwarf_search_unwind_table
108	    match _U${plat}_get_elf_image
109	    match _U${plat}_setcontext
110	    ;;
111	ia64)
112	    match _UL${plat}_search_unwind_table
113	    match _U${plat}_get_elf_image
114	    ;;
115	x86)
116	    match _U${plat}_get_elf_image
117	    match _U${plat}_is_fpreg
118	    match _UL${plat}_dwarf_search_unwind_table
119	    ;;
120	x86_64)
121	    match _U${plat}_get_elf_image
122	    match _U${plat}_is_fpreg
123	    match _UL${plat}_dwarf_search_unwind_table
124	    match _U${plat}_setcontext
125	    ;;
126	*)
127	    match _U${plat}_is_fpreg
128	    match _UL${plat}_dwarf_search_unwind_table
129	    ;;
130    esac
131}
132
133check_generic_unw_abi () {
134    match _U${plat}_create_addr_space
135    match _U${plat}_destroy_addr_space
136    match _U${plat}_flush_cache
137    match _U${plat}_get_accessors
138    match _U${plat}_get_fpreg
139    match _U${plat}_get_proc_info
140    match _U${plat}_get_proc_info_by_ip
141    match _U${plat}_get_proc_name
142    match _U${plat}_get_reg
143    match _U${plat}_get_save_loc
144    match _U${plat}_init_local
145    match _U${plat}_init_remote
146    match _U${plat}_is_signal_frame
147    match _U${plat}_local_addr_space
148    match _U${plat}_regname
149    match _U${plat}_resume
150    match _U${plat}_set_caching_policy
151    match _U${plat}_set_fpreg
152    match _U${plat}_set_reg
153    match _U${plat}_step
154    match _U${plat}_strerror
155
156    case ${plat} in
157	hppa)
158	    match _U${plat}_dwarf_search_unwind_table
159	    match _U${plat}_get_elf_image
160	    ;;
161	ia64)
162	    match _U${plat}_search_unwind_table
163	    match _U${plat}_find_dyn_list
164	    if [ $plat = $build_plat ]; then
165		match _U${plat}_get_elf_image
166		case $os in
167		    linux*)
168			match _U${plat}_get_kernel_table
169			;;
170		esac
171	    fi
172	    ;;
173	x86)
174	    match _U${plat}_get_elf_image
175	    match _U${plat}_is_fpreg
176	    match _U${plat}_dwarf_search_unwind_table
177	    ;;
178	x86_64)
179	    match _U${plat}_get_elf_image
180	    match _U${plat}_is_fpreg
181	    match _U${plat}_dwarf_search_unwind_table
182	    ;;
183	*)
184	    match _U${plat}_is_fpreg
185	    match _U${plat}_dwarf_search_unwind_table
186	    ;;
187    esac
188}
189
190check_cxx_abi () {
191    match _Unwind_Backtrace
192    match _Unwind_DeleteException
193    match _Unwind_FindEnclosingFunction
194    match _Unwind_ForcedUnwind
195    match _Unwind_GetBSP
196    match _Unwind_GetCFA
197    match _Unwind_GetDataRelBase
198    match _Unwind_GetGR
199    match _Unwind_GetIP
200    match _Unwind_GetLanguageSpecificData
201    match _Unwind_GetRegionStart
202    match _Unwind_GetTextRelBase
203    match _Unwind_RaiseException
204    match _Unwind_Resume
205    match _Unwind_Resume_or_Rethrow
206    match _Unwind_SetGR
207    match _Unwind_SetIP
208    match __libunwind_Unwind_Backtrace
209    match __libunwind_Unwind_DeleteException
210    match __libunwind_Unwind_FindEnclosingFunction
211    match __libunwind_Unwind_ForcedUnwind
212    match __libunwind_Unwind_GetBSP
213    match __libunwind_Unwind_GetCFA
214    match __libunwind_Unwind_GetDataRelBase
215    match __libunwind_Unwind_GetGR
216    match __libunwind_Unwind_GetIP
217    match __libunwind_Unwind_GetLanguageSpecificData
218    match __libunwind_Unwind_GetRegionStart
219    match __libunwind_Unwind_GetTextRelBase
220    match __libunwind_Unwind_RaiseException
221    match __libunwind_Unwind_Resume
222    match __libunwind_Unwind_Resume_or_Rethrow
223    match __libunwind_Unwind_SetGR
224    match __libunwind_Unwind_SetIP
225    case $os in
226	linux*)
227	    # needed only for Intel 8.0 bug-compatibility
228	    match _ReadSLEB
229	    match _ReadULEB
230	    ;;
231    esac
232}
233
234check_empty () {
235    if [ -n "$symtab" ]; then
236	echo -e "  ERROR: Extraneous symbols:\n$symtab"
237	num_errors=`expr $num_errors + 1`
238    fi
239}
240
241if [ $plat = $build_plat ]; then
242    fetch_symtab $LIBUNWIND
243    filter_misc
244    check_local_unw_abi
245    check_cxx_abi
246    check_empty
247fi
248
249fetch_symtab $LIBUNWIND_GENERIC
250filter_misc
251check_generic_unw_abi
252check_empty
253
254if [ $num_errors -gt 0 ]; then
255    echo "FAILURE: Detected $num_errors errors"
256    exit 1
257fi
258
259if $verbose; then
260    echo "  SUCCESS: all checks passed"
261fi
262exit 0
263