Index: contrib/elftoolchain/elfcopy/binary.c =================================================================== --- contrib/elftoolchain/elfcopy/binary.c +++ contrib/elftoolchain/elfcopy/binary.c @@ -49,6 +49,7 @@ Elf *e; Elf_Scn *scn; Elf_Data *d; + Elf64_Addr baseaddr; GElf_Shdr sh; off_t base, off; int elferr; @@ -76,8 +77,10 @@ sh.sh_type == SHT_NOBITS || sh.sh_size == 0) continue; - if (base == -1 || (off_t) sh.sh_offset < base) + if (base == -1 || (off_t) sh.sh_offset < base) { base = sh.sh_offset; + baseaddr = sh.sh_addr; + } } elferr = elf_errno(); if (elferr != 0) @@ -111,7 +114,7 @@ continue; /* lseek to section offset relative to `base'. */ - off = sh.sh_offset - base; + off = sh.sh_addr - baseaddr; if (lseek(ofd, off, SEEK_SET) < 0) err(EXIT_FAILURE, "lseek failed");