8 #define MAPS ((struct link_map *) _r_debug.r_map)
11 check_loaded_objects (const char **loaded
)
18 for (n
= 0; loaded
[n
]; n
++)
23 found
= (int *) alloca (sizeof (int) * n
);
24 memset (found
, 0, sizeof (int) * n
);
28 printf(" --------------------------------------------------------\n");
29 for (lm
= MAPS
; lm
; lm
= lm
->l_next
)
31 if (lm
->l_name
&& lm
->l_name
[0])
32 printf(" %s, count = %d\n", lm
->l_name
, (int) lm
->l_direct_opencount
);
33 if (lm
->l_type
== lt_loaded
&& lm
->l_name
)
36 for (n
= 0; loaded
[n
] != NULL
; n
++)
38 if (strcmp (basename (loaded
[n
]), basename (lm
->l_name
)) == 0)
49 printf ("ERRORS: %s is not unloaded\n", lm
->l_name
);
54 for (n
= 0; loaded
[n
] != NULL
; n
++)
59 printf ("ERRORS: %s is not loaded\n", loaded
[n
]);
67 load_dso (const char **loading
, int undef
, int flag
)
70 const char *loaded
[] = { NULL
, NULL
, NULL
, NULL
};
72 const char *errstring
;
74 printf ("\nThis is what is in memory now:\n");
75 errors
+= check_loaded_objects (loaded
);
77 printf ("Loading shared object %s: %s\n", loading
[0],
78 flag
== RTLD_LAZY
? "RTLD_LAZY" : "RTLD_NOW");
79 obj
= dlopen (loading
[0], flag
);
82 if (flag
== RTLD_LAZY
)
85 printf ("ERRORS: dlopen shouldn't fail for RTLD_LAZY\n");
88 errstring
= dlerror ();
89 if (strstr (errstring
, "undefined symbol") == 0
90 || strstr (errstring
, "circlemod2_undefined") == 0)
93 printf ("ERRORS: dlopen: `%s': Invalid error string\n",
97 printf ("dlopen: %s\n", errstring
);
101 if (undef
&& flag
== RTLD_NOW
)
104 printf ("ERRORS: dlopen shouldn't work for RTLD_NOW\n");
111 func
= dlsym (obj
, "circlemod1");
115 printf ("ERRORS: cannot get address of \"circlemod1\": %s\n",
118 else if (func () != 3)
121 printf ("ERRORS: function \"circlemod1\" returned wrong result\n");
125 loaded
[0] = loading
[0];
126 loaded
[1] = loading
[1];
127 loaded
[2] = loading
[2];
129 errors
+= check_loaded_objects (loaded
);
133 printf ("UnLoading shared object %s\n", loading
[0]);
138 errors
+= check_loaded_objects (loaded
);
148 const char *loading
[3];
150 loading
[0] = "circlemod1a.so";
151 loading
[1] = "circlemod2a.so";
152 loading
[2] = "circlemod3a.so";
153 errors
+= load_dso (loading
, 0, RTLD_LAZY
);
154 errors
+= load_dso (loading
, 0, RTLD_NOW
);
156 loading
[0] = "circlemod1.so";
157 loading
[1] = "circlemod2.so";
158 loading
[2] = "circlemod3.so";
159 errors
+= load_dso (loading
, 1, RTLD_LAZY
);
160 errors
+= load_dso (loading
, 1, RTLD_NOW
);
163 printf ("%d errors found\n", errors
);