From: Luca P. <luc...@gm...> - 2010-03-02 13:12:53
|
Hi to all. I'm Luca and I'm using libelf on FreeBSD 7.3 to develop a tool that manipulate ELF binaries. I hope that mailing list is right to post this problem. My tool changes some information in the dynamic symbol table (using gelf_update_sym()), save the elf and quit. elf_update(e, ELF_C_WRITE) fails with a DATA class error (Invalid data buffer descriptor). Investigations revealed that _libelf_xlate() fails because src->d_buf is NULL. Further investigations revealed that the caller function _libelf_write_elf() when wants to write the program header table, use the e_phdr32 field of the _Elf struct. Seems that this field is not correctly initialized. As workaround I call gelf_getphdr() and the problem goes away. I attach a very simple test that shows (and solve with -DWORKAROUND) the problem. Is this the right behavior of the library (and I need to read the tutorial more deeply) or I've found an unlikely bug? I've checked the source of libelf and _libelf_getphdr() (c)allocate the phdr in _Elf struct. May be it has to be called by elf_begin()? Have I to open a PR? Thanks in advance Luca PS: In the tutorial (libelf-by-example-20100112), I've found some errors in the Listing 3.1 (Program 2): the functions elf_getshdrnum(), elf_getshdrstrndx() and elf_phdrnum() doesn't exist. The right names are: elf_getshnum(), elf_getshstrndx() and elf_phdrnum(). PS2: I like this topic and should be great if you need help and I could be a little involved in this project! |