diff options
author | Jake Ehrlich <jakehehrlich@google.com> | 2017-10-11 02:42:29 +0000 |
---|---|---|
committer | Jake Ehrlich <jakehehrlich@google.com> | 2017-10-11 02:42:29 +0000 |
commit | d9a283463a2a3688d355a7fd0bdb9ae2b13d6baf (patch) | |
tree | 11278d0e196b1ec9491870f4023a77da7653bb4b /llvm/tools/llvm-objcopy/Object.cpp | |
parent | 183aa2731e08ed8c46eb82386d8bcbf33fa88762 (diff) | |
download | bcm5719-llvm-d9a283463a2a3688d355a7fd0bdb9ae2b13d6baf.tar.gz bcm5719-llvm-d9a283463a2a3688d355a7fd0bdb9ae2b13d6baf.zip |
Revert "[llvm-objcopy] Add support for --strip-sections to remove all section headers leaving only program headers and loadable segment data"
This reverts commit rL315412
llvm-svn: 315417
Diffstat (limited to 'llvm/tools/llvm-objcopy/Object.cpp')
-rw-r--r-- | llvm/tools/llvm-objcopy/Object.cpp | 45 |
1 files changed, 17 insertions, 28 deletions
diff --git a/llvm/tools/llvm-objcopy/Object.cpp b/llvm/tools/llvm-objcopy/Object.cpp index 797d8f961e4..2bd3aa16f0b 100644 --- a/llvm/tools/llvm-objcopy/Object.cpp +++ b/llvm/tools/llvm-objcopy/Object.cpp @@ -575,20 +575,14 @@ void Object<ELFT>::writeHeader(FileOutputBuffer &Out) const { Ehdr.e_version = Version; Ehdr.e_entry = Entry; Ehdr.e_phoff = sizeof(Elf_Ehdr); + Ehdr.e_shoff = SHOffset; Ehdr.e_flags = Flags; Ehdr.e_ehsize = sizeof(Elf_Ehdr); Ehdr.e_phentsize = sizeof(Elf_Phdr); Ehdr.e_phnum = Segments.size(); Ehdr.e_shentsize = sizeof(Elf_Shdr); - if (WriteSectionHeaders) { - Ehdr.e_shoff = SHOffset; - Ehdr.e_shnum = Sections.size() + 1; - Ehdr.e_shstrndx = SectionNames->Index; - } else { - Ehdr.e_shoff = 0; - Ehdr.e_shnum = 0; - Ehdr.e_shstrndx = 0; - } + Ehdr.e_shnum = Sections.size() + 1; + Ehdr.e_shstrndx = SectionNames->Index; } template <class ELFT> @@ -639,10 +633,12 @@ void Object<ELFT>::removeSections( if (SymbolTable != nullptr && ToRemove(*SymbolTable)) SymbolTable = nullptr; if (ToRemove(*SectionNames)) { - if (WriteSectionHeaders) - error("Cannot remove " + SectionNames->Name + - " because it is the section header string table."); - SectionNames = nullptr; + // Right now llvm-objcopy always outputs section headers. This will not + // always be the case. Eventully the section header table will become + // optional and if no section header is output then there dosn't need to be + // a section header string table. + error("Cannot remove " + SectionNames->Name + + " because it is the section header string table."); } // Now make sure there are no remaining references to the sections that will // be removed. Sometimes it is impossible to remove a reference so we emit @@ -736,34 +732,29 @@ template <class ELFT> void ELFObject<ELFT>::assignOffsets() { } } - if (this->WriteSectionHeaders) { - Offset = alignTo(Offset, sizeof(typename ELFT::Addr)); - } + Offset = alignTo(Offset, sizeof(typename ELFT::Addr)); this->SHOffset = Offset; } template <class ELFT> size_t ELFObject<ELFT>::totalSize() const { // We already have the section header offset so we can calculate the total // size by just adding up the size of each section header. - auto NullSectionSize = this->WriteSectionHeaders ? sizeof(Elf_Shdr) : 0; return this->SHOffset + this->Sections.size() * sizeof(Elf_Shdr) + - NullSectionSize; + sizeof(Elf_Shdr); } template <class ELFT> void ELFObject<ELFT>::write(FileOutputBuffer &Out) const { this->writeHeader(Out); this->writeProgramHeaders(Out); this->writeSectionData(Out); - if (this->WriteSectionHeaders) - this->writeSectionHeaders(Out); + this->writeSectionHeaders(Out); } template <class ELFT> void ELFObject<ELFT>::finalize() { // Make sure we add the names of all the sections. - if (this->SectionNames != nullptr) - for (const auto &Section : this->Sections) { - this->SectionNames->addString(Section->Name); - } + for (const auto &Section : this->Sections) { + this->SectionNames->addString(Section->Name); + } // Make sure we add the names of all the symbols. if (this->SymbolTable != nullptr) this->SymbolTable->addSymbolNames(); @@ -772,16 +763,14 @@ template <class ELFT> void ELFObject<ELFT>::finalize() { assignOffsets(); // Finalize SectionNames first so that we can assign name indexes. - if (this->SectionNames != nullptr) - this->SectionNames->finalize(); + this->SectionNames->finalize(); // Finally now that all offsets and indexes have been set we can finalize any // remaining issues. uint64_t Offset = this->SHOffset + sizeof(Elf_Shdr); for (auto &Section : this->Sections) { Section->HeaderOffset = Offset; Offset += sizeof(Elf_Shdr); - if (this->WriteSectionHeaders) - Section->NameIndex = this->SectionNames->findIndex(Section->Name); + Section->NameIndex = this->SectionNames->findIndex(Section->Name); Section->finalize(); } } |