Avoid using EhFrameHdr->Sections.
authorRafael Espindola <rafael.espindola@gmail.com>
Fri, 26 May 2017 17:28:17 +0000 (17:28 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Fri, 26 May 2017 17:28:17 +0000 (17:28 +0000)
This is a necessary step for moving clearOutputSections earlier.

llvm-svn: 304009

lld/ELF/Writer.cpp

index eae5337..7e0b0f1 100644 (file)
@@ -1785,7 +1785,9 @@ template <class ELFT> void Writer<ELFT>::writeSections() {
   }
 
   OutputSection *EhFrameHdr =
-      In<ELFT>::EhFrameHdr ? In<ELFT>::EhFrameHdr->OutSec : nullptr;
+      (In<ELFT>::EhFrameHdr && !In<ELFT>::EhFrameHdr->empty())
+          ? In<ELFT>::EhFrameHdr->OutSec
+          : nullptr;
 
   // In -r or -emit-relocs mode, write the relocation sections first as in
   // ELf_Rel targets we might find out that we need to modify the relocated
@@ -1811,7 +1813,7 @@ template <class ELFT> void Writer<ELFT>::writeSections() {
 
   // The .eh_frame_hdr depends on .eh_frame section contents, therefore
   // it should be written after .eh_frame is written.
-  if (EhFrameHdr && !EhFrameHdr->Sections.empty()) {
+  if (EhFrameHdr) {
     OutputSectionCommand *Cmd = Script->getCmd(EhFrameHdr);
     Cmd->writeTo<ELFT>(Buf + EhFrameHdr->Offset);
   }