PATCH: support compressed sections in addr2line, objdump, readelf

Nick Clifton nickc@redhat.com
Tue Jul 8 08:17:00 GMT 2008


Hi Craig,

> Hmm, this is in bfd.h (or bfd-in2.h or bfd-in3.h)?  These files are
> autogenerated.  It looks like all the declarations in this file have
> the format above (with return type and function name on the same
> line), so I assume it's intentional on the part of the person who
> wrote the autogeneration script.

Doh!  I should have remembered that.

> } Hmm - can the compressed section name always be deduced from the
> } uncompressed name ?
> 
> Yes.  However, every way I had of doing that autodeduction was either
> annoying (creating a temporary buffer, which is always annoying to
> size, and sprintf'ing into it) or confusing (passing in a subset of
> the section-name to read_section, which makes the call-site look
> odd).
> 
> I decided repeating was the cleanest way to do it, and also the most
> flexible, in case the pattern breaks later.  It also allows us an easy
> way to say, "This section has no compressed variant" (by passing in
> NULL as the second argument), which I could see being useful.
> 
> I think the flexibility is worth the repetition, but I can change it
> if you think it's important to.

No, your approach is good.  Although it might be worth adding an test 
along the lines of:

> +  msec = bfd_get_section_by_name (abfd, section_name);
> +  if (! msec && compressed_section_name)
> +    {
> +      msec = bfd_get_section_by_name (abfd, compressed_section_name);
> +      section_is_compressed = TRUE;

          /* The convention is that the compressed version of a section
             name has a 'z' prefix to the ascii portion of the
             uncompressed version of the name, so the compressed version
             of .foo is .zfoo.  If we failed to get the expected
             compressed section here then there could be a coding error
             somewhere which has resulted in an incorrect compressed
             section name, so apply a simple heuristic to try to catch
             such a case.  */
          if (msec == NULL && strcmp (section_name + 1, 
compressed_section_name + 2) != 0)
             _bfd_error_handler (_("Mismatched compressed version of 
section name: %s vs %s"), section_name, compressed_section_name);

> bfd/
> 	* Makefile.am (BFD32_LIBS): Add compress.lo.
> 	(BFD32_LIBS_CFILES): Add compress.c.
> 	(BFD_H_FILES): Likewise.
> 	* Makefile.in: Regenerate.
> 	* bfd-in2.h: Regenerate.
> 	* config.in: Add HAVE_ZLIB_H
> 	* configure.in: Add test for libz and zlib.h
> 	* configure: Regenerate.
> 	* dwarf2.c (read_section): New function.
> 	(read_indirect_string): Call new function read_section.
> 	(read_abbrevs): Likewise.
> 	(decode_line_info): Likewise.
> 	(read_debug_ranges): Likewise.
> 	(find_line): Call new function read_section when just one
> 	.zdebug_info section is found, otherwise read and compress
> 	multiple sections.
> 	(_bfd_dwarf2_cleanup_debug_info): Free sec_info_ptr.
> 	* elf.c (_bfd_elf_make_section_from_shdr): Add zdebug prefix.
> 	(special_sections_z): New struct.
> 	(special_sections): Refer to special_sections_z.
> 	* elfxx-mips.c (_bfd_mips_elf_section_from_shdr): Recognize
> 	sections named .zdebug_*.
> 	(_bfd_mips_elf_fake_sections): Likewise.
> 	* compress.c: New file.
> 	(bfd_uncompress_section_contents): New function.
> bfd/doc/
> 	Makefile.am (BFD_H_DEP): Add ../compress.c.
> 	Makefile.in: Regenerate.
> binutils/
> 	* config.in: Add HAVE_ZLIB_H
> 	* configure.in: Add test for libz and zlib.h
> 	* configure: Regenerate.
> 	* dwarf.c (debug_displays): Add .zdebug_* strings.
> 	* dwarf.h (struct dwarf_section): Add fields uncompressed_namd
> 	and compressed_name.
> 	* objdump.c (load_debug_section): Call
> 	bfd_uncompress_section_contents when loading a compressed
> 	section.
> 	(dump_dwarf_section): Recognize compressed section name.
> 	(mach_o_dwarf_sections): Rename as
> 	mach_o_uncompressed_dwarf_sections.
> 	(mach_o_compressed_dwarf_sections): New variable.
> 	(generic_dwarf_section): Rename as
> 	generic_uncompressed_dwarf_sections.
> 	(generic_compressed_dwarf_sections): New variable.
> 	(check_mach_o_dwarf): Save and restore
> 	mach_o_compressed_dwarf_sections.
> 	* readelf.c: Add #include for config.h and zlib.h
> 	(process_section_headers): Recognize compressed section name.
> 	(uncompress_section_contents): New function.
> 	(load_debug_section): Call uncompress_section_contents when
> 	loading a compressed section.
> 	(display_debug_section): Recognize compressed section name.
> binutils/testsuite:
> 	* binutils-all/objdump.exp: Add test for objdump -s on a file
> 	with a compressed debug section.  Add test for objdump -W on a
> 	file that contains a compressed debug section.
> 	* binutils-all/readelf.exp: Call readelf_compressed_wa_test.
> 	(readelf_compressed_wa_test): New function.
> 	* binutils-all/dw2-compressed.S: New file.
> 	* binutils-all/objdump.W: New file.
> 	* binutils-all/objdump.s: New file.
> 	* binutils-all/readelf.wa: New file.

Approved - please apply.

Cheers
   Nick



More information about the Binutils mailing list