(root)/
glibc-2.38/
elf/
unload4.c
       1  #include <dlfcn.h>
       2  #include <stdio.h>
       3  #include <malloc.h>
       4  
       5  int
       6  main (void)
       7  {
       8  #ifdef M_PERTURB
       9    mallopt (M_PERTURB, 0xaa);
      10  #endif
      11  
      12    void *h;
      13    int (*fn) (int);
      14    h = dlopen ("unload4mod1.so", RTLD_LAZY);
      15    if (h == NULL)
      16      {
      17        puts ("1st dlopen failed");
      18        return 1;
      19      }
      20    fn = dlsym (h, "foo");
      21    if (fn == NULL)
      22      {
      23        puts ("dlsym failed");
      24        return 1;
      25      }
      26    int n = fn (10);
      27    if (n != 28)
      28      {
      29        printf ("foo (10) returned %d != 28\n", n);
      30        return 1;
      31      }
      32    dlclose (h);
      33    h = dlopen ("unload4mod3.so", RTLD_LAZY);
      34    fn = dlsym (h, "mod3fn2");
      35    if (fn == NULL)
      36      {
      37        puts ("second dlsym failed");
      38        return 1;
      39      }
      40    n = fn (10);
      41    if (n != 22)
      42      {
      43        printf ("mod3fn2 (10) returned %d != 22\n", n);
      44        return 1;
      45      }
      46    dlclose (h);
      47    return 0;
      48  }