Fix linker tests to work with 16-bit targets.
[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 #endif
75
76 /* This function calls a function defined by the main program. */
77
78 #ifndef XCOFF_TEST
79 extern int main_called ();
80
81 int
82 shlib_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
91 int
92 shlib_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
102 int
103 shlib_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
112 int
113 (*shlib_getfunptr1 ()) ()
114 {
115 return shlib_shlibvar1;
116 }
117
118 /* This function returns a pointer to main_called. */
119
120 #ifndef XCOFF_TEST
121 int
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
135 static int i = 6;
136 static const char *str = "Hello, world\n";
137
138 int
139 shlib_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.044961 seconds and 4 git commands to generate.