OSDN Git Service

llvm-objcopy: Implement --extract-partition and --extract-main-partition.
authorPeter Collingbourne <peter@pcc.me.uk>
Fri, 7 Jun 2019 17:57:48 +0000 (17:57 +0000)
committerPeter Collingbourne <peter@pcc.me.uk>
Fri, 7 Jun 2019 17:57:48 +0000 (17:57 +0000)
commitf208621845a05c6d9eb0129230d961c21eca898d
tree8efe148eb23f61cfae5cbeabb984efade698fc3c
parent1ef5698ce17151998511b30393a8f0f7bf8eef0f
llvm-objcopy: Implement --extract-partition and --extract-main-partition.

This implements the functionality described in
https://lld.llvm.org/Partitions.html. It works as follows:

- Reads the section headers using the ELF header at file offset 0;
- If extracting a loadable partition:
  - Finds the section containing the required partition ELF header by looking it up in the section table;
  - Reads the ELF and program headers from the section.
- If extracting the main partition:
  - Reads the ELF and program headers from file offset 0.
- Filters the section table according to which sections are in the program headers that it read:
  - If ParentSegment != nullptr or section is not SHF_ALLOC, then it goes in.
  - Sections containing partition ELF headers or program headers are excluded as there are no headers for these in ordinary ELF files.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@362818 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/BinaryFormat/ELF.h
test/tools/llvm-objcopy/ELF/Inputs/partitions.elf [new file with mode: 0644]
test/tools/llvm-objcopy/ELF/Inputs/partitions.elf.test [new file with mode: 0644]
test/tools/llvm-objcopy/ELF/partitions.test [new file with mode: 0644]
tools/llvm-objcopy/CopyConfig.cpp
tools/llvm-objcopy/CopyConfig.h
tools/llvm-objcopy/ELF/ELFObjcopy.cpp
tools/llvm-objcopy/ELF/Object.cpp
tools/llvm-objcopy/ELF/Object.h
tools/llvm-objcopy/ObjcopyOpts.td