* [patch] Parse NT_GNU_BUILD_ID into elf_obj_tdata->build_id*
@ 2007-08-18 13:03 Jan Kratochvil
2007-08-19 11:35 ` Roland McGrath
0 siblings, 1 reply; 6+ messages in thread
From: Jan Kratochvil @ 2007-08-18 13:03 UTC (permalink / raw)
To: binutils; +Cc: Roland McGrath
[-- Attachment #1: Type: text/plain, Size: 681 bytes --]
Hi,
so far BFD was parsing notes only for core files. GDB should now parse the
build-id notes even from executables/libraries. Excerpt from the GDB patch
using this parsed build-id info is below.
Regards,
Jan
static struct build_id *
build_id_bfd_shdr_get (bfd *abfd)
{
struct build_id *retval;
if (!bfd_check_format (abfd, bfd_object)
|| bfd_get_flavour (abfd) != bfd_target_elf_flavour
|| elf_tdata (abfd)->build_id == NULL)
return NULL;
retval = xmalloc (sizeof *retval - 1 + elf_tdata (abfd)->build_id_size);
retval->size = elf_tdata (abfd)->build_id_size;
memcpy (retval->data, elf_tdata (abfd)->build_id, retval->size);
return retval;
}
[-- Attachment #2: bfd-buildid-fetch.patch --]
[-- Type: text/plain, Size: 5976 bytes --]
2007-08-18 Jan Kratochvil <jan.kratochvil@redhat.com>
* bfd/elf-bfd.h (struct elf_obj_tdata): New build_id_size, build_id.
* bfd/elf.c (elfcore_read_notes): Split to ...
(elf_read_notes) ... here ...
(elf_parse_notes): ... and here. Check `bfd_get_format (abfd)' with
the former subfunctions called only for BFD_CORE.
Call ELFOBJ_GROK_NOTE for BFD_OBJECT files.
(_bfd_elf_make_section_from_shdr): Call ELF_PARSE_NOTES for all the
sections with the name starting with `.note.'.
(bfd_section_from_phdr): Update the call for renamed ELFCORE_READ_NOTES.
(elfobj_grok_gnu_build_id, elfobj_grok_note): New functions.
--- bfd/elf-bfd.h 4 Aug 2007 16:31:00 -0000 1.239
+++ bfd/elf-bfd.h 18 Aug 2007 11:21:45 -0000
@@ -1472,6 +1472,10 @@ struct elf_obj_tdata
/* Called at the end of _bfd_elf_write_object_contents if not NULL. */
bfd_boolean (*after_write_object_contents) (bfd *);
void *after_write_object_contents_info;
+
+ /* NT_GNU_BUILD_ID note type. */
+ bfd_size_type build_id_size;
+ bfd_byte *build_id;
};
#define elf_tdata(bfd) ((bfd) -> tdata.elf_obj_data)
--- bfd/elf.c 16 Aug 2007 18:49:42 -0000 1.410
+++ bfd/elf.c 18 Aug 2007 11:21:47 -0000
@@ -48,7 +48,9 @@ static int elf_sort_sections (const void
static bfd_boolean assign_file_positions_except_relocs (bfd *, struct bfd_link_info *);
static bfd_boolean prep_headers (bfd *);
static bfd_boolean swap_out_syms (bfd *, struct bfd_strtab_hash **, int) ;
-static bfd_boolean elfcore_read_notes (bfd *, file_ptr, bfd_size_type) ;
+static bfd_boolean elf_read_notes (bfd *, file_ptr, bfd_size_type) ;
+static bfd_boolean elf_parse_notes (bfd *abfd, char *buf, size_t size,
+ file_ptr offset);
/* Swap version information in and out. The version information is
currently size independent. If that ever changes, this code will
@@ -899,6 +901,28 @@ _bfd_elf_make_section_from_shdr (bfd *ab
if (! bfd_set_section_flags (abfd, newsect, flags))
return FALSE;
+ /* We do not parse the PT_NOTE segments as we are interested even in the
+ separate debug info files which may have the segments offsets corrupted.
+ PT_NOTEs from the core files are currently not parsed using BFD. */
+ if (CONST_STRNEQ (name, ".note."))
+ {
+ char *contents;
+
+ contents = bfd_malloc (hdr->sh_size);
+ if (!contents)
+ return FALSE;
+
+ if (!bfd_get_section_contents (abfd, hdr->bfd_section, contents, 0,
+ hdr->sh_size)
+ || !elf_parse_notes (abfd, contents, hdr->sh_size, -1))
+ {
+ free (contents);
+ return FALSE;
+ }
+
+ free (contents);
+ }
+
if ((flags & SEC_ALLOC) != 0)
{
Elf_Internal_Phdr *phdr;
@@ -2341,7 +2365,7 @@ bfd_section_from_phdr (bfd *abfd, Elf_In
case PT_NOTE:
if (! _bfd_elf_make_section_from_phdr (abfd, hdr, index, "note"))
return FALSE;
- if (! elfcore_read_notes (abfd, hdr->p_offset, hdr->p_filesz))
+ if (! elf_read_notes (abfd, hdr->p_offset, hdr->p_filesz))
return FALSE;
return TRUE;
@@ -7713,6 +7737,32 @@ elfcore_grok_note (bfd *abfd, Elf_Intern
}
static bfd_boolean
+elfobj_grok_gnu_build_id (bfd *abfd, Elf_Internal_Note *note)
+{
+ elf_tdata (abfd)->build_id_size = note->descsz;
+ elf_tdata (abfd)->build_id = bfd_alloc (abfd, note->descsz);
+ if (elf_tdata (abfd)->build_id == NULL)
+ return FALSE;
+
+ memcpy (elf_tdata (abfd)->build_id, note->descdata, note->descsz);
+
+ return TRUE;
+}
+
+static bfd_boolean
+elfobj_grok_note (bfd *abfd, Elf_Internal_Note *note)
+{
+ switch (note->type)
+ {
+ default:
+ return TRUE;
+
+ case NT_GNU_BUILD_ID:
+ return elfobj_grok_gnu_build_id (abfd, note);
+ }
+}
+
+static bfd_boolean
elfcore_netbsd_get_lwpid (Elf_Internal_Note *note, int *lwpidp)
{
char *cp;
@@ -8186,28 +8236,10 @@ elfcore_write_prxfpreg (bfd *abfd,
}
static bfd_boolean
-elfcore_read_notes (bfd *abfd, file_ptr offset, bfd_size_type size)
+elf_parse_notes (bfd *abfd, char *buf, size_t size, file_ptr offset)
{
- char *buf;
char *p;
- if (size <= 0)
- return TRUE;
-
- if (bfd_seek (abfd, offset, SEEK_SET) != 0)
- return FALSE;
-
- buf = bfd_malloc (size);
- if (buf == NULL)
- return FALSE;
-
- if (bfd_bread (buf, size, abfd) != size)
- {
- error:
- free (buf);
- return FALSE;
- }
-
p = buf;
while (p < buf + size)
{
@@ -8224,25 +8256,63 @@ elfcore_read_notes (bfd *abfd, file_ptr
in.descdata = in.namedata + BFD_ALIGN (in.namesz, 4);
in.descpos = offset + (in.descdata - buf);
- if (CONST_STRNEQ (in.namedata, "NetBSD-CORE"))
- {
- if (! elfcore_grok_netbsd_note (abfd, &in))
- goto error;
- }
- else if (CONST_STRNEQ (in.namedata, "QNX"))
- {
- if (! elfcore_grok_nto_note (abfd, &in))
- goto error;
- }
- else
- {
- if (! elfcore_grok_note (abfd, &in))
- goto error;
+ switch (bfd_get_format (abfd))
+ {
+ default:
+ return TRUE;
+
+ case bfd_core:
+ if (CONST_STRNEQ (in.namedata, "NetBSD-CORE"))
+ {
+ if (! elfcore_grok_netbsd_note (abfd, &in))
+ return FALSE;
+ }
+ else if (CONST_STRNEQ (in.namedata, "QNX"))
+ {
+ if (! elfcore_grok_nto_note (abfd, &in))
+ return FALSE;
+ }
+ else
+ {
+ if (! elfcore_grok_note (abfd, &in))
+ return FALSE;
+ }
+ break;
+
+ case bfd_object:
+ if (! elfobj_grok_note (abfd, &in))
+ return FALSE;
+ break;
}
p = in.descdata + BFD_ALIGN (in.descsz, 4);
}
+ return TRUE;
+}
+
+static bfd_boolean
+elf_read_notes (bfd *abfd, file_ptr offset, bfd_size_type size)
+{
+ char *buf;
+
+ if (size <= 0)
+ return TRUE;
+
+ if (bfd_seek (abfd, offset, SEEK_SET) != 0)
+ return FALSE;
+
+ buf = bfd_malloc (size);
+ if (buf == NULL)
+ return FALSE;
+
+ if (bfd_bread (buf, size, abfd) != size
+ || !elf_parse_notes (abfd, buf, size, offset))
+ {
+ free (buf);
+ return FALSE;
+ }
+
free (buf);
return TRUE;
}
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [patch] Parse NT_GNU_BUILD_ID into elf_obj_tdata->build_id*
2007-08-18 13:03 [patch] Parse NT_GNU_BUILD_ID into elf_obj_tdata->build_id* Jan Kratochvil
@ 2007-08-19 11:35 ` Roland McGrath
2007-08-19 15:28 ` Jan Kratochvil
0 siblings, 1 reply; 6+ messages in thread
From: Roland McGrath @ 2007-08-19 11:35 UTC (permalink / raw)
To: Jan Kratochvil; +Cc: binutils
> (_bfd_elf_make_section_from_shdr): Call ELF_PARSE_NOTES for all the
> sections with the name starting with `.note.'.
This should be driven by sh_type == SHT_NOTE, not by names.
> +static bfd_boolean
> +elfobj_grok_note (bfd *abfd, Elf_Internal_Note *note)
> +{
> + switch (note->type)
This needs to check the name field. The NT_GNU_* type number assignments
only apply to notes with name "GNU" (n_namesz = 4).
Thanks,
Roland
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [patch] Parse NT_GNU_BUILD_ID into elf_obj_tdata->build_id*
2007-08-19 11:35 ` Roland McGrath
@ 2007-08-19 15:28 ` Jan Kratochvil
2007-08-20 0:56 ` Roland McGrath
0 siblings, 1 reply; 6+ messages in thread
From: Jan Kratochvil @ 2007-08-19 15:28 UTC (permalink / raw)
To: Roland McGrath; +Cc: binutils
[-- Attachment #1: Type: text/plain, Size: 374 bytes --]
Hi,
On Sun, 19 Aug 2007 01:33:01 +0200, Roland McGrath wrote:
> > (_bfd_elf_make_section_from_shdr): Call ELF_PARSE_NOTES for all the
> > sections with the name starting with `.note.'.
>
> This should be driven by sh_type == SHT_NOTE, not by names.
Thanks, I did not like the name based identification there myself.
Patch updated with both fixes.
Best Regards,
Jan
[-- Attachment #2: bfd-buildid-fetch2.patch --]
[-- Type: text/plain, Size: 6074 bytes --]
2007-08-19 Jan Kratochvil <jan.kratochvil@redhat.com>
* bfd/elf-bfd.h (struct elf_obj_tdata): New build_id_size, build_id.
* bfd/elf.c (elfcore_read_notes): Split to ...
(elf_read_notes) ... here ...
(elf_parse_notes): ... and here. Check `bfd_get_format (abfd)' with
the former subfunctions called only for BFD_CORE.
Call ELFOBJ_GROK_GNU_NOTE for BFD_OBJECT files with the owner "GNU".
(_bfd_elf_make_section_from_shdr): Call ELF_PARSE_NOTES for SHT_NOTEs.
(bfd_section_from_phdr): Update the call for renamed ELFCORE_READ_NOTES.
(elfobj_grok_gnu_build_id, elfobj_grok_gnu_note): New functions.
Code advisory: Roland McGrath
--- bfd/elf-bfd.h 4 Aug 2007 16:31:00 -0000 1.239
+++ bfd/elf-bfd.h 19 Aug 2007 10:58:07 -0000
@@ -1472,6 +1472,10 @@ struct elf_obj_tdata
/* Called at the end of _bfd_elf_write_object_contents if not NULL. */
bfd_boolean (*after_write_object_contents) (bfd *);
void *after_write_object_contents_info;
+
+ /* NT_GNU_BUILD_ID note type. */
+ bfd_size_type build_id_size;
+ bfd_byte *build_id;
};
#define elf_tdata(bfd) ((bfd) -> tdata.elf_obj_data)
--- bfd/elf.c 16 Aug 2007 18:49:42 -0000 1.410
+++ bfd/elf.c 19 Aug 2007 10:58:09 -0000
@@ -48,7 +48,9 @@ static int elf_sort_sections (const void
static bfd_boolean assign_file_positions_except_relocs (bfd *, struct bfd_link_info *);
static bfd_boolean prep_headers (bfd *);
static bfd_boolean swap_out_syms (bfd *, struct bfd_strtab_hash **, int) ;
-static bfd_boolean elfcore_read_notes (bfd *, file_ptr, bfd_size_type) ;
+static bfd_boolean elf_read_notes (bfd *, file_ptr, bfd_size_type) ;
+static bfd_boolean elf_parse_notes (bfd *abfd, char *buf, size_t size,
+ file_ptr offset);
/* Swap version information in and out. The version information is
currently size independent. If that ever changes, this code will
@@ -899,6 +901,28 @@ _bfd_elf_make_section_from_shdr (bfd *ab
if (! bfd_set_section_flags (abfd, newsect, flags))
return FALSE;
+ /* We do not parse the PT_NOTE segments as we are interested even in the
+ separate debug info files which may have the segments offsets corrupted.
+ PT_NOTEs from the core files are currently not parsed using BFD. */
+ if (hdr->sh_type == SHT_NOTE)
+ {
+ char *contents;
+
+ contents = bfd_malloc (hdr->sh_size);
+ if (!contents)
+ return FALSE;
+
+ if (!bfd_get_section_contents (abfd, hdr->bfd_section, contents, 0,
+ hdr->sh_size)
+ || !elf_parse_notes (abfd, contents, hdr->sh_size, -1))
+ {
+ free (contents);
+ return FALSE;
+ }
+
+ free (contents);
+ }
+
if ((flags & SEC_ALLOC) != 0)
{
Elf_Internal_Phdr *phdr;
@@ -2341,7 +2365,7 @@ bfd_section_from_phdr (bfd *abfd, Elf_In
case PT_NOTE:
if (! _bfd_elf_make_section_from_phdr (abfd, hdr, index, "note"))
return FALSE;
- if (! elfcore_read_notes (abfd, hdr->p_offset, hdr->p_filesz))
+ if (! elf_read_notes (abfd, hdr->p_offset, hdr->p_filesz))
return FALSE;
return TRUE;
@@ -7713,6 +7737,32 @@ elfcore_grok_note (bfd *abfd, Elf_Intern
}
static bfd_boolean
+elfobj_grok_gnu_build_id (bfd *abfd, Elf_Internal_Note *note)
+{
+ elf_tdata (abfd)->build_id_size = note->descsz;
+ elf_tdata (abfd)->build_id = bfd_alloc (abfd, note->descsz);
+ if (elf_tdata (abfd)->build_id == NULL)
+ return FALSE;
+
+ memcpy (elf_tdata (abfd)->build_id, note->descdata, note->descsz);
+
+ return TRUE;
+}
+
+static bfd_boolean
+elfobj_grok_gnu_note (bfd *abfd, Elf_Internal_Note *note)
+{
+ switch (note->type)
+ {
+ default:
+ return TRUE;
+
+ case NT_GNU_BUILD_ID:
+ return elfobj_grok_gnu_build_id (abfd, note);
+ }
+}
+
+static bfd_boolean
elfcore_netbsd_get_lwpid (Elf_Internal_Note *note, int *lwpidp)
{
char *cp;
@@ -8186,28 +8236,10 @@ elfcore_write_prxfpreg (bfd *abfd,
}
static bfd_boolean
-elfcore_read_notes (bfd *abfd, file_ptr offset, bfd_size_type size)
+elf_parse_notes (bfd *abfd, char *buf, size_t size, file_ptr offset)
{
- char *buf;
char *p;
- if (size <= 0)
- return TRUE;
-
- if (bfd_seek (abfd, offset, SEEK_SET) != 0)
- return FALSE;
-
- buf = bfd_malloc (size);
- if (buf == NULL)
- return FALSE;
-
- if (bfd_bread (buf, size, abfd) != size)
- {
- error:
- free (buf);
- return FALSE;
- }
-
p = buf;
while (p < buf + size)
{
@@ -8224,25 +8256,66 @@ elfcore_read_notes (bfd *abfd, file_ptr
in.descdata = in.namedata + BFD_ALIGN (in.namesz, 4);
in.descpos = offset + (in.descdata - buf);
- if (CONST_STRNEQ (in.namedata, "NetBSD-CORE"))
- {
- if (! elfcore_grok_netbsd_note (abfd, &in))
- goto error;
- }
- else if (CONST_STRNEQ (in.namedata, "QNX"))
- {
- if (! elfcore_grok_nto_note (abfd, &in))
- goto error;
- }
- else
- {
- if (! elfcore_grok_note (abfd, &in))
- goto error;
+ switch (bfd_get_format (abfd))
+ {
+ default:
+ return TRUE;
+
+ case bfd_core:
+ if (CONST_STRNEQ (in.namedata, "NetBSD-CORE"))
+ {
+ if (! elfcore_grok_netbsd_note (abfd, &in))
+ return FALSE;
+ }
+ else if (CONST_STRNEQ (in.namedata, "QNX"))
+ {
+ if (! elfcore_grok_nto_note (abfd, &in))
+ return FALSE;
+ }
+ else
+ {
+ if (! elfcore_grok_note (abfd, &in))
+ return FALSE;
+ }
+ break;
+
+ case bfd_object:
+ if (in.namesz == 4 && memcmp (in.namedata, "GNU", 4) == 0)
+ {
+ if (! elfobj_grok_gnu_note (abfd, &in))
+ return FALSE;
+ }
+ break;
}
p = in.descdata + BFD_ALIGN (in.descsz, 4);
}
+ return TRUE;
+}
+
+static bfd_boolean
+elf_read_notes (bfd *abfd, file_ptr offset, bfd_size_type size)
+{
+ char *buf;
+
+ if (size <= 0)
+ return TRUE;
+
+ if (bfd_seek (abfd, offset, SEEK_SET) != 0)
+ return FALSE;
+
+ buf = bfd_malloc (size);
+ if (buf == NULL)
+ return FALSE;
+
+ if (bfd_bread (buf, size, abfd) != size
+ || !elf_parse_notes (abfd, buf, size, offset))
+ {
+ free (buf);
+ return FALSE;
+ }
+
free (buf);
return TRUE;
}
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [patch] Parse NT_GNU_BUILD_ID into elf_obj_tdata->build_id*
2007-08-19 15:28 ` Jan Kratochvil
@ 2007-08-20 0:56 ` Roland McGrath
2007-08-20 8:25 ` Jan Kratochvil
0 siblings, 1 reply; 6+ messages in thread
From: Roland McGrath @ 2007-08-20 0:56 UTC (permalink / raw)
To: Jan Kratochvil; +Cc: binutils
I tend to use sizeof "GNU" rather than a literal 4. But that is a tiny nit.
Thanks,
Roland
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [patch] Parse NT_GNU_BUILD_ID into elf_obj_tdata->build_id*
2007-08-20 0:56 ` Roland McGrath
@ 2007-08-20 8:25 ` Jan Kratochvil
2007-08-24 14:05 ` Daniel Jacobowitz
0 siblings, 1 reply; 6+ messages in thread
From: Jan Kratochvil @ 2007-08-20 8:25 UTC (permalink / raw)
To: Roland McGrath; +Cc: binutils
[-- Attachment #1: Type: text/plain, Size: 445 bytes --]
On Sun, 19 Aug 2007 21:57:50 +0200, Roland McGrath wrote:
> I tend to use sizeof "GNU" rather than a literal 4. But that is a tiny nit.
Updated/attached. I had there originally the sizeof() but later adjusted it to
exactly match the style of your mail's literal `(n_namesz = 4)'. :-)
-+ if (in.namesz == 4 && memcmp (in.namedata, "GNU", 4) == 0)
++ if (in.namesz == sizeof "GNU" && strcmp (in.namedata, "GNU") == 0)
Best Regards,
Jan
[-- Attachment #2: bfd-buildid-fetch3.patch --]
[-- Type: text/plain, Size: 6082 bytes --]
2007-08-19 Jan Kratochvil <jan.kratochvil@redhat.com>
* bfd/elf-bfd.h (struct elf_obj_tdata): New build_id_size, build_id.
* bfd/elf.c (elfcore_read_notes): Split to ...
(elf_read_notes) ... here ...
(elf_parse_notes): ... and here. Check `bfd_get_format (abfd)' with
the former subfunctions called only for BFD_CORE.
Call ELFOBJ_GROK_GNU_NOTE for BFD_OBJECT files with the owner "GNU".
(_bfd_elf_make_section_from_shdr): Call ELF_PARSE_NOTES for SHT_NOTEs.
(bfd_section_from_phdr): Update the call for renamed ELFCORE_READ_NOTES.
(elfobj_grok_gnu_build_id, elfobj_grok_gnu_note): New functions.
Code advisory: Roland McGrath
--- bfd/elf-bfd.h 4 Aug 2007 16:31:00 -0000 1.239
+++ bfd/elf-bfd.h 19 Aug 2007 20:12:14 -0000
@@ -1472,6 +1472,10 @@ struct elf_obj_tdata
/* Called at the end of _bfd_elf_write_object_contents if not NULL. */
bfd_boolean (*after_write_object_contents) (bfd *);
void *after_write_object_contents_info;
+
+ /* NT_GNU_BUILD_ID note type. */
+ bfd_size_type build_id_size;
+ bfd_byte *build_id;
};
#define elf_tdata(bfd) ((bfd) -> tdata.elf_obj_data)
--- bfd/elf.c 16 Aug 2007 18:49:42 -0000 1.410
+++ bfd/elf.c 19 Aug 2007 20:12:16 -0000
@@ -48,7 +48,9 @@ static int elf_sort_sections (const void
static bfd_boolean assign_file_positions_except_relocs (bfd *, struct bfd_link_info *);
static bfd_boolean prep_headers (bfd *);
static bfd_boolean swap_out_syms (bfd *, struct bfd_strtab_hash **, int) ;
-static bfd_boolean elfcore_read_notes (bfd *, file_ptr, bfd_size_type) ;
+static bfd_boolean elf_read_notes (bfd *, file_ptr, bfd_size_type) ;
+static bfd_boolean elf_parse_notes (bfd *abfd, char *buf, size_t size,
+ file_ptr offset);
/* Swap version information in and out. The version information is
currently size independent. If that ever changes, this code will
@@ -899,6 +901,28 @@ _bfd_elf_make_section_from_shdr (bfd *ab
if (! bfd_set_section_flags (abfd, newsect, flags))
return FALSE;
+ /* We do not parse the PT_NOTE segments as we are interested even in the
+ separate debug info files which may have the segments offsets corrupted.
+ PT_NOTEs from the core files are currently not parsed using BFD. */
+ if (hdr->sh_type == SHT_NOTE)
+ {
+ char *contents;
+
+ contents = bfd_malloc (hdr->sh_size);
+ if (!contents)
+ return FALSE;
+
+ if (!bfd_get_section_contents (abfd, hdr->bfd_section, contents, 0,
+ hdr->sh_size)
+ || !elf_parse_notes (abfd, contents, hdr->sh_size, -1))
+ {
+ free (contents);
+ return FALSE;
+ }
+
+ free (contents);
+ }
+
if ((flags & SEC_ALLOC) != 0)
{
Elf_Internal_Phdr *phdr;
@@ -2341,7 +2365,7 @@ bfd_section_from_phdr (bfd *abfd, Elf_In
case PT_NOTE:
if (! _bfd_elf_make_section_from_phdr (abfd, hdr, index, "note"))
return FALSE;
- if (! elfcore_read_notes (abfd, hdr->p_offset, hdr->p_filesz))
+ if (! elf_read_notes (abfd, hdr->p_offset, hdr->p_filesz))
return FALSE;
return TRUE;
@@ -7713,6 +7737,32 @@ elfcore_grok_note (bfd *abfd, Elf_Intern
}
static bfd_boolean
+elfobj_grok_gnu_build_id (bfd *abfd, Elf_Internal_Note *note)
+{
+ elf_tdata (abfd)->build_id_size = note->descsz;
+ elf_tdata (abfd)->build_id = bfd_alloc (abfd, note->descsz);
+ if (elf_tdata (abfd)->build_id == NULL)
+ return FALSE;
+
+ memcpy (elf_tdata (abfd)->build_id, note->descdata, note->descsz);
+
+ return TRUE;
+}
+
+static bfd_boolean
+elfobj_grok_gnu_note (bfd *abfd, Elf_Internal_Note *note)
+{
+ switch (note->type)
+ {
+ default:
+ return TRUE;
+
+ case NT_GNU_BUILD_ID:
+ return elfobj_grok_gnu_build_id (abfd, note);
+ }
+}
+
+static bfd_boolean
elfcore_netbsd_get_lwpid (Elf_Internal_Note *note, int *lwpidp)
{
char *cp;
@@ -8186,28 +8236,10 @@ elfcore_write_prxfpreg (bfd *abfd,
}
static bfd_boolean
-elfcore_read_notes (bfd *abfd, file_ptr offset, bfd_size_type size)
+elf_parse_notes (bfd *abfd, char *buf, size_t size, file_ptr offset)
{
- char *buf;
char *p;
- if (size <= 0)
- return TRUE;
-
- if (bfd_seek (abfd, offset, SEEK_SET) != 0)
- return FALSE;
-
- buf = bfd_malloc (size);
- if (buf == NULL)
- return FALSE;
-
- if (bfd_bread (buf, size, abfd) != size)
- {
- error:
- free (buf);
- return FALSE;
- }
-
p = buf;
while (p < buf + size)
{
@@ -8224,25 +8256,66 @@ elfcore_read_notes (bfd *abfd, file_ptr
in.descdata = in.namedata + BFD_ALIGN (in.namesz, 4);
in.descpos = offset + (in.descdata - buf);
- if (CONST_STRNEQ (in.namedata, "NetBSD-CORE"))
- {
- if (! elfcore_grok_netbsd_note (abfd, &in))
- goto error;
- }
- else if (CONST_STRNEQ (in.namedata, "QNX"))
- {
- if (! elfcore_grok_nto_note (abfd, &in))
- goto error;
- }
- else
- {
- if (! elfcore_grok_note (abfd, &in))
- goto error;
+ switch (bfd_get_format (abfd))
+ {
+ default:
+ return TRUE;
+
+ case bfd_core:
+ if (CONST_STRNEQ (in.namedata, "NetBSD-CORE"))
+ {
+ if (! elfcore_grok_netbsd_note (abfd, &in))
+ return FALSE;
+ }
+ else if (CONST_STRNEQ (in.namedata, "QNX"))
+ {
+ if (! elfcore_grok_nto_note (abfd, &in))
+ return FALSE;
+ }
+ else
+ {
+ if (! elfcore_grok_note (abfd, &in))
+ return FALSE;
+ }
+ break;
+
+ case bfd_object:
+ if (in.namesz == sizeof "GNU" && strcmp (in.namedata, "GNU") == 0)
+ {
+ if (! elfobj_grok_gnu_note (abfd, &in))
+ return FALSE;
+ }
+ break;
}
p = in.descdata + BFD_ALIGN (in.descsz, 4);
}
+ return TRUE;
+}
+
+static bfd_boolean
+elf_read_notes (bfd *abfd, file_ptr offset, bfd_size_type size)
+{
+ char *buf;
+
+ if (size <= 0)
+ return TRUE;
+
+ if (bfd_seek (abfd, offset, SEEK_SET) != 0)
+ return FALSE;
+
+ buf = bfd_malloc (size);
+ if (buf == NULL)
+ return FALSE;
+
+ if (bfd_bread (buf, size, abfd) != size
+ || !elf_parse_notes (abfd, buf, size, offset))
+ {
+ free (buf);
+ return FALSE;
+ }
+
free (buf);
return TRUE;
}
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [patch] Parse NT_GNU_BUILD_ID into elf_obj_tdata->build_id*
2007-08-20 8:25 ` Jan Kratochvil
@ 2007-08-24 14:05 ` Daniel Jacobowitz
0 siblings, 0 replies; 6+ messages in thread
From: Daniel Jacobowitz @ 2007-08-24 14:05 UTC (permalink / raw)
To: Jan Kratochvil; +Cc: Roland McGrath, binutils
On Sun, Aug 19, 2007 at 10:16:32PM +0200, Jan Kratochvil wrote:
> 2007-08-19 Jan Kratochvil <jan.kratochvil@redhat.com>
>
> * bfd/elf-bfd.h (struct elf_obj_tdata): New build_id_size, build_id.
> * bfd/elf.c (elfcore_read_notes): Split to ...
> (elf_read_notes) ... here ...
> (elf_parse_notes): ... and here. Check `bfd_get_format (abfd)' with
> the former subfunctions called only for BFD_CORE.
> Call ELFOBJ_GROK_GNU_NOTE for BFD_OBJECT files with the owner "GNU".
> (_bfd_elf_make_section_from_shdr): Call ELF_PARSE_NOTES for SHT_NOTEs.
> (bfd_section_from_phdr): Update the call for renamed ELFCORE_READ_NOTES.
> (elfobj_grok_gnu_build_id, elfobj_grok_gnu_note): New functions.
OK.
--
Daniel Jacobowitz
CodeSourcery
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2007-08-24 13:57 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-08-18 13:03 [patch] Parse NT_GNU_BUILD_ID into elf_obj_tdata->build_id* Jan Kratochvil
2007-08-19 11:35 ` Roland McGrath
2007-08-19 15:28 ` Jan Kratochvil
2007-08-20 0:56 ` Roland McGrath
2007-08-20 8:25 ` Jan Kratochvil
2007-08-24 14:05 ` Daniel Jacobowitz
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).