[lld] r320599 - Move Repl check to a symbol method.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 13 09:46:30 PST 2017


Author: rafael
Date: Wed Dec 13 09:46:29 2017
New Revision: 320599

URL: http://llvm.org/viewvc/llvm-project?rev=320599&view=rev
Log:
Move Repl check to a symbol method.

Having a SectionBase method check Repl is inconsistent with how we
handle other section information.

For example, if a section is replaced, Sec->Live is false and it is
natural for Sec->getOutputSection() to be null.

It is the symbol that is moved to the replacement section.

Modified:
    lld/trunk/ELF/InputSection.cpp
    lld/trunk/ELF/Symbols.cpp

Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=320599&r1=320598&r2=320599&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Wed Dec 13 09:46:29 2017
@@ -186,7 +186,7 @@ uint64_t SectionBase::getOffset(uint64_t
 OutputSection *SectionBase::getOutputSection() {
   InputSection *Sec;
   if (auto *IS = dyn_cast<InputSection>(this))
-    Sec = cast<InputSection>(IS->Repl);
+    return IS->getParent();
   else if (auto *MS = dyn_cast<MergeInputSection>(this))
     Sec = MS->getParent();
   else if (auto *EH = dyn_cast<EhInputSection>(this))

Modified: lld/trunk/ELF/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.cpp?rev=320599&r1=320598&r2=320599&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.cpp (original)
+++ lld/trunk/ELF/Symbols.cpp Wed Dec 13 09:46:29 2017
@@ -161,8 +161,11 @@ uint64_t Symbol::getSize() const {
 
 OutputSection *Symbol::getOutputSection() const {
   if (auto *S = dyn_cast<Defined>(this)) {
-    if (S->Section)
-      return S->Section->getOutputSection();
+    if (auto *Sec = S->Section) {
+      if (auto *IS = dyn_cast<InputSection>(Sec))
+        Sec = IS->Repl;
+      return Sec->getOutputSection();
+    }
     return nullptr;
   }
 




More information about the llvm-commits mailing list