summaryrefslogtreecommitdiffstats
path: root/llvm/tools
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/tools')
-rw-r--r--llvm/tools/llvm-objcopy/Object.cpp27
-rw-r--r--llvm/tools/llvm-objcopy/Object.h27
2 files changed, 20 insertions, 34 deletions
diff --git a/llvm/tools/llvm-objcopy/Object.cpp b/llvm/tools/llvm-objcopy/Object.cpp
index e4c268d115c..c7ce2309ffb 100644
--- a/llvm/tools/llvm-objcopy/Object.cpp
+++ b/llvm/tools/llvm-objcopy/Object.cpp
@@ -353,9 +353,9 @@ void DynamicRelocationSection::accept(SectionVisitor &Visitor) const {
Visitor.visit(*this);
}
-void SectionWithStrTab::removeSectionReferences(const SectionBase *Sec) {
- if (StrTab == Sec) {
- error("String table " + StrTab->Name +
+void Section::removeSectionReferences(const SectionBase *Sec) {
+ if (LinkSection == Sec) {
+ error("Section " + LinkSection->Name +
" cannot be removed because it is "
"referenced by the section " +
this->Name);
@@ -367,23 +367,18 @@ void GroupSection::finalize() {
this->Link = SymTab->Index;
}
-bool SectionWithStrTab::classof(const SectionBase *S) {
- return isa<DynamicSymbolTableSection>(S) || isa<DynamicSection>(S);
+void Section::initialize(SectionTableRef SecTable) {
+ if (Link != ELF::SHN_UNDEF)
+ LinkSection =
+ SecTable.getSection(Link, "Link field value " + Twine(Link) +
+ " in section " + Name + " is invalid");
}
-void SectionWithStrTab::initialize(SectionTableRef SecTable) {
- auto StrTab =
- SecTable.getSection(Link, "Link field value " + Twine(Link) +
- " in section " + Name + " is invalid");
- if (StrTab->Type != SHT_STRTAB) {
- error("Link field value " + Twine(Link) + " in section " + Name +
- " is not a string table");
- }
- setStrTab(StrTab);
+void Section::finalize() {
+ if (LinkSection)
+ this->Link = LinkSection->Index;
}
-void SectionWithStrTab::finalize() { this->Link = StrTab->Index; }
-
void GnuDebugLinkSection::init(StringRef File, StringRef Data) {
FileName = sys::path::filename(File);
// The format for the .gnu_debuglink starts with the file name and is
diff --git a/llvm/tools/llvm-objcopy/Object.h b/llvm/tools/llvm-objcopy/Object.h
index bf8b52244d8..ddc0da16aa4 100644
--- a/llvm/tools/llvm-objcopy/Object.h
+++ b/llvm/tools/llvm-objcopy/Object.h
@@ -259,11 +259,15 @@ class Section : public SectionBase {
MAKE_SEC_WRITER_FRIEND
ArrayRef<uint8_t> Contents;
+ SectionBase *LinkSection = nullptr;
public:
explicit Section(ArrayRef<uint8_t> Data) : Contents(Data) {}
void accept(SectionVisitor &Visitor) const override;
+ void removeSectionReferences(const SectionBase *Sec) override;
+ void initialize(SectionTableRef SecTable) override;
+ void finalize() override;
};
class OwnedDataSection : public SectionBase {
@@ -456,7 +460,7 @@ public:
void setFlagWord(ELF::Elf32_Word W) { FlagWord = W; }
void addMember(SectionBase *Sec) { GroupMembers.push_back(Sec); }
- void initialize(SectionTableRef SecTable) override {};
+ void initialize(SectionTableRef SecTable) override{};
void accept(SectionVisitor &) const override;
void finalize() override;
@@ -465,31 +469,18 @@ public:
}
};
-class SectionWithStrTab : public Section {
- const SectionBase *StrTab = nullptr;
- void setStrTab(const SectionBase *StringTable) { StrTab = StringTable; }
-
-public:
- explicit SectionWithStrTab(ArrayRef<uint8_t> Data) : Section(Data) {}
- void removeSectionReferences(const SectionBase *Sec) override;
- void initialize(SectionTableRef SecTable) override;
- void finalize() override;
- static bool classof(const SectionBase *S);
-};
-
-class DynamicSymbolTableSection : public SectionWithStrTab {
+class DynamicSymbolTableSection : public Section {
public:
- explicit DynamicSymbolTableSection(ArrayRef<uint8_t> Data)
- : SectionWithStrTab(Data) {}
+ explicit DynamicSymbolTableSection(ArrayRef<uint8_t> Data) : Section(Data) {}
static bool classof(const SectionBase *S) {
return S->Type == ELF::SHT_DYNSYM;
}
};
-class DynamicSection : public SectionWithStrTab {
+class DynamicSection : public Section {
public:
- explicit DynamicSection(ArrayRef<uint8_t> Data) : SectionWithStrTab(Data) {}
+ explicit DynamicSection(ArrayRef<uint8_t> Data) : Section(Data) {}
static bool classof(const SectionBase *S) {
return S->Type == ELF::SHT_DYNAMIC;
OpenPOWER on IntegriCloud