diff options
| author | Peter Collingbourne <peter@pcc.me.uk> | 2019-06-07 17:57:48 +0000 |
|---|---|---|
| committer | Peter Collingbourne <peter@pcc.me.uk> | 2019-06-07 17:57:48 +0000 |
| commit | 8d58a98c594bb472b01158ba825cd632650ec2be (patch) | |
| tree | 732ab6f7744e8e10e3f791d336d68550a35aee08 /llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp | |
| parent | 076ad57f8dbb7a26b6c17d5d2de0060f9f1e0ad6 (diff) | |
| download | bcm5719-llvm-8d58a98c594bb472b01158ba825cd632650ec2be.tar.gz bcm5719-llvm-8d58a98c594bb472b01158ba825cd632650ec2be.zip | |
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
llvm-svn: 362818
Diffstat (limited to 'llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp')
| -rw-r--r-- | llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp b/llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp index efb8f0582ec..adc7a9587ff 100644 --- a/llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp +++ b/llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp @@ -507,6 +507,16 @@ static Error replaceAndRemoveSections(const CopyConfig &Config, Object &Obj) { return (Sec.Flags & SHF_ALLOC) == 0; }; + if (Config.ExtractPartition || Config.ExtractMainPartition) { + RemovePred = [RemovePred, &Obj](const SectionBase &Sec) { + if (RemovePred(Sec)) + return true; + if (Sec.Type == SHT_LLVM_PART_EHDR || Sec.Type == SHT_LLVM_PART_PHDR) + return true; + return (Sec.Flags & SHF_ALLOC) != 0 && !Sec.ParentSegment; + }; + } + // Explicit copies: if (!Config.OnlySection.empty()) { RemovePred = [&Config, RemovePred, &Obj](const SectionBase &Sec) { @@ -747,7 +757,7 @@ Error executeObjcopyOnRawBinary(const CopyConfig &Config, MemoryBuffer &In, Error executeObjcopyOnBinary(const CopyConfig &Config, object::ELFObjectFileBase &In, Buffer &Out) { - ELFReader Reader(&In); + ELFReader Reader(&In, Config.ExtractPartition); std::unique_ptr<Object> Obj = Reader.create(); // Prefer OutputArch (-O<format>) if set, otherwise infer it from the input. const ElfType OutputElfType = |

