[PATCH] PR binutils/18218: bad handling of .debug_str_offsets section
Doug Evans
dje@google.com
Thu Apr 9 19:35:00 GMT 2015
H.J. Lu writes:
> On Thu, Apr 9, 2015 at 11:03 AM, Doug Evans <dje@google.com> wrote:
> > On Thu, Apr 9, 2015 at 10:41 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> >>> Even better, treat the "sec" argument to load_specific_debug_section
> >>> as "const Elf_Internal_Shdr * sec".
> >>> Modifying sec->sh_size to be the size of the now-uncompressed section
> >>> is fragile and what led to this bug. Leave this data be the
> >>> representation of what's actually on disk, and build on it, not modify
> >>> it.
> >>
> >> We need to update sh_size to get readelf to work right.
> >
> > I don't understand.
> > There are lots of ways to make readelf work right.
> > Some better than others.
>
> Patches are welcome.
I would have expected a more technical explanation of why
the proposed patch is ok.
How about this?
[I can imagine there's more work to do along these lines.
At least this headed in a good direction.
Ultimately, I can imagine adding a backlink from
dwarf_section to Elf_Internal_Shdr, though a more sound
proposal would need more research.]
2015-04-09 Doug Evans <dje@google.com>
PR binutils/18218
* readelf.c (printable_section_name): Constify sec argument.
(apply_relocations): Ditto. New arg "size". All callers updated.
(load_specific_debug_section): Constify sec argument.
Remove side-effect of modifying sec->sh_size.
diff --git a/binutils/readelf.c b/binutils/readelf.c
index fea372f..44ac68a 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -550,7 +550,7 @@ print_symbol (int width, const char *symbol)
to print multibyte characters, it just interprets them as hex values. */
static const char *
-printable_section_name (Elf_Internal_Shdr * sec)
+printable_section_name (const Elf_Internal_Shdr * sec)
{
#define MAX_PRINT_SEC_NAME_LEN 128
static char sec_name_buf [MAX_PRINT_SEC_NAME_LEN + 1];
@@ -11630,11 +11630,11 @@ is_none_reloc (unsigned int reloc_type)
static void
apply_relocations (void * file,
- Elf_Internal_Shdr * section,
- unsigned char * start)
+ const Elf_Internal_Shdr * section,
+ unsigned char * start, bfd_size_type size)
{
Elf_Internal_Shdr * relsec;
- unsigned char * end = start + section->sh_size;
+ unsigned char * end = start + size;
if (elf_header.e_type != ET_REL)
return;
@@ -11926,7 +11926,7 @@ dump_section_as_bytes (Elf_Internal_Shdr * section,
if (relocate)
{
- apply_relocations (file, section, start);
+ apply_relocations (file, section, start, section->sh_size);
}
else
{
@@ -12066,7 +12066,7 @@ uncompress_section_contents (unsigned char **buffer,
static int
load_specific_debug_section (enum dwarf_section_display_enum debug,
- Elf_Internal_Shdr * sec, void * file)
+ const Elf_Internal_Shdr * sec, void * file)
{
struct dwarf_section * section = &debug_displays [debug].section;
char buf [64];
@@ -12106,7 +12106,6 @@ load_specific_debug_section (enum dwarf_section_display_enum debug,
and the section size if uncompress is successful. */
free (section->start);
section->start = start;
- sec->sh_size = size;
}
section->size = size;
}
@@ -12115,7 +12114,7 @@ load_specific_debug_section (enum dwarf_section_display_enum debug,
return 0;
if (debug_displays [debug].relocate)
- apply_relocations ((FILE *) file, sec, section->start);
+ apply_relocations ((FILE *) file, sec, section->start, section->size);
return 1;
}
More information about the Binutils
mailing list