dl-debug.c 4.5 KB

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