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