dladdr1.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /* Locate the shared object symbol nearest a given address.
  2. Copyright (C) 2003-2026 Free Software Foundation, Inc.
  3. 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.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <https://www.gnu.org/licenses/>. */
  15. #include <dlfcn.h>
  16. #include <ldsodefs.h>
  17. #include <shlib-compat.h>
  18. int
  19. __dladdr1 (const void *address, Dl_info *info, void **extra, int flags)
  20. {
  21. #ifdef SHARED
  22. if (GLRO (dl_dlfcn_hook) != NULL)
  23. return GLRO (dl_dlfcn_hook)->dladdr1 (address, info, extra, flags);
  24. #endif
  25. switch (flags)
  26. {
  27. default: /* Make this an error? */
  28. case 0:
  29. return _dl_addr (address, info, NULL, NULL);
  30. case RTLD_DL_SYMENT:
  31. return _dl_addr (address, info, NULL, (const ElfW(Sym) **) extra);
  32. case RTLD_DL_LINKMAP:
  33. return _dl_addr (address, info, (struct link_map **) extra, NULL);
  34. }
  35. }
  36. versioned_symbol (libc, __dladdr1, dladdr1, GLIBC_2_34);
  37. #if OTHER_SHLIB_COMPAT (libdl, GLIBC_2_3_3, GLIBC_2_34)
  38. compat_symbol (libdl, __dladdr1, dladdr1, GLIBC_2_3_3);
  39. #endif