mirror of
https://github.com/RPCS3/llvm.git
synced 2025-05-13 08:56:04 +00:00
[llvm-objcopy] Add -strip-non-alloc option to remove all non-allocated sections
This change adds a new flag not present in GNU objcopy that we call --strip-non-alloc. Differential Revision: https://reviews.llvm.org/D39926 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@318168 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
eb711fee66
commit
168e9744a4
26
test/tools/llvm-objcopy/strip-non-alloc.test
Normal file
26
test/tools/llvm-objcopy/strip-non-alloc.test
Normal file
@ -0,0 +1,26 @@
|
||||
# RUN: yaml2obj %s > %t
|
||||
# RUN: llvm-objcopy --strip-non-alloc %t %t2
|
||||
# RUN: llvm-readobj -file-headers -sections %t2 | FileCheck %s
|
||||
|
||||
!ELF
|
||||
FileHeader:
|
||||
Class: ELFCLASS64
|
||||
Data: ELFDATA2LSB
|
||||
Type: ET_REL
|
||||
Machine: EM_X86_64
|
||||
Sections:
|
||||
- Name: .bss
|
||||
Type: SHT_NOBITS
|
||||
Flags: [ SHF_ALLOC ]
|
||||
- Name: .text
|
||||
Type: SHT_PROGBITS
|
||||
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
|
||||
- Name: .blarg
|
||||
Type: SHT_PROGBITS
|
||||
Flags: [ ]
|
||||
|
||||
# CHECK: SectionHeaderCount: 4
|
||||
|
||||
# CHECK: Name: .bss
|
||||
# CHECK: Name: .text
|
||||
# CHECK: Name: .shstrtab
|
@ -87,6 +87,8 @@ static cl::opt<bool> StripDebug("strip-debug",
|
||||
cl::desc("Removes all debug information"));
|
||||
static cl::opt<bool> StripSections("strip-sections",
|
||||
cl::desc("Remove all section headers"));
|
||||
static cl::opt<bool> StripNonAlloc("strip-non-alloc",
|
||||
cl::desc("Remove all non-allocated sections"));
|
||||
static cl::opt<bool>
|
||||
StripDWO("strip-dwo", cl::desc("remove all DWARF .dwo sections from file"));
|
||||
static cl::opt<bool> ExtractDWO(
|
||||
@ -206,6 +208,15 @@ void CopyBinary(const ELFObjectFile<ELFT> &ObjFile) {
|
||||
};
|
||||
}
|
||||
|
||||
if (StripNonAlloc)
|
||||
RemovePred = [RemovePred, &Obj](const SectionBase &Sec) {
|
||||
if (RemovePred(Sec))
|
||||
return true;
|
||||
if (&Sec == Obj->getSectionHeaderStrTab())
|
||||
return false;
|
||||
return (Sec.Flags & SHF_ALLOC) == 0;
|
||||
};
|
||||
|
||||
Obj->removeSections(RemovePred);
|
||||
Obj->finalize();
|
||||
WriteObjectFile(*Obj, OutputFilename.getValue());
|
||||
|
Loading…
x
Reference in New Issue
Block a user