Skip to contentSkip to conversation

perf symbols: Not using the ubuntu debuginfo when dso load

PATCH New Jin Yao 1 participant 1 message Sep 1, 2016 perf events

lore
Share & tools
lore

Jin Yao

author
#0 lore raw

PATCH 1/1 perf symbols: Not using the ubuntu debuginfo when dso load

In dso__load, it iterates over *interesting" debug images which have symtab/dynsym/opd section. For example, for loading the libc-2.23.so on ubuntu 16.04, it will try 2 images in turn.

Try image 1: /lib/x86_64-linux-gnu/libc-2.23.so. Since it doesn't have ".symtab" section, after symsrc__init return, runtime_ss = ss (ss is associated with /lib/x86_64-linux-gnu/libc-2.23.so), and syms_ss = NULL.

Try image 2: /usr/lib/debug/lib/x86_64-linux-gnu/libc-2.23.so.
Since it has ".symtab" section, after symsrc__init return,
syms_ss = ss (ss is associated with /usr/lib/debug/lib/x86_64-linux-gnu/libc-2.23.so), and runtime_ss is not changed.

Now at the dso__load_sym(dso, map, syms_ss, runtime_ss, filter, kmod), syms_ss is associated with /usr/lib/debug/lib/x86_64-linux-gnu/libc-2.23.so, But the dso->name is /lib/x86_64-linux-gnu/libc-2.23.so.

In dso__load_sym, it needs to compute the dso->text_offset.

	if (elf_section_by_name(elf, &ehdr, &tshdr, ".text", NULL))
		dso->text_offset = tshdr.sh_addr - tshdr.sh_offset;

The issue is that tshdr is the ELF section header for /usr/lib/debug/lib/x86_64-linux-gnu/libc-2.23.so not the header for /lib/x86_64-linux-gnu/libc-2.23.so. So the result of dso->text_offset is not correct.

In symbol__disassemble, it calls map__rip_2objdump to convert symbol start address to objdump address. The converted address is
rip + map->dso->text_offset

Since this text_offset is not correct, so finally objdump uses wrong start address to disassemble /lib/x86_64-linux-gnu/libc-2.23.so.

This patch lets dso__load not try ubuntu debuginfo (/usr/lib/debug/lib/x86_64-linux-gnu/libc-2.23.so in this example), because 1: the image doesn't have valid assembly code (check output of objdump) 2: it can avoid above issue.

---
 tools/perf/util/symbol.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/symbol.c +1 -1
index 37e8d20..25a10a3 100644
@@ -1324,7 +1324,6 @@ static bool dso__is_compatible_symtab_type(struct dso *dso, bool kmod,
 	case DSO_BINARY_TYPE__DEBUGLINK:
 	case DSO_BINARY_TYPE__SYSTEM_PATH_DSO:
 	case DSO_BINARY_TYPE__FEDORA_DEBUGINFO:
-	case DSO_BINARY_TYPE__UBUNTU_DEBUGINFO:
 	case DSO_BINARY_TYPE__BUILDID_DEBUGINFO:
 	case DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO:
 		return !kmod && dso->kernel == DSO_TYPE_USER;
@@ -1353,6 +1352,7 @@ static bool dso__is_compatible_symtab_type(struct dso *dso, bool kmod,
 		return true;
 
 	case DSO_BINARY_TYPE__NOT_FOUND:
+	case DSO_BINARY_TYPE__UBUNTU_DEBUGINFO:
 	default:
 		return false;
 	}
Signature · 1 line
2.7.4