Fix linker tests to work with 16-bit targets.
[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}
252b5132
RH
74#endif
75
76/* This function calls a function defined by the main program. */
77
78#ifndef XCOFF_TEST
79extern int main_called ();
80
81int
82shlib_maincall ()
83{
84 return main_called ();
85}
86#endif
87
88/* This function is passed a function pointer to shlib_mainvar. It
89 confirms that the pointer compares equally. */
90
91int
92shlib_checkfunptr1 (p)
93 int (*p) ();
94{
95 return p == shlib_shlibvar1;
96}
97
98/* This function is passed a function pointer to main_called. It
99 confirms that the pointer compares equally. */
100
101#ifndef XCOFF_TEST
102int
103shlib_checkfunptr2 (p)
104 int (*p) ();
105{
106 return p == main_called;
107}
108#endif
109
110/* This function returns a pointer to shlib_mainvar. */
111
112int
113(*shlib_getfunptr1 ()) ()
114{
115 return shlib_shlibvar1;
116}
117
118/* This function returns a pointer to main_called. */
119
120#ifndef XCOFF_TEST
121int
122(*shlib_getfunptr2 ()) ()
123{
124 return main_called;
125}
126#endif
127
128/* This function makes sure that constant data and local functions
129 work. */
130
131#ifndef __STDC__
132#define const
133#endif
134
135static int i = 6;
136static const char *str = "Hello, world\n";
137
138int
139shlib_check ()
140{
141 const char *s1, *s2;
142
143 if (i != 6)
144 return 0;
145
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;
155
156 if (shlib_shlibvar1 () != 3)
157 return 0;
158
159 return 1;
160}
This page took 0.85394 seconds and 4 git commands to generate.