llvm-project/llvm/tools/llvm-objcopy
Fangrui Song d28c6d51d1 [llvm-objcopy][ELF] -O binary: use LMA instead of sh_offset to decide where to write section contents
.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_offset-p_offset+p_paddr for each candidate section, and removes the
gap before the first address.

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

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D71035
2019-12-15 21:45:25 -08:00
..
COFF [llvm-objcopy] [COFF] Fix a typo in a comment. NFC. 2019-11-27 10:44:42 +02:00
ELF [llvm-objcopy][ELF] -O binary: use LMA instead of sh_offset to decide where to write section contents 2019-12-15 21:45:25 -08:00
MachO [llvm-objcopy][MachO] Implement --add-section 2019-12-16 14:07:29 +09:00
Buffer.cpp [llvm-objcopy][NFC] Remove unnecessary llvm-objcopy.h #includes 2019-03-13 23:40:16 +00:00
Buffer.h [llvm-objcopy] Fix crash when writing empty binary output 2019-01-28 15:02:40 +00:00
CMakeLists.txt Introduce llvm-install-name-tool 2019-11-19 23:42:37 -08:00
CommonOpts.td [llvm-objcopy][ELF] Implement --only-keep-debug 2019-11-05 08:56:15 -08:00
CopyConfig.cpp Introduce llvm-install-name-tool 2019-11-19 23:42:37 -08:00
CopyConfig.h Introduce llvm-install-name-tool 2019-11-19 23:42:37 -08:00
InstallNameToolOpts.td Introduce llvm-install-name-tool 2019-11-19 23:42:37 -08:00
LLVMBuild.txt Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
ObjcopyOpts.td [llvm-objcopy] Add --set-section-alignment 2019-10-02 12:41:25 +00:00
StripOpts.td [llvm-objcopy] Move duplicate tablegen from objcopy and strip into one file 2019-08-15 04:45:41 +00:00
llvm-objcopy.cpp Introduce llvm-install-name-tool 2019-11-19 23:42:37 -08:00
llvm-objcopy.h Small refactoring of FileError. NFC. 2019-02-11 09:49:37 +00:00