[lld] r328569 - Reduce code duplication a bit. NFC
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 26 11:49:31 PDT 2018
Author: rafael
Date: Mon Mar 26 11:49:31 2018
New Revision: 328569
URL: http://llvm.org/viewvc/llvm-project?rev=328569&view=rev
Log:
Reduce code duplication a bit. NFC
Modified:
lld/trunk/ELF/InputSection.cpp
lld/trunk/ELF/LinkerScript.cpp
lld/trunk/ELF/Writer.cpp
Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=328569&r1=328568&r2=328569&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Mon Mar 26 11:49:31 2018
@@ -330,7 +330,8 @@ template <class ELFT> void InputSection:
}
InputSectionBase *InputSection::getRelocatedSection() {
- assert(Type == SHT_RELA || Type == SHT_REL);
+ if (!File || (Type != SHT_RELA && Type != SHT_REL))
+ return nullptr;
ArrayRef<InputSectionBase *> Sections = File->getSections();
return Sections[Info];
}
Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=328569&r1=328568&r2=328569&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Mon Mar 26 11:49:31 2018
@@ -665,9 +665,8 @@ void LinkerScript::addOrphanSections() {
// to create target sections first. We do not want priority handling
// for synthetic sections because them are special.
for (InputSectionBase *IS : InputSections) {
- if ((IS->Type == SHT_REL || IS->Type == SHT_RELA) &&
- !isa<SyntheticSection>(IS))
- if (auto *Rel = cast<InputSection>(IS)->getRelocatedSection())
+ if (auto *Sec = dyn_cast<InputSection>(IS))
+ if (InputSectionBase *Rel = Sec->getRelocatedSection())
if (auto *RelIS = dyn_cast_or_null<InputSectionBase>(Rel->Parent))
Add(RelIS);
Add(IS);
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=328569&r1=328568&r2=328569&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Mon Mar 26 11:49:31 2018
@@ -94,13 +94,13 @@ StringRef elf::getOutputSectionName(Inpu
// This is for --emit-relocs. If .text.foo is emitted as .text.bar, we want
// to emit .rela.text.foo as .rela.text.bar for consistency (this is not
// technically required, but not doing it is odd). This code guarantees that.
- if ((S->Type == SHT_REL || S->Type == SHT_RELA) &&
- !isa<SyntheticSection>(S)) {
- OutputSection *Out =
- cast<InputSection>(S)->getRelocatedSection()->getOutputSection();
- if (S->Type == SHT_RELA)
- return Saver.save(".rela" + Out->Name);
- return Saver.save(".rel" + Out->Name);
+ if (auto *IS = dyn_cast<InputSection>(S)) {
+ if (InputSectionBase *Rel = IS->getRelocatedSection()) {
+ OutputSection *Out = Rel->getOutputSection();
+ if (S->Type == SHT_RELA)
+ return Saver.save(".rela" + Out->Name);
+ return Saver.save(".rel" + Out->Name);
+ }
}
for (StringRef V :
More information about the llvm-commits
mailing list