dl-debug.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /* vi: set sw=4 ts=4: */
  2. /* common debug code for ELF shared library loader
  3. *
  4. * Copyright (c) 1994-2000 Eric Youngdale, Peter MacDonald,
  5. * David Engel, Hongjiu Lu and Mitch D'Souza
  6. * Copyright (C) 2001-2004 Erik Andersen
  7. * Copyright (C) 2002-2004, Axis Communications AB
  8. * Copyright (C) 2003, 2004 Red Hat, Inc.
  9. * Copyright (C) 2002, Steven J. Hill (sjhill@realitydiluted.com)
  10. * Copyright (C) 2001-2002 David A. Schleef
  11. * Copyright (C) 2004 Joakim Tjernlund
  12. * Copyright (C) 2002, Stefan Allius <allius@atecom.com> and
  13. * Eddie C. Dost <ecd@atecom.com>
  14. * Copyright (C) 2003, 2004, 2005 Paul Mundt <lethal@linux-sh.org>
  15. *
  16. * All rights reserved.
  17. *
  18. * Redistribution and use in source and binary forms, with or without
  19. * modification, are permitted provided that the following conditions
  20. * are met:
  21. * 1. Redistributions of source code must retain the above copyright
  22. * notice, this list of conditions and the following disclaimer.
  23. * 2. The name of the above contributors may not be
  24. * used to endorse or promote products derived from this software
  25. * without specific prior written permission.
  26. *
  27. * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND
  28. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  29. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  30. * ARE DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE
  31. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  32. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  33. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  34. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  35. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  36. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  37. * SUCH DAMAGE.
  38. */
  39. #include "ldso.h"
  40. #if defined (__SUPPORT_LD_DEBUG__)
  41. /* include the arch-specific _dl_reltypes_tab */
  42. #include "dl-debug.h"
  43. static const char *_dl_reltypes(int type)
  44. {
  45. static char buf[50];
  46. const char *str;
  47. int tabsize;
  48. tabsize = (int)(sizeof(_dl_reltypes_tab) / sizeof(_dl_reltypes_tab[0]));
  49. if (type >= tabsize || (str = _dl_reltypes_tab[type]) == NULL)
  50. str = _dl_simple_ltoa(buf, (unsigned long)type);
  51. return str;
  52. }
  53. static void debug_sym(ElfW(Sym) *symtab, char *strtab, int symtab_index)
  54. {
  55. if (!_dl_debug_symbols || !symtab_index)
  56. return;
  57. _dl_dprintf(_dl_debug_file,
  58. "\n%s\n\tvalue=%x\tsize=%x\tinfo=%x\tother=%x\tshndx=%x",
  59. strtab + symtab[symtab_index].st_name,
  60. symtab[symtab_index].st_value,
  61. symtab[symtab_index].st_size,
  62. symtab[symtab_index].st_info,
  63. symtab[symtab_index].st_other,
  64. symtab[symtab_index].st_shndx);
  65. }
  66. static void debug_reloc(ElfW(Sym) *symtab, char *strtab, ELF_RELOC *rpnt)
  67. {
  68. if (!_dl_debug_reloc)
  69. return;
  70. if (_dl_debug_symbols) {
  71. _dl_dprintf(_dl_debug_file, "\n\t");
  72. } else {
  73. int symtab_index;
  74. const char *sym;
  75. symtab_index = ELF_R_SYM(rpnt->r_info);
  76. sym = symtab_index ? strtab + symtab[symtab_index].st_name : "sym=0x0";
  77. _dl_dprintf(_dl_debug_file, "\n%s\n\t", sym);
  78. }
  79. _dl_dprintf(_dl_debug_file, "%s\toffset=%x",
  80. _dl_reltypes(ELF_R_TYPE(rpnt->r_info)),
  81. rpnt->r_offset);
  82. #ifdef ELF_USES_RELOCA
  83. _dl_dprintf(_dl_debug_file, "\taddend=%x", rpnt->r_addend);
  84. #endif
  85. _dl_dprintf(_dl_debug_file, "\n");
  86. }
  87. #else
  88. #define debug_sym(symtab, strtab, symtab_index)
  89. #define debug_reloc(symtab, strtab, rpnt)
  90. #endif /* __SUPPORT_LD_DEBUG__ */