[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
Wed Dec 4 14:48:13 PST 2019


MaskRay created this revision.
MaskRay added reviewers: jakehehrlich, jhenderson, rupprecht.
Herald added subscribers: llvm-commits, seiya, abrachet, arichardson, emaste.
Herald added a reviewer: espindola.
Herald added a reviewer: alexshap.
Herald added a project: LLVM.
MaskRay updated this revision to Diff 232219.
MaskRay added a comment.

Delete unneeded parts of the test


.text sh_address=0x1000 sh_offset=0x1000
.data sh_address=0x3000 sh_offset=0x2000

In an objcopy -O binary output, the distance between two sections equal
their LMA differences (0x3000-0x1000), instead of their sh_offset
differences (0x2000-0x1000). This patch changes our behavior to match
GNU.

This rule gets more complex when the containing PT_LOAD has
p_vaddr!=p_paddr. GNU objcopy essentially computes
sh_address-p_paddr+p_vaddr for each candidate section, and removes the
gap before the first address.

Added two tests to binary-paddr.test to catch the compatibility problem.


Repository:
  rG LLVM Github Monorepo

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.232219.patch
Type: text/x-patch
Size: 7258 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191204/5ee93fee/attachment.bin>


More information about the llvm-commits mailing list