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    # Ignore symbols generated by the ARM Linux default linker script.
74    # For details see the binutils sources (src/ld/emulparams/armelf_linux.sh).
75    if [ ${plat} = "arm" ]; then
76	ignore __bss_start__
77	ignore __bss_end__
78	ignore __end__
79	ignore _bss_end__
80    fi
81
82    if [ ${plat} = "mips" ]; then
83	ignore _fbss
84	ignore _fdata
85	ignore _ftext
86	ignore _gp
87    fi
88}
89
90check_local_unw_abi () {
91    match _UL${plat}_create_addr_space
92    match _UL${plat}_destroy_addr_space
93    match _UL${plat}_get_fpreg
94    match _UL${plat}_get_proc_info
95    match _UL${plat}_get_proc_info_by_ip
96    match _UL${plat}_get_proc_name
97    match _UL${plat}_get_reg
98    match _UL${plat}_get_save_loc
99    match _UL${plat}_init_local
100    match _UL${plat}_init_remote
101    match _UL${plat}_is_signal_frame
102    match _UL${plat}_handle_signal_frame
103    match _UL${plat}_local_addr_space
104    match _UL${plat}_resume
105    match _UL${plat}_set_caching_policy
106    match _UL${plat}_set_reg
107    match _UL${plat}_set_fpreg
108    match _UL${plat}_step
109
110    match _U${plat}_flush_cache
111    match _U${plat}_get_accessors
112    match _U${plat}_getcontext
113    match _U${plat}_regname
114    match _U${plat}_strerror
115
116    match _U_dyn_cancel
117    match _U_dyn_info_list_addr
118    match _U_dyn_register
119
120    match unw_backtrace
121    match backtrace
122
123    case ${plat} in
124	arm)
125	    match _U${plat}_get_elf_image
126	    match _U${plat}_is_fpreg
127	    match _UL${plat}_search_unwind_table
128	    match _UL${plat}_dwarf_search_unwind_table
129	    match _UL${plat}_dwarf_find_unwind_table
130	    ;;
131	hppa)
132	    match _UL${plat}_dwarf_search_unwind_table
133	    match _UL${plat}_dwarf_find_unwind_table
134	    match _U${plat}_get_elf_image
135	    match _U${plat}_setcontext
136	    ;;
137	ia64)
138	    match _UL${plat}_search_unwind_table
139	    match _U${plat}_get_elf_image
140	    ;;
141	x86)
142	    match _U${plat}_get_elf_image
143	    match _U${plat}_is_fpreg
144	    match _UL${plat}_dwarf_search_unwind_table
145	    match _UL${plat}_dwarf_find_unwind_table
146	    ;;
147	x86_64)
148	    match _U${plat}_get_elf_image
149	    match _U${plat}_is_fpreg
150	    match _UL${plat}_dwarf_search_unwind_table
151	    match _UL${plat}_dwarf_find_unwind_table
152	    match _U${plat}_setcontext
153	    ;;
154	ppc*)
155	    match _U${plat}_get_func_addr
156	    match _U${plat}_get_elf_image
157	    match _U${plat}_is_fpreg
158	    match _UL${plat}_dwarf_search_unwind_table
159	    match _UL${plat}_dwarf_find_unwind_table
160	    ;;
161	*)
162	    match _U${plat}_is_fpreg
163	    match _UL${plat}_dwarf_search_unwind_table
164	    match _UL${plat}_dwarf_find_unwind_table
165	    ;;
166    esac
167
168    if [ x@enable_debug_frame@ = xyes ]; then
169	match _UL${plat}_dwarf_find_debug_frame
170    fi
171
172}
173
174check_generic_unw_abi () {
175    match _U${plat}_create_addr_space
176    match _U${plat}_destroy_addr_space
177    match _U${plat}_flush_cache
178    match _U${plat}_get_accessors
179    match _U${plat}_get_fpreg
180    match _U${plat}_get_proc_info
181    match _U${plat}_get_proc_info_by_ip
182    match _U${plat}_get_proc_name
183    match _U${plat}_get_reg
184    match _U${plat}_get_save_loc
185    match _U${plat}_init_local
186    match _U${plat}_init_remote
187    match _U${plat}_is_signal_frame
188    match _U${plat}_handle_signal_frame
189    match _U${plat}_local_addr_space
190    match _U${plat}_regname
191    match _U${plat}_resume
192    match _U${plat}_set_caching_policy
193    match _U${plat}_set_fpreg
194    match _U${plat}_set_reg
195    match _U${plat}_step
196    match _U${plat}_strerror
197
198    case ${plat} in
199	arm)
200	    match _U${plat}_is_fpreg
201	    match _U${plat}_get_elf_image
202	    match _U${plat}_search_unwind_table
203	    match _U${plat}_dwarf_search_unwind_table
204	    match _U${plat}_dwarf_find_unwind_table
205	    ;;
206	hppa)
207	    match _U${plat}_dwarf_search_unwind_table
208	    match _U${plat}_dwarf_find_unwind_table
209	    match _U${plat}_get_elf_image
210	    ;;
211	ia64)
212	    match _U${plat}_search_unwind_table
213	    match _U${plat}_find_dyn_list
214	    if [ $plat = $build_plat ]; then
215		match _U${plat}_get_elf_image
216		case $os in
217		    linux*)
218			match _U${plat}_get_kernel_table
219			;;
220		esac
221	    fi
222	    ;;
223	x86)
224	    match _U${plat}_get_elf_image
225	    match _U${plat}_is_fpreg
226	    match _U${plat}_dwarf_search_unwind_table
227	    match _U${plat}_dwarf_find_unwind_table
228	    ;;
229	x86_64)
230	    match _U${plat}_get_elf_image
231	    match _U${plat}_is_fpreg
232	    match _U${plat}_dwarf_search_unwind_table
233	    match _U${plat}_dwarf_find_unwind_table
234	    ;;
235	ppc*)
236	    match _U${plat}_get_elf_image
237	    match _U${plat}_get_func_addr
238	    match _U${plat}_is_fpreg
239	    match _U${plat}_dwarf_search_unwind_table
240	    match _U${plat}_dwarf_find_unwind_table
241	    ;;
242	*)
243	    match _U${plat}_is_fpreg
244	    match _U${plat}_dwarf_search_unwind_table
245	    match _U${plat}_dwarf_find_unwind_table
246	    ;;
247    esac
248
249    if [ x@enable_debug_frame@ = xyes ]; then
250	match _U${plat}_dwarf_find_debug_frame
251    fi
252}
253
254check_cxx_abi () {
255    match _Unwind_Backtrace
256    match _Unwind_DeleteException
257    match _Unwind_FindEnclosingFunction
258    match _Unwind_ForcedUnwind
259    match _Unwind_GetBSP
260    match _Unwind_GetCFA
261    match _Unwind_GetDataRelBase
262    match _Unwind_GetGR
263    match _Unwind_GetIP
264    match _Unwind_GetIPInfo
265    match _Unwind_GetLanguageSpecificData
266    match _Unwind_GetRegionStart
267    match _Unwind_GetTextRelBase
268    match _Unwind_RaiseException
269    match _Unwind_Resume
270    match _Unwind_Resume_or_Rethrow
271    match _Unwind_SetGR
272    match _Unwind_SetIP
273    match __libunwind_Unwind_Backtrace
274    match __libunwind_Unwind_DeleteException
275    match __libunwind_Unwind_FindEnclosingFunction
276    match __libunwind_Unwind_ForcedUnwind
277    match __libunwind_Unwind_GetBSP
278    match __libunwind_Unwind_GetCFA
279    match __libunwind_Unwind_GetDataRelBase
280    match __libunwind_Unwind_GetGR
281    match __libunwind_Unwind_GetIP
282    match __libunwind_Unwind_GetIPInfo
283    match __libunwind_Unwind_GetLanguageSpecificData
284    match __libunwind_Unwind_GetRegionStart
285    match __libunwind_Unwind_GetTextRelBase
286    match __libunwind_Unwind_RaiseException
287    match __libunwind_Unwind_Resume
288    match __libunwind_Unwind_Resume_or_Rethrow
289    match __libunwind_Unwind_SetGR
290    match __libunwind_Unwind_SetIP
291    case $os in
292	linux*)
293	    # needed only for Intel 8.0 bug-compatibility
294	    match _ReadSLEB
295	    match _ReadULEB
296	    ;;
297    esac
298}
299
300check_empty () {
301    if [ -n "$symtab" ]; then
302	printf "  ERROR: Extraneous symbols:\n$symtab\n"
303	num_errors=`expr $num_errors + 1`
304    fi
305}
306
307if [ $plat = $build_plat ]; then
308    fetch_symtab $LIBUNWIND
309    filter_misc
310    check_local_unw_abi
311    if [ x@enable_cxx_exceptions@ = xyes ]; then
312      check_cxx_abi
313    fi
314    check_empty
315fi
316
317fetch_symtab $LIBUNWIND_GENERIC
318filter_misc
319check_generic_unw_abi
320check_empty
321
322if [ $num_errors -gt 0 ]; then
323    echo "FAILURE: Detected $num_errors errors"
324    exit 1
325fi
326
327if $verbose; then
328    echo "  SUCCESS: all checks passed"
329fi
330exit 0
331