1 /* Return build ID information for a module.
2 Copyright (C) 2007-2010, 2014 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/>. */
32 found_build_id (Dwfl_Module *mod, bool set,
33 const void *bits, int len, GElf_Addr vaddr)
36 /* When checking bits, we do not compare VADDR because the
37 address found in a debuginfo file may not match the main
38 file as modified by prelink. */
39 return 1 + (mod->build_id_len == len
40 && !memcmp (bits, mod->build_id_bits, len));
42 void *copy = malloc (len);
43 if (unlikely (copy == NULL))
45 __libdwfl_seterrno (DWFL_E_NOMEM);
49 mod->build_id_bits = memcpy (copy, bits, len);
50 mod->build_id_vaddr = vaddr;
51 mod->build_id_len = len;
57 __libdwfl_find_build_id (Dwfl_Module *mod, bool set, Elf *elf)
59 const void *build_id_bits;
60 GElf_Addr build_id_elfaddr;
63 /* For mod == NULL use dwelf_elf_gnu_build_id directly. */
66 int result = __libdwfl_find_elf_build_id (mod, elf, &build_id_bits,
67 &build_id_elfaddr, &build_id_len);
71 GElf_Addr build_id_vaddr = build_id_elfaddr + (build_id_elfaddr != 0
72 ? mod->main_bias : 0);
73 return found_build_id (mod, set, build_id_bits, build_id_len, build_id_vaddr);
77 dwfl_module_build_id (Dwfl_Module *mod,
78 const unsigned char **bits, GElf_Addr *vaddr)
83 if (mod->build_id_len == 0 && mod->main.elf != NULL)
85 /* We have the file, but have not examined it yet. */
86 int result = __libdwfl_find_build_id (mod, true, mod->main.elf);
89 mod->build_id_len = -1; /* Cache negative result. */
94 if (mod->build_id_len <= 0)
97 *bits = mod->build_id_bits;
98 *vaddr = mod->build_id_vaddr;
99 return mod->build_id_len;
101 INTDEF (dwfl_module_build_id)
102 NEW_VERSION (dwfl_module_build_id, ELFUTILS_0.138)
104 #ifdef SYMBOL_VERSIONING
105 COMPAT_VERSION (dwfl_module_build_id, ELFUTILS_0.130, vaddr_at_end)
108 _compat_vaddr_at_end_dwfl_module_build_id (Dwfl_Module *mod,
109 const unsigned char **bits,
112 int result = INTUSE(dwfl_module_build_id) (mod, bits, vaddr);
114 *vaddr += (result + 3) & -4;