sh1.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. #ifndef NULL
  2. #define NULL ((void *) 0)
  3. #endif
  4. /* This is part of the shared library ld test. This file becomes part
  5. of a shared library. */
  6. /* This variable is supplied by the main program. */
  7. extern int mainvar;
  8. /* This variable is defined in the shared library, and overridden by
  9. the main program. */
  10. #ifndef XCOFF_TEST
  11. #ifdef SHARED
  12. /* SHARED is defined if we are compiling with -fpic/-fPIC. */
  13. int overriddenvar = -1;
  14. #else
  15. /* Without -fpic, newer versions of gcc assume that we are not
  16. compiling for a shared library, and thus that overriddenvar is
  17. local. */
  18. extern int overriddenvar;
  19. #endif
  20. #endif
  21. /* This variable is defined in the shared library. */
  22. int shlibvar1 = 3;
  23. /* This variable is defined by another object in the shared library. */
  24. extern int shlibvar2;
  25. /* These functions return the values of the above variables as seen in
  26. the shared library. */
  27. int
  28. shlib_mainvar ()
  29. {
  30. return mainvar;
  31. }
  32. #ifndef XCOFF_TEST
  33. int
  34. shlib_overriddenvar ()
  35. {
  36. return overriddenvar;
  37. }
  38. #endif
  39. int
  40. shlib_shlibvar1 ()
  41. {
  42. return shlibvar1;
  43. }
  44. int
  45. shlib_shlibvar2 ()
  46. {
  47. return shlibvar2;
  48. }
  49. /* This function calls a function defined by another object in the
  50. shared library. */
  51. extern int shlib_shlibcalled ();
  52. int
  53. shlib_shlibcall ()
  54. {
  55. return shlib_shlibcalled ();
  56. }
  57. #ifndef XCOFF_TEST
  58. /* This function calls a function defined in this object in the shared
  59. library. The main program will override the called function. */
  60. extern int shlib_overriddencall2 ();
  61. int
  62. shlib_shlibcall2 ()
  63. {
  64. return shlib_overriddencall2 ();
  65. }
  66. #ifdef SHARED
  67. int
  68. shlib_overriddencall2 ()
  69. {
  70. return 7;
  71. }
  72. #endif
  73. #endif
  74. /* This function calls a function defined by the main program. */
  75. extern int main_called ();
  76. int
  77. shlib_maincall ()
  78. {
  79. return main_called ();
  80. }
  81. /* This function is passed a function pointer to shlib_mainvar. It
  82. confirms that the pointer compares equally. */
  83. int
  84. shlib_checkfunptr1 (p)
  85. int (*p) ();
  86. {
  87. return p == shlib_shlibvar1;
  88. }
  89. /* This function is passed a function pointer to main_called. It
  90. confirms that the pointer compares equally. */
  91. int
  92. shlib_checkfunptr2 (p)
  93. int (*p) ();
  94. {
  95. return p == main_called;
  96. }
  97. /* This function returns a pointer to shlib_mainvar. */
  98. int
  99. (*shlib_getfunptr1 ()) ()
  100. {
  101. return shlib_shlibvar1;
  102. }
  103. /* This function returns a pointer to main_called. */
  104. int
  105. (*shlib_getfunptr2 ()) ()
  106. {
  107. return main_called;
  108. }
  109. /* This function makes sure that constant data and local functions
  110. work. */
  111. #ifndef __STDC__
  112. #define const
  113. #endif
  114. static int i = 6;
  115. static const char *str = "Hello, world\n";
  116. int
  117. shlib_check ()
  118. {
  119. const char *s1, *s2;
  120. if (i != 6)
  121. return 0;
  122. /* To isolate the test, don't rely on any external functions, such
  123. as strcmp. */
  124. s1 = "Hello, world\n";
  125. s2 = str;
  126. while (*s1 != '\0')
  127. if (*s1++ != *s2++)
  128. return 0;
  129. if (*s2 != '\0')
  130. return 0;
  131. if (shlib_shlibvar1 () != 3)
  132. return 0;
  133. return 1;
  134. }
  135. #ifdef HIDDEN_WEAK_TEST
  136. #define HIDDEN_UNDEF_TEST
  137. #define WEAK_TEST
  138. #endif
  139. #ifdef PROTECTED_WEAK_TEST
  140. #define PROTECTED_UNDEF_TEST
  141. #define WEAK_TEST
  142. #endif
  143. #if defined (HIDDEN_UNDEF_TEST) || defined (PROTECTED_UNDEF_TEST)
  144. #ifdef WEAK_TEST
  145. #pragma weak visibility
  146. #endif
  147. extern int visibility ();
  148. #else
  149. int
  150. visibility ()
  151. {
  152. return 2;
  153. }
  154. #endif
  155. #ifdef HIDDEN_NORMAL_TEST
  156. __asm__ (".hidden visibility_normal");
  157. int
  158. visibility_normal ()
  159. {
  160. return 2;
  161. }
  162. #endif
  163. int
  164. visibility_checkfunptr ()
  165. {
  166. #ifdef WEAK_TEST
  167. return 1;
  168. #else
  169. #ifdef HIDDEN_NORMAL_TEST
  170. int (*v) () = visibility_normal;
  171. #else
  172. int (*v) () = visibility;
  173. #endif
  174. return (*v) () == 2;
  175. #endif
  176. }
  177. int
  178. visibility_check ()
  179. {
  180. #ifdef WEAK_TEST
  181. if (&visibility)
  182. return visibility () == 1;
  183. else
  184. return 1;
  185. #else
  186. #ifdef HIDDEN_NORMAL_TEST
  187. return visibility_normal () == 2;
  188. #else
  189. return visibility () == 2;
  190. #endif
  191. #endif
  192. }
  193. void *
  194. visibility_funptr ()
  195. {
  196. #ifdef WEAK_TEST
  197. if (&visibility == NULL)
  198. return NULL;
  199. else
  200. #endif
  201. return visibility;
  202. }
  203. #if defined (HIDDEN_UNDEF_TEST) || defined (PROTECTED_UNDEF_TEST)
  204. #ifdef WEAK_TEST
  205. #pragma weak visibility_var
  206. #endif
  207. extern int visibility_var;
  208. #else
  209. int visibility_var = 2;
  210. #endif
  211. #ifdef HIDDEN_NORMAL_TEST
  212. __asm__ (".hidden visibility_var_normal");
  213. int visibility_var_normal = 2;
  214. #endif
  215. int
  216. visibility_checkvarptr ()
  217. {
  218. #ifdef WEAK_TEST
  219. if (&visibility_var)
  220. return visibility_var == 1;
  221. else
  222. return 1;
  223. #else
  224. #ifdef HIDDEN_NORMAL_TEST
  225. int *v = &visibility_var_normal;
  226. #else
  227. int *v = &visibility_var;
  228. #endif
  229. return *v == 2;
  230. #endif
  231. }
  232. int
  233. visibility_checkvar ()
  234. {
  235. #ifdef WEAK_TEST
  236. return 1;
  237. #else
  238. #ifdef HIDDEN_NORMAL_TEST
  239. return visibility_var_normal == 2;
  240. #else
  241. return visibility_var == 2;
  242. #endif
  243. #endif
  244. }
  245. void *
  246. visibility_varptr ()
  247. {
  248. #ifdef WEAK_TEST
  249. if (&visibility_var == NULL)
  250. return NULL;
  251. else
  252. #endif
  253. return &visibility_var;
  254. }
  255. int
  256. visibility_varval ()
  257. {
  258. #ifdef WEAK_TEST
  259. if (&visibility_var == NULL)
  260. return 0;
  261. else
  262. #endif
  263. return visibility_var;
  264. }
  265. #if defined (HIDDEN_TEST) || defined (HIDDEN_UNDEF_TEST)
  266. __asm__ (".hidden visibility");
  267. __asm__ (".hidden visibility_var");
  268. #else
  269. #if defined (PROTECTED_TEST) || defined (PROTECTED_UNDEF_TEST) || defined (PROTECTED_WEAK_TEST)
  270. __asm__ (".protected visibility");
  271. __asm__ (".protected visibility_var");
  272. #endif
  273. #endif
  274. #ifdef HIDDEN_NORMAL_TEST
  275. int shlib_visibility_com;
  276. __asm__ (".hidden shlib_visibility_com");
  277. int
  278. shlib_visibility_checkcom ()
  279. {
  280. return shlib_visibility_com == 0;
  281. }
  282. int
  283. shlib_visibility_checkweak ()
  284. {
  285. return 1;
  286. }
  287. #elif defined (HIDDEN_WEAK_TEST)
  288. #pragma weak shlib_visibility_undef_var_weak
  289. extern int shlib_visibility_undef_var_weak;
  290. __asm__ (".hidden shlib_visibility_undef_var_weak");
  291. #pragma weak shlib_visibility_undef_func_weak
  292. extern int shlib_visibility_undef_func_weak ();
  293. __asm__ (".hidden shlib_visibility_undef_func_weak");
  294. #pragma weak shlib_visibility_var_weak
  295. extern int shlib_visibility_var_weak;
  296. __asm__ (".hidden shlib_visibility_var_weak");
  297. #pragma weak shlib_visibility_func_weak
  298. extern int shlib_visibility_func_weak ();
  299. __asm__ (".hidden shlib_visibility_func_weak");
  300. int
  301. shlib_visibility_checkcom ()
  302. {
  303. return 1;
  304. }
  305. int
  306. shlib_visibility_checkweak ()
  307. {
  308. return &shlib_visibility_undef_var_weak == NULL
  309. && &shlib_visibility_undef_func_weak == NULL
  310. && &shlib_visibility_func_weak == NULL
  311. && &shlib_visibility_var_weak == NULL;
  312. }
  313. #else
  314. int
  315. shlib_visibility_checkcom ()
  316. {
  317. return 1;
  318. }
  319. int
  320. shlib_visibility_checkweak ()
  321. {
  322. return 1;
  323. }
  324. #endif
  325. #ifdef PROTECTED_TEST
  326. #ifdef SHARED
  327. int shared_data = 100;
  328. #else
  329. extern int shared_data;
  330. #endif
  331. int *
  332. shared_data_p ()
  333. {
  334. return &shared_data;
  335. }
  336. int
  337. shared_func ()
  338. {
  339. return 100;
  340. }
  341. void *
  342. shared_func_p ()
  343. {
  344. return shared_func;
  345. }
  346. #endif