This commit was generated by cvs2svn to track changes on a CVS vendor
[deliverable/binutils-gdb.git] / ld / testsuite / ld-shared / sh1.c
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
6 extern 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
12 int overriddenvar = -1;
13 #endif
14
15 /* This variable is defined in the shared library. */
16 int shlibvar1 = 3;
17
18 /* This variable is defined by another object in the shared library. */
19 extern 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
25 int
26 shlib_mainvar ()
27 {
28 return mainvar;
29 }
30 #endif
31
32 #ifndef XCOFF_TEST
33 int
34 shlib_overriddenvar ()
35 {
36 return overriddenvar;
37 }
38 #endif
39
40 int
41 shlib_shlibvar1 ()
42 {
43 return shlibvar1;
44 }
45
46 int
47 shlib_shlibvar2 ()
48 {
49 return shlibvar2;
50 }
51
52 /* This function calls a function defined by another object in the
53 shared library. */
54
55 extern int shlib_shlibcalled ();
56
57 int
58 shlib_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
67 extern int shlib_overriddencall2 ();
68
69 int
70 shlib_shlibcall2 ()
71 {
72 return shlib_overriddencall2 ();
73 }
74
75 int
76 shlib_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
85 extern int main_called ();
86
87 int
88 shlib_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
97 int
98 shlib_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
108 int
109 shlib_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
118 int
119 (*shlib_getfunptr1 ()) ()
120 {
121 return shlib_shlibvar1;
122 }
123
124 /* This function returns a pointer to main_called. */
125
126 #ifndef XCOFF_TEST
127 int
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
141 static int i = 6;
142 static const char *str = "Hello, world\n";
143
144 int
145 shlib_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.033197 seconds and 5 git commands to generate.