Imported Upstream version 1.3.1
[platform/upstream/libunwind.git] / tests / check-namespace.sh.in
1 #!/bin/sh
2 verbose=false
3 if [ "$1" = "-v" ]; then
4     verbose=true
5     shift
6 fi
7
8 build_plat=@build_arch@
9 plat=@arch@
10 os=@target_os@
11 num_errors=0
12
13 LIBUNWIND=../src/.libs/libunwind.so
14 LIBUNWIND_GENERIC=../src/.libs/libunwind-${plat}.so
15
16 fetch_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
41 ignore () {
42     sym=$1
43     symtab=`echo "$symtab" | grep -v " ${sym}\$"`
44 }
45
46 match () {
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 #
60 filter_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
90 check_local_unw_abi () {
91     match _UL${plat}_apply_reg_state
92     match _UL${plat}_reg_states_iterate
93     match _UL${plat}_create_addr_space
94     match _UL${plat}_destroy_addr_space
95     match _UL${plat}_get_fpreg
96     match _UL${plat}_get_proc_info
97     match _UL${plat}_get_proc_info_by_ip
98     match _UL${plat}_get_proc_name
99     match _UL${plat}_get_reg
100     match _UL${plat}_get_save_loc
101     match _UL${plat}_init_local
102     match _UL${plat}_init_local2
103     match _UL${plat}_init_remote
104     match _UL${plat}_is_signal_frame
105     match _UL${plat}_local_addr_space
106     match _UL${plat}_resume
107     match _UL${plat}_set_caching_policy
108     match _UL${plat}_set_cache_size
109     match _UL${plat}_set_reg
110     match _UL${plat}_set_fpreg
111     match _UL${plat}_step
112
113     match _U${plat}_flush_cache
114     match _U${plat}_get_accessors
115     match _U${plat}_getcontext
116     match _U${plat}_regname
117     match _U${plat}_strerror
118
119     match _U_dyn_cancel
120     match _U_dyn_info_list_addr
121     match _U_dyn_register
122
123     match unw_backtrace
124     match backtrace
125
126     case ${plat} in
127         arm)
128             match _U${plat}_get_elf_image
129             match _U${plat}_get_exe_image_path
130             match _U${plat}_is_fpreg
131             match _UL${plat}_search_unwind_table
132             match _UL${plat}_dwarf_search_unwind_table
133             match _UL${plat}_dwarf_find_unwind_table
134             ;;
135         hppa)
136             match _UL${plat}_dwarf_search_unwind_table
137             match _UL${plat}_dwarf_find_unwind_table
138             match _U${plat}_get_elf_image
139             match _U${plat}_get_exe_image_path
140             match _U${plat}_setcontext
141             ;;
142         ia64)
143             match _UL${plat}_search_unwind_table
144             match _U${plat}_get_elf_image
145             match _U${plat}_get_exe_image_path
146             ;;
147         x86)
148             match _U${plat}_get_elf_image
149             match _U${plat}_get_exe_image_path
150             match _U${plat}_is_fpreg
151             match _UL${plat}_dwarf_search_unwind_table
152             match _UL${plat}_dwarf_find_unwind_table
153             ;;
154         x86_64)
155             match _U${plat}_get_elf_image
156             match _U${plat}_get_exe_image_path
157             match _U${plat}_is_fpreg
158             match _UL${plat}_dwarf_search_unwind_table
159             match _UL${plat}_dwarf_find_unwind_table
160             match _U${plat}_setcontext
161             ;;
162         ppc*)
163             match _U${plat}_get_func_addr
164             match _U${plat}_get_elf_image
165             match _U${plat}_get_exe_image_path
166             match _U${plat}_is_fpreg
167             match _UL${plat}_dwarf_search_unwind_table
168             match _UL${plat}_dwarf_find_unwind_table
169             ;;
170         tilegx)
171             match _U${plat}_is_fpreg
172             match _UL${plat}_dwarf_search_unwind_table
173             match _UL${plat}_dwarf_find_unwind_table
174             match _UL${plat}_local_addr_space_init
175             match _U${plat}_get_elf_image
176             match _U${plat}_get_exe_image_path
177             match ${plat}_lock
178             ;;
179
180         *)
181             match _U${plat}_is_fpreg
182             match _UL${plat}_dwarf_search_unwind_table
183             match _UL${plat}_dwarf_find_unwind_table
184             ;;
185     esac
186
187     if [ x@enable_debug_frame@ = xyes ]; then
188         match _UL${plat}_dwarf_find_debug_frame
189     fi
190
191 }
192
193 check_generic_unw_abi () {
194     match _U${plat}_apply_reg_state
195     match _U${plat}_reg_states_iterate
196     match _U${plat}_create_addr_space
197     match _U${plat}_destroy_addr_space
198     match _U${plat}_flush_cache
199     match _U${plat}_get_accessors
200     match _U${plat}_get_fpreg
201     match _U${plat}_get_proc_info
202     match _U${plat}_get_proc_info_by_ip
203     match _U${plat}_get_proc_name
204     match _U${plat}_get_reg
205     match _U${plat}_get_save_loc
206     match _U${plat}_init_local
207     match _U${plat}_init_local2
208     match _U${plat}_init_remote
209     match _U${plat}_is_signal_frame
210     match _U${plat}_local_addr_space
211     match _U${plat}_regname
212     match _U${plat}_resume
213     match _U${plat}_set_caching_policy
214     match _U${plat}_set_cache_size
215     match _U${plat}_set_fpreg
216     match _U${plat}_set_reg
217     match _U${plat}_step
218     match _U${plat}_strerror
219
220     case ${plat} in
221         arm)
222             match _U${plat}_is_fpreg
223             match _U${plat}_get_elf_image
224             match _U${plat}_get_exe_image_path
225             match _U${plat}_search_unwind_table
226             match _U${plat}_dwarf_search_unwind_table
227             match _U${plat}_dwarf_find_unwind_table
228             ;;
229         hppa)
230             match _U${plat}_dwarf_search_unwind_table
231             match _U${plat}_dwarf_find_unwind_table
232             match _U${plat}_get_elf_image
233             match _U${plat}_get_exe_image_path
234             ;;
235         ia64)
236             match _U${plat}_search_unwind_table
237             match _U${plat}_find_dyn_list
238             if [ $plat = $build_plat ]; then
239                 match _U${plat}_get_elf_image
240                 match _U${plat}_get_exe_image_path
241                 case $os in
242                     linux*)
243                         match _U${plat}_get_kernel_table
244                         ;;
245                 esac
246             fi
247             ;;
248         x86)
249             match _U${plat}_get_elf_image
250             match _U${plat}_get_exe_image_path
251             match _U${plat}_is_fpreg
252             match _U${plat}_dwarf_search_unwind_table
253             match _U${plat}_dwarf_find_unwind_table
254             ;;
255         x86_64)
256             match _U${plat}_get_elf_image
257             match _U${plat}_get_exe_image_path
258             match _U${plat}_is_fpreg
259             match _U${plat}_dwarf_search_unwind_table
260             match _U${plat}_dwarf_find_unwind_table
261             ;;
262         ppc*)
263             match _U${plat}_get_elf_image
264             match _U${plat}_get_exe_image_path
265             match _U${plat}_get_func_addr
266             match _U${plat}_is_fpreg
267             match _U${plat}_dwarf_search_unwind_table
268             match _U${plat}_dwarf_find_unwind_table
269             ;;
270         tilegx)
271             match _U${plat}_dwarf_search_unwind_table
272             match _U${plat}_dwarf_find_unwind_table
273             match _U${plat}_get_elf_image
274             match _U${plat}_get_exe_image_path
275             match _U${plat}_is_fpreg
276             match _U${plat}_local_addr_space_init
277             match ${plat}_lock
278             ;;
279         *)
280             match _U${plat}_is_fpreg
281             match _U${plat}_dwarf_search_unwind_table
282             match _U${plat}_dwarf_find_unwind_table
283             ;;
284     esac
285
286     if [ x@enable_debug_frame@ = xyes ]; then
287         match _U${plat}_dwarf_find_debug_frame
288     fi
289 }
290
291 check_cxx_abi () {
292     match _Unwind_Backtrace
293     match _Unwind_DeleteException
294     match _Unwind_FindEnclosingFunction
295     match _Unwind_ForcedUnwind
296     match _Unwind_GetBSP
297     match _Unwind_GetCFA
298     match _Unwind_GetDataRelBase
299     match _Unwind_GetGR
300     match _Unwind_GetIP
301     match _Unwind_GetIPInfo
302     match _Unwind_GetLanguageSpecificData
303     match _Unwind_GetRegionStart
304     match _Unwind_GetTextRelBase
305     match _Unwind_RaiseException
306     match _Unwind_Resume
307     match _Unwind_Resume_or_Rethrow
308     match _Unwind_SetGR
309     match _Unwind_SetIP
310     match __libunwind_Unwind_Backtrace
311     match __libunwind_Unwind_DeleteException
312     match __libunwind_Unwind_FindEnclosingFunction
313     match __libunwind_Unwind_ForcedUnwind
314     match __libunwind_Unwind_GetBSP
315     match __libunwind_Unwind_GetCFA
316     match __libunwind_Unwind_GetDataRelBase
317     match __libunwind_Unwind_GetGR
318     match __libunwind_Unwind_GetIP
319     match __libunwind_Unwind_GetIPInfo
320     match __libunwind_Unwind_GetLanguageSpecificData
321     match __libunwind_Unwind_GetRegionStart
322     match __libunwind_Unwind_GetTextRelBase
323     match __libunwind_Unwind_RaiseException
324     match __libunwind_Unwind_Resume
325     match __libunwind_Unwind_Resume_or_Rethrow
326     match __libunwind_Unwind_SetGR
327     match __libunwind_Unwind_SetIP
328     case $os in
329         linux*)
330             # needed only for Intel 8.0 bug-compatibility
331             match _ReadSLEB
332             match _ReadULEB
333             ;;
334     esac
335 }
336
337 check_empty () {
338     if [ -n "$symtab" ]; then
339         printf "  ERROR: Extraneous symbols:\n$symtab\n"
340         num_errors=`expr $num_errors + 1`
341     fi
342 }
343
344 if [ $plat = $build_plat ]; then
345     fetch_symtab $LIBUNWIND
346     filter_misc
347     check_local_unw_abi
348     if [ x@enable_cxx_exceptions@ = xyes ]; then
349       check_cxx_abi
350     fi
351     check_empty
352 fi
353
354 fetch_symtab $LIBUNWIND_GENERIC
355 filter_misc
356 check_generic_unw_abi
357 check_empty
358
359 if [ $num_errors -gt 0 ]; then
360     echo "FAILURE: Detected $num_errors errors"
361     exit 1
362 fi
363
364 if $verbose; then
365     echo "  SUCCESS: all checks passed"
366 fi
367 exit 0