From: Jan Kratochvil Date: Wed, 17 Oct 2012 19:49:10 +0000 (+0200) Subject: libdwfl/ X-Git-Tag: elfutils-0.156~71 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3fdcdcbcb424c45645aff1200adfb34450caf0b2;p=thirdparty%2Felfutils.git libdwfl/ 2012-10-17 Jan Kratochvil * dwfl_module_getdwarf.c (mod_verify_build_id): New function with code from ... (__libdwfl_getelf): ... here. Call it. tests/ 2012-10-17 Jan Kratochvil * run-addrname-test.sh: New test for DSO with build-id bias. * testfile69.core.bz2: New file. * testfile69.so.bz2: New file. Signed-off-by: Jan Kratochvil --- diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog index 638a09661..bdd9440f1 100644 --- a/libdwfl/ChangeLog +++ b/libdwfl/ChangeLog @@ -1,3 +1,9 @@ +2012-10-17 Jan Kratochvil + + * dwfl_module_getdwarf.c (mod_verify_build_id): New function with code + from ... + (__libdwfl_getelf): ... here. Call it. + 2012-10-17 Jan Kratochvil * libdwfl.h (dwfl_module_getelf): Add __nonnull_attribute__. diff --git a/libdwfl/dwfl_module_getdwarf.c b/libdwfl/dwfl_module_getdwarf.c index bbf9ff3d8..025cb8ac8 100644 --- a/libdwfl/dwfl_module_getdwarf.c +++ b/libdwfl/dwfl_module_getdwarf.c @@ -139,6 +139,43 @@ open_elf (Dwfl_Module *mod, struct dwfl_file *file) return DWFL_E_NOERROR; } +/* We have an authoritative build ID for this module MOD, so don't use + a file by name that doesn't match that ID. */ +static void +mod_verify_build_id (Dwfl_Module *mod) +{ + assert (mod->build_id_len > 0); + + switch (__builtin_expect (__libdwfl_find_build_id (mod, false, + mod->main.elf), 2)) + { + case 2: + /* Build ID matches as it should. */ + return; + + case -1: /* ELF error. */ + mod->elferr = INTUSE(dwfl_errno) (); + break; + + case 0: /* File has no build ID note. */ + case 1: /* FIle has a build ID that does not match. */ + mod->elferr = DWFL_E_WRONG_ID_ELF; + break; + + default: + abort (); + } + + /* We get here when it was the right ELF file. Clear it out. */ + elf_end (mod->main.elf); + mod->main.elf = NULL; + if (mod->main.fd >= 0) + { + close (mod->main.fd); + mod->main.fd = -1; + } +} + /* Find the main ELF file for this module and open libelf on it. When we return success, MOD->main.elf and MOD->main.bias are set up. */ void @@ -166,41 +203,7 @@ __libdwfl_getelf (Dwfl_Module *mod) mod->build_id_len = 0; } else if (fallback) - { - /* We have an authoritative build ID for this module, so - don't use a file by name that doesn't match that ID. */ - - assert (mod->build_id_len > 0); - - switch (__builtin_expect (__libdwfl_find_build_id (mod, false, - mod->main.elf), 2)) - { - case 2: - /* Build ID matches as it should. */ - return; - - case -1: /* ELF error. */ - mod->elferr = INTUSE(dwfl_errno) (); - break; - - case 0: /* File has no build ID note. */ - case 1: /* FIle has a build ID that does not match. */ - mod->elferr = DWFL_E_WRONG_ID_ELF; - break; - - default: - abort (); - } - - /* We get here when it was the right ELF file. Clear it out. */ - elf_end (mod->main.elf); - mod->main.elf = NULL; - if (mod->main.fd >= 0) - { - close (mod->main.fd); - mod->main.fd = -1; - } - } + mod_verify_build_id (mod); mod->main_bias = mod->e_type == ET_REL ? 0 : mod->low_addr - mod->main.vaddr; } diff --git a/tests/ChangeLog b/tests/ChangeLog index 2495fb58c..9e8ad2c15 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,9 @@ +2012-10-17 Jan Kratochvil + + * run-addrname-test.sh: New test for DSO with build-id bias. + * testfile69.core.bz2: New file. + * testfile69.so.bz2: New file. + 2012-10-10 Jan Kratochvil * run-addrname-test.sh: New test for core vDSO bias. diff --git a/tests/run-addrname-test.sh b/tests/run-addrname-test.sh index 4feb19365..cc8aa335a 100755 --- a/tests/run-addrname-test.sh +++ b/tests/run-addrname-test.sh @@ -298,4 +298,12 @@ __vdso_time ??:0 EOF +testfiles testfile69.core testfile69.so +testrun_compare ../src/addr2line --core=./testfile69.core -S 0x7f0bc6a33535 0x7f0bc6a33546 <<\EOF +libstatic+0x9 +??:0 +libglobal+0x9 +??:0 +EOF + exit 0 diff --git a/tests/testfile69.core.bz2 b/tests/testfile69.core.bz2 new file mode 100644 index 000000000..99553182a Binary files /dev/null and b/tests/testfile69.core.bz2 differ diff --git a/tests/testfile69.so.bz2 b/tests/testfile69.so.bz2 new file mode 100755 index 000000000..fdddab98c Binary files /dev/null and b/tests/testfile69.so.bz2 differ