summaryrefslogtreecommitdiffstats
path: root/libdwfl/link_map.c
diff options
context:
space:
mode:
authorJan Kratochvil <[email protected]>2013-07-23 16:30:01 +0200
committerJan Kratochvil <[email protected]>2013-07-23 16:30:01 +0200
commit596d430f23f85f3cd019bd0ac560ecd5371fc7e0 (patch)
treeb441bdc4625b42a5b7185497e66951f4f0949829 /libdwfl/link_map.c
parent934d36cb5fec8156fab96bcdf3939a20ff7d473f (diff)
Fix false match of non-build-id disk library to build-id memory library.
this patch: Use DT_DEBUG library search first. 8ff862960efb648cdff647d7fad1be5acffe9b11 [patch 2/2] Fix loading core files without build-ids https://lists.fedorahosted.org/pipermail/elfutils-devel/2013-April/003031.html [patch 2/2 v2] Fix loading core files without build-ids https://lists.fedorahosted.org/pipermail/elfutils-devel/2013-May/003065.html has PASS->FAIL regression on CentOS-5 for run-unstrip-n.sh: -actual on CentOS-5 +expected by testcase -0xf77b3000+0x822c - /lib/librt.so.1 - librt.so.1 -0xf7603000+0x15c5c4 - /lib/libc.so.6 - libc.so.6 -0xf75e9000+0x191e4 - /lib/libpthread.so.0 - libpthread.so.0 -0xf77d7000+0x1c670 - /lib/ld-linux.so.2 - ld-linux.so.2 0x8048000+0x2000 f1c600bc36cb91bf01f9a63a634ecb79aa4c3199@0x8048178 . - [exe] +0xf75e9000+0x1a000 29a103420abe341e92072fb14274e250e4072148@0xf75e9164 - - libpthread.so.0 +0xf7603000+0x1b0000 0b9bf374699e141e5dfc14757ff42b8c2373b4de@0xf7603184 - - libc.so.6 +0xf77b3000+0x9000 c6c5b5e35ab9589d4762ac85b4bd56b1b2720e37@0xf77b3164 - - librt.so.1 0xf77d6000+0x1000 676560b1b765cde9c2e53f134f4ee354ea894747@0xf77d6210 . - linux-gate.so.1 +0xf77d7000+0x21000 6d2cb32650054f1c176d01d48713a4a5e5e84c1a@0xf77d7124 - - ld-linux.so.2 Therefore elfutils now incorrectly matches on-disk file without build-id to an in-core (in-memory) file with build-id. In fact due to its known FIXME: This verification gives false positive if in-core ELF had build-id but on-disk ELF does not have any. But we cannot reliably find ELF header and/or the ELF build id just from the link map (and checking core segments is also not reliable). */ So it probably should not be so ignorable as I did, one may want to analyze build-id core files on CentOS-5, not sure. In fact it can be fixed, when we find in dwfl_segment_report_module a module with build-id with conflicts in its address range with existing non-build-id dwfl_link_map_report module we should prefer the build-id module instead. The problem is that once Dwfl_Module is added to Dwfl it cannot be easily removed. Originally elfutils called dwfl_segment_report_module first and then dwfl_link_map_report. Currently the order is dwfl_link_map_report and then dwfl_segment_report_module only for modules missing from dwfl_link_map_report. Patch below unfortunately needs bidirectional negotiation between the two functions, therefore dwfl_link_map_report now no longer adds Dwfl_Modules to Dwfl but it only stores information about them to r_debug_info_module. This information is filtered then by dwfl_segment_report_module and only filtered r_debug_info_module entries get finally added to Dwfl (in dwfl_core_file_report). NT_FILE would make all this magic easy but it is true that on CentOS-5 it definitely does not exist. libdwfl/ 2013-07-23 Jan Kratochvil <[email protected]> * core-file.c (clear_r_debug_info): Close also ELF and FD. (dwfl_core_file_report): Call __libdwfl_report_elf for R_DEBUG_INFO.MODULE. * dwfl_report_elf.c (__libdwfl_elf_address_range): New function from code of ... (__libdwfl_report_elf): ... this function. Call it. * dwfl_segment_report_module.c: Include unistd.h. (dwfl_segment_report_module): Use basename for MODULE->NAME. Clear MODULE if it has no build-id and we have segment with build-id. Ignore this segment only if MODULE still contains valid ELF. * libdwflP.h (__libdwfl_elf_address_range): New declaration. (struct r_debug_info_module): New fields fd, elf, l_addr, start, end and disk_file_has_build_id. (dwfl_link_map_report): Extend the comment. * link_map.c (report_r_debug): Extend the comment. Always fill in new r_debug_info_module. Initialize also the new r_debug_info_module fields. Remove one FIXME comment. Call __libdwfl_elf_address_range instead of __libdwfl_report_elf when R_DEBUG_INFO is not NULL. tests/ 2013-07-23 Jan Kratochvil <[email protected]> * run-unstrip-n.sh (test-core.*): Ignore libc.so.6 entry and order of the entries. Signed-off-by: Jan Kratochvil <[email protected]>
Diffstat (limited to 'libdwfl/link_map.c')
-rw-r--r--libdwfl/link_map.c83
1 files changed, 55 insertions, 28 deletions
diff --git a/libdwfl/link_map.c b/libdwfl/link_map.c
index fecf616d..65e1c3a6 100644
--- a/libdwfl/link_map.c
+++ b/libdwfl/link_map.c
@@ -224,7 +224,9 @@ addrsize (uint_fast8_t elfclass)
/* Report a module for each struct link_map in the linked list at r_map
in the struct r_debug at R_DEBUG_VADDR. For r_debug_info description
- see dwfl_link_map_report in libdwflP.h.
+ see dwfl_link_map_report in libdwflP.h. If R_DEBUG_INFO is not NULL then no
+ modules get added to DWFL, caller has to add them from filled in
+ R_DEBUG_INFO.
For each link_map entry, if an existing module resides at its address,
this just modifies that module's name and suggested file name. If
@@ -355,6 +357,28 @@ report_r_debug (uint_fast8_t elfclass, uint_fast8_t elfdata,
if (iterations == 1 && dwfl->executable_for_core != NULL)
name = dwfl->executable_for_core;
+ struct r_debug_info_module *r_debug_info_module = NULL;
+ if (r_debug_info != NULL)
+ {
+ /* Save link map information about valid shared library (or
+ executable) which has not been found on disk. */
+ const char *name1 = name == NULL ? "" : name;
+ r_debug_info_module = malloc (sizeof (*r_debug_info_module)
+ + strlen (name1) + 1);
+ if (r_debug_info_module == NULL)
+ return release_buffer (result);
+ r_debug_info_module->fd = -1;
+ r_debug_info_module->elf = NULL;
+ r_debug_info_module->l_addr = l_addr;
+ r_debug_info_module->l_ld = l_ld;
+ r_debug_info_module->start = 0;
+ r_debug_info_module->end = 0;
+ r_debug_info_module->disk_file_has_build_id = false;
+ strcpy (r_debug_info_module->name, name1);
+ r_debug_info_module->next = r_debug_info->module;
+ r_debug_info->module = r_debug_info_module;
+ }
+
Dwfl_Module *mod = NULL;
if (name != NULL)
{
@@ -374,19 +398,15 @@ report_r_debug (uint_fast8_t elfclass, uint_fast8_t elfdata,
/* FIXME: Bias L_ADDR should be computed from the prelink
state in memory (when the file got loaded), not against
- the current on-disk file state as is computed below.
-
- This verification gives false positive if in-core ELF had
- build-id but on-disk ELF does not have any. But we cannot
- reliably find ELF header and/or the ELF build id just from
- the link map (and checking core segments is also not
- reliable). */
+ the current on-disk file state as is computed below. */
if (__libdwfl_find_elf_build_id (NULL, elf, &build_id_bits,
&build_id_elfaddr,
&build_id_len) > 0
&& build_id_elfaddr != 0)
{
+ if (r_debug_info_module != NULL)
+ r_debug_info_module->disk_file_has_build_id = true;
GElf_Addr build_id_vaddr = build_id_elfaddr + l_addr;
release_buffer (0);
int segndx = INTUSE(dwfl_addrsegment) (dwfl,
@@ -410,31 +430,38 @@ report_r_debug (uint_fast8_t elfclass, uint_fast8_t elfdata,
}
if (valid)
- // XXX hook for sysroot
- mod = __libdwfl_report_elf (dwfl, basename (name), name,
- fd, elf, l_addr, true, true);
- if (mod == NULL)
{
- elf_end (elf);
- close (fd);
+ if (r_debug_info_module == NULL)
+ {
+ // XXX hook for sysroot
+ mod = __libdwfl_report_elf (dwfl, basename (name),
+ name, fd, elf, l_addr,
+ true, true);
+ if (mod != NULL)
+ {
+ elf = NULL;
+ fd = -1;
+ }
+ }
+ else if (__libdwfl_elf_address_range (elf, l_addr, true,
+ true, NULL, NULL,
+ &r_debug_info_module->start,
+ &r_debug_info_module->end,
+ NULL, NULL))
+ {
+ r_debug_info_module->elf = elf;
+ r_debug_info_module->fd = fd;
+ elf = NULL;
+ fd = -1;
+ }
}
+ if (elf != NULL)
+ elf_end (elf);
+ if (fd != -1)
+ close (fd);
}
}
}
- if (r_debug_info != NULL && mod == NULL)
- {
- /* Save link map information about valid shared library (or
- executable) which has not been found on disk. */
- const char *base = name == NULL ? "" : basename (name);
- struct r_debug_info_module *module;
- module = malloc (sizeof (*module) + strlen (base) + 1);
- if (module == NULL)
- return release_buffer (result);
- module->l_ld = l_ld;
- strcpy (module->name, base);
- module->next = r_debug_info->module;
- r_debug_info->module = module;
- }
if (mod != NULL)
{