From f208621845a05c6d9eb0129230d961c21eca898d Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Fri, 7 Jun 2019 17:57:48 +0000 Subject: [PATCH] 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 | 2 + test/tools/llvm-objcopy/ELF/Inputs/partitions.elf | Bin 0 -> 26864 bytes .../llvm-objcopy/ELF/Inputs/partitions.elf.test | 28 +++ test/tools/llvm-objcopy/ELF/partitions.test | 187 +++++++++++++++++++++ tools/llvm-objcopy/CopyConfig.cpp | 9 + tools/llvm-objcopy/CopyConfig.h | 2 + tools/llvm-objcopy/ELF/ELFObjcopy.cpp | 12 +- tools/llvm-objcopy/ELF/Object.cpp | 87 ++++++---- tools/llvm-objcopy/ELF/Object.h | 16 +- tools/llvm-objcopy/ObjcopyOpts.td | 7 + 10 files changed, 314 insertions(+), 36 deletions(-) create mode 100644 test/tools/llvm-objcopy/ELF/Inputs/partitions.elf create mode 100644 test/tools/llvm-objcopy/ELF/Inputs/partitions.elf.test create mode 100644 test/tools/llvm-objcopy/ELF/partitions.test diff --git a/include/llvm/BinaryFormat/ELF.h b/include/llvm/BinaryFormat/ELF.h index 1ad586684df..5d397c7e31e 100644 --- a/include/llvm/BinaryFormat/ELF.h +++ b/include/llvm/BinaryFormat/ELF.h @@ -843,6 +843,8 @@ enum : unsigned { // for safe ICF. SHT_LLVM_DEPENDENT_LIBRARIES = 0x6fff4c04, // LLVM Dependent Library Specifiers. SHT_LLVM_SYMPART = 0x6fff4c05, // Symbol partition specification. + SHT_LLVM_PART_EHDR = 0x6fff4c06, // ELF header for loadable partition. + SHT_LLVM_PART_PHDR = 0x6fff4c07, // Phdrs for loadable partition. // Android's experimental support for SHT_RELR sections. // https://android.googlesource.com/platform/bionic/+/b7feec74547f84559a1467aca02708ff61346d2a/libc/include/elf.h#512 SHT_ANDROID_RELR = 0x6fffff00, // Relocation entries; only offsets. diff --git a/test/tools/llvm-objcopy/ELF/Inputs/partitions.elf b/test/tools/llvm-objcopy/ELF/Inputs/partitions.elf new file mode 100644 index 0000000000000000000000000000000000000000..4b693b386526d20add09c9051224351d001d48d8 GIT binary patch literal 26864 zcmeHQO>bL86uogv6F`7fK$tISShC>Bb~nHR9->r2GRWQE_L@`47P;5ji71bLg zmR^9w&)^Rrkl19wKVZ!gR)Dg?%)N8Z^Ye2IL~RhDGm_t#xpU9lnKN!Gdu}Fo-|Agy ztgQ)3LtYbWHG`RQ@A#_lN`zcqmW}v)UY?Z;v3=fbsXv!s72vl%G;kxiiJFx+FTtw` zKX0TaP@1W&ya%-EZSi>mJ)Dhij0#WZD#5G~z2Z1=GZ5qJc*>h@#)p<^Feov#D)UJO zo&IU!L6>Vkj<-yg-~+FiXLWw+c{TDZp409Xblpu|0rd3&)sELQWsvh5YP&S};U`_U zzO=niZj8po;aCphqhrsm{4$%(CND*=w#d)1K7K#d7kF$?0V+TRr~nn90#twsPys4H z1*pJ%QQ*7pS*QRNpaN8Y3Qz$mKn17(6`%rCfC^B7|GNTD*1kn3&yX9zdLH)vmZP1$ z$NJFwA9DK>j=%ms+t+H_`*FtK_qMwcr~nn90#twsPys4H1*iZOpaN8Y3Q&Q6P=UL( z{Qq;v|MxlMC(K3j|JNn;==TK+`Ty-;jNI`vPXq@dFI*Ad4H&`w#qm{5B98@F&3Cu& zD3Jf32lErhX=(|u&YObQcOKAr$ioL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