1 /* Copyright (C) 2004-2021 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
27 #define leq(l,r) (((r) - (l)) <= ~0ULL / 2)
30 callback (struct dl_phdr_info
*info
, size_t size
, void *ptr
)
32 static int last_adds
= 0, last_subs
= 0;
33 intptr_t cmd
= (intptr_t) ptr
;
35 printf (" size = %Zu\n", size
);
36 if (size
< (offsetof (struct dl_phdr_info
, dlpi_subs
)
37 + sizeof (info
->dlpi_subs
)))
39 fprintf (stderr
, "dl_iterate_phdr failed to pass dlpi_adds/dlpi_subs\n");
43 printf (" dlpi_adds = %Lu dlpi_subs = %Lu\n",
44 info
->dlpi_adds
, info
->dlpi_subs
);
52 if (leq (info
->dlpi_adds
, last_adds
))
54 fprintf (stderr
, "dlpi_adds failed to get incremented!\n");
60 if (leq (info
->dlpi_subs
, last_subs
))
62 fprintf (stderr
, "dlpi_subs failed to get incremented!\n");
67 last_adds
= info
->dlpi_adds
;
68 last_subs
= info
->dlpi_subs
;
73 load (const char *path
)
77 printf ("loading `%s'\n", path
);
78 handle
= dlopen (path
, RTLD_LAZY
);
81 dl_iterate_phdr (callback
, (void *)(intptr_t) ADD
);
86 unload (const char *path
, void *handle
)
88 printf ("unloading `%s'\n", path
);
89 if (dlclose (handle
) < 0)
91 dl_iterate_phdr (callback
, (void *)(intptr_t) REMOVE
);
97 void *handle1
, *handle2
;
99 dl_iterate_phdr (callback
, (void *)(intptr_t) SET
);
100 handle1
= load ("firstobj.so");
101 handle2
= load ("globalmod1.so");
102 unload ("firstobj.so", handle1
);
103 unload ("globalmod1.so", handle2
);
107 #include <support/test-driver.c>