9 check_loaded_objects (const char **loaded
)
16 for (n
= 0; loaded
[n
]; n
++)
21 found
= (int *) alloca (sizeof (int) * n
);
22 memset (found
, 0, sizeof (int) * n
);
26 printf(" --------------------------------------------------------\n");
27 for (lm
= _r_debug
.r_map
; lm
; lm
= lm
->l_next
)
29 if (lm
->l_name
&& lm
->l_name
[0])
30 printf(" %s, count = %d\n", lm
->l_name
, (int) lm
->l_opencount
);
31 if (lm
->l_type
== lt_loaded
&& lm
->l_name
)
34 for (n
= 0; loaded
[n
] != NULL
; n
++)
36 if (strcmp (basename (loaded
[n
]), basename (lm
->l_name
)) == 0)
47 printf ("ERRORS: %s is not unloaded\n", lm
->l_name
);
52 for (n
= 0; loaded
[n
] != NULL
; n
++)
57 printf ("ERRORS: %s is not loaded\n", loaded
[n
]);
65 load_dso (const char **loading
, int undef
, int flag
)
68 const char *loaded
[] = { NULL
, NULL
, NULL
, NULL
};
70 const char *errstring
;
72 printf ("\nThis is what is in memory now:\n");
73 errors
+= check_loaded_objects (loaded
);
75 printf ("Loading shared object %s: %s\n", loading
[0],
76 flag
== RTLD_LAZY
? "RTLD_LAZY" : "RTLD_NOW");
77 obj
= dlopen (loading
[0], flag
);
80 if (flag
== RTLD_LAZY
)
83 printf ("ERRORS: dlopen shouldn't fail for RTLD_LAZY\n");
86 errstring
= dlerror ();
87 if (strstr (errstring
, "undefined symbol") == 0
88 || strstr (errstring
, "circlemod2_undefined") == 0)
91 printf ("ERRORS: dlopen: `%s': Invalid error string\n",
95 printf ("dlopen: %s\n", errstring
);
99 if (undef
&& flag
== RTLD_NOW
)
102 printf ("ERRORS: dlopen shouldn't work for RTLD_NOW\n");
109 func
= dlsym (obj
, "circlemod1");
113 printf ("ERRORS: cannot get address of \"circlemod1\": %s\n",
116 else if (func () != 3)
119 printf ("ERRORS: function \"circlemod1\" returned wrong result\n");
123 loaded
[0] = loading
[0];
124 loaded
[1] = loading
[1];
125 loaded
[2] = loading
[2];
127 errors
+= check_loaded_objects (loaded
);
131 printf ("UnLoading shared object %s\n", loading
[0]);
136 errors
+= check_loaded_objects (loaded
);
146 const char *loading
[3];
148 loading
[0] = "circlemod1a.so";
149 loading
[1] = "circlemod2a.so";
150 loading
[2] = "circlemod3a.so";
151 errors
+= load_dso (loading
, 0, RTLD_LAZY
);
152 errors
+= load_dso (loading
, 0, RTLD_NOW
);
154 loading
[0] = "circlemod1.so";
155 loading
[1] = "circlemod2.so";
156 loading
[2] = "circlemod3.so";
157 errors
+= load_dso (loading
, 1, RTLD_LAZY
);
158 errors
+= load_dso (loading
, 1, RTLD_NOW
);
161 printf ("%d errors found\n", errors
);