Don't lazily allocate eh_frame. We're not lazily allocating things like the LSDA...
authorDavid Chisnall <csdavec@swan.ac.uk>
Fri, 17 Feb 2012 16:32:07 +0000 (16:32 +0000)
committerDavid Chisnall <csdavec@swan.ac.uk>
Fri, 17 Feb 2012 16:32:07 +0000 (16:32 +0000)
Fix the type of eh_frame on Solaris so that Sun ld doesn't fail to combine them (thus making it impossible for the unwind library to find them and breaking exceptions).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@150814 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/MC/MCObjectFileInfo.h
lib/MC/MCObjectFileInfo.cpp

index e58e7d68f7fd55709e5c27dd880ff435a0ac55b8..7525f003fb09257bfd414a72a0368bad1d20a059 100644 (file)
@@ -284,8 +284,6 @@ public:
   const MCSection *getXDataSection() const { return XDataSection; }
 
   const MCSection *getEHFrameSection() {
-    if (!EHFrameSection)
-      InitEHFrameSection();
     return EHFrameSection;
   }
 
@@ -300,9 +298,6 @@ private:
   void InitELFMCObjectFileInfo(Triple T);
   void InitCOFFMCObjectFileInfo(Triple T);
 
-  /// InitEHFrameSection - Initialize EHFrameSection on demand.
-  ///
-  void InitEHFrameSection();
 };
 
 } // end namespace llvm
index 1b8653531e8293ed819ef96815a5073804e06395..3c3b50c134982da192bbe1299a2a751093e916c0 100644 (file)
@@ -142,6 +142,14 @@ void MCObjectFileInfo::InitMachOMCObjectFileInfo(Triple T) {
   }
 
   // Exception Handling.
+  EHFrameSection =
+    Ctx->getMachOSection("__TEXT", "__eh_frame",
+                         MCSectionMachO::S_COALESCED |
+                         MCSectionMachO::S_ATTR_NO_TOC |
+                         MCSectionMachO::S_ATTR_STRIP_STATIC_SYMS |
+                         MCSectionMachO::S_ATTR_LIVE_SUPPORT,
+                         SectionKind::getReadOnly());
+
   LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0,
                                      SectionKind::getReadOnlyWithRel());
 
@@ -339,6 +347,17 @@ void MCObjectFileInfo::InitELFMCObjectFileInfo(Triple T) {
 
   // Exception Handling Sections.
 
+  // Solaris requires different flags for .eh_frame to seemingly every other
+  // platform.
+  unsigned EHSectionFlags = ELF::SHF_ALLOC;
+  if (T.getOS() == Triple::Solaris)
+    EHSectionFlags |= ELF::SHF_WRITE;
+
+  EHFrameSection =
+    Ctx->getELFSection(".eh_frame", ELF::SHT_PROGBITS, 
+                       EHSectionFlags,
+                       SectionKind::getDataRel());
+
   // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
   // it contains relocatable pointers.  In PIC mode, this is probably a big
   // runtime hit for C++ apps.  Either the contents of the LSDA need to be
@@ -415,6 +434,13 @@ void MCObjectFileInfo::InitCOFFMCObjectFileInfo(Triple T) {
                         COFF::IMAGE_SCN_MEM_WRITE,
                         SectionKind::getDataRel());
 
+  EHFrameSection =
+    Ctx->getCOFFSection(".eh_frame",
+                        COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
+                        COFF::IMAGE_SCN_MEM_READ |
+                        COFF::IMAGE_SCN_MEM_WRITE,
+                        SectionKind::getDataRel());
+
   // FIXME: We're emitting LSDA info into a readonly section on COFF, even
   // though it contains relocatable pointers.  In PIC mode, this is probably a
   // big runtime hit for C++ apps.  Either the contents of the LSDA need to be
@@ -547,25 +573,3 @@ void MCObjectFileInfo::InitMCObjectFileInfo(StringRef TT, Reloc::Model relocm,
   }
 }
 
-void MCObjectFileInfo::InitEHFrameSection() {
-  if (Env == IsMachO)
-    EHFrameSection =
-      Ctx->getMachOSection("__TEXT", "__eh_frame",
-                           MCSectionMachO::S_COALESCED |
-                           MCSectionMachO::S_ATTR_NO_TOC |
-                           MCSectionMachO::S_ATTR_STRIP_STATIC_SYMS |
-                           MCSectionMachO::S_ATTR_LIVE_SUPPORT,
-                           SectionKind::getReadOnly());
-  else if (Env == IsELF)
-    EHFrameSection =
-      Ctx->getELFSection(".eh_frame", ELF::SHT_PROGBITS,
-                         ELF::SHF_ALLOC,
-                         SectionKind::getDataRel());
-  else
-    EHFrameSection =
-      Ctx->getCOFFSection(".eh_frame",
-                          COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
-                          COFF::IMAGE_SCN_MEM_READ |
-                          COFF::IMAGE_SCN_MEM_WRITE,
-                          SectionKind::getDataRel());
-}