Roland McGrath | d17fac7 | 2005-08-23 08:20:21 +0000 | [diff] [blame] | 1 | /* Recover relocatibility for addresses computed from debug information. |
Mark Wielaard | be17786 | 2015-05-18 16:23:06 +0200 | [diff] [blame] | 2 | Copyright (C) 2005-2010, 2013, 2015 Red Hat, Inc. |
Mark Wielaard | de2ed97 | 2012-06-05 17:15:16 +0200 | [diff] [blame] | 3 | This file is part of elfutils. |
Roland McGrath | d17fac7 | 2005-08-23 08:20:21 +0000 | [diff] [blame] | 4 | |
Mark Wielaard | de2ed97 | 2012-06-05 17:15:16 +0200 | [diff] [blame] | 5 | This file is free software; you can redistribute it and/or modify |
| 6 | it under the terms of either |
Roland McGrath | d17fac7 | 2005-08-23 08:20:21 +0000 | [diff] [blame] | 7 | |
Mark Wielaard | de2ed97 | 2012-06-05 17:15:16 +0200 | [diff] [blame] | 8 | * the GNU Lesser General Public License as published by the Free |
| 9 | Software Foundation; either version 3 of the License, or (at |
| 10 | your option) any later version |
| 11 | |
| 12 | or |
| 13 | |
| 14 | * the GNU General Public License as published by the Free |
| 15 | Software Foundation; either version 2 of the License, or (at |
| 16 | your option) any later version |
| 17 | |
| 18 | or both in parallel, as here. |
| 19 | |
| 20 | elfutils is distributed in the hope that it will be useful, but |
Ulrich Drepper | 361df7d | 2006-04-04 21:38:57 +0000 | [diff] [blame] | 21 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 23 | General Public License for more details. |
| 24 | |
Mark Wielaard | de2ed97 | 2012-06-05 17:15:16 +0200 | [diff] [blame] | 25 | You should have received copies of the GNU General Public License and |
| 26 | the GNU Lesser General Public License along with this program. If |
| 27 | not, see <http://www.gnu.org/licenses/>. */ |
Roland McGrath | d17fac7 | 2005-08-23 08:20:21 +0000 | [diff] [blame] | 28 | |
| 29 | #include "libdwflP.h" |
| 30 | |
| 31 | struct dwfl_relocation |
| 32 | { |
| 33 | size_t count; |
| 34 | struct |
| 35 | { |
| 36 | Elf_Scn *scn; |
Roland McGrath | e4c22ea | 2007-10-23 13:07:39 +0000 | [diff] [blame] | 37 | Elf_Scn *relocs; |
Roland McGrath | d17fac7 | 2005-08-23 08:20:21 +0000 | [diff] [blame] | 38 | const char *name; |
| 39 | GElf_Addr start, end; |
| 40 | } refs[0]; |
| 41 | }; |
| 42 | |
| 43 | |
| 44 | struct secref |
| 45 | { |
| 46 | struct secref *next; |
| 47 | Elf_Scn *scn; |
Roland McGrath | e4c22ea | 2007-10-23 13:07:39 +0000 | [diff] [blame] | 48 | Elf_Scn *relocs; |
Roland McGrath | d17fac7 | 2005-08-23 08:20:21 +0000 | [diff] [blame] | 49 | const char *name; |
| 50 | GElf_Addr start, end; |
| 51 | }; |
| 52 | |
| 53 | static int |
| 54 | compare_secrefs (const void *a, const void *b) |
| 55 | { |
| 56 | struct secref *const *p1 = a; |
| 57 | struct secref *const *p2 = b; |
| 58 | |
Roland McGrath | 43da989 | 2007-04-16 23:13:37 +0000 | [diff] [blame] | 59 | /* No signed difference calculation is correct here, since the |
| 60 | terms are unsigned and could be more than INT64_MAX apart. */ |
| 61 | if ((*p1)->start < (*p2)->start) |
| 62 | return -1; |
| 63 | if ((*p1)->start > (*p2)->start) |
| 64 | return 1; |
| 65 | |
| 66 | return 0; |
Roland McGrath | d17fac7 | 2005-08-23 08:20:21 +0000 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | static int |
| 70 | cache_sections (Dwfl_Module *mod) |
| 71 | { |
Mark Wielaard | f43feb5 | 2011-10-20 16:53:54 +0200 | [diff] [blame] | 72 | if (likely (mod->reloc_info != NULL)) |
| 73 | return mod->reloc_info->count; |
| 74 | |
Ulrich Drepper | b597dfa | 2007-10-16 05:21:27 +0000 | [diff] [blame] | 75 | struct secref *refs = NULL; |
| 76 | size_t nrefs = 0; |
| 77 | |
| 78 | size_t shstrndx; |
Ulrich Drepper | f189493 | 2009-06-13 15:55:42 -0700 | [diff] [blame] | 79 | if (unlikely (elf_getshdrstrndx (mod->main.elf, &shstrndx) < 0)) |
Roland McGrath | d17fac7 | 2005-08-23 08:20:21 +0000 | [diff] [blame] | 80 | { |
Ulrich Drepper | b597dfa | 2007-10-16 05:21:27 +0000 | [diff] [blame] | 81 | elf_error: |
Roland McGrath | d17fac7 | 2005-08-23 08:20:21 +0000 | [diff] [blame] | 82 | __libdwfl_seterrno (DWFL_E_LIBELF); |
Mark Wielaard | be17786 | 2015-05-18 16:23:06 +0200 | [diff] [blame] | 83 | nrefs = -1; |
| 84 | goto free_refs; |
Roland McGrath | d17fac7 | 2005-08-23 08:20:21 +0000 | [diff] [blame] | 85 | } |
| 86 | |
Roland McGrath | e4c22ea | 2007-10-23 13:07:39 +0000 | [diff] [blame] | 87 | bool check_reloc_sections = false; |
Roland McGrath | d17fac7 | 2005-08-23 08:20:21 +0000 | [diff] [blame] | 88 | Elf_Scn *scn = NULL; |
Ulrich Drepper | b597dfa | 2007-10-16 05:21:27 +0000 | [diff] [blame] | 89 | while ((scn = elf_nextscn (mod->main.elf, scn)) != NULL) |
Roland McGrath | d17fac7 | 2005-08-23 08:20:21 +0000 | [diff] [blame] | 90 | { |
| 91 | GElf_Shdr shdr_mem; |
| 92 | GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem); |
| 93 | if (shdr == NULL) |
Ulrich Drepper | b597dfa | 2007-10-16 05:21:27 +0000 | [diff] [blame] | 94 | goto elf_error; |
Roland McGrath | d17fac7 | 2005-08-23 08:20:21 +0000 | [diff] [blame] | 95 | |
Roland McGrath | 19a8e4d | 2009-04-21 15:44:07 -0700 | [diff] [blame] | 96 | if ((shdr->sh_flags & SHF_ALLOC) && shdr->sh_addr == 0 |
| 97 | && mod->e_type == ET_REL) |
Ulrich Drepper | aa915fd | 2007-02-05 07:25:33 +0000 | [diff] [blame] | 98 | { |
| 99 | /* This section might not yet have been looked at. */ |
Ulrich Drepper | b597dfa | 2007-10-16 05:21:27 +0000 | [diff] [blame] | 100 | if (__libdwfl_relocate_value (mod, mod->main.elf, &shstrndx, |
| 101 | elf_ndxscn (scn), |
Ulrich Drepper | aa915fd | 2007-02-05 07:25:33 +0000 | [diff] [blame] | 102 | &shdr->sh_addr) != DWFL_E_NOERROR) |
| 103 | continue; |
| 104 | shdr = gelf_getshdr (scn, &shdr_mem); |
Ulrich Drepper | b597dfa | 2007-10-16 05:21:27 +0000 | [diff] [blame] | 105 | if (unlikely (shdr == NULL)) |
| 106 | goto elf_error; |
Ulrich Drepper | aa915fd | 2007-02-05 07:25:33 +0000 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | if (shdr->sh_flags & SHF_ALLOC) |
Roland McGrath | d17fac7 | 2005-08-23 08:20:21 +0000 | [diff] [blame] | 110 | { |
Ulrich Drepper | b597dfa | 2007-10-16 05:21:27 +0000 | [diff] [blame] | 111 | const char *name = elf_strptr (mod->main.elf, shstrndx, |
Roland McGrath | d17fac7 | 2005-08-23 08:20:21 +0000 | [diff] [blame] | 112 | shdr->sh_name); |
Ulrich Drepper | b597dfa | 2007-10-16 05:21:27 +0000 | [diff] [blame] | 113 | if (unlikely (name == NULL)) |
| 114 | goto elf_error; |
Roland McGrath | d17fac7 | 2005-08-23 08:20:21 +0000 | [diff] [blame] | 115 | |
Mark Wielaard | be17786 | 2015-05-18 16:23:06 +0200 | [diff] [blame] | 116 | struct secref *newref = malloc (sizeof *newref); |
| 117 | if (unlikely (newref == NULL)) |
| 118 | { |
| 119 | nomem: |
| 120 | __libdwfl_seterrno (DWFL_E_NOMEM); |
| 121 | nrefs = -1; |
| 122 | goto free_refs; |
| 123 | } |
| 124 | |
Roland McGrath | d17fac7 | 2005-08-23 08:20:21 +0000 | [diff] [blame] | 125 | newref->scn = scn; |
Roland McGrath | e4c22ea | 2007-10-23 13:07:39 +0000 | [diff] [blame] | 126 | newref->relocs = NULL; |
Roland McGrath | d17fac7 | 2005-08-23 08:20:21 +0000 | [diff] [blame] | 127 | newref->name = name; |
Roland McGrath | 1743d7f | 2010-11-12 16:46:47 -0800 | [diff] [blame] | 128 | newref->start = dwfl_adjusted_address (mod, shdr->sh_addr); |
Roland McGrath | 43da989 | 2007-04-16 23:13:37 +0000 | [diff] [blame] | 129 | newref->end = newref->start + shdr->sh_size; |
Roland McGrath | d17fac7 | 2005-08-23 08:20:21 +0000 | [diff] [blame] | 130 | newref->next = refs; |
| 131 | refs = newref; |
| 132 | ++nrefs; |
| 133 | } |
Roland McGrath | e4c22ea | 2007-10-23 13:07:39 +0000 | [diff] [blame] | 134 | |
| 135 | if (mod->e_type == ET_REL |
| 136 | && shdr->sh_size != 0 |
| 137 | && (shdr->sh_type == SHT_REL || shdr->sh_type == SHT_RELA) |
| 138 | && mod->dwfl->callbacks->section_address != NULL) |
| 139 | { |
| 140 | if (shdr->sh_info < elf_ndxscn (scn)) |
| 141 | { |
| 142 | /* We've already looked at the section these relocs apply to. */ |
| 143 | Elf_Scn *tscn = elf_getscn (mod->main.elf, shdr->sh_info); |
| 144 | if (likely (tscn != NULL)) |
| 145 | for (struct secref *sec = refs; sec != NULL; sec = sec->next) |
| 146 | if (sec->scn == tscn) |
| 147 | { |
| 148 | sec->relocs = scn; |
| 149 | break; |
| 150 | } |
| 151 | } |
| 152 | else |
| 153 | /* We'll have to do a second pass. */ |
| 154 | check_reloc_sections = true; |
| 155 | } |
Roland McGrath | d17fac7 | 2005-08-23 08:20:21 +0000 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | mod->reloc_info = malloc (offsetof (struct dwfl_relocation, refs[nrefs])); |
Mark Wielaard | be17786 | 2015-05-18 16:23:06 +0200 | [diff] [blame] | 159 | if (unlikely (mod->reloc_info == NULL)) |
| 160 | goto nomem; |
Roland McGrath | d17fac7 | 2005-08-23 08:20:21 +0000 | [diff] [blame] | 161 | |
Mark Wielaard | be17786 | 2015-05-18 16:23:06 +0200 | [diff] [blame] | 162 | struct secref **sortrefs = malloc (nrefs * sizeof sortrefs[0]); |
| 163 | if (unlikely (sortrefs == NULL)) |
| 164 | goto nomem; |
| 165 | |
Roland McGrath | d17fac7 | 2005-08-23 08:20:21 +0000 | [diff] [blame] | 166 | for (size_t i = nrefs; i-- > 0; refs = refs->next) |
| 167 | sortrefs[i] = refs; |
| 168 | assert (refs == NULL); |
| 169 | |
| 170 | qsort (sortrefs, nrefs, sizeof sortrefs[0], &compare_secrefs); |
| 171 | |
| 172 | mod->reloc_info->count = nrefs; |
| 173 | for (size_t i = 0; i < nrefs; ++i) |
| 174 | { |
| 175 | mod->reloc_info->refs[i].name = sortrefs[i]->name; |
| 176 | mod->reloc_info->refs[i].scn = sortrefs[i]->scn; |
Roland McGrath | e4c22ea | 2007-10-23 13:07:39 +0000 | [diff] [blame] | 177 | mod->reloc_info->refs[i].relocs = sortrefs[i]->relocs; |
Roland McGrath | d17fac7 | 2005-08-23 08:20:21 +0000 | [diff] [blame] | 178 | mod->reloc_info->refs[i].start = sortrefs[i]->start; |
| 179 | mod->reloc_info->refs[i].end = sortrefs[i]->end; |
Mark Wielaard | 93d8959 | 2015-06-06 22:49:34 +0200 | [diff] [blame] | 180 | free (sortrefs[i]); |
Roland McGrath | d17fac7 | 2005-08-23 08:20:21 +0000 | [diff] [blame] | 181 | } |
| 182 | |
Mark Wielaard | be17786 | 2015-05-18 16:23:06 +0200 | [diff] [blame] | 183 | free (sortrefs); |
| 184 | |
Roland McGrath | e4c22ea | 2007-10-23 13:07:39 +0000 | [diff] [blame] | 185 | if (unlikely (check_reloc_sections)) |
| 186 | { |
| 187 | /* There was a reloc section that preceded its target section. |
| 188 | So we have to scan again now that we have cached all the |
| 189 | possible target sections we care about. */ |
| 190 | |
| 191 | scn = NULL; |
| 192 | while ((scn = elf_nextscn (mod->main.elf, scn)) != NULL) |
| 193 | { |
| 194 | GElf_Shdr shdr_mem; |
| 195 | GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem); |
| 196 | if (shdr == NULL) |
| 197 | goto elf_error; |
| 198 | |
| 199 | if (shdr->sh_size != 0 |
| 200 | && (shdr->sh_type == SHT_REL || shdr->sh_type == SHT_RELA)) |
| 201 | { |
| 202 | Elf_Scn *tscn = elf_getscn (mod->main.elf, shdr->sh_info); |
| 203 | if (likely (tscn != NULL)) |
| 204 | for (size_t i = 0; i < nrefs; ++i) |
| 205 | if (mod->reloc_info->refs[i].scn == tscn) |
| 206 | { |
| 207 | mod->reloc_info->refs[i].relocs = scn; |
| 208 | break; |
| 209 | } |
| 210 | } |
| 211 | } |
| 212 | } |
| 213 | |
Mark Wielaard | be17786 | 2015-05-18 16:23:06 +0200 | [diff] [blame] | 214 | free_refs: |
| 215 | while (refs != NULL) |
| 216 | { |
| 217 | struct secref *ref = refs; |
| 218 | refs = ref->next; |
| 219 | free (ref); |
| 220 | } |
| 221 | |
Roland McGrath | d17fac7 | 2005-08-23 08:20:21 +0000 | [diff] [blame] | 222 | return nrefs; |
| 223 | } |
| 224 | |
| 225 | |
| 226 | int |
| 227 | dwfl_module_relocations (Dwfl_Module *mod) |
| 228 | { |
| 229 | if (mod == NULL) |
| 230 | return -1; |
| 231 | |
Roland McGrath | d17fac7 | 2005-08-23 08:20:21 +0000 | [diff] [blame] | 232 | switch (mod->e_type) |
| 233 | { |
| 234 | case ET_REL: |
| 235 | return cache_sections (mod); |
| 236 | |
| 237 | case ET_DYN: |
| 238 | return 1; |
| 239 | |
| 240 | case ET_EXEC: |
Roland McGrath | 1743d7f | 2010-11-12 16:46:47 -0800 | [diff] [blame] | 241 | assert (mod->main.vaddr == mod->low_addr); |
Roland McGrath | d17fac7 | 2005-08-23 08:20:21 +0000 | [diff] [blame] | 242 | break; |
| 243 | } |
| 244 | |
| 245 | return 0; |
| 246 | } |
| 247 | |
| 248 | const char * |
| 249 | dwfl_module_relocation_info (Dwfl_Module *mod, unsigned int idx, |
| 250 | Elf32_Word *shndxp) |
| 251 | { |
| 252 | if (mod == NULL) |
| 253 | return NULL; |
| 254 | |
| 255 | switch (mod->e_type) |
| 256 | { |
| 257 | case ET_REL: |
| 258 | break; |
| 259 | |
| 260 | case ET_DYN: |
| 261 | if (idx != 0) |
| 262 | return NULL; |
| 263 | if (shndxp) |
| 264 | *shndxp = SHN_ABS; |
| 265 | return ""; |
| 266 | |
| 267 | default: |
| 268 | return NULL; |
| 269 | } |
| 270 | |
Mark Wielaard | f43feb5 | 2011-10-20 16:53:54 +0200 | [diff] [blame] | 271 | if (cache_sections (mod) < 0) |
Roland McGrath | d17fac7 | 2005-08-23 08:20:21 +0000 | [diff] [blame] | 272 | return NULL; |
| 273 | |
| 274 | struct dwfl_relocation *sections = mod->reloc_info; |
| 275 | |
| 276 | if (idx >= sections->count) |
| 277 | return NULL; |
| 278 | |
| 279 | if (shndxp) |
| 280 | *shndxp = elf_ndxscn (sections->refs[idx].scn); |
| 281 | |
| 282 | return sections->refs[idx].name; |
| 283 | } |
| 284 | |
Roland McGrath | 43da989 | 2007-04-16 23:13:37 +0000 | [diff] [blame] | 285 | /* Check that MOD is valid and make sure its relocation has been done. */ |
| 286 | static bool |
| 287 | check_module (Dwfl_Module *mod) |
Roland McGrath | d17fac7 | 2005-08-23 08:20:21 +0000 | [diff] [blame] | 288 | { |
Mark Wielaard | e115bda | 2015-05-24 00:07:33 +0200 | [diff] [blame] | 289 | if (mod == NULL) |
| 290 | return true; |
| 291 | |
Roland McGrath | 43da989 | 2007-04-16 23:13:37 +0000 | [diff] [blame] | 292 | if (INTUSE(dwfl_module_getsymtab) (mod) < 0) |
| 293 | { |
| 294 | Dwfl_Error error = dwfl_errno (); |
| 295 | if (error != DWFL_E_NO_SYMTAB) |
| 296 | { |
| 297 | __libdwfl_seterrno (error); |
| 298 | return true; |
| 299 | } |
| 300 | } |
Roland McGrath | d17fac7 | 2005-08-23 08:20:21 +0000 | [diff] [blame] | 301 | |
| 302 | if (mod->dw == NULL) |
| 303 | { |
| 304 | Dwarf_Addr bias; |
| 305 | if (INTUSE(dwfl_module_getdwarf) (mod, &bias) == NULL) |
Roland McGrath | 43da989 | 2007-04-16 23:13:37 +0000 | [diff] [blame] | 306 | { |
| 307 | Dwfl_Error error = dwfl_errno (); |
| 308 | if (error != DWFL_E_NO_DWARF) |
| 309 | { |
| 310 | __libdwfl_seterrno (error); |
| 311 | return true; |
| 312 | } |
| 313 | } |
Roland McGrath | d17fac7 | 2005-08-23 08:20:21 +0000 | [diff] [blame] | 314 | } |
| 315 | |
Roland McGrath | 43da989 | 2007-04-16 23:13:37 +0000 | [diff] [blame] | 316 | return false; |
| 317 | } |
Roland McGrath | d17fac7 | 2005-08-23 08:20:21 +0000 | [diff] [blame] | 318 | |
Roland McGrath | 43da989 | 2007-04-16 23:13:37 +0000 | [diff] [blame] | 319 | /* Find the index in MOD->reloc_info.refs containing *ADDR. */ |
| 320 | static int |
| 321 | find_section (Dwfl_Module *mod, Dwarf_Addr *addr) |
| 322 | { |
Mark Wielaard | f43feb5 | 2011-10-20 16:53:54 +0200 | [diff] [blame] | 323 | if (cache_sections (mod) < 0) |
Roland McGrath | d17fac7 | 2005-08-23 08:20:21 +0000 | [diff] [blame] | 324 | return -1; |
| 325 | |
| 326 | struct dwfl_relocation *sections = mod->reloc_info; |
| 327 | |
| 328 | /* The sections are sorted by address, so we can use binary search. */ |
| 329 | size_t l = 0, u = sections->count; |
| 330 | while (l < u) |
| 331 | { |
| 332 | size_t idx = (l + u) / 2; |
| 333 | if (*addr < sections->refs[idx].start) |
| 334 | u = idx; |
| 335 | else if (*addr > sections->refs[idx].end) |
| 336 | l = idx + 1; |
| 337 | else |
| 338 | { |
| 339 | /* Consider the limit of a section to be inside it, unless it's |
| 340 | inside the next one. A section limit address can appear in |
| 341 | line records. */ |
| 342 | if (*addr == sections->refs[idx].end |
Mark Wielaard | 5b25782 | 2012-10-01 16:10:46 +0200 | [diff] [blame] | 343 | && idx + 1 < sections->count |
Roland McGrath | d17fac7 | 2005-08-23 08:20:21 +0000 | [diff] [blame] | 344 | && *addr == sections->refs[idx + 1].start) |
| 345 | ++idx; |
| 346 | |
| 347 | *addr -= sections->refs[idx].start; |
| 348 | return idx; |
| 349 | } |
| 350 | } |
| 351 | |
Ulrich Drepper | b597dfa | 2007-10-16 05:21:27 +0000 | [diff] [blame] | 352 | __libdwfl_seterrno (DWFL_E (LIBDW, DWARF_E_NO_MATCH)); |
Roland McGrath | d17fac7 | 2005-08-23 08:20:21 +0000 | [diff] [blame] | 353 | return -1; |
| 354 | } |
Roland McGrath | 43da989 | 2007-04-16 23:13:37 +0000 | [diff] [blame] | 355 | |
Mark Wielaard | 159ac52 | 2013-12-18 11:05:54 +0100 | [diff] [blame] | 356 | size_t |
| 357 | internal_function |
| 358 | __libdwfl_find_section_ndx (Dwfl_Module *mod, Dwarf_Addr *addr) |
| 359 | { |
| 360 | int idx = find_section (mod, addr); |
| 361 | if (unlikely (idx == -1)) |
| 362 | return SHN_UNDEF; |
| 363 | |
| 364 | return elf_ndxscn (mod->reloc_info->refs[idx].scn); |
| 365 | } |
| 366 | |
Roland McGrath | 43da989 | 2007-04-16 23:13:37 +0000 | [diff] [blame] | 367 | int |
| 368 | dwfl_module_relocate_address (Dwfl_Module *mod, Dwarf_Addr *addr) |
| 369 | { |
Roland McGrath | 7d9b821 | 2008-12-18 15:08:09 -0800 | [diff] [blame] | 370 | if (unlikely (check_module (mod))) |
Roland McGrath | 43da989 | 2007-04-16 23:13:37 +0000 | [diff] [blame] | 371 | return -1; |
| 372 | |
Roland McGrath | 7d9b821 | 2008-12-18 15:08:09 -0800 | [diff] [blame] | 373 | switch (mod->e_type) |
Roland McGrath | 43da989 | 2007-04-16 23:13:37 +0000 | [diff] [blame] | 374 | { |
Roland McGrath | 7d9b821 | 2008-12-18 15:08:09 -0800 | [diff] [blame] | 375 | case ET_REL: |
| 376 | return find_section (mod, addr); |
| 377 | |
| 378 | case ET_DYN: |
| 379 | /* All relative to first and only relocation base: module start. */ |
| 380 | *addr -= mod->low_addr; |
| 381 | break; |
| 382 | |
| 383 | default: |
| 384 | /* Already absolute, dwfl_module_relocations returned zero. We |
| 385 | shouldn't really have been called, but it's a harmless no-op. */ |
| 386 | break; |
Roland McGrath | 43da989 | 2007-04-16 23:13:37 +0000 | [diff] [blame] | 387 | } |
| 388 | |
Roland McGrath | 7d9b821 | 2008-12-18 15:08:09 -0800 | [diff] [blame] | 389 | return 0; |
Roland McGrath | 43da989 | 2007-04-16 23:13:37 +0000 | [diff] [blame] | 390 | } |
Roland McGrath | d17fac7 | 2005-08-23 08:20:21 +0000 | [diff] [blame] | 391 | INTDEF (dwfl_module_relocate_address) |
Roland McGrath | 43da989 | 2007-04-16 23:13:37 +0000 | [diff] [blame] | 392 | |
| 393 | Elf_Scn * |
| 394 | dwfl_module_address_section (Dwfl_Module *mod, Dwarf_Addr *address, |
| 395 | Dwarf_Addr *bias) |
| 396 | { |
| 397 | if (check_module (mod)) |
| 398 | return NULL; |
| 399 | |
| 400 | int idx = find_section (mod, address); |
| 401 | if (idx < 0) |
| 402 | return NULL; |
| 403 | |
Roland McGrath | e4c22ea | 2007-10-23 13:07:39 +0000 | [diff] [blame] | 404 | if (mod->reloc_info->refs[idx].relocs != NULL) |
| 405 | { |
| 406 | assert (mod->e_type == ET_REL); |
| 407 | |
| 408 | Elf_Scn *tscn = mod->reloc_info->refs[idx].scn; |
| 409 | Elf_Scn *relocscn = mod->reloc_info->refs[idx].relocs; |
| 410 | Dwfl_Error result = __libdwfl_relocate_section (mod, mod->main.elf, |
| 411 | relocscn, tscn, true); |
| 412 | if (likely (result == DWFL_E_NOERROR)) |
| 413 | mod->reloc_info->refs[idx].relocs = NULL; |
| 414 | else |
| 415 | { |
| 416 | __libdwfl_seterrno (result); |
| 417 | return NULL; |
| 418 | } |
| 419 | } |
| 420 | |
Roland McGrath | 1743d7f | 2010-11-12 16:46:47 -0800 | [diff] [blame] | 421 | *bias = dwfl_adjusted_address (mod, 0); |
Roland McGrath | 43da989 | 2007-04-16 23:13:37 +0000 | [diff] [blame] | 422 | return mod->reloc_info->refs[idx].scn; |
| 423 | } |
Roland McGrath | b4d6f0f | 2008-08-25 22:55:17 +0000 | [diff] [blame] | 424 | INTDEF (dwfl_module_address_section) |