MC/X86/COFF: Allow quotes in names when targeting MS/Windows,
authorMichael J. Spencer <bigcheesegs@gmail.com>
Tue, 29 Nov 2011 18:00:06 +0000 (18:00 +0000)
committerMichael J. Spencer <bigcheesegs@gmail.com>
Tue, 29 Nov 2011 18:00:06 +0000 (18:00 +0000)
as MC is the only assembler we support.

This splits MS/Windows and GNU/Windows ASM infos into two seperate classes.
While there is currently only one difference, full MS C++ ABI support will
require many more.

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

include/llvm/MC/MCAsmInfoCOFF.h
lib/MC/MCAsmInfoCOFF.cpp
lib/Target/X86/MCTargetDesc/X86MCAsmInfo.cpp
lib/Target/X86/MCTargetDesc/X86MCAsmInfo.h
lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp
test/MC/COFF/symbol-mangling.ll [new file with mode: 0644]

index a3ee1593c3ac4c09ab630995c0066685b9737407..ba699d78529f7b669266fb68d9ab6e69d52a2dd1 100644 (file)
@@ -18,6 +18,16 @@ namespace llvm {
     explicit MCAsmInfoCOFF();
       
   };
+
+  class MCAsmInfoMicrosoft : public MCAsmInfoCOFF {
+  protected:
+    explicit MCAsmInfoMicrosoft();
+  };
+
+  class MCAsmInfoGNUCOFF : public MCAsmInfoCOFF {
+  protected:
+    explicit MCAsmInfoGNUCOFF();
+  };
 }
 
 
index 434d9103a71adacd37e9588af18b3b73f5336364..6d34801f5c45fb95ce56814b34f42c73ced78785 100644 (file)
@@ -38,3 +38,11 @@ MCAsmInfoCOFF::MCAsmInfoCOFF() {
 
   SupportsDataRegions = false;
 }
+
+MCAsmInfoMicrosoft::MCAsmInfoMicrosoft() {
+  AllowQuotesInName = true;
+}
+
+MCAsmInfoGNUCOFF::MCAsmInfoGNUCOFF() {
+
+}
index 27031005bd0987ef29faab77ef8068e6eaa914f1..eb64ad112bc438147b89f0e473f629962a7a56ce 100644 (file)
@@ -125,7 +125,19 @@ getNonexecutableStackSection(MCContext &Ctx) const {
                            0, SectionKind::getMetadata());
 }
 
-X86MCAsmInfoCOFF::X86MCAsmInfoCOFF(const Triple &Triple) {
+X86MCAsmInfoMicrosoft::X86MCAsmInfoMicrosoft(const Triple &Triple) {
+  if (Triple.getArch() == Triple::x86_64) {
+    GlobalPrefix = "";
+    PrivateGlobalPrefix = ".L";
+  }
+
+  AsmTransCBE = x86_asm_table;
+  AssemblerDialect = AsmWriterFlavor;
+
+  TextAlignFillValue = 0x90;
+}
+
+X86MCAsmInfoGNUCOFF::X86MCAsmInfoGNUCOFF(const Triple &Triple) {
   if (Triple.getArch() == Triple::x86_64) {
     GlobalPrefix = "";
     PrivateGlobalPrefix = ".L";
index 2cd4c8eb30ec908dbad9205c39c0f0e6cedab75d..5d619e8b17b43e9725b322870cd0397550919a5c 100644 (file)
@@ -38,8 +38,12 @@ namespace llvm {
     virtual const MCSection *getNonexecutableStackSection(MCContext &Ctx) const;
   };
 
-  struct X86MCAsmInfoCOFF : public MCAsmInfoCOFF {
-    explicit X86MCAsmInfoCOFF(const Triple &Triple);
+  struct X86MCAsmInfoMicrosoft : public MCAsmInfoMicrosoft {
+    explicit X86MCAsmInfoMicrosoft(const Triple &Triple);
+  };
+
+  struct X86MCAsmInfoGNUCOFF : public MCAsmInfoGNUCOFF {
+    explicit X86MCAsmInfoGNUCOFF(const Triple &Triple);
   };
 } // namespace llvm
 
index a8435152e2bbc8dd617862a277e77647c2700558..f2a34edc5c4b00474cb8680f87ecc140487bbb50 100644 (file)
@@ -361,8 +361,10 @@ static MCAsmInfo *createX86MCAsmInfo(const Target &T, StringRef TT) {
       MAI = new X86_64MCAsmInfoDarwin(TheTriple);
     else
       MAI = new X86MCAsmInfoDarwin(TheTriple);
-  } else if (TheTriple.isOSWindows()) {
-    MAI = new X86MCAsmInfoCOFF(TheTriple);
+  } else if (TheTriple.getOS() == Triple::Win32) {
+    MAI = new X86MCAsmInfoMicrosoft(TheTriple);
+  } else if (TheTriple.getOS() == Triple::MinGW32 || TheTriple.getOS() == Triple::Cygwin) {
+    MAI = new X86MCAsmInfoGNUCOFF(TheTriple);
   } else {
     MAI = new X86ELFMCAsmInfo(TheTriple);
   }
diff --git a/test/MC/COFF/symbol-mangling.ll b/test/MC/COFF/symbol-mangling.ll
new file mode 100644 (file)
index 0000000..f1b4b4b
--- /dev/null
@@ -0,0 +1,17 @@
+; The purpose of this test is to see if the MC layer properly handles symbol
+; names needing quoting on MS/Windows. This code is generated by clang when
+; using -cxx-abi microsoft.
+
+; RUN: llc -filetype=asm -mtriple i686-pc-win32 %s -o - | FileCheck %s
+
+; CHECK: ?sayhi@A@@QBEXXZ
+
+%struct.A = type {}
+
+define i32 @main() {
+entry:
+  tail call void @"\01?sayhi@A@@QBEXXZ"(%struct.A* null)
+  ret i32 0
+}
+
+declare void @"\01?sayhi@A@@QBEXXZ"(%struct.A*)