Set OSABI field back to 0 (SysV), to avoid interoperability problems
[nacl-binutils.git] / ld / testsuite / ld-shared / sh1.c
blob20f183c2642c507119a1834df219a9129d0543ad
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 ();
75 int
76 shlib_overriddencall2 ()
78 return 7;
80 #endif
82 /* This function calls a function defined by the main program. */
84 #ifndef XCOFF_TEST
85 extern int main_called ();
87 int
88 shlib_maincall ()
90 return main_called ();
92 #endif
94 /* This function is passed a function pointer to shlib_mainvar. It
95 confirms that the pointer compares equally. */
97 int
98 shlib_checkfunptr1 (p)
99 int (*p) ();
101 return p == shlib_shlibvar1;
104 /* This function is passed a function pointer to main_called. It
105 confirms that the pointer compares equally. */
107 #ifndef XCOFF_TEST
109 shlib_checkfunptr2 (p)
110 int (*p) ();
112 return p == main_called;
114 #endif
116 /* This function returns a pointer to shlib_mainvar. */
119 (*shlib_getfunptr1 ()) ()
121 return shlib_shlibvar1;
124 /* This function returns a pointer to main_called. */
126 #ifndef XCOFF_TEST
128 (*shlib_getfunptr2 ()) ()
130 return main_called;
132 #endif
134 /* This function makes sure that constant data and local functions
135 work. */
137 #ifndef __STDC__
138 #define const
139 #endif
141 static int i = 6;
142 static const char *str = "Hello, world\n";
145 shlib_check ()
147 const char *s1, *s2;
149 if (i != 6)
150 return 0;
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;
162 if (shlib_shlibvar1 () != 3)
163 return 0;
165 return 1;