Reduce code duplication a bit. NFC
authorRafael Espindola <rafael.espindola@gmail.com>
Mon, 26 Mar 2018 18:49:31 +0000 (18:49 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Mon, 26 Mar 2018 18:49:31 +0000 (18:49 +0000)
llvm-svn: 328569

lld/ELF/InputSection.cpp
lld/ELF/LinkerScript.cpp
lld/ELF/Writer.cpp

index c65a5bb..5964c86 100644 (file)
@@ -330,7 +330,8 @@ template <class ELFT> void InputSection::copyShtGroup(uint8_t *Buf) {
 }
 
 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];
 }
index 3f9b24a..81ff5c4 100644 (file)
@@ -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);
index ffa2920..76bf661 100644 (file)
@@ -94,13 +94,13 @@ StringRef elf::getOutputSectionName(InputSectionBase *S) {
   // 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 :