public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* libdw errors for DW_FORM_GNU_strp_alt attributes
@ 2014-04-04 11:47 Florian Weimer
  0 siblings, 0 replies; 5+ messages in thread
From: Florian Weimer @ 2014-04-04 11:47 UTC (permalink / raw)
  To: elfutils-devel

[-- Attachment #1: Type: text/plain, Size: 517 bytes --]

If I run the attached test program on the file 
/usr/lib/debug/usr/bin/bsdiff.debug from the Fedora package 
bsdiff-debuginfo-4.3-12.fc20.x86_64, I get the following output:

Compilation unit at offset 0, tag 17:
   name (format 0xe): "bsdiff.c"
   comp_dir (format 0x1f21) present with error 36: no alternative debug 
link found
   producer (format 0x1f21) present with error 36: no alternative debug 
link found

How can I obtain these attributes?

-- 
Florian Weimer / Red Hat Product Security Team

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: report-cu.c --]
[-- Type: text/x-csrc, Size: 2379 bytes --]

#define _GNU_SOURCE

#include <err.h>
#include <fcntl.h>
#include <stdbool.h>
#include <stdio.h>

#include <dwarf.h>
#include <elfutils/libdw.h>

static void doit(Dwarf_Off cu_offset, Dwarf_Die *die);

int
main(int argc, char **argv)
{
  if (argc != 2) {
    fprintf(stderr, "usage: %s FILE\n", argv[0]);
    return 2;
  }

  int fd = open64(argv[1], O_RDONLY | O_CLOEXEC);
  if (fd < 0) {
    err(1, "open64(%s)", argv[1]);
  }

  Dwarf *dwarf = dwarf_begin(fd, DWARF_C_READ);
  if (dwarf == NULL) {
    errx(1, "dwarf_begin: %s", dwarf_errmsg(dwarf_errno()));
  }

  Dwarf_Off off;
  Dwarf_Off next_off = 0;
  size_t header_size;
  Dwarf_Off abbrev_offset;
  uint8_t address_size;
  uint8_t offset_size;
  while (true) {
    off = next_off;
    next_off = 0;
    if (dwarf_nextcu(dwarf, off, &next_off, &header_size, &abbrev_offset,
		     &address_size, &offset_size) == 0) {
      Dwarf_Off die_offset = off + header_size;
      Dwarf_Die die;
      if (dwarf_offdie(dwarf, die_offset, &die) == NULL) {
	errx(1, "dwarf_offdie(%lu): %s", off, dwarf_errmsg(dwarf_errno()));
      }
      doit(off, &die);
    } else {
      if (next_off != (Dwarf_Off) -1) {
	errx(1, "dwarf_nextcu(%lu): %s", off, dwarf_errmsg(dwarf_errno()));
      }
      break;
    }
  }
  return 0;
}

static void
report_string_attribute
  (Dwarf_Die *die, unsigned int name, const char *name_str)
{
  Dwarf_Attribute attr;
  if (dwarf_attr(die, name, &attr) == NULL) {
    printf("  %s not present\n", name_str);
    return;
  }
  const char *ptr = dwarf_formstring(&attr);
  if (ptr == NULL) {
    int code = dwarf_errno();
    printf("  %s (format 0x%x) present with error %d: %s\n",
	   name_str, dwarf_whatform(&attr), code, dwarf_errmsg(code));
    return;
  }
  printf("  %s (format 0x%x): \"", name_str, dwarf_whatform(&attr));
  for (; *ptr; ++ptr) {
    unsigned char ch = *ptr;
    if (ch == '\'' || ch == '"') {
      putchar('\\');
      putchar(ch);
    } else if (' ' <= ch && ch <= '~') {
      putchar(ch);
    } else {
      printf("\\%03o", ch);
    }
  }
  puts("\"");
}

static void doit(Dwarf_Off cu_offset, Dwarf_Die *die)
{
  printf("Compilation unit at offset %lu, tag %d:\n",
	 cu_offset, dwarf_tag(die));
  report_string_attribute(die, DW_AT_name, "name");
  report_string_attribute(die, DW_AT_comp_dir, "comp_dir");
  report_string_attribute(die, DW_AT_producer, "producer");
}

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: libdw errors for DW_FORM_GNU_strp_alt attributes
@ 2014-04-08 16:18 Florian Weimer
  0 siblings, 0 replies; 5+ messages in thread
From: Florian Weimer @ 2014-04-08 16:18 UTC (permalink / raw)
  To: elfutils-devel

[-- Attachment #1: Type: text/plain, Size: 705 bytes --]

On 04/07/2014 06:29 PM, Josh Stone wrote:
> On 04/07/2014 08:55 AM, Florian Weimer wrote:
>> Thanks for the explanation.  I find it kind of surprising that libdw
>> goes behind my back and opens random files based on paths extracted from
>> the data I supply.  I would have expected that from libdwfl, not libdw.
>
> Yes, in fact this was in Mark's 0.159 planning email:
>
> - Move .gnu_debugaltlink handling from libdw to libdwfl and make
>    ENABLE_DWZ the default. As discussed before:
> https://lists.fedorahosted.org/pipermail/elfutils-devel/2013-December/003626.html

Interesting.  I've submitted a first patch in that direction.

-- 
Florian Weimer / Red Hat Product Security Team

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: libdw errors for DW_FORM_GNU_strp_alt attributes
@ 2014-04-07 16:29 Josh Stone
  0 siblings, 0 replies; 5+ messages in thread
From: Josh Stone @ 2014-04-07 16:29 UTC (permalink / raw)
  To: elfutils-devel

[-- Attachment #1: Type: text/plain, Size: 528 bytes --]

On 04/07/2014 08:55 AM, Florian Weimer wrote:
> Thanks for the explanation.  I find it kind of surprising that libdw 
> goes behind my back and opens random files based on paths extracted from 
> the data I supply.  I would have expected that from libdwfl, not libdw.

Yes, in fact this was in Mark's 0.159 planning email:

- Move .gnu_debugaltlink handling from libdw to libdwfl and make
  ENABLE_DWZ the default. As discussed before:
https://lists.fedorahosted.org/pipermail/elfutils-devel/2013-December/003626.html

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: libdw errors for DW_FORM_GNU_strp_alt attributes
@ 2014-04-07 15:55 Florian Weimer
  0 siblings, 0 replies; 5+ messages in thread
From: Florian Weimer @ 2014-04-07 15:55 UTC (permalink / raw)
  To: elfutils-devel

[-- Attachment #1: Type: text/plain, Size: 2228 bytes --]

On 04/07/2014 04:37 PM, Mark Wielaard wrote:

>> How can I obtain these attributes?
>
> If elfutils was configure with --enable-dwz then it should automagically
> find the alternative debug (dwz) file. And it does for me on f20 with
> elfutils-libs-0.158-1.fc20.x86_64:
>
> ./report-cu /usr/lib/debug/usr/bin/bsdiff.debug
> Compilation unit at offset 0, tag 17:
>    name (format 0xe): "bsdiff.c"
>    comp_dir (format 0x1f21): "/usr/src/debug/bsdiff-4.3"
>    producer (format 0x1f21): "GNU C 4.8.1 20130717 (Red Hat 4.8.1-5) -m64 -mtune=generic -march=x86-64 -g -O2 -fexceptions -fstack-protector-strong --param ssp-buffer-size=4"
>
> The alt file is found by inspecting the .gnu_debugaltlink section in the
> bsdiff.debug file and resolving either the file name
> (../../.dwz/bsdiff-4.3-12.fc20.x86_64 which
> is /lib/debug/.dwz/bsdiff-4.3-12.fc20.x86_64) or the build-id given in
> that section (42643ed4e062195a11211c3696fc5e6cec73d0fb) which resolves
> to /lib/debug/.build-id/42/643ed4e062195a11211c3696fc5e6cec73d0fb.debug
> -> ../../.dwz/bsdiff-4.3-12.fc20.x86_64 (the same file through a soft
> link).

Thanks for the explanation.  I find it kind of surprising that libdw 
goes behind my back and opens random files based on paths extracted from 
the data I supply.  I would have expected that from libdwfl, not libdw.

Does libelf do something similar?

> We currently don't have an interface to explicitly set the alt-debug
> file for a Dwarf but should (and then the magic lookup should be moved
> from libdw to libdwfl, but that has as drawback that a simple
> dwarf_begin () won't set it automagically anymore and you'll have to
> either use dwfl_begin () to set it automagically or use an explicit
> setter for it).

Should I propose a patch with a dwarf_begin_elf function that takes an 
additional flag argument which makes this behavior user-controllable? 
Or would it be better to overload the Elf_Scn * argument?

I can't use the current file location code anyway, even if it were 
exported, because my data does not actually reside in the file system 
and certainly not at the paths expected by the library.

-- 
Florian Weimer / Red Hat Product Security Team

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: libdw errors for DW_FORM_GNU_strp_alt attributes
@ 2014-04-07 14:37 Mark Wielaard
  0 siblings, 0 replies; 5+ messages in thread
From: Mark Wielaard @ 2014-04-07 14:37 UTC (permalink / raw)
  To: elfutils-devel

[-- Attachment #1: Type: text/plain, Size: 2133 bytes --]

On Fri, 2014-04-04 at 13:47 +0200, Florian Weimer wrote:
> If I run the attached test program on the file 
> /usr/lib/debug/usr/bin/bsdiff.debug from the Fedora package 
> bsdiff-debuginfo-4.3-12.fc20.x86_64, I get the following output:
> 
> Compilation unit at offset 0, tag 17:
>    name (format 0xe): "bsdiff.c"
>    comp_dir (format 0x1f21) present with error 36: no alternative debug 
> link found
>    producer (format 0x1f21) present with error 36: no alternative debug 
> link found

That means those attributes use DW_FORM_GNU_ref_alt or
DW_FORM_GNU_strp_alt and are referencing a value in the alternative
debug file. The error means that alternative debug file wasn't found.

> How can I obtain these attributes?

If elfutils was configure with --enable-dwz then it should automagically
find the alternative debug (dwz) file. And it does for me on f20 with
elfutils-libs-0.158-1.fc20.x86_64:

./report-cu /usr/lib/debug/usr/bin/bsdiff.debug
Compilation unit at offset 0, tag 17:
  name (format 0xe): "bsdiff.c"
  comp_dir (format 0x1f21): "/usr/src/debug/bsdiff-4.3"
  producer (format 0x1f21): "GNU C 4.8.1 20130717 (Red Hat 4.8.1-5) -m64 -mtune=generic -march=x86-64 -g -O2 -fexceptions -fstack-protector-strong --param ssp-buffer-size=4"

The alt file is found by inspecting the .gnu_debugaltlink section in the
bsdiff.debug file and resolving either the file name
(../../.dwz/bsdiff-4.3-12.fc20.x86_64 which
is /lib/debug/.dwz/bsdiff-4.3-12.fc20.x86_64) or the build-id given in
that section (42643ed4e062195a11211c3696fc5e6cec73d0fb) which resolves
to /lib/debug/.build-id/42/643ed4e062195a11211c3696fc5e6cec73d0fb.debug
-> ../../.dwz/bsdiff-4.3-12.fc20.x86_64 (the same file through a soft
link).

We currently don't have an interface to explicitly set the alt-debug
file for a Dwarf but should (and then the magic lookup should be moved
from libdw to libdwfl, but that has as drawback that a simple
dwarf_begin () won't set it automagically anymore and you'll have to
either use dwfl_begin () to set it automagically or use an explicit
setter for it).

Cheers,

Mark


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-04-08 16:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-04 11:47 libdw errors for DW_FORM_GNU_strp_alt attributes Florian Weimer
2014-04-07 14:37 Mark Wielaard
2014-04-07 15:55 Florian Weimer
2014-04-07 16:29 Josh Stone
2014-04-08 16:18 Florian Weimer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).