[lld] r263395 - ELF: Split initializeSections and add comments.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Sun Mar 13 14:52:57 PDT 2016
Author: ruiu
Date: Sun Mar 13 16:52:57 2016
New Revision: 263395
URL: http://llvm.org/viewvc/llvm-project?rev=263395&view=rev
Log:
ELF: Split initializeSections and add comments.
Modified:
lld/trunk/ELF/InputFiles.cpp
lld/trunk/ELF/InputFiles.h
Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=263395&r1=263394&r2=263395&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Sun Mar 13 16:52:57 2016
@@ -202,31 +202,30 @@ void elf::ObjectFile<ELFT>::initializeSe
break;
case SHT_RELA:
case SHT_REL: {
- uint32_t RelocatedSectionIndex = Sec.sh_info;
- if (RelocatedSectionIndex >= Size)
- fatal("invalid relocated section index");
- InputSectionBase<ELFT> *RelocatedSection =
- Sections[RelocatedSectionIndex];
- // Strictly speaking, a relocation section must be included in the
- // group of the section it relocates. However, LLVM 3.3 and earlier
- // would fail to do so, so we gracefully handle that case.
- if (RelocatedSection == InputSection<ELFT>::Discarded)
- continue;
- if (!RelocatedSection)
- fatal("unsupported relocation reference");
+ // This section contains relocation information.
+ // If -r is given, we do not interpret or apply relocation
+ // but just copy relocation sections to output.
if (Config->Relocatable) {
- // For -r, relocation sections are handled as regular input sections.
Sections[I] = new (Alloc) InputSection<ELFT>(this, &Sec);
- } else if (auto *S = dyn_cast<InputSection<ELFT>>(RelocatedSection)) {
+ break;
+ }
+
+ // Find the relocation target section and associate this
+ // section with it.
+ InputSectionBase<ELFT> *Target = getRelocTarget(Sec);
+ if (!Target)
+ break;
+ if (auto *S = dyn_cast<InputSection<ELFT>>(Target)) {
S->RelocSections.push_back(&Sec);
- } else if (auto *S = dyn_cast<EHInputSection<ELFT>>(RelocatedSection)) {
+ break;
+ }
+ if (auto *S = dyn_cast<EHInputSection<ELFT>>(Target)) {
if (S->RelocSection)
fatal("multiple relocation sections to .eh_frame are not supported");
S->RelocSection = &Sec;
- } else {
- fatal("relocations pointing to SHF_MERGE are not supported");
+ break;
}
- break;
+ fatal("relocations pointing to SHF_MERGE are not supported");
}
default:
Sections[I] = createInputSection(Sec);
@@ -235,6 +234,25 @@ void elf::ObjectFile<ELFT>::initializeSe
}
template <class ELFT>
+InputSectionBase<ELFT> *
+elf::ObjectFile<ELFT>::getRelocTarget(const Elf_Shdr &Sec) {
+ uint32_t Idx = Sec.sh_info;
+ if (Idx >= Sections.size())
+ fatal("invalid relocated section index");
+ InputSectionBase<ELFT> *Target = Sections[Idx];
+
+ // Strictly speaking, a relocation section must be included in the
+ // group of the section it relocates. However, LLVM 3.3 and earlier
+ // would fail to do so, so we gracefully handle that case.
+ if (Target == InputSection<ELFT>::Discarded)
+ return nullptr;
+
+ if (!Target)
+ fatal("unsupported relocation reference");
+ return Target;
+}
+
+template <class ELFT>
InputSectionBase<ELFT> *
elf::ObjectFile<ELFT>::createInputSection(const Elf_Shdr &Sec) {
StringRef Name = check(this->ELFObj.getSectionName(&Sec));
Modified: lld/trunk/ELF/InputFiles.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.h?rev=263395&r1=263394&r2=263395&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.h (original)
+++ lld/trunk/ELF/InputFiles.h Sun Mar 13 16:52:57 2016
@@ -139,6 +139,7 @@ public:
private:
void initializeSections(llvm::DenseSet<StringRef> &ComdatGroups);
void initializeSymbols();
+ InputSectionBase<ELFT> *getRelocTarget(const Elf_Shdr &Sec);
InputSectionBase<ELFT> *createInputSection(const Elf_Shdr &Sec);
SymbolBody *createSymbolBody(const Elf_Sym *Sym);
More information about the llvm-commits
mailing list