[PATCH] D71035: [llvm-objcopy][ELF] -O binary: use LMA instead of sh_offset to decide where to write section contents
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 9 15:48:31 PST 2019
MaskRay updated this revision to Diff 232953.
MaskRay edited the summary of this revision.
MaskRay added a comment.
Fix formula: sh_offset - p_offset + p_paddr
See bfd/elf.c:1182 for a reference.
/* We used to use the same adjustment for SEC_LOAD
sections, but that doesn't work if the segment
is packed with code from multiple VMAs.
Instead we calculate the section LMA based on
the segment LMA. It is assumed that the
segment will contain sections with contiguous
LMAs, even if the VMAs are not. */
newsect->lma = (phdr->p_paddr + hdr->sh_offset - phdr->p_offset);
For sections not in a PT_LOAD, the BFD code uses a different formula.
newsect->lma = (phdr->p_paddr
+ hdr->sh_addr - phdr->p_vaddr);
We don't need care about that because -O binary does not dump non-SHF_ALLOC sections.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D71035/new/
https://reviews.llvm.org/D71035
Files:
llvm/test/tools/llvm-objcopy/ELF/binary-paddr.test
llvm/tools/llvm-objcopy/ELF/Object.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71035.232953.patch
Type: text/x-patch
Size: 6050 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191209/ea29ff9e/attachment.bin>
More information about the llvm-commits
mailing list