Dear Mark, Mark Wielaard wrote on 08.08.2015 00:35: > On Thu, Aug 06, 2015 at 05:14:25PM +0200, Kai Wasserbäch wrote: >>> Could you compile the following with: >>> gcc -g -lelf -o elfrel elfrel.c >> >> this does not work for several reasons: >> 1. I certainly need -std=c99 for the inline initialisation of the >> counter in the for() statement. > > Ah, yes, this system has gcc 5.1 which defaults to gnu11.
ah, ok. GCC 5.x is currently in unstable and still needs to migrate to testing. >> 2. *section (first used in »gelf_getshdr(section, §ion_header)«) isn't >> defined/filled anywhere: >> [...] >> Long story short: did you paste the entire/correct code? > > Drat, so sorry. I must have copy/pasted an earlier version, that didn't > even compile. No problem. I'm just not familiar with libelf's API and didn't have time to read the documentation to fix the bug by myself (or at least attempt that). > Attached is a version I double checked, that includes one > extra check (the size of the .text section). Here you go (first the output when elfrel is linked against libelf1: $ for i in 794488_elfs/libelf*/dump.elf.*; do ./elfrel $i; done file: 794488_elfs/libelf1/dump.elf.EL5kJT .text code size: 24 Nothing found file: 794488_elfs/libelf1/dump.elf.J4EnbO .text code size: 11c symbols: 5 1: not global or undefined 2: not global or undefined 3: not global or undefined 4: not global or undefined 5: 0 relocations: 2 0: 10, SCRATCH_RSRC_DWORD1 1: 200000081, file: 794488_elfs/libelfg0/dump.elf.7NnBvc .text code size: 24 Nothing found file: 794488_elfs/libelfg0/dump.elf.ahPsJJ .text code size: 11c symbols: 5 1: not global or undefined 2: not global or undefined 3: not global or undefined 4: not global or undefined 5: 0 relocations: 2 0: 10, SCRATCH_RSRC_DWORD1 1: 200000081, file: 794488_elfs/libelfg0/dump.elf.DYTjdO .text code size: 28 Nothing found file: 794488_elfs/libelfg0/dump.elf.Lke6Xg .text code size: 38 Nothing found Now linked with libelfg0: $ for i in 794488_elfs/libelf*/dump.elf.*; do ./elfrel_elfg0 $i; done file: 794488_elfs/libelf1/dump.elf.EL5kJT .text code size: 24 Nothing found file: 794488_elfs/libelf1/dump.elf.J4EnbO .text code size: 11c symbols: 5 1: not global or undefined 2: not global or undefined 3: not global or undefined 4: not global or undefined 5: 0 relocations: 2 0: 10, SCRATCH_RSRC_DWORD1 1: 2c, SCRATCH_RSRC_DWORD0 file: 794488_elfs/libelfg0/dump.elf.7NnBvc .text code size: 24 Nothing found file: 794488_elfs/libelfg0/dump.elf.ahPsJJ .text code size: 11c symbols: 5 1: not global or undefined 2: not global or undefined 3: not global or undefined 4: not global or undefined 5: 0 relocations: 2 0: 10, SCRATCH_RSRC_DWORD1 1: 2c, SCRATCH_RSRC_DWORD0 file: 794488_elfs/libelfg0/dump.elf.DYTjdO .text code size: 28 Nothing found file: 794488_elfs/libelfg0/dump.elf.Lke6Xg .text code size: 38 Nothing found And there *IS* a difference vs. your output: for you the relocations in 794488_elfs/libelf1/dump.elf.J4EnbO look fine, for me the second relocation is botched with libelf1 while it works with libelfg0. libelf1: relocations: 2 0: 10, SCRATCH_RSRC_DWORD1 1: 200000081, libelfg0: relocations: 2 0: 10, SCRATCH_RSRC_DWORD1 1: 2c, SCRATCH_RSRC_DWORD0 I also went ahead and checked Michel's information, that 0.159-4.2 worked. And indeed, if I link elfrel with that older libelf1 I get a good looking relocation section again: $ for i in 794488_elfs/libelf*/dump.elf.*; do ./elfrel_elf1-old $i; done file: 794488_elfs/libelf1/dump.elf.EL5kJT .text code size: 24 Nothing found file: 794488_elfs/libelf1/dump.elf.J4EnbO .text code size: 11c symbols: 5 1: not global or undefined 2: not global or undefined 3: not global or undefined 4: not global or undefined 5: 0 relocations: 2 0: 10, SCRATCH_RSRC_DWORD1 1: 2c, SCRATCH_RSRC_DWORD0 file: 794488_elfs/libelfg0/dump.elf.7NnBvc .text code size: 24 Nothing found file: 794488_elfs/libelfg0/dump.elf.ahPsJJ .text code size: 11c symbols: 5 1: not global or undefined 2: not global or undefined 3: not global or undefined 4: not global or undefined 5: 0 relocations: 2 0: 10, SCRATCH_RSRC_DWORD1 1: 2c, SCRATCH_RSRC_DWORD0 file: 794488_elfs/libelfg0/dump.elf.DYTjdO .text code size: 28 Nothing found file: 794488_elfs/libelfg0/dump.elf.Lke6Xg .text code size: 38 Nothing found If you want to take a look at Debian's builds of libelf{g0,1}, check out: - libelfg0 (0.8.13-5): <https://packages.debian.org/stretch/amd64/libelfg0/download> (working) - libelf1 (0.159-4.2): <http://snapshot.debian.org/package/elfutils/0.159-4.2/#libelf1_0.159-4.2> (working) - libelf1 (0.163-4): <https://packages.debian.org/stretch/amd64/libelf1/download> (failing) In case the versions change on packages.debian.org, snapshot.debian.org is your friend. ;-) Let me know, if you need something else. Cheers, Kai
signature.asc
Description: OpenPGP digital signature