OSDN Git Service

[llvm-objcopy] Fix handling of zero-size segments in llvm-objcopy
authorJake Ehrlich <jakehehrlich@google.com>
Wed, 14 Feb 2018 23:31:33 +0000 (23:31 +0000)
committerJake Ehrlich <jakehehrlich@google.com>
Wed, 14 Feb 2018 23:31:33 +0000 (23:31 +0000)
commit2785020fa23868a202e9f0212513c731226d59ee
tree62745b10a2d58558f10780f1619411466f3cdba0
parent4ba06d7558ac34e13ed4d32b9ac9e21b5e8c20da
[llvm-objcopy] Fix handling of zero-size segments in llvm-objcopy

Some ELF files produced by lld may have zero-size segment placeholders as shown
below. Since GNU_STACK Offset is 0, the current code makes it the lowest used
offset, and relocates all the segments over the ELF header. The resulting
binary is total garbage.

This change fixes how llvm-objcopy handles PT_PHDR properlly by treating ELF
headers and the program header table as segments to allow the layout algorithm
decide where those should go.

Author: vit9696

Differential Revision: https://reviews.llvm.org/D42872

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@325189 91177308-0d34-0410-b5e6-96231b3b80d8
test/tools/llvm-objcopy/marker-segment.test [new file with mode: 0644]
tools/llvm-objcopy/Object.cpp
tools/llvm-objcopy/Object.h