summaryrefslogtreecommitdiff
path: root/bfd
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2013-10-08 19:56:13 +0000
committerTom Tromey <tromey@redhat.com>2013-10-08 19:56:13 +0000
commitc51c811a1dc0cf922503200494c2d2570f91fbe2 (patch)
treee88f540c3d6f61efdeecfb0610033a00a57ed0ff /bfd
parent15c3f4e7ef24427a8bdac90369c73f26165f67b5 (diff)
downloadbinutils-redhat-c51c811a1dc0cf922503200494c2d2570f91fbe2.tar.gz
fix PR symtab/15597
This patch fixes gdb PR symtab/15597. The bug is that the .gnu_debugaltlink section includes the build-id of the alt file, but gdb does not use it. This patch fixes the problem by changing gdb to do what it ought to always have done: verify the build id of the file found using the filename in .gnu_debugaltlink; and if that does not match, try to find the correct debug file using the build-id and debug-file-directory. This patch touches BFD. Previously, gdb had its own code for parsing .gnu_debugaltlink; I changed it to use the BFD functions after those were introduced. However, the BFD functions are incorrect -- they assume that .gnu_debugaltlink is formatted like .gnu_debuglink. However, it it is not. Instead, it consists of a file name followed by the build-id -- no alignment, and the build-id is not a CRC. Fixing this properly is a bit of a pain. But, because separate_alt_debug_file_exists just has a FIXME for the build-id case, I did not fix it properly. Instead I introduced a hack. This leaves BFD working just as well as it did before my patch. I'm willing to do something better here but I could use some guidance as to what. It seems that the build-id code in BFD is largely punted on. FWIW gdb is the only user of bfd_get_alt_debug_link_info outside of BFD itself. I moved the build-id logic out of elfread.c and into a new file. This seemed cleanest to me. Writing a test case was a bit of a pain. I added a couple new features to the DWARF assembler to handle this. Built and regtested on x86-64 Fedora 18. * bfd-in2.h: Rebuild. * opncls.c (bfd_get_alt_debug_link_info): Add buildid_len parameter. Change type of buildid_out. Update. (get_alt_debug_link_info_shim): New function. (bfd_follow_gnu_debuglink): Use it. * Makefile.in (SFILES): Add build-id.c. (HFILES_NO_SRCDIR): Add build-id.h. * build-id.c: New file, largely from elfread.c. Modified most functions. * build-id.h: New file. * dwarf2read.c (dwarf2_get_dwz_file): Update for change to bfd_get_alt_debug_link_info. Verify dwz file's build-id. Search for dwz file using build-id. * elfread.c (build_id_bfd_get, build_id_verify) (build_id_to_debug_filename, find_separate_debug_file): Remove. * gdb.dwarf2/dwzbuildid.exp: New file. * lib/dwarf.exp (Dwarf::_section): Add "flags" and "type" parameters. (Dwarf::_defer_output): Change "section" parameter to "section_spec"; update. (Dwarf::gnu_debugaltlink, Dwarf::_note, Dwarf::build_id): New procs.
Diffstat (limited to 'bfd')
-rw-r--r--bfd/ChangeLog8
-rw-r--r--bfd/bfd-in2.h3
-rw-r--r--bfd/opncls.c41
3 files changed, 42 insertions, 10 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index c5d98271d1..e8534ddaee 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,11 @@
+2013-10-08 Tom Tromey <tromey@redhat.com>
+
+ * bfd-in2.h: Rebuild.
+ * opncls.c (bfd_get_alt_debug_link_info): Add buildid_len
+ parameter. Change type of buildid_out. Update.
+ (get_alt_debug_link_info_shim): New function.
+ (bfd_follow_gnu_debuglink): Use it.
+
2013-10-08 Andreas Schwab <schwab@suse.de>
* elf32-m68k.c (elf_m68k_size_dynamic_sections): Add DT_DEBUG also
diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
index 41f7a682c3..67eb7da2e3 100644
--- a/bfd/bfd-in2.h
+++ b/bfd/bfd-in2.h
@@ -1067,7 +1067,8 @@ unsigned long bfd_calc_gnu_debuglink_crc32
char *bfd_get_debug_link_info (bfd *abfd, unsigned long *crc32_out);
-char *bfd_get_alt_debug_link_info (bfd *abfd, unsigned long *crc32_out);
+char *bfd_get_alt_debug_link_info (bfd * abfd, size_t *buildid_len,
+ bfd_byte **buildid_out);
char *bfd_follow_gnu_debuglink (bfd *abfd, const char *dir);
diff --git a/bfd/opncls.c b/bfd/opncls.c
index cd9c826dd4..f29b2c8a37 100644
--- a/bfd/opncls.c
+++ b/bfd/opncls.c
@@ -1194,18 +1194,21 @@ FUNCTION
bfd_get_alt_debug_link_info
SYNOPSIS
- char *bfd_get_alt_debug_link_info (bfd *abfd, unsigned long *crc32_out);
+ char *bfd_get_alt_debug_link_info (bfd * abfd, size_t *buildid_len,
+ bfd_byte **buildid_out);
DESCRIPTION
Fetch the filename and BuildID value for any alternate debuginfo
associated with @var{abfd}. Return NULL if no such info found,
- otherwise return filename and update @var{buildid_out}. The
- returned filename is allocated with @code{malloc}; freeing it
- is the responsibility of the caller.
+ otherwise return filename and update @var{buildid_len} and
+ @var{buildid_out}. The returned filename and build_id are
+ allocated with @code{malloc}; freeing them is the
+ responsibility of the caller.
*/
char *
-bfd_get_alt_debug_link_info (bfd * abfd, unsigned long * buildid_out)
+bfd_get_alt_debug_link_info (bfd * abfd, size_t *buildid_len,
+ bfd_byte **buildid_out)
{
asection *sect;
bfd_byte *contents;
@@ -1213,6 +1216,7 @@ bfd_get_alt_debug_link_info (bfd * abfd, unsigned long * buildid_out)
char *name;
BFD_ASSERT (abfd);
+ BFD_ASSERT (buildid_len);
BFD_ASSERT (buildid_out);
sect = bfd_get_section_by_name (abfd, GNU_DEBUGALTLINK);
@@ -1227,12 +1231,13 @@ bfd_get_alt_debug_link_info (bfd * abfd, unsigned long * buildid_out)
return NULL;
}
- /* BuildID value is stored after the filename, aligned up to 4 bytes. */
+ /* BuildID value is stored after the filename. */
name = (char *) contents;
buildid_offset = strlen (name) + 1;
- buildid_offset = (buildid_offset + 3) & ~3;
- * buildid_out = bfd_get_32 (abfd, contents + buildid_offset);
+ *buildid_len = bfd_get_section_size (sect) - buildid_offset;
+ *buildid_out = bfd_malloc (*buildid_len);
+ memcpy (*buildid_out, contents + buildid_offset, *buildid_len);
return name;
}
@@ -1466,6 +1471,24 @@ bfd_follow_gnu_debuglink (bfd *abfd, const char *dir)
separate_debug_file_exists);
}
+/* Helper for bfd_follow_gnu_debugaltlink. It just pretends to return
+ a CRC. .gnu_debugaltlink supplies a build-id, which is different,
+ but this is ok because separate_alt_debug_file_exists ignores the
+ CRC anyway. */
+
+static char *
+get_alt_debug_link_info_shim (bfd * abfd, unsigned long *crc32_out)
+{
+ size_t len;
+ bfd_byte *buildid = NULL;
+ char *result = bfd_get_alt_debug_link_info (abfd, &len, &buildid);
+
+ *crc32_out = 0;
+ free (buildid);
+
+ return result;
+}
+
/*
FUNCTION
bfd_follow_gnu_debugaltlink
@@ -1496,7 +1519,7 @@ char *
bfd_follow_gnu_debugaltlink (bfd *abfd, const char *dir)
{
return find_separate_debug_file (abfd, dir,
- bfd_get_alt_debug_link_info,
+ get_alt_debug_link_info_shim,
separate_alt_debug_file_exists);
}