summaryrefslogtreecommitdiff
path: root/libdwelf
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2014-04-24 14:06:43 +0200
committerMark Wielaard <mjw@redhat.com>2014-04-24 14:40:59 +0200
commit4813dbbcb81a0f5ebbc9756fe6f4ed62d298b011 (patch)
treeb00792bab97d23b5648056635b40126ec51902b1 /libdwelf
parent35e2a765c002374f1b88dc81ce154bed42f9b1d8 (diff)
downloadelfutils-4813dbbcb81a0f5ebbc9756fe6f4ed62d298b011.tar.gz
libdwelf: Add dwelf_dwarf_gnu_debugaltlink
Signed-off-by: Florian Weimer <fweimer@redhat.com>
Diffstat (limited to 'libdwelf')
-rw-r--r--libdwelf/ChangeLog8
-rw-r--r--libdwelf/Makefile.am2
-rw-r--r--libdwelf/dwelf_dwarf_gnu_debugaltlink.c62
-rw-r--r--libdwelf/libdwelf.h10
-rw-r--r--libdwelf/libdwelfP.h1
5 files changed, 82 insertions, 1 deletions
diff --git a/libdwelf/ChangeLog b/libdwelf/ChangeLog
index caf1c5dd..aa291320 100644
--- a/libdwelf/ChangeLog
+++ b/libdwelf/ChangeLog
@@ -1,3 +1,11 @@
+2014-04-24 Florian Weimer <fweimer@redhat.com>
+
+ * dwelf_dwarf_gnu_debugaltlink.c: New file.
+ * Makefile.am (libdwelf_a_SOURCES): Add it.
+ * libdwelf.h (dwelf_dwarf_gnu_debugaltlink): Declare new function.
+ * libdwelfP.h (dwelf_dwarf_gnu_debugaltlink): Add internal
+ declaration.
+
2014-04-11 Mark Wielaard <mjw@redhat.com>
* Makefile.am: New file.
diff --git a/libdwelf/Makefile.am b/libdwelf/Makefile.am
index 0f684d4a..1ca3a5cd 100644
--- a/libdwelf/Makefile.am
+++ b/libdwelf/Makefile.am
@@ -38,7 +38,7 @@ noinst_LIBRARIES = libdwelf.a libdwelf_pic.a
pkginclude_HEADERS = libdwelf.h
noinst_HEADERS = libdwelfP.h
-libdwelf_a_SOURCES = dwelf_elf_gnu_debuglink.c
+libdwelf_a_SOURCES = dwelf_elf_gnu_debuglink.c dwelf_dwarf_gnu_debugaltlink.c
libdwelf = $(libdw)
diff --git a/libdwelf/dwelf_dwarf_gnu_debugaltlink.c b/libdwelf/dwelf_dwarf_gnu_debugaltlink.c
new file mode 100644
index 00000000..b8285d09
--- /dev/null
+++ b/libdwelf/dwelf_dwarf_gnu_debugaltlink.c
@@ -0,0 +1,62 @@
+/* Returns the file name and build ID stored in the .gnu_altdebuglink if found.
+ Copyright (C) 2014 Red Hat, Inc.
+ This file is part of elfutils.
+
+ This file is free software; you can redistribute it and/or modify
+ it under the terms of either
+
+ * the GNU Lesser General Public License as published by the Free
+ Software Foundation; either version 3 of the License, or (at
+ your option) any later version
+
+ or
+
+ * the GNU General Public License as published by the Free
+ Software Foundation; either version 2 of the License, or (at
+ your option) any later version
+
+ or both in parallel, as here.
+
+ elfutils is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received copies of the GNU General Public License and
+ the GNU Lesser General Public License along with this program. If
+ not, see <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "libdwelfP.h"
+
+ssize_t
+dwelf_dwarf_gnu_debugaltlink (Dwarf *dwarf,
+ const char **name_p,
+ const void **build_idp)
+{
+ Elf_Data *data = dwarf->sectiondata[IDX_gnu_debugaltlink];
+ if (data == NULL)
+ {
+ return 0;
+ }
+
+ const void *ptr = memchr (data->d_buf, '\0', data->d_size);
+ if (ptr == NULL)
+ {
+ __libdw_seterrno (DWARF_E_INVALID_ELF);
+ return -1;
+ }
+ size_t build_id_len = data->d_size - (ptr - data->d_buf + 1);
+ if (build_id_len == 0 || (size_t) (ssize_t) build_id_len != build_id_len)
+ {
+ __libdw_seterrno (DWARF_E_INVALID_ELF);
+ return -1;
+ }
+ *name_p = data->d_buf;
+ *build_idp = ptr + 1;
+ return build_id_len;
+}
+INTDEF(dwelf_dwarf_gnu_debugaltlink)
diff --git a/libdwelf/libdwelf.h b/libdwelf/libdwelf.h
index 5d636d16..6f1dbd3a 100644
--- a/libdwelf/libdwelf.h
+++ b/libdwelf/libdwelf.h
@@ -47,6 +47,16 @@ extern "C" {
section or some other error occured. */
extern const char *dwelf_elf_gnu_debuglink (Elf *elf, GElf_Word *crc);
+/* Returns the name and build ID from the .gnu_debugaltlink section if
+ found in the ELF. On success, pointers to the name and build ID
+ are written to *NAMEP and *BUILDID_P, and the positive length of
+ the build ID is returned. Returns 0 if the ELF lacks a
+ .gnu_debugaltlink section. Returns -1 in case of malformed data or
+ other errors. */
+extern ssize_t dwelf_dwarf_gnu_debugaltlink (Dwarf *dwarf,
+ const char **namep,
+ const void **build_idp);
+
#ifdef __cplusplus
}
#endif
diff --git a/libdwelf/libdwelfP.h b/libdwelf/libdwelfP.h
index bdadc8b7..c00a834c 100644
--- a/libdwelf/libdwelfP.h
+++ b/libdwelf/libdwelfP.h
@@ -36,5 +36,6 @@
/* Avoid PLT entries. */
INTDECL (dwelf_elf_gnu_debuglink)
+INTDECL (dwelf_dwarf_gnu_debugaltlink)
#endif /* libdwelfP.h */