[PATCH] Propagate -fno-unwind-tables to EHABI

Renato Golin renato.golin at linaro.org
Fri Mar 14 07:47:21 PDT 2014


Hi keith.walker.arm, asl, logan,

Make the EHABI behaviour with regards to -fno-unwind-tables the same
as for Dwarf CFI exception, ie. avoid printing the EH table altogether
if the flag is set. This is needed to get C code to not emit EH tables
(thus saving a lot of space in the final binary). Since C code can
still interoperate with C++, the default to generate EH tables is a
good conservative default.

Fixes PR18758.

http://llvm-reviews.chandlerc.com/D3079

Files:
  include/llvm/CodeGen/AsmPrinter.h
  lib/CodeGen/AsmPrinter/ARMException.cpp
  lib/CodeGen/AsmPrinter/AsmPrinter.cpp
  lib/CodeGen/AsmPrinter/DwarfException.h
  lib/CodeGen/AsmPrinter/Win64Exception.cpp
  lib/Target/ARM/ARMAsmPrinter.cpp
  test/CodeGen/ARM/ehabi.ll
  test/MC/ARM/data-in-code.ll
  test/MC/ARM/elf-thumbfunc-reloc.ll

Index: include/llvm/CodeGen/AsmPrinter.h
===================================================================
--- include/llvm/CodeGen/AsmPrinter.h
+++ include/llvm/CodeGen/AsmPrinter.h
@@ -219,7 +219,8 @@
     };
     CFIMoveType needsCFIMoves();
 
-    bool needsSEHMoves();
+    /// True if the function needs unwinding of Type provided
+    bool needsEHMoves(unsigned EHType);
 
     /// EmitConstantPool - Print to the current output stream assembly
     /// representations of the constants in the constant pool MCP. This is
Index: lib/CodeGen/AsmPrinter/ARMException.cpp
===================================================================
--- lib/CodeGen/AsmPrinter/ARMException.cpp
+++ lib/CodeGen/AsmPrinter/ARMException.cpp
@@ -38,6 +38,7 @@
 
 ARMException::ARMException(AsmPrinter *A)
   : DwarfException(A),
+    shouldEmitEH(false),
     shouldEmitCFI(false) {}
 
 ARMException::~ARMException() {}
@@ -57,10 +58,14 @@
 /// beginFunction - Gather pre-function exception information. Assumes it's
 /// being emitted immediately after the function entry point.
 void ARMException::beginFunction(const MachineFunction *MF) {
-  getTargetStreamer().emitFnStart();
-  if (Asm->MF->getFunction()->needsUnwindTableEntry())
-    Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("eh_func_begin",
-                                                  Asm->getFunctionNumber()));
+  shouldEmitEH = Asm->needsEHMoves(ExceptionHandling::ARM);
+
+  if (shouldEmitEH) {
+    getTargetStreamer().emitFnStart();
+    if (Asm->MF->getFunction()->needsUnwindTableEntry())
+      Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("eh_func_begin",
+                                                    Asm->getFunctionNumber()));
+  }
   // See if we need call frame info.
   AsmPrinter::CFIMoveType MoveType = Asm->needsCFIMoves();
   assert(MoveType != AsmPrinter::CFI_M_EH &&
@@ -77,8 +82,11 @@
   if (shouldEmitCFI)
     Asm->OutStreamer.EmitCFIEndProc();
 
+  if (!shouldEmitEH)
+    return;
+
   ARMTargetStreamer &ATS = getTargetStreamer();
-  if (!Asm->MF->getFunction()->needsUnwindTableEntry())
+  if (Asm->MF->getFunction()->doesNotThrow())
     ATS.emitCantUnwind();
   else {
     Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("eh_func_end",
Index: lib/CodeGen/AsmPrinter/AsmPrinter.cpp
===================================================================
--- lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -681,22 +681,21 @@
   return true;
 }
 
+bool AsmPrinter::needsEHMoves(unsigned EHType) {
+  return (MAI->getExceptionHandlingType() == EHType &&
+      MF->getFunction()->needsUnwindTableEntry());
+}
+
 AsmPrinter::CFIMoveType AsmPrinter::needsCFIMoves() {
-  if (MAI->getExceptionHandlingType() == ExceptionHandling::DwarfCFI &&
-      MF->getFunction()->needsUnwindTableEntry())
+  if (needsEHMoves(ExceptionHandling::DwarfCFI))
     return CFI_M_EH;
 
   if (MMI->hasDebugInfo())
     return CFI_M_Debug;
 
   return CFI_M_None;
 }
 
-bool AsmPrinter::needsSEHMoves() {
-  return MAI->getExceptionHandlingType() == ExceptionHandling::Win64 &&
-    MF->getFunction()->needsUnwindTableEntry();
-}
-
 void AsmPrinter::emitCFIInstruction(const MachineInstr &MI) {
   ExceptionHandling::ExceptionsType ExceptionHandlingType =
       MAI->getExceptionHandlingType();
Index: lib/CodeGen/AsmPrinter/DwarfException.h
===================================================================
--- lib/CodeGen/AsmPrinter/DwarfException.h
+++ lib/CodeGen/AsmPrinter/DwarfException.h
@@ -183,6 +183,9 @@
   void EmitTypeInfos(unsigned TTypeEncoding) override;
   ARMTargetStreamer &getTargetStreamer();
 
+  /// shouldEmitEH - Per-function flag to indicate if frame EH info
+  /// should be emitted.
+  bool shouldEmitEH;
   /// shouldEmitCFI - Per-function flag to indicate if frame CFI info
   /// should be emitted.
   bool shouldEmitCFI;
Index: lib/CodeGen/AsmPrinter/Win64Exception.cpp
===================================================================
--- lib/CodeGen/AsmPrinter/Win64Exception.cpp
+++ lib/CodeGen/AsmPrinter/Win64Exception.cpp
@@ -57,7 +57,7 @@
   // If any landing pads survive, we need an EH table.
   bool hasLandingPads = !MMI->getLandingPads().empty();
 
-  shouldEmitMoves = Asm->needsSEHMoves();
+  shouldEmitMoves = Asm->needsEHMoves(ExceptionHandling::Win64);
 
   const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering();
   unsigned PerEncoding = TLOF.getPersonalityEncoding();
Index: lib/Target/ARM/ARMAsmPrinter.cpp
===================================================================
--- lib/Target/ARM/ARMAsmPrinter.cpp
+++ lib/Target/ARM/ARMAsmPrinter.cpp
@@ -907,6 +907,9 @@
   assert(MI->getFlag(MachineInstr::FrameSetup) &&
       "Only instruction which are involved into frame setup code are allowed");
 
+  if (!MF->getFunction()->needsUnwindTableEntry())
+    return;
+
   MCTargetStreamer &TS = *OutStreamer.getTargetStreamer();
   ARMTargetStreamer &ATS = static_cast<ARMTargetStreamer &>(TS);
   const MachineFunction &MF = *MI->getParent()->getParent();
Index: test/CodeGen/ARM/ehabi.ll
===================================================================
--- test/CodeGen/ARM/ehabi.ll
+++ test/CodeGen/ARM/ehabi.ll
@@ -280,7 +280,7 @@
 ; Test 4
 ;-------------------------------------------------------------------------------
 
-define void @test4() nounwind {
+define void @test4() uwtable nounwind {
 entry:
   ret void
 }
Index: test/MC/ARM/data-in-code.ll
===================================================================
--- test/MC/ARM/data-in-code.ll
+++ test/MC/ARM/data-in-code.ll
@@ -144,16 +144,6 @@
 ;; ARM-NEXT:     Other:
 ;; ARM-NEXT:     Section: [[MIXED_SECT]]
 
-;; ARM:        Symbol {
-;; ARM:          Name: $d
-;; ARM-NEXT:     Value: 0x0
-;; ARM-NEXT:     Size: 0
-;; ARM-NEXT:     Binding: Local (0x0)
-;; ARM-NEXT:     Type: None (0x0)
-;; ARM-NEXT:     Other: 0
-;; ARM-NEXT:     Section: .ARM.exidx
-;; ARM-NEXT:   }
-
 ;; ARM-NOT:     ${{[atd]}}
 
 ;; TMB:        Symbol {
Index: test/MC/ARM/elf-thumbfunc-reloc.ll
===================================================================
--- test/MC/ARM/elf-thumbfunc-reloc.ll
+++ test/MC/ARM/elf-thumbfunc-reloc.ll
@@ -32,10 +32,6 @@
 ; CHECK-NEXT:   Section (2) .rel.text {
 ; CHECK-NEXT:     0x8 R_ARM_THM_CALL foo 0x0
 ; CHECK-NEXT:   }
-; CHECK-NEXT:   Section (7) .rel.ARM.exidx {
-; CHECK-NEXT:     0x0 R_ARM_PREL31 .text 0x0
-; CHECK-NEXT:     0x8 R_ARM_PREL31 .text 0x0
-; CHECK-NEXT:   }
 ; CHECK-NEXT: ]
 
 ; make sure foo is thumb function: bit 0 = 1
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D3079.1.patch
Type: text/x-patch
Size: 6516 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140314/f9e344f6/attachment.bin>


More information about the llvm-commits mailing list