[PATCH] D42471: [ARM] Fix lld crash introduced by r321154

vit9696 via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 24 05:27:00 PST 2018


vit9696 created this revision.
vit9696 added reviewers: rafael, peter.smith, ruiu, ikudrin.
vit9696 added a project: lld.
Herald added subscribers: llvm-commits, kristof.beyls, emaste, aemerson.

Since SyntheticSection::getParent() may return null, dereferencing this pointer in ARMExidxSentinelSection::empty() call from removeUnusedSyntheticSections() results in crashes when linking ARM binaries.

A check against null is added to ARMExidxSentinelSection::empty() similarly to SyntheticSection::getVA(). Another check is added to removeUnusedSyntheticSections, because in other functions (e.g. applySynthetic) getParent is normally checked first. While either change will fix the code, both of them seem reasonable to me.

Please commit this for me after review, since I do not have commit access.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D42471

Files:
  ELF/SyntheticSections.cpp
  ELF/Writer.cpp


Index: ELF/Writer.cpp
===================================================================
--- ELF/Writer.cpp
+++ ELF/Writer.cpp
@@ -1309,7 +1309,7 @@
     if (!SS)
       return;
     OutputSection *OS = SS->getParent();
-    if (!SS->empty() || !OS)
+    if (!OS || !SS->empty())
       continue;
 
     std::vector<BaseCommand *>::iterator Empty = OS->SectionCommands.end();
Index: ELF/SyntheticSections.cpp
===================================================================
--- ELF/SyntheticSections.cpp
+++ ELF/SyntheticSections.cpp
@@ -2585,12 +2585,13 @@
 
 // The sentinel has to be removed if there are no other .ARM.exidx entries.
 bool ARMExidxSentinelSection::empty() const {
-  OutputSection *OS = getParent();
-  for (auto *B : OS->SectionCommands)
-    if (auto *ISD = dyn_cast<InputSectionDescription>(B))
-      for (auto *S : ISD->Sections)
-        if (!isa<ARMExidxSentinelSection>(S))
-          return false;
+  if (OutputSection *OS = getParent()) {
+    for (auto *B : OS->SectionCommands)
+      if (auto *ISD = dyn_cast<InputSectionDescription>(B))
+        for (auto *S : ISD->Sections)
+          if (!isa<ARMExidxSentinelSection>(S))
+            return false;
+  }
   return true;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42471.131231.patch
Type: text/x-patch
Size: 1216 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180124/6dea0235/attachment.bin>


More information about the llvm-commits mailing list