failtestmod.c 444 B

12345678910111213141516171819202122232425
  1. #include <dlfcn.h>
  2. #include <stdio.h>
  3. extern void constr (void) __attribute__ ((__constructor__));
  4. void
  5. __attribute__ ((__constructor__))
  6. constr (void)
  7. {
  8. void *handle;
  9. /* Open the library. */
  10. handle = dlopen (NULL, RTLD_NOW);
  11. if (handle == NULL)
  12. {
  13. puts ("Cannot get handle to own object");
  14. return;
  15. }
  16. /* Get a symbol. */
  17. dlsym (handle, "main");
  18. puts ("called dlsym() to get main");
  19. dlclose (handle);
  20. }