Index: tools/llvm-objcopy/Object.h =================================================================== --- tools/llvm-objcopy/Object.h +++ tools/llvm-objcopy/Object.h @@ -130,6 +130,8 @@ void finalize() override; void writeSection(llvm::FileOutputBuffer &Out) const override; static bool classof(const SectionBase *S) { + if (S->Flags & llvm::ELF::SHF_ALLOC) + return false; return S->Type == llvm::ELF::SHT_STRTAB; } }; @@ -246,11 +248,11 @@ class SectionWithStrTab : public Section { private: - StringTableSection *StrTab = nullptr; + const SectionBase *StrTab = nullptr; public: SectionWithStrTab(llvm::ArrayRef Data) : Section(Data) {} - void setStrTab(StringTableSection *StringTable) { StrTab = StringTable; } + void setStrTab(const SectionBase *StringTable) { StrTab = StringTable; } void removeSectionReferences(const SectionBase *Sec) override; void initialize(SectionTableRef SecTable) override; void finalize() override; Index: tools/llvm-objcopy/Object.cpp =================================================================== --- tools/llvm-objcopy/Object.cpp +++ tools/llvm-objcopy/Object.cpp @@ -301,11 +301,9 @@ } void SectionWithStrTab::initialize(SectionTableRef SecTable) { - setStrTab(SecTable.getSectionOfType( - Link, - "Link field value " + Twine(Link) + " in section " + Name + " is invalid", - "Link field value " + Twine(Link) + " in section " + Name + - " is not a string table")); + setStrTab(SecTable.getSection(Link, + "Link field value " + Twine(Link) + + " in section " + Name + " is invalid")); } void SectionWithStrTab::finalize() { this->Link = StrTab->Index; } @@ -547,15 +545,6 @@ initRelocations(RelSec, SymbolTable, unwrapOrError(ElfFile.relas(Shdr))); } - - if (auto Sec = dyn_cast(Section.get())) { - Sec->setStrTab(SecTable.getSectionOfType( - Sec->Link, - "Link field value " + Twine(Sec->Link) + " in section " + Sec->Name + - " is invalid", - "Link field value " + Twine(Sec->Link) + " in section " + Sec->Name + - " is not a string table")); - } } return SecTable;