1 /* Report modules by examining dynamic linker data structures.
2 Copyright (C) 2008-2013 Red Hat, Inc.
3 This file is part of elfutils.
5 This file is free software; you can redistribute it and/or modify
6 it under the terms of either
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
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
18 or both in parallel, as here.
20 elfutils is distributed in the hope that it will be useful, but
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.
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/>. */
31 #include "../libdw/memory-access.h"
38 /* This element is always provided and always has a constant value.
39 This makes it an easy thing to scan for to discern the format. */
40 #define PROBE_TYPE AT_PHENT
41 #define PROBE_VAL32 sizeof (Elf32_Phdr)
42 #define PROBE_VAL64 sizeof (Elf64_Phdr)
45 /* Examine an auxv data block and determine its format.
46 Return true iff we figured it out. */
48 auxv_format_probe (const void *auxv, size_t size,
49 uint_fast8_t *elfclass, uint_fast8_t *elfdata)
54 Elf32_auxv_t a32[size / sizeof (Elf32_auxv_t)];
55 Elf64_auxv_t a64[size / sizeof (Elf64_auxv_t)];
58 inline bool check64 (size_t i)
60 /* The AUXV pointer might not even be naturally aligned for 64-bit
61 data, because note payloads in a core file are not aligned.
62 But we assume the data is 32-bit aligned. */
64 uint64_t type = read_8ubyte_unaligned_noncvt (&u->a64[i].a_type);
65 uint64_t val = read_8ubyte_unaligned_noncvt (&u->a64[i].a_un.a_val);
67 if (type == BE64 (PROBE_TYPE)
68 && val == BE64 (PROBE_VAL64))
70 *elfdata = ELFDATA2MSB;
74 if (type == LE64 (PROBE_TYPE)
75 && val == LE64 (PROBE_VAL64))
77 *elfdata = ELFDATA2LSB;
84 inline bool check32 (size_t i)
86 if (u->a32[i].a_type == BE32 (PROBE_TYPE)
87 && u->a32[i].a_un.a_val == BE32 (PROBE_VAL32))
89 *elfdata = ELFDATA2MSB;
93 if (u->a32[i].a_type == LE32 (PROBE_TYPE)
94 && u->a32[i].a_un.a_val == LE32 (PROBE_VAL32))
96 *elfdata = ELFDATA2LSB;
103 for (size_t i = 0; i < size / sizeof (Elf64_auxv_t); ++i)
107 *elfclass = ELFCLASS64;
111 if (check32 (i * 2) || check32 (i * 2 + 1))
113 *elfclass = ELFCLASS32;
121 /* This is a Dwfl_Memory_Callback that wraps another memory callback.
122 If the underlying callback cannot fill the data, then this will
123 fall back to fetching data from module files. */
125 struct integrated_memory_callback
127 Dwfl_Memory_Callback *memory_callback;
128 void *memory_callback_arg;
133 integrated_memory_callback (Dwfl *dwfl, int ndx,
134 void **buffer, size_t *buffer_available,
139 struct integrated_memory_callback *info = arg;
143 /* Called for cleanup. */
144 if (info->buffer != NULL)
146 /* The last probe buffer came from the underlying callback.
147 Let it do its cleanup. */
148 assert (*buffer == info->buffer); /* XXX */
149 *buffer = info->buffer;
151 return (*info->memory_callback) (dwfl, ndx, buffer, buffer_available,
153 info->memory_callback_arg);
156 *buffer_available = 0;
161 /* For a final-read request, we only use the underlying callback. */
162 return (*info->memory_callback) (dwfl, ndx, buffer, buffer_available,
163 vaddr, minread, info->memory_callback_arg);
165 /* Let the underlying callback try to fill this request. */
166 if ((*info->memory_callback) (dwfl, ndx, &info->buffer, buffer_available,
167 vaddr, minread, info->memory_callback_arg))
169 *buffer = info->buffer;
173 /* Now look for module text covering this address. */
176 (void) INTUSE(dwfl_addrsegment) (dwfl, vaddr, &mod);
181 Elf_Scn *scn = INTUSE(dwfl_module_address_section) (mod, &vaddr, &bias);
182 if (unlikely (scn == NULL))
184 #if 0 // XXX would have to handle ndx=-1 cleanup calls passed down.
185 /* If we have no sections we can try to fill it from the module file
186 based on its phdr mappings. */
187 if (likely (mod->e_type != ET_REL) && mod->main.elf != NULL)
188 return INTUSE(dwfl_elf_phdr_memory_callback)
189 (dwfl, 0, buffer, buffer_available,
190 vaddr - mod->main.bias, minread, mod->main.elf);
195 Elf_Data *data = elf_rawdata (scn, NULL);
196 if (unlikely (data == NULL))
200 if (unlikely (data->d_size < vaddr))
203 /* Provide as much data as we have. */
204 void *contents = data->d_buf + vaddr;
205 size_t avail = data->d_size - vaddr;
206 if (unlikely (avail < minread))
209 /* If probing for a string, make sure it's terminated. */
210 if (minread == 0 && unlikely (memchr (contents, '\0', avail) == NULL))
215 *buffer_available = avail;
220 addrsize (uint_fast8_t elfclass)
225 /* Report a module for each struct link_map in the linked list at r_map
226 in the struct r_debug at R_DEBUG_VADDR. For r_debug_info description
227 see dwfl_link_map_report in libdwflP.h. If R_DEBUG_INFO is not NULL then no
228 modules get added to DWFL, caller has to add them from filled in
231 For each link_map entry, if an existing module resides at its address,
232 this just modifies that module's name and suggested file name. If
233 no such module exists, this calls dwfl_report_elf on the l_name string.
235 Returns the number of modules found, or -1 for errors. */
238 report_r_debug (uint_fast8_t elfclass, uint_fast8_t elfdata,
239 Dwfl *dwfl, GElf_Addr r_debug_vaddr,
240 Dwfl_Memory_Callback *memory_callback,
241 void *memory_callback_arg,
242 struct r_debug_info *r_debug_info)
244 /* Skip r_version, to aligned r_map field. */
245 GElf_Addr read_vaddr = r_debug_vaddr + addrsize (elfclass);
248 size_t buffer_available = 0;
249 inline int release_buffer (int result)
252 (void) (*memory_callback) (dwfl, -1, &buffer, &buffer_available, 0, 0,
253 memory_callback_arg);
258 inline bool read_addrs (GElf_Addr vaddr, size_t n)
260 size_t nb = n * addrsize (elfclass); /* Address words -> bytes to read. */
262 /* Read a new buffer if the old one doesn't cover these words. */
264 || vaddr < read_vaddr
265 || vaddr - read_vaddr + nb > buffer_available)
270 int segndx = INTUSE(dwfl_addrsegment) (dwfl, vaddr, NULL);
271 if (unlikely (segndx < 0)
272 || unlikely (! (*memory_callback) (dwfl, segndx,
273 &buffer, &buffer_available,
274 vaddr, nb, memory_callback_arg)))
282 } *in = vaddr - read_vaddr + buffer;
284 if (elfclass == ELFCLASS32)
286 if (elfdata == ELFDATA2MSB)
287 for (size_t i = 0; i < n; ++i)
288 addrs[i] = BE32 (in->a32[i]);
290 for (size_t i = 0; i < n; ++i)
291 addrs[i] = LE32 (in->a32[i]);
295 if (elfdata == ELFDATA2MSB)
296 for (size_t i = 0; i < n; ++i)
297 addrs[i] = BE64 (in->a64[i]);
299 for (size_t i = 0; i < n; ++i)
300 addrs[i] = LE64 (in->a64[i]);
306 if (unlikely (read_addrs (read_vaddr, 1)))
307 return release_buffer (-1);
309 GElf_Addr next = addrs[0];
311 Dwfl_Module **lastmodp = &dwfl->modulelist;
314 /* There can't be more elements in the link_map list than there are
315 segments. DWFL->lookup_elts is probably twice that number, so it
316 is certainly above the upper bound. If we iterate too many times,
317 there must be a loop in the pointers due to link_map clobberation. */
318 size_t iterations = 0;
319 while (next != 0 && ++iterations < dwfl->lookup_elts)
321 if (read_addrs (next, 4))
322 return release_buffer (-1);
324 GElf_Addr l_addr = addrs[0];
325 GElf_Addr l_name = addrs[1];
326 GElf_Addr l_ld = addrs[2];
329 /* If a clobbered or truncated memory image has no useful pointer,
330 just skip this element. */
334 /* Fetch the string at the l_name address. */
335 const char *name = NULL;
337 && read_vaddr <= l_name
338 && l_name + 1 - read_vaddr < buffer_available
339 && memchr (l_name - read_vaddr + buffer, '\0',
340 buffer_available - (l_name - read_vaddr)) != NULL)
341 name = l_name - read_vaddr + buffer;
346 int segndx = INTUSE(dwfl_addrsegment) (dwfl, l_name, NULL);
347 if (likely (segndx >= 0)
348 && (*memory_callback) (dwfl, segndx,
349 &buffer, &buffer_available,
350 l_name, 0, memory_callback_arg))
354 if (name != NULL && name[0] == '\0')
357 if (iterations == 1 && dwfl->executable_for_core != NULL)
358 name = dwfl->executable_for_core;
360 struct r_debug_info_module *r_debug_info_module = NULL;
361 if (r_debug_info != NULL)
363 /* Save link map information about valid shared library (or
364 executable) which has not been found on disk. */
365 const char *name1 = name == NULL ? "" : name;
366 r_debug_info_module = malloc (sizeof (*r_debug_info_module)
367 + strlen (name1) + 1);
368 if (r_debug_info_module == NULL)
369 return release_buffer (result);
370 r_debug_info_module->fd = -1;
371 r_debug_info_module->elf = NULL;
372 r_debug_info_module->l_ld = l_ld;
373 r_debug_info_module->start = 0;
374 r_debug_info_module->end = 0;
375 r_debug_info_module->disk_file_has_build_id = false;
376 strcpy (r_debug_info_module->name, name1);
377 r_debug_info_module->next = r_debug_info->module;
378 r_debug_info->module = r_debug_info_module;
381 Dwfl_Module *mod = NULL;
384 /* This code is mostly inlined dwfl_report_elf. */
385 // XXX hook for sysroot
386 int fd = open64 (name, O_RDONLY);
390 Dwfl_Error error = __libdw_open_file (&fd, &elf, true, false);
391 GElf_Addr elf_dynamic_vaddr;
392 if (error == DWFL_E_NOERROR
393 && __libdwfl_dynamic_vaddr_get (elf, &elf_dynamic_vaddr))
395 const void *build_id_bits;
396 GElf_Addr build_id_elfaddr;
400 if (__libdwfl_find_elf_build_id (NULL, elf, &build_id_bits,
403 && build_id_elfaddr != 0)
405 if (r_debug_info_module != NULL)
406 r_debug_info_module->disk_file_has_build_id = true;
407 GElf_Addr build_id_vaddr = (build_id_elfaddr
408 - elf_dynamic_vaddr + l_ld);
411 int segndx = INTUSE(dwfl_addrsegment) (dwfl,
414 if (! (*memory_callback) (dwfl, segndx,
415 &buffer, &buffer_available,
416 build_id_vaddr, build_id_len,
417 memory_callback_arg))
419 /* File has valid build-id which cannot be read from
420 memory. This happens for core files without bit 4
421 (0x10) set in Linux /proc/PID/coredump_filter. */
425 if (memcmp (build_id_bits, buffer, build_id_len) != 0)
426 /* File has valid build-id which does not match
427 the one in memory. */
435 if (r_debug_info_module == NULL)
437 // XXX hook for sysroot
438 mod = __libdwfl_report_elf (dwfl, basename (name),
439 name, fd, elf, l_addr,
447 else if (__libdwfl_elf_address_range (elf, l_addr, true,
449 &r_debug_info_module->start,
450 &r_debug_info_module->end,
453 r_debug_info_module->elf = elf;
454 r_debug_info_module->fd = fd;
471 /* Move this module to the end of the list, so that we end
472 up with a list in the same order as the link_map chain. */
473 if (mod->next != NULL)
475 if (*lastmodp != mod)
477 lastmodp = &dwfl->modulelist;
478 while (*lastmodp != mod)
479 lastmodp = &(*lastmodp)->next;
481 *lastmodp = mod->next;
483 while (*lastmodp != NULL)
484 lastmodp = &(*lastmodp)->next;
488 lastmodp = &mod->next;
492 return release_buffer (result);
496 consider_executable (Dwfl_Module *mod, GElf_Addr at_phdr, GElf_Addr at_entry,
497 uint_fast8_t *elfclass, uint_fast8_t *elfdata,
498 Dwfl_Memory_Callback *memory_callback,
499 void *memory_callback_arg)
502 if (unlikely (gelf_getehdr (mod->main.elf, &ehdr) == NULL))
507 /* If we have an AT_ENTRY value, reject this executable if
508 its entry point address could not have supplied that. */
510 if (ehdr.e_entry == 0)
513 if (mod->e_type == ET_EXEC)
515 if (ehdr.e_entry != at_entry)
520 /* It could be a PIE. */
524 // XXX this could be saved in the file cache: phdr vaddr, DT_DEBUG d_val vaddr
525 /* Find the vaddr of the DT_DEBUG's d_ptr. This is the memory
526 address where &r_debug was written at runtime. */
527 GElf_Xword align = mod->dwfl->segment_align;
528 GElf_Addr d_val_vaddr = 0;
529 for (uint_fast16_t i = 0; i < ehdr.e_phnum; ++i)
532 GElf_Phdr *phdr = gelf_getphdr (mod->main.elf, i, &phdr_mem);
536 if (phdr->p_align > 1 && (align == 0 || phdr->p_align < align))
537 align = phdr->p_align;
540 && phdr->p_type == PT_LOAD
541 && (phdr->p_offset & -align) == (ehdr.e_phoff & -align))
543 /* This is the segment that would map the phdrs.
544 If we have an AT_PHDR value, reject this executable
545 if its phdr mapping could not have supplied that. */
546 if (mod->e_type == ET_EXEC)
548 if (ehdr.e_phoff - phdr->p_offset + phdr->p_vaddr != at_phdr)
553 /* It could be a PIE. If the AT_PHDR value and our
554 phdr address don't match modulo ALIGN, then this
555 could not have been the right PIE. */
556 if (((ehdr.e_phoff - phdr->p_offset + phdr->p_vaddr) & -align)
557 != (at_phdr & -align))
560 /* Calculate the bias applied to the PIE's p_vaddr values. */
561 GElf_Addr bias = (at_phdr - (ehdr.e_phoff - phdr->p_offset
564 /* Final sanity check: if we have an AT_ENTRY value,
565 reject this PIE unless its biased e_entry matches. */
566 if (at_entry != 0 && at_entry != ehdr.e_entry + bias)
569 /* If we're changing the module's address range,
570 we've just invalidated the module lookup table. */
571 GElf_Addr mod_bias = dwfl_adjusted_address (mod, 0);
572 if (bias != mod_bias)
574 mod->low_addr -= mod_bias;
575 mod->high_addr -= mod_bias;
576 mod->low_addr += bias;
577 mod->high_addr += bias;
579 free (mod->dwfl->lookup_module);
580 mod->dwfl->lookup_module = NULL;
585 if (phdr->p_type == PT_DYNAMIC)
587 Elf_Data *data = elf_getdata_rawchunk (mod->main.elf, phdr->p_offset,
588 phdr->p_filesz, ELF_T_DYN);
591 const size_t entsize = gelf_fsize (mod->main.elf,
592 ELF_T_DYN, 1, EV_CURRENT);
593 const size_t n = data->d_size / entsize;
594 for (size_t j = 0; j < n; ++j)
597 GElf_Dyn *dyn = gelf_getdyn (data, j, &dyn_mem);
598 if (dyn != NULL && dyn->d_tag == DT_DEBUG)
600 d_val_vaddr = phdr->p_vaddr + entsize * j + entsize / 2;
607 if (d_val_vaddr != 0)
609 /* Now we have the final address from which to read &r_debug. */
610 d_val_vaddr = dwfl_adjusted_address (mod, d_val_vaddr);
613 size_t buffer_available = addrsize (ehdr.e_ident[EI_CLASS]);
615 int segndx = INTUSE(dwfl_addrsegment) (mod->dwfl, d_val_vaddr, NULL);
617 if ((*memory_callback) (mod->dwfl, segndx,
618 &buffer, &buffer_available,
619 d_val_vaddr, buffer_available,
620 memory_callback_arg))
629 if (ehdr.e_ident[EI_CLASS] == ELFCLASS32)
630 vaddr = (ehdr.e_ident[EI_DATA] == ELFDATA2MSB
631 ? BE32 (u->a32) : LE32 (u->a32));
633 vaddr = (ehdr.e_ident[EI_DATA] == ELFDATA2MSB
634 ? BE64 (u->a64) : LE64 (u->a64));
636 (*memory_callback) (mod->dwfl, -1, &buffer, &buffer_available, 0, 0,
637 memory_callback_arg);
639 if (*elfclass == ELFCLASSNONE)
640 *elfclass = ehdr.e_ident[EI_CLASS];
641 else if (*elfclass != ehdr.e_ident[EI_CLASS])
644 if (*elfdata == ELFDATANONE)
645 *elfdata = ehdr.e_ident[EI_DATA];
646 else if (*elfdata != ehdr.e_ident[EI_DATA])
656 /* Try to find an existing executable module with a DT_DEBUG. */
658 find_executable (Dwfl *dwfl, GElf_Addr at_phdr, GElf_Addr at_entry,
659 uint_fast8_t *elfclass, uint_fast8_t *elfdata,
660 Dwfl_Memory_Callback *memory_callback,
661 void *memory_callback_arg)
663 for (Dwfl_Module *mod = dwfl->modulelist; mod != NULL; mod = mod->next)
664 if (mod->main.elf != NULL)
666 GElf_Addr r_debug_vaddr = consider_executable (mod, at_phdr, at_entry,
669 memory_callback_arg);
670 if (r_debug_vaddr != 0)
671 return r_debug_vaddr;
679 dwfl_link_map_report (Dwfl *dwfl, const void *auxv, size_t auxv_size,
680 Dwfl_Memory_Callback *memory_callback,
681 void *memory_callback_arg,
682 struct r_debug_info *r_debug_info)
684 GElf_Addr r_debug_vaddr = 0;
686 uint_fast8_t elfclass = ELFCLASSNONE;
687 uint_fast8_t elfdata = ELFDATANONE;
688 if (likely (auxv != NULL)
689 && likely (auxv_format_probe (auxv, auxv_size, &elfclass, &elfdata)))
693 GElf_Xword phent = 0;
694 GElf_Xword phnum = 0;
696 #define READ_AUXV32(ptr) read_4ubyte_unaligned_noncvt (ptr)
697 #define READ_AUXV64(ptr) read_8ubyte_unaligned_noncvt (ptr)
698 #define AUXV_SCAN(NN, BL) do \
700 const Elf##NN##_auxv_t *av = auxv; \
701 for (size_t i = 0; i < auxv_size / sizeof av[0]; ++i) \
703 uint##NN##_t type = READ_AUXV##NN (&av[i].a_type); \
704 uint##NN##_t val = BL##NN (READ_AUXV##NN (&av[i].a_un.a_val)); \
705 if (type == BL##NN (AT_ENTRY)) \
707 else if (type == BL##NN (AT_PHDR)) \
709 else if (type == BL##NN (AT_PHNUM)) \
711 else if (type == BL##NN (AT_PHENT)) \
713 else if (type == BL##NN (AT_PAGESZ)) \
716 && (dwfl->segment_align == 0 \
717 || val < dwfl->segment_align)) \
718 dwfl->segment_align = val; \
724 if (elfclass == ELFCLASS32)
726 if (elfdata == ELFDATA2MSB)
733 if (elfdata == ELFDATA2MSB)
739 /* If we found the phdr dimensions, search phdrs for PT_DYNAMIC. */
740 GElf_Addr dyn_vaddr = 0;
741 GElf_Xword dyn_filesz = 0;
742 GElf_Addr dyn_bias = (GElf_Addr) -1;
744 inline bool consider_phdr (GElf_Word type,
745 GElf_Addr vaddr, GElf_Xword filesz)
750 if (dyn_bias == (GElf_Addr) -1
751 /* Do a sanity check on the putative address. */
752 && ((vaddr & (dwfl->segment_align - 1))
753 == (phdr & (dwfl->segment_align - 1))))
755 dyn_bias = phdr - vaddr;
756 return dyn_vaddr != 0;
763 return dyn_bias != (GElf_Addr) -1;
769 if (phdr != 0 && phnum != 0)
771 Dwfl_Module *phdr_mod;
772 int phdr_segndx = INTUSE(dwfl_addrsegment) (dwfl, phdr, &phdr_mod);
775 .d_type = ELF_T_PHDR,
776 .d_version = EV_CURRENT,
777 .d_size = phnum * phent,
780 bool in_ok = (*memory_callback) (dwfl, phdr_segndx, &in.d_buf,
781 &in.d_size, phdr, phnum * phent,
782 memory_callback_arg);
783 if (! in_ok && dwfl->executable_for_core != NULL)
785 /* AUXV -> PHDR -> DYNAMIC
786 Both AUXV and DYNAMIC should be always present in a core file.
787 PHDR may be missing in core file, try to read it from
788 EXECUTABLE_FOR_CORE to find where DYNAMIC is located in the
791 int fd = open (dwfl->executable_for_core, O_RDONLY);
793 Dwfl_Error error = DWFL_E_ERRNO;
795 error = __libdw_open_file (&fd, &elf, true, false);
796 if (error != DWFL_E_NOERROR)
798 __libdwfl_seterrno (error);
801 GElf_Ehdr ehdr_mem, *ehdr = gelf_getehdr (elf, &ehdr_mem);
806 __libdwfl_seterrno (DWFL_E_LIBELF);
809 if (ehdr->e_phnum != phnum || ehdr->e_phentsize != phent)
813 __libdwfl_seterrno (DWFL_E_BADELF);
816 off_t off = ehdr->e_phoff;
817 assert (in.d_buf == NULL);
818 assert (in.d_size == phnum * phent);
819 in.d_buf = malloc (in.d_size);
820 if (unlikely (in.d_buf == NULL))
824 __libdwfl_seterrno (DWFL_E_NOMEM);
827 ssize_t nread = pread_retry (fd, in.d_buf, in.d_size, off);
830 if (nread != (ssize_t) in.d_size)
833 __libdwfl_seterrno (DWFL_E_ERRNO);
844 char data[phnum * phent];
848 .d_type = ELF_T_PHDR,
849 .d_version = EV_CURRENT,
850 .d_size = phnum * phent,
853 in.d_size = out.d_size;
854 if (likely ((elfclass == ELFCLASS32
855 ? elf32_xlatetom : elf64_xlatetom)
856 (&out, &in, elfdata) != NULL))
858 /* We are looking for PT_DYNAMIC. */
861 Elf32_Phdr p32[phnum];
862 Elf64_Phdr p64[phnum];
863 } *u = (void *) &buf;
864 if (elfclass == ELFCLASS32)
866 for (size_t i = 0; i < phnum; ++i)
867 if (consider_phdr (u->p32[i].p_type,
874 for (size_t i = 0; i < phnum; ++i)
875 if (consider_phdr (u->p64[i].p_type,
882 (*memory_callback) (dwfl, -1, &in.d_buf, &in.d_size, 0, 0,
883 memory_callback_arg);
886 /* We could not read the executable's phdrs from the
887 memory image. If we have a presupplied executable,
888 we can still use the AT_PHDR and AT_ENTRY values to
889 verify it, and to adjust its bias if it's a PIE.
891 If there was an ET_EXEC module presupplied that contains
892 the AT_PHDR address, then we only consider that one.
893 We'll either accept it if its phdr location and e_entry
894 make sense or reject it if they don't. If there is no
895 presupplied ET_EXEC, then look for a presupplied module,
896 which might be a PIE (ET_DYN) that needs its bias adjusted. */
897 r_debug_vaddr = ((phdr_mod == NULL
898 || phdr_mod->main.elf == NULL
899 || phdr_mod->e_type != ET_EXEC)
900 ? find_executable (dwfl, phdr, entry,
904 : consider_executable (phdr_mod, phdr, entry,
907 memory_callback_arg));
910 /* If we found PT_DYNAMIC, search it for DT_DEBUG. */
913 if (dyn_bias != (GElf_Addr) -1)
914 dyn_vaddr += dyn_bias;
919 .d_version = EV_CURRENT,
920 .d_size = dyn_filesz,
923 int dyn_segndx = dwfl_addrsegment (dwfl, dyn_vaddr, NULL);
924 if ((*memory_callback) (dwfl, dyn_segndx, &in.d_buf, &in.d_size,
925 dyn_vaddr, dyn_filesz, memory_callback_arg))
931 char data[dyn_filesz];
936 .d_version = EV_CURRENT,
937 .d_size = dyn_filesz,
940 in.d_size = out.d_size;
941 if (likely ((elfclass == ELFCLASS32
942 ? elf32_xlatetom : elf64_xlatetom)
943 (&out, &in, elfdata) != NULL))
945 /* We are looking for DT_DEBUG. */
948 Elf32_Dyn d32[dyn_filesz / sizeof (Elf32_Dyn)];
949 Elf64_Dyn d64[dyn_filesz / sizeof (Elf64_Dyn)];
950 } *u = (void *) &buf;
951 if (elfclass == ELFCLASS32)
953 size_t n = dyn_filesz / sizeof (Elf32_Dyn);
954 for (size_t i = 0; i < n; ++i)
955 if (u->d32[i].d_tag == DT_DEBUG)
957 r_debug_vaddr = u->d32[i].d_un.d_val;
963 size_t n = dyn_filesz / sizeof (Elf64_Dyn);
964 for (size_t i = 0; i < n; ++i)
965 if (u->d64[i].d_tag == DT_DEBUG)
967 r_debug_vaddr = u->d64[i].d_un.d_val;
973 (*memory_callback) (dwfl, -1, &in.d_buf, &in.d_size, 0, 0,
974 memory_callback_arg);
979 /* We have to look for a presupplied executable file to determine
980 the vaddr of its dynamic section and DT_DEBUG therein. */
981 r_debug_vaddr = find_executable (dwfl, 0, 0, &elfclass, &elfdata,
982 memory_callback, memory_callback_arg);
984 if (r_debug_vaddr == 0)
987 /* For following pointers from struct link_map, we will use an
988 integrated memory access callback that can consult module text
989 elided from the core file. This is necessary when the l_name
990 pointer for the dynamic linker's own entry is a pointer into the
991 executable's .interp section. */
992 struct integrated_memory_callback mcb =
994 .memory_callback = memory_callback,
995 .memory_callback_arg = memory_callback_arg
998 /* Now we can follow the dynamic linker's library list. */
999 return report_r_debug (elfclass, elfdata, dwfl, r_debug_vaddr,
1000 &integrated_memory_callback, &mcb, r_debug_info);
1002 INTDEF (dwfl_link_map_report)