[llvm-commits] [llvm] r132205 - in /llvm/trunk: include/llvm/CodeGen/TargetLoweringObjectFileImpl.h include/llvm/MC/MCWin64EH.h include/llvm/Target/TargetAsmInfo.h include/llvm/Target/TargetLoweringObjectFile.h lib/MC/MCAsmStreamer.cpp lib/MC/MCWin64EH.cpp

Charles Davis cdavis at mines.edu
Fri May 27 12:09:24 PDT 2011


Author: cdavis
Date: Fri May 27 14:09:24 2011
New Revision: 132205

URL: http://llvm.org/viewvc/llvm-project?rev=132205&view=rev
Log:
Add a parameter to the Win64 EH section getters to get a section with a
suffix (e.g. .xdata$myfunc). The suffix part isn't implemented yet, but
I'll get to it in the next patch.

Fix up all callers of the affected functions. Make them pass said suffix to
the function.

Modified:
    llvm/trunk/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
    llvm/trunk/include/llvm/MC/MCWin64EH.h
    llvm/trunk/include/llvm/Target/TargetAsmInfo.h
    llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h
    llvm/trunk/lib/MC/MCAsmStreamer.cpp
    llvm/trunk/lib/MC/MCWin64EH.cpp

Modified: llvm/trunk/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h?rev=132205&r1=132204&r2=132205&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h (original)
+++ llvm/trunk/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h Fri May 27 14:09:24 2011
@@ -58,8 +58,10 @@
   virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
 
   virtual const MCSection *getEHFrameSection() const;
-  virtual const MCSection *getWin64EHFuncTableSection() const { return NULL; }
-  virtual const MCSection *getWin64EHTableSection() const { return NULL; }
+  virtual const MCSection *getWin64EHFuncTableSection(StringRef) const {
+    return NULL;
+  }
+  virtual const MCSection *getWin64EHTableSection(StringRef) const{return NULL;}
 
   virtual void emitPersonalityValue(MCStreamer &Streamer,
                                     const TargetMachine &TM,
@@ -135,8 +137,10 @@
   virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
 
   virtual const MCSection *getEHFrameSection() const;
-  virtual const MCSection *getWin64EHFuncTableSection() const { return NULL; }
-  virtual const MCSection *getWin64EHTableSection() const { return NULL; }
+  virtual const MCSection *getWin64EHFuncTableSection(StringRef) const {
+    return NULL;
+  }
+  virtual const MCSection *getWin64EHTableSection(StringRef) const{return NULL;}
 
   virtual const MCSection *
   SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
@@ -209,10 +213,12 @@
   virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
 
   virtual const MCSection *getEHFrameSection() const;
-  virtual const MCSection *getWin64EHFuncTableSection() const {
+  virtual const MCSection *getWin64EHFuncTableSection(StringRef) const {
     return PDataSection;
   }
-  virtual const MCSection *getWin64EHTableSection() const {return XDataSection;}
+  virtual const MCSection *getWin64EHTableSection(StringRef) const {
+    return XDataSection;
+  }
 
   virtual const MCSection *getDrectveSection() const { return DrectveSection; }
 

Modified: llvm/trunk/include/llvm/MC/MCWin64EH.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCWin64EH.h?rev=132205&r1=132204&r2=132205&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCWin64EH.h (original)
+++ llvm/trunk/include/llvm/MC/MCWin64EH.h Fri May 27 14:09:24 2011
@@ -20,6 +20,7 @@
 #include <vector>
 
 namespace llvm {
+  class StringRef;
   class MCStreamer;
   class MCSymbol;
 
@@ -80,6 +81,7 @@
 
   class MCWin64EHUnwindEmitter {
   public:
+    static StringRef GetSectionSuffix(const MCSymbol *func);
     //
     // This emits the unwind info sections (.pdata and .xdata in PE/COFF).
     //

Modified: llvm/trunk/include/llvm/Target/TargetAsmInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetAsmInfo.h?rev=132205&r1=132204&r2=132205&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Target/TargetAsmInfo.h (original)
+++ llvm/trunk/include/llvm/Target/TargetAsmInfo.h Fri May 27 14:09:24 2011
@@ -63,12 +63,12 @@
     return TLOF->getDwarfFrameSection();
   }
 
-  const MCSection *getWin64EHFuncTableSection() const {
-    return TLOF->getWin64EHFuncTableSection();
+  const MCSection *getWin64EHFuncTableSection(StringRef Suffix) const {
+    return TLOF->getWin64EHFuncTableSection(Suffix);
   }
 
-  const MCSection *getWin64EHTableSection() const {
-    return TLOF->getWin64EHTableSection();
+  const MCSection *getWin64EHTableSection(StringRef Suffix) const {
+    return TLOF->getWin64EHTableSection(Suffix);
   }
 
   unsigned getFDEEncoding(bool CFI) const {

Modified: llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h?rev=132205&r1=132204&r2=132205&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h (original)
+++ llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h Fri May 27 14:09:24 2011
@@ -155,8 +155,8 @@
   const MCSection *getTLSExtraDataSection() const {
     return TLSExtraDataSection;
   }
-  virtual const MCSection *getWin64EHFuncTableSection() const = 0;
-  virtual const MCSection *getWin64EHTableSection() const = 0;
+  virtual const MCSection *getWin64EHFuncTableSection(StringRef suffix)const=0;
+  virtual const MCSection *getWin64EHTableSection(StringRef suffix) const = 0;
   
   /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
   /// decide not to emit the UsedDirective for some symbols in llvm.used.

Modified: llvm/trunk/lib/MC/MCAsmStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmStreamer.cpp?rev=132205&r1=132204&r2=132205&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAsmStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCAsmStreamer.cpp Fri May 27 14:09:24 2011
@@ -977,8 +977,10 @@
   // cause the section switch to be visible in the emitted assembly.
   // We only do this so the section switch that terminates the handler
   // data block is visible.
+  MCWin64EHUnwindInfo *CurFrame = getCurrentW64UnwindInfo();
+  StringRef suffix=MCWin64EHUnwindEmitter::GetSectionSuffix(CurFrame->Function);
   const MCSection *xdataSect =
-                       getContext().getTargetAsmInfo().getWin64EHTableSection();
+    getContext().getTargetAsmInfo().getWin64EHTableSection(suffix);
   if (xdataSect)
     SwitchSectionNoChange(xdataSect);
 

Modified: llvm/trunk/lib/MC/MCWin64EH.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCWin64EH.cpp?rev=132205&r1=132204&r2=132205&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCWin64EH.cpp (original)
+++ llvm/trunk/lib/MC/MCWin64EH.cpp Fri May 27 14:09:24 2011
@@ -10,6 +10,8 @@
 #include "llvm/MC/MCWin64EH.h"
 #include "llvm/MC/MCStreamer.h"
 #include "llvm/MC/MCContext.h"
+#include "llvm/MC/MCSymbol.h"
+#include "llvm/MC/MCSectionCOFF.h"
 #include "llvm/MC/MCExpr.h"
 #include "llvm/Target/TargetAsmInfo.h"
 
@@ -199,13 +201,33 @@
   }
 }
 
+StringRef MCWin64EHUnwindEmitter::GetSectionSuffix(const MCSymbol *func) {
+  if (!func || !func->isInSection()) return "";
+  const MCSection *section = &func->getSection();
+  const MCSectionCOFF *COFFSection;
+  if ((COFFSection = dyn_cast<MCSectionCOFF>(section))) {
+    StringRef name = COFFSection->getSectionName();
+    size_t dollar = name.find('$');
+    size_t dot = name.find('.', 1);
+    if (dollar == StringRef::npos && dot == StringRef::npos)
+      return "";
+    if (dot == StringRef::npos)
+      return name.substr(dollar);
+    if (dollar == StringRef::npos || dot < dollar)
+      return name.substr(dot);
+    return name.substr(dollar);
+  }
+  return "";
+}
+
 void MCWin64EHUnwindEmitter::EmitUnwindInfo(MCStreamer &streamer,
                                             MCWin64EHUnwindInfo *info) {
   // Switch sections (the static function above is meant to be called from
   // here and from Emit().
   MCContext &context = streamer.getContext();
   const TargetAsmInfo &asmInfo = context.getTargetAsmInfo();
-  const MCSection *xdataSect = asmInfo.getWin64EHTableSection();
+  const MCSection *xdataSect =
+    asmInfo.getWin64EHTableSection(GetSectionSuffix(info->Function));
   streamer.SwitchSection(xdataSect);
 
   llvm::EmitUnwindInfo(streamer, info);
@@ -215,15 +237,21 @@
   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));
+  for (unsigned i = 0; i < streamer.getNumW64UnwindInfos(); ++i) {
+    MCWin64EHUnwindInfo &info = streamer.getW64UnwindInfo(i);
+    const MCSection *xdataSect =
+      asmInfo.getWin64EHTableSection(GetSectionSuffix(info.Function));
+    streamer.SwitchSection(xdataSect);
+    llvm::EmitUnwindInfo(streamer, &info);
+  }
   // 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));
+  for (unsigned i = 0; i < streamer.getNumW64UnwindInfos(); ++i) {
+    MCWin64EHUnwindInfo &info = streamer.getW64UnwindInfo(i);
+    const MCSection *pdataSect =
+      asmInfo.getWin64EHFuncTableSection(GetSectionSuffix(info.Function));
+    streamer.SwitchSection(pdataSect);
+    EmitRuntimeFunction(streamer, &info);
+  }
 }
 
 } // End of namespace llvm





More information about the llvm-commits mailing list