diff options
author | Jan Kratochvil <jan.kratochvil@redhat.com> | 2012-10-17 21:49:10 +0200 |
---|---|---|
committer | Jan Kratochvil <jan.kratochvil@redhat.com> | 2012-10-17 22:17:14 +0200 |
commit | 3fdcdcbcb424c45645aff1200adfb34450caf0b2 (patch) | |
tree | 6f6c56c685228efca740d74564027e44bc85e012 /libdwfl/dwfl_module_getdwarf.c | |
parent | 50f413ee377f3e3987b89f9726ba493a2038e9a2 (diff) | |
download | elfutils-3fdcdcbcb424c45645aff1200adfb34450caf0b2.tar.gz |
libdwfl/
2012-10-17 Jan Kratochvil <jan.kratochvil@redhat.com>
* dwfl_module_getdwarf.c (mod_verify_build_id): New function with code
from ...
(__libdwfl_getelf): ... here. Call it.
tests/
2012-10-17 Jan Kratochvil <jan.kratochvil@redhat.com>
* 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 <jan.kratochvil@redhat.com>
Diffstat (limited to 'libdwfl/dwfl_module_getdwarf.c')
-rw-r--r-- | libdwfl/dwfl_module_getdwarf.c | 73 |
1 files changed, 38 insertions, 35 deletions
diff --git a/libdwfl/dwfl_module_getdwarf.c b/libdwfl/dwfl_module_getdwarf.c index bbf9ff3d..025cb8ac 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; } |