summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2017-05-01 20:49:09 +0000
committerRui Ueyama <ruiu@google.com>2017-05-01 20:49:09 +0000
commit92a8d798b8d2b9333c6ad0cbfbd9d5d4b91aa9d2 (patch)
tree223bb5f462352b2f3944cb7c1b6c5749a21df932
parentc15d60b772b1d02134b3d3bdd8e456ed33674279 (diff)
downloadbcm5719-llvm-92a8d798b8d2b9333c6ad0cbfbd9d5d4b91aa9d2.tar.gz
bcm5719-llvm-92a8d798b8d2b9333c6ad0cbfbd9d5d4b91aa9d2.zip
Add comments about how we handle mergeable sections with relocations.
Also factored out code. llvm-svn: 301833
-rw-r--r--lld/ELF/InputFiles.cpp24
1 files changed, 18 insertions, 6 deletions
diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp
index 2f4d8f106e8..9f14adda409 100644
--- a/lld/ELF/InputFiles.cpp
+++ b/lld/ELF/InputFiles.cpp
@@ -361,6 +361,15 @@ InputSectionBase *elf::ObjectFile<ELFT>::getRelocTarget(const Elf_Shdr &Sec) {
return Target;
}
+// Create a regular InputSection class that has the same contents
+// as a given section.
+InputSectionBase *toRegularSection(MergeInputSection *Sec) {
+ auto *Ret = make<InputSection>(Sec->Flags, Sec->Type, Sec->Alignment,
+ Sec->Data, Sec->Name);
+ Ret->File = Sec->File;
+ return Ret;
+}
+
template <class ELFT>
InputSectionBase *
elf::ObjectFile<ELFT>::createInputSection(const Elf_Shdr &Sec,
@@ -398,12 +407,15 @@ elf::ObjectFile<ELFT>::createInputSection(const Elf_Shdr &Sec,
if (Target->FirstRelocation)
fatal(toString(this) +
": multiple relocation sections to one section are not supported");
- if (isa<MergeInputSection>(Target)) {
- this->Sections[Sec.sh_info] =
- make<InputSection>(Target->Flags, Target->Type, Target->Alignment,
- Target->Data, Target->Name);
- this->Sections[Sec.sh_info]->File = Target->File;
- Target = this->Sections[Sec.sh_info];
+
+ // Mergeable sections with relocations are tricky because relocations
+ // need to be taken into account when comparing section contents for
+ // merging. The MergeInputSection class currently doesn't care about
+ // relocations, and it's unlikely to support it in future because such
+ // sections are rare. We simply handle such sections as non-mergeable.
+ if (auto *MS = dyn_cast<MergeInputSection>(Target)) {
+ Target = toRegularSection(MS);
+ this->Sections[Sec.sh_info] = Target;
}
size_t NumRelocations;
OpenPOWER on IntegriCloud