[mips] Make TTypeEncoding indirect to allow .eh_frame to be read-only.
authorDaniel Sanders <daniel.sanders@imgtec.com>
Tue, 26 May 2015 10:19:18 +0000 (10:19 +0000)
committerDaniel Sanders <daniel.sanders@imgtec.com>
Tue, 26 May 2015 10:19:18 +0000 (10:19 +0000)
Summary:
Following on from r209907 which made personality encodings indirect, do the
same for TType encodings. This fixes the case where a try/catch block needs
to generate references to, for example, std::exception in the
.gcc_except_table.

This commit uses DW_EH_PE_sdata8 for N64 as far as is possible at the moment.
However, it is possible to end up with DW_EH_PE_sdata4 when a TargetMachine is
not available. There's no risk of issues with inconsistency here since the
tables are self describing but it does mean there is a small chance of the
PC-relative offset being out of range for particularly large programs.

Reviewers: petarj

Reviewed By: petarj

Subscribers: srhines, joerg, tberghammer, llvm-commits

Differential Revision: http://reviews.llvm.org/D9669

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

include/llvm/MC/MCObjectFileInfo.h
lib/MC/MCObjectFileInfo.cpp
lib/Target/Mips/MipsTargetObjectFile.cpp
lib/Target/Mips/MipsTargetObjectFile.h
test/CodeGen/Mips/ehframe-indirect.ll

index f28b9c668cdc8c12415a3341e106e9b7c7bd4140..c3e2a8b4e4ed03bc4d9c54cbdd0ad3ca7d5a993d 100644 (file)
@@ -352,6 +352,8 @@ private:
   ///
   void InitEHFrameSection();
 
   ///
   void InitEHFrameSection();
 
+  virtual unsigned SelectMipsTTypeEncoding() const;
+
 public:
   const Triple &getTargetTriple() const { return TT; }
 };
 public:
   const Triple &getTargetTriple() const { return TT; }
 };
index e99f036af160a5628275d162d5cfdacbd4338810..c189d19c12dee19c5f2b2cec08ffd43c8716e7ae 100644 (file)
@@ -324,10 +324,13 @@ void MCObjectFileInfo::InitELFMCObjectFileInfo(Triple T) {
   case Triple::mipsel:
   case Triple::mips64:
   case Triple::mips64el:
   case Triple::mipsel:
   case Triple::mips64:
   case Triple::mips64el:
-    // MIPS uses indirect pointer to refer personality functions, so that the
-    // eh_frame section can be read-only.  DW.ref.personality will be generated
-    // for relocation.
+    // MIPS uses indirect pointer to refer personality functions and types, so
+    // that the eh_frame section can be read-only. DW.ref.personality will be
+    // generated for relocation.
     PersonalityEncoding = dwarf::DW_EH_PE_indirect;
     PersonalityEncoding = dwarf::DW_EH_PE_indirect;
+    TTypeEncoding = SelectMipsTTypeEncoding();
+    // We don't support PC-relative LSDA references in GAS so we use the default
+    // DW_EH_PE_absptr for those.
     break;
   case Triple::ppc64:
   case Triple::ppc64le:
     break;
   case Triple::ppc64:
   case Triple::ppc64le:
@@ -793,3 +796,11 @@ void MCObjectFileInfo::InitEHFrameSection() {
                           COFF::IMAGE_SCN_MEM_WRITE,
                           SectionKind::getDataRel());
 }
                           COFF::IMAGE_SCN_MEM_WRITE,
                           SectionKind::getDataRel());
 }
+
+unsigned MCObjectFileInfo::SelectMipsTTypeEncoding() const {
+  // FIXME: The N64 ABI ought to use DW_EH_PE_sdata8 but we can't
+  //        identify N64 from just a triple. We currently fix this by
+  //        overriding this function in MipsTargetObjectFile.
+  return dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
+         dwarf::DW_EH_PE_sdata4;
+}
index 0f2db6039b6a3c4eff953a3b5a9fc2bc9a4b9032..adbe526376e03525344e89c43badaa70eb1252d8 100644 (file)
@@ -37,6 +37,7 @@ ExternSData("mextern-sdata", cl::Hidden,
             cl::init(true));
 
 void MipsTargetObjectFile::Initialize(MCContext &Ctx, const TargetMachine &TM){
             cl::init(true));
 
 void MipsTargetObjectFile::Initialize(MCContext &Ctx, const TargetMachine &TM){
+  this->TM = &static_cast<const MipsTargetMachine &>(TM);
   TargetLoweringObjectFileELF::Initialize(Ctx, TM);
   InitializeELF(TM.Options.UseInitArray);
 
   TargetLoweringObjectFileELF::Initialize(Ctx, TM);
   InitializeELF(TM.Options.UseInitArray);
 
@@ -45,7 +46,6 @@ void MipsTargetObjectFile::Initialize(MCContext &Ctx, const TargetMachine &TM){
 
   SmallBSSSection = getContext().getELFSection(".sbss", ELF::SHT_NOBITS,
                                                ELF::SHF_WRITE | ELF::SHF_ALLOC);
 
   SmallBSSSection = getContext().getELFSection(".sbss", ELF::SHT_NOBITS,
                                                ELF::SHF_WRITE | ELF::SHF_ALLOC);
-  this->TM = &static_cast<const MipsTargetMachine &>(TM);
 }
 
 // A address must be loaded from a small section if its size is less than the
 }
 
 // A address must be loaded from a small section if its size is less than the
@@ -146,3 +146,9 @@ MipsTargetObjectFile::getSectionForConstant(SectionKind Kind,
   // Otherwise, we work the same as ELF.
   return TargetLoweringObjectFileELF::getSectionForConstant(Kind, C);
 }
   // Otherwise, we work the same as ELF.
   return TargetLoweringObjectFileELF::getSectionForConstant(Kind, C);
 }
+
+unsigned MipsTargetObjectFile::SelectMipsTTypeEncoding() const {
+  return dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
+         (TM->getABI().ArePtrs64bit() ? dwarf::DW_EH_PE_sdata8
+                                      : dwarf::DW_EH_PE_sdata4);
+}
index 725f2ffd93dd21e74f97ae643bad21e7b403a43e..72338d275f8128779a4572e13030468eaf27eed9 100644 (file)
@@ -41,6 +41,8 @@ class MipsTargetMachine;
 
     MCSection *getSectionForConstant(SectionKind Kind,
                                      const Constant *C) const override;
 
     MCSection *getSectionForConstant(SectionKind Kind,
                                      const Constant *C) const override;
+
+    unsigned SelectMipsTTypeEncoding() const override;
   };
 } // end namespace llvm
 
   };
 } // end namespace llvm
 
index f124881a472fcfae7ae17cc8a74d2ce086430dce..a4a82fc352eba37dc8afe92fb240d5b4ec9a8d53 100644 (file)
@@ -1,9 +1,11 @@
-; RUN: llc -mtriple=mipsel-linux-gnu < %s | FileCheck -check-prefix=ALL -check-prefix=O32 %s
-; RUN: llc -mtriple=mipsel-linux-android < %s | FileCheck -check-prefix=ALL -check-prefix=O32 %s
-; RUN: llc -mtriple=mips64el-linux-gnu -target-abi=n32 < %s | FileCheck -check-prefix=ALL -check-prefix=N32 %s
-; RUN: llc -mtriple=mips64el-linux-android -target-abi=n32 < %s | FileCheck -check-prefix=ALL -check-prefix=N32 %s
-; RUN: llc -mtriple=mips64el-linux-gnu < %s | FileCheck -check-prefix=ALL -check-prefix=N64 %s
-; RUN: llc -mtriple=mips64el-linux-android < %s | FileCheck -check-prefix=ALL -check-prefix=N64 %s
+; RUN: llc -mtriple=mipsel-linux-gnu < %s -asm-verbose | FileCheck -check-prefix=ALL -check-prefix=O32 %s
+; RUN: llc -mtriple=mipsel-linux-android < %s -asm-verbose | FileCheck -check-prefix=ALL -check-prefix=O32 %s
+; RUN: llc -mtriple=mips64el-linux-gnu -target-abi=n32 < %s -asm-verbose | FileCheck -check-prefix=ALL -check-prefix=N32 %s
+; RUN: llc -mtriple=mips64el-linux-android -target-abi=n32 < %s -asm-verbose | FileCheck -check-prefix=ALL -check-prefix=N32 %s
+; RUN: llc -mtriple=mips64el-linux-gnu < %s -asm-verbose | FileCheck -check-prefix=ALL -check-prefix=N64 %s
+; RUN: llc -mtriple=mips64el-linux-android < %s -asm-verbose | FileCheck -check-prefix=ALL -check-prefix=N64 %s
+
+@_ZTISt9exception = external constant i8*
 
 define i32 @main() {
 ; ALL: .cfi_startproc
 
 define i32 @main() {
 ; ALL: .cfi_startproc
@@ -16,7 +18,9 @@ entry:
 
 lpad:
   %0 = landingpad { i8*, i32 } personality i8*
 
 lpad:
   %0 = landingpad { i8*, i32 } personality i8*
-    bitcast (i32 (...)* @__gxx_personality_v0 to i8*) catch i8* null
+    bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
+    catch i8* null
+    catch i8* bitcast (i8** @_ZTISt9exception to i8*)
   ret i32 0
 
 cont:
   ret i32 0
 
 cont:
@@ -28,6 +32,18 @@ declare i32 @__gxx_personality_v0(...)
 
 declare void @foo()
 
 
 declare void @foo()
 
+; ALL: GCC_except_table{{[0-9]+}}:
+; O32: .byte 155 # @TType Encoding = indirect pcrel sdata4
+; N32: .byte 155 # @TType Encoding = indirect pcrel sdata4
+; N64: .byte 156 # @TType Encoding = indirect pcrel sdata8
+; ALL: $[[PC_LABEL:tmp[0-9]+]]:
+; O32: .4byte  ($_ZTISt9exception.DW.stub)-($[[PC_LABEL]])
+; N32: .4byte  ($_ZTISt9exception.DW.stub)-($[[PC_LABEL]])
+; N64: .8byte  ($_ZTISt9exception.DW.stub)-($[[PC_LABEL]])
+; ALL: $_ZTISt9exception.DW.stub:
+; O32: .4byte _ZTISt9exception
+; N32: .4byte _ZTISt9exception
+; N64: .8byte _ZTISt9exception
 ; ALL: .hidden DW.ref.__gxx_personality_v0
 ; ALL: .weak DW.ref.__gxx_personality_v0
 ; ALL: .section .data.DW.ref.__gxx_personality_v0,"aGw",@progbits,DW.ref.__gxx_personality_v0,comdat
 ; ALL: .hidden DW.ref.__gxx_personality_v0
 ; ALL: .weak DW.ref.__gxx_personality_v0
 ; ALL: .section .data.DW.ref.__gxx_personality_v0,"aGw",@progbits,DW.ref.__gxx_personality_v0,comdat