This commit was generated by cvs2svn to track changes on a CVS vendor
[deliverable/binutils-gdb.git] / ld / testsuite / ld-shared / sh1.c
CommitLineData
252b5132
RH
1/* This is part of the shared library ld test. This file becomes part
2 of a shared library. */
3
4/* This variable is supplied by the main program. */
5#ifndef XCOFF_TEST
6extern int mainvar;
7#endif
8
9/* This variable is defined in the shared library, and overridden by
10 the main program. */
11#ifndef XCOFF_TEST
12int overriddenvar = -1;
13#endif
14
15/* This variable is defined in the shared library. */
16int shlibvar1 = 3;
17
18/* This variable is defined by another object in the shared library. */
19extern int shlibvar2;
20
21/* These functions return the values of the above variables as seen in
22 the shared library. */
23
24#ifndef XCOFF_TEST
25int
26shlib_mainvar ()
27{
28 return mainvar;
29}
30#endif
31
32#ifndef XCOFF_TEST
33int
34shlib_overriddenvar ()
35{
36 return overriddenvar;
37}
38#endif
39
40int
41shlib_shlibvar1 ()
42{
43 return shlibvar1;
44}
45
46int
47shlib_shlibvar2 ()
48{
49 return shlibvar2;
50}
51
52/* This function calls a function defined by another object in the
53 shared library. */
54
55extern int shlib_shlibcalled ();
56
57int
58shlib_shlibcall ()
59{
60 return shlib_shlibcalled ();
61}
62
63#ifndef XCOFF_TEST
64/* This function calls a function defined in this object in the shared
65 library. The main program will override the called function. */
66
2bdba6c9 67extern int shlib_overriddencall2 ();
252b5132
RH
68
69int
70shlib_shlibcall2 ()
71{
72 return shlib_overriddencall2 ();
73}
74
75int
76shlib_overriddencall2 ()
77{
78 return 7;
79}
80#endif
81
82/* This function calls a function defined by the main program. */
83
84#ifndef XCOFF_TEST
85extern int main_called ();
86
87int
88shlib_maincall ()
89{
90 return main_called ();
91}
92#endif
93
94/* This function is passed a function pointer to shlib_mainvar. It
95 confirms that the pointer compares equally. */
96
97int
98shlib_checkfunptr1 (p)
99 int (*p) ();
100{
101 return p == shlib_shlibvar1;
102}
103
104/* This function is passed a function pointer to main_called. It
105 confirms that the pointer compares equally. */
106
107#ifndef XCOFF_TEST
108int
109shlib_checkfunptr2 (p)
110 int (*p) ();
111{
112 return p == main_called;
113}
114#endif
115
116/* This function returns a pointer to shlib_mainvar. */
117
118int
119(*shlib_getfunptr1 ()) ()
120{
121 return shlib_shlibvar1;
122}
123
124/* This function returns a pointer to main_called. */
125
126#ifndef XCOFF_TEST
127int
128(*shlib_getfunptr2 ()) ()
129{
130 return main_called;
131}
132#endif
133
134/* This function makes sure that constant data and local functions
135 work. */
136
137#ifndef __STDC__
138#define const
139#endif
140
141static int i = 6;
142static const char *str = "Hello, world\n";
143
144int
145shlib_check ()
146{
147 const char *s1, *s2;
148
149 if (i != 6)
150 return 0;
151
152 /* To isolate the test, don't rely on any external functions, such
153 as strcmp. */
154 s1 = "Hello, world\n";
155 s2 = str;
156 while (*s1 != '\0')
157 if (*s1++ != *s2++)
158 return 0;
159 if (*s2 != '\0')
160 return 0;
161
162 if (shlib_shlibvar1 () != 3)
163 return 0;
164
165 return 1;
166}
This page took 0.277525 seconds and 4 git commands to generate.