This is the mail archive of the
elfutils-devel@sourceware.org
mailing list for the elfutils project.
[PATCH v2 3/3] dwarf_begin, dwarf_begin_elf: DWARF_C_FLAG_NO_DEBUGALTLINK command flag
- From: Florian Weimer <fweimer at redhat dot com>
- To: elfutils-devel at lists dot fedorahosted dot org
- Date: Thu, 10 Apr 2014 13:08:25 +0200
- Subject: [PATCH v2 3/3] dwarf_begin, dwarf_begin_elf: DWARF_C_FLAG_NO_DEBUGALTLINK command flag
Signed-off-by: Florian Weimer <fweimer@redhat.com>
---
libdw/ChangeLog | 9 +++++++++
libdw/dwarf_begin.c | 2 +-
libdw/dwarf_begin_elf.c | 36 +++++++++++++++++++++---------------
libdw/libdw.h | 3 +++
libdw/libdwP.h | 2 ++
5 files changed, 36 insertions(+), 16 deletions(-)
diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index 798e2ba..5af07a8 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -18,6 +18,15 @@
* dwarf_begin_elf.c (try_debugaltlink): Call dwarf_set_alt.
* dwarf_end.c (dwarf_end): Likewise.
+ * libdw.h (enum Dwarf_Cmd): New member
+ DWARF_C_FLAG_NO_DEBUGALTLINK.
+ * libdwP.h (DWARF_C_FLAG_MASK): New macro.
+ * dwarf_begin_elf.c (check_section): Move call to to
+ open_debugaltlink to ...
+ (dwarf_begin_elf): here. Mask command flags and handle
+ DWARF_C_FLAG_NO_DEBUGALTLINK.
+ * dwarf_begin.c (dwarf_begin): Mask command flags.
+
2014-03-03 Jan Kratochvil <jan.kratochvil@redhat.com>
Fix abort() on missing section headers.
diff --git a/libdw/dwarf_begin.c b/libdw/dwarf_begin.c
index 9f3050f..45320d2 100644
--- a/libdw/dwarf_begin.c
+++ b/libdw/dwarf_begin.c
@@ -47,7 +47,7 @@ dwarf_begin (fd, cmd)
Elf_Cmd elfcmd;
Dwarf *result = NULL;
- switch (cmd)
+ switch (cmd & ~DWARF_C_FLAG_MASK)
{
case DWARF_C_READ:
elfcmd = ELF_C_READ_MMAP;
diff --git a/libdw/dwarf_begin_elf.c b/libdw/dwarf_begin_elf.c
index e530a88..241ff9e 100644
--- a/libdw/dwarf_begin_elf.c
+++ b/libdw/dwarf_begin_elf.c
@@ -313,19 +313,6 @@ check_section (Dwarf *result, GElf_Ehdr *ehdr, Elf_Scn *scn, bool inscngrp)
}
#endif
-#ifdef ENABLE_DWZ
- /* For dwz multifile support, ignore if it looks wrong. */
- if (result->sectiondata[IDX_gnu_debugaltlink] != NULL)
- {
- const char *alt_name;
- const void *build_id;
- size_t id_len;
- if (INTUSE (dwarf_debugaltlink) (result, &alt_name, &build_id, &id_len)
- == 0)
- return open_debugaltlink (result, alt_name, build_id, id_len);
- }
-#endif /* ENABLE_DWZ */
-
return result;
}
@@ -416,6 +403,10 @@ dwarf_begin_elf (elf, cmd, scngrp)
{
GElf_Ehdr *ehdr;
GElf_Ehdr ehdr_mem;
+ bool load_debugaltlink = (cmd & DWARF_C_FLAG_NO_DEBUGALTLINK) == 0;
+
+ /* Restrict to the actual command flags. */
+ cmd &= ~DWARF_C_FLAG_MASK;
/* Get the ELF header of the file. We need various pieces of
information from it. */
@@ -468,9 +459,24 @@ dwarf_begin_elf (elf, cmd, scngrp)
sections with the name are ignored. The DWARF specification
does not really say this is allowed. */
if (scngrp == NULL)
- return global_read (result, elf, ehdr);
+ result = global_read (result, elf, ehdr);
else
- return scngrp_read (result, elf, ehdr, scngrp);
+ result = scngrp_read (result, elf, ehdr, scngrp);
+
+#ifdef ENABLE_DWZ
+ /* For dwz multifile support, ignore if it looks wrong. */
+ if (result && load_debugaltlink
+ && result->sectiondata[IDX_gnu_debugaltlink] != NULL)
+ {
+ const char *alt_name;
+ const void *build_id;
+ size_t id_len;
+ if (INTUSE (dwarf_debugaltlink)
+ (result, &alt_name, &build_id, &id_len) == 0)
+ result = open_debugaltlink (result, alt_name, build_id, id_len);
+ }
+#endif /* ENABLE_DWZ */
+ return result;
}
else if (cmd == DWARF_C_WRITE)
{
diff --git a/libdw/libdw.h b/libdw/libdw.h
index 1880c9a..ce8ffb9 100644
--- a/libdw/libdw.h
+++ b/libdw/libdw.h
@@ -56,6 +56,9 @@ typedef enum
DWARF_C_READ, /* Read .. */
DWARF_C_RDWR, /* Read and write .. */
DWARF_C_WRITE, /* Write .. */
+
+ /* Do not load files referenced from .gnu_debugaltlink. */
+ DWARF_C_FLAG_NO_DEBUGALTLINK = 0x40
}
Dwarf_Cmd;
diff --git a/libdw/libdwP.h b/libdw/libdwP.h
index db71466..f12fed1 100644
--- a/libdw/libdwP.h
+++ b/libdw/libdwP.h
@@ -36,6 +36,8 @@
#include <libdw.h>
#include <dwarf.h>
+/* Non-command flags in Dwarf_Cmd. */
+#define DWARF_C_FLAG_MASK DWARF_C_FLAG_NO_DEBUGALTLINK
/* gettext helper macros. */
#define _(Str) dgettext ("elfutils", Str)
--
1.9.0