Typo fix in most recent entry.
[binutils.git] / ld / testsuite / ld-shared / sh1.c
blobc8e523249a32b6e86881d61607d875167552bcef
1 /* This is part of the shared library ld test. This file becomes part
2 of a shared library. */
4 /* This variable is supplied by the main program. */
5 #ifndef XCOFF_TEST
6 extern int mainvar;
7 #endif
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
15 /* This variable is defined in the shared library. */
16 int shlibvar1 = 3;
18 /* This variable is defined by another object in the shared library. */
19 extern int shlibvar2;
21 /* These functions return the values of the above variables as seen in
22 the shared library. */
24 #ifndef XCOFF_TEST
25 int
26 shlib_mainvar ()
28 return mainvar;
30 #endif
32 #ifndef XCOFF_TEST
33 int
34 shlib_overriddenvar ()
36 return overriddenvar;
38 #endif
40 int
41 shlib_shlibvar1 ()
43 return shlibvar1;
46 int
47 shlib_shlibvar2 ()
49 return shlibvar2;
52 /* This function calls a function defined by another object in the
53 shared library. */
55 extern int shlib_shlibcalled ();
57 int
58 shlib_shlibcall ()
60 return shlib_shlibcalled ();
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. */
67 extern int shlib_overriddencall2 ();
69 int
70 shlib_shlibcall2 ()
72 return shlib_overriddencall2 ();
74 #endif
76 /* This function calls a function defined by the main program. */
78 #ifndef XCOFF_TEST
79 extern int main_called ();
81 int
82 shlib_maincall ()
84 return main_called ();
86 #endif
88 /* This function is passed a function pointer to shlib_mainvar. It
89 confirms that the pointer compares equally. */
91 int
92 shlib_checkfunptr1 (p)
93 int (*p) ();
95 return p == shlib_shlibvar1;
98 /* This function is passed a function pointer to main_called. It
99 confirms that the pointer compares equally. */
101 #ifndef XCOFF_TEST
103 shlib_checkfunptr2 (p)
104 int (*p) ();
106 return p == main_called;
108 #endif
110 /* This function returns a pointer to shlib_mainvar. */
113 (*shlib_getfunptr1 ()) ()
115 return shlib_shlibvar1;
118 /* This function returns a pointer to main_called. */
120 #ifndef XCOFF_TEST
122 (*shlib_getfunptr2 ()) ()
124 return main_called;
126 #endif
128 /* This function makes sure that constant data and local functions
129 work. */
131 #ifndef __STDC__
132 #define const
133 #endif
135 static int i = 6;
136 static const char *str = "Hello, world\n";
139 shlib_check ()
141 const char *s1, *s2;
143 if (i != 6)
144 return 0;
146 /* To isolate the test, don't rely on any external functions, such
147 as strcmp. */
148 s1 = "Hello, world\n";
149 s2 = str;
150 while (*s1 != '\0')
151 if (*s1++ != *s2++)
152 return 0;
153 if (*s2 != '\0')
154 return 0;
156 if (shlib_shlibvar1 () != 3)
157 return 0;
159 return 1;