Hello,

the attached tiny patch fixes the output of `eu-readelf --exception 
/path/to/binary` for 32-bit stripped binaries. Both elfutils-0.152 and recent 
git are affected, AFAICT.


Reproducer:
$ eu-readelf --exception zyGrib-3.9.9-3.fc16.i686/usr/bin/zyGrib
...
Call frame information section [17] '.eh_frame' at offset 0x109440:

 [     0] CIE length=20
...
 [    18] FDE length=16 cie=[     0]
...
 [    2c] CIE length=28
   CIE_id:                   0
   version:                  1
   augmentation:             "zPLR"
   code_alignment_factor:    1
   data_alignment_factor:    -4
   return_address_register:  8
   Augmentation data:        0 eu-readelf: invalid encoding
<end of output>


What happens (all functions are in readelf.c):
1. In function print_debug, the 'dwfl_module_getdwarf (dwflmod, &dwbias)' call 
returns NULL as the binary is stripped, so 'dummy_dbg' from the same function 
is assigned to 'dbg' variable.

Dwarf dummy_dbg = { .other_byte_order = MY_ELFDATA != ehdr->e_ident[EI_DATA] };
dbg = &dummy_dbg;

2. Later, when reading the .eh_frame contents in function 
print_debug_frame_section, read_encoded is called.
3. The parameter encoding of read_encoded represents DW_EH_PE_absptr.
4. read_encoded: gelf_getclass (dbg->elf) is called.
5. read_encoded: dbg->elf is NULL, because elf member is not being assigned for 
'dummy_dbg'.
6. read_encoded: So gelf_getclass (NULL) returns ELFCLASSNONE
7. read_encoded: "encoding = gelf_getclass (dbg->elf) == ELFCLASS32 ? 
DW_EH_PE_udata4 : DW_EH_PE_udata8" is evaluated to DW_EH_PE_udata8.
8. read_encoded: Reading of udata8 fails, because this is 32-bit ELF, so there 
is only udata4 in the binary.


Karel
diff -up elfutils-0.152/src/readelf.c.encoding elfutils-0.152/src/readelf.c
--- elfutils-0.152/src/readelf.c.encoding	2011-12-20 16:35:17.990838753 +0100
+++ elfutils-0.152/src/readelf.c	2011-12-20 16:38:16.648605225 +0100
@@ -6956,7 +6964,10 @@ print_debug (Dwfl_Module *dwflmod, Ebl *
   /* Before we start the real work get a debug context descriptor.  */
   Dwarf_Addr dwbias;
   Dwarf *dbg = dwfl_module_getdwarf (dwflmod, &dwbias);
-  Dwarf dummy_dbg = { .other_byte_order = MY_ELFDATA != ehdr->e_ident[EI_DATA] };
+  Dwarf dummy_dbg = {
+    .elf = ebl->elf,
+    .other_byte_order = MY_ELFDATA != ehdr->e_ident[EI_DATA]
+  };
   if (dbg == NULL)
     {
       if ((print_debug_sections & ~section_exception) != 0)
_______________________________________________
elfutils-devel mailing list
[email protected]
https://fedorahosted.org/mailman/listinfo/elfutils-devel

Reply via email to