test-static-link-loc.c revision f42a8de0fa4b99c04e38a35bb5fd48a1ba9188b8
1/* libunwind - a platform-independent unwind library
2   Copyright (C) 2004 Hewlett-Packard Co
3	Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
4
5This file is part of libunwind.
6
7Copyright (c) 2003 Hewlett-Packard Co.
8
9Permission is hereby granted, free of charge, to any person obtaining
10a copy of this software and associated documentation files (the
11"Software"), to deal in the Software without restriction, including
12without limitation the rights to use, copy, modify, merge, publish,
13distribute, sublicense, and/or sell copies of the Software, and to
14permit persons to whom the Software is furnished to do so, subject to
15the following conditions:
16
17The above copyright notice and this permission notice shall be
18included in all copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  */
27
28/* The purpose of this program is simply to link in all libunwind-API
29   functions both in their local-only and generic variants and to make
30   sure that the final result can be linked statically.  */
31
32#include <stdio.h>
33
34#define UNW_LOCAL_ONLY
35#include <libunwind.h>
36
37extern int test_generic (void);
38
39int verbose;
40
41#ifdef UNW_REMOTE_ONLY
42
43int
44test_local (void)
45{
46  return 0;
47}
48
49#else /* !UNW_REMOTE_ONLY */
50
51static void *funcs[] =
52  {
53    (void *) &unw_get_reg,
54    (void *) &unw_get_fpreg,
55    (void *) &unw_set_reg,
56    (void *) &unw_set_fpreg,
57    (void *) &unw_resume,
58    (void *) &unw_create_addr_space,
59    (void *) &unw_destroy_addr_space,
60    (void *) &unw_get_accessors,
61    (void *) &unw_flush_cache,
62    (void *) &unw_set_caching_policy,
63    (void *) &unw_regname,
64    (void *) &unw_get_proc_info,
65    (void *) &unw_get_save_loc,
66    (void *) &unw_is_signal_frame,
67    (void *) &unw_get_proc_name,
68    (void *) &_U_dyn_register,
69    (void *) &_U_dyn_cancel
70  };
71
72int
73test_local (void)
74{
75  unw_context_t uc;
76  unw_cursor_t c;
77
78  if (verbose)
79    printf (__FILE__": funcs[0]=%p\n", funcs[0]);
80
81  unw_getcontext (&uc);
82  unw_init_local (&c, &uc);
83  unw_init_remote (&c, unw_local_addr_space, &uc);
84  return unw_step (&c);
85}
86
87#endif /* !UNW_REMOTE_ONLY */
88
89int
90main (int argc, char **argv __attribute__((unused)))
91{
92  if (argc > 1)
93    verbose = 1;
94
95  if (test_local () < 0)
96    return -1;
97  if (test_generic () < 0)
98    return -1;
99  return 0;
100}
101