Implement emission of all Win64 exception tables. Make the COFF streamer emit
authorCharles Davis <cdavis@mines.edu>
Sun, 22 May 2011 04:15:07 +0000 (04:15 +0000)
committerCharles Davis <cdavis@mines.edu>
Sun, 22 May 2011 04:15:07 +0000 (04:15 +0000)
these tables.

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

include/llvm/MC/MCStreamer.h
lib/MC/MCStreamer.cpp
lib/MC/MCWin64EH.cpp
lib/MC/WinCOFFStreamer.cpp

index bfcb4609aee77e3fb8fcee8d9ada81df509348ac..c12caf01b03d0cd9af725a79886f8de5e4ebd66d 100644 (file)
@@ -81,6 +81,7 @@ namespace llvm {
     void EmitFrames(bool usingCFI);
 
     MCWin64EHUnwindInfo *getCurrentW64UnwindInfo(){return CurrentW64UnwindInfo;}
+    void EmitW64Tables();
 
   public:
     virtual ~MCStreamer();
@@ -95,6 +96,14 @@ namespace llvm {
       return FrameInfos[i];
     }
 
+    unsigned getNumW64UnwindInfos() {
+      return W64UnwindInfos.size();
+    }
+
+    MCWin64EHUnwindInfo &getW64UnwindInfo(unsigned i) {
+      return W64UnwindInfos[i];
+    }
+
     /// @name Assembly File Formatting.
     /// @{
 
index 164325e8f4f588492c54c9c0e537b68167d76820..f268f9e3756e10da53ff724033ad15142b76026b 100644 (file)
@@ -506,3 +506,10 @@ void MCStreamer::EmitFrames(bool usingCFI) {
   if (EmitDebugFrame)
     MCDwarfFrameEmitter::Emit(*this, usingCFI, false);
 }
+
+void MCStreamer::EmitW64Tables() {
+  if (!getNumW64UnwindInfos())
+    return;
+
+  MCWin64EHUnwindEmitter::Emit(*this);
+}
index 9884f66e5fb549c2e629609ec9265b27150b5d9d..fc394504bfb768530fab240a756705a807f36dfe 100644 (file)
@@ -110,7 +110,7 @@ static void EmitUnwindCode(MCStreamer &streamer, MCWin64EHInstruction &inst) {
 }
 
 static void EmitRuntimeFunction(MCStreamer &streamer,
-                                MCWin64EHUnwindInfo *info) {
+                                const MCWin64EHUnwindInfo *info) {
   MCContext &context = streamer.getContext();
 
   streamer.EmitValue(MCSymbolRefExpr::Create(info->Begin, context), 4);
@@ -185,5 +185,20 @@ void MCWin64EHUnwindEmitter::EmitUnwindInfo(MCStreamer &streamer,
   llvm::EmitUnwindInfo(streamer, info);
 }
 
+void MCWin64EHUnwindEmitter::Emit(MCStreamer &streamer) {
+  MCContext &context = streamer.getContext();
+  // Emit the unwind info structs first.
+  const TargetAsmInfo &asmInfo = context.getTargetAsmInfo();
+  const MCSection *xdataSect = asmInfo.getWin64EHTableSection();
+  streamer.SwitchSection(xdataSect);
+  for (unsigned i = 0; i < streamer.getNumW64UnwindInfos(); ++i)
+    llvm::EmitUnwindInfo(streamer, &streamer.getW64UnwindInfo(i));
+  // Now emit RUNTIME_FUNCTION entries.
+  const MCSection *pdataSect = asmInfo.getWin64EHFuncTableSection();
+  streamer.SwitchSection(pdataSect);
+  for (unsigned i = 0; i < streamer.getNumW64UnwindInfos(); ++i)
+    EmitRuntimeFunction(streamer, &streamer.getW64UnwindInfo(i));
+}
+
 } // End of namespace llvm
 
index 8b0cfcbd62ccb6f65cdb430691f8c533decba9a0..6c36c1231c8354cb684ef326fab56466d09fb3db 100644 (file)
@@ -388,6 +388,7 @@ void WinCOFFStreamer::EmitWin64EHHandlerData() {
 }
 
 void WinCOFFStreamer::Finish() {
+  EmitW64Tables();
   MCObjectStreamer::Finish();
 }