Fix bug 3202.
authorRafael Espindola <rafael.espindola@gmail.com>
Fri, 19 Dec 2008 10:55:56 +0000 (10:55 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Fri, 19 Dec 2008 10:55:56 +0000 (10:55 +0000)
The EH_frame and .eh symbols are now private, except for darwin9 and earlier.
The patch also fixes the definition of PrivateGlobalPrefix on pcc linux.

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

include/llvm/Target/TargetAsmInfo.h
lib/CodeGen/AsmPrinter/AsmPrinter.cpp
lib/CodeGen/AsmPrinter/DwarfWriter.cpp
lib/Target/PowerPC/PPCSubtarget.h
lib/Target/PowerPC/PPCTargetAsmInfo.cpp
lib/Target/PowerPC/PPCTargetAsmInfo.h
lib/Target/X86/X86TargetAsmInfo.cpp
lib/Target/X86/X86TargetAsmInfo.h
test/CodeGen/PowerPC/20081212.ll [new file with mode: 0644]
test/CodeGen/X86/20081212.ll [new file with mode: 0644]

index 3c71dc8d1d6a1a85e26aca47fa6bcd43074c74ed..d4aadb964bd66d001d503c879ad1a1b777486305 100644 (file)
@@ -646,6 +646,12 @@ namespace llvm {
     const char *getPrivateGlobalPrefix() const {
       return PrivateGlobalPrefix;
     }
+    /// EHGlobalPrefix - Prefix for EH_frame and the .eh symbols.
+    /// This is normally PrivateGlobalPrefix, but some targets want
+    /// these symbols to be visible.
+    virtual const char *getEHGlobalPrefix() const {
+      return PrivateGlobalPrefix;
+    }
     const char *getLessPrivateGlobalPrefix() const {
       return LessPrivateGlobalPrefix;
     }
index b640a589badac6ff06c3aaa84d8692ab410271ce..e3cc3b0a2706e193a088bbc74aaa2c0352906783 100644 (file)
@@ -239,7 +239,8 @@ std::string AsmPrinter::getCurrentFunctionEHName(const MachineFunction *MF) {
   std::string Name = MF->getFunction()->getName();
   if (Name.empty())
     Name = Mang->getValueName(MF->getFunction());
-  return Mang->makeNameProper(Name + ".eh", TAI->getGlobalPrefix());
+  return Mang->makeNameProper(TAI->getEHGlobalPrefix() +
+                              Name + ".eh", TAI->getGlobalPrefix());
 }
 
 void AsmPrinter::SetupMachineFunction(MachineFunction &MF) {
index e41e4cbb6e0957bd4669a8b858189408b9ea20f0..88589d584dae127a6a4037a1fd02c11c37353d30 100644 (file)
@@ -2962,7 +2962,7 @@ private:
 
     // Begin eh frame section.
     Asm->SwitchToTextSection(TAI->getDwarfEHFrameSection());
-    O << "EH_frame" << Index << ":\n";
+    O << TAI->getEHGlobalPrefix() << "EH_frame" << Index << ":\n";
     EmitLabel("section_eh_frame", Index);
 
     // Define base labels.
index be4c21cd448ce45395e49750c1ae320ba78e2479..bb29d449507a31af0156725fa8c8b73ce43d5142 100644 (file)
@@ -141,6 +141,9 @@ public:
   /// isDarwin - True if this is darwin9 (leopard, 10.5) or above.
   bool isDarwin9() const { return DarwinVers >= 9; }
 
+  /// getDarwinVers - Return the darwin version number, 8 = tiger, 9 = leopard.
+  unsigned getDarwinVers() const { return DarwinVers; }
+
   bool isMachoABI() const { return isDarwin() || IsPPC64; }
   bool isELF32_ABI() const { return !isDarwin() && !IsPPC64; }
 
index 4151064c6a1289634d3f7e2ba4f1235a8c23b3e3..c69e591a6632d81eab00925033c17dc3e1e22c74 100644 (file)
@@ -89,12 +89,21 @@ PPCDarwinTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
     return DW_EH_PE_absptr;
 }
 
+const char *
+PPCDarwinTargetAsmInfo::getEHGlobalPrefix() const
+{
+  const PPCSubtarget* Subtarget = &TM.getSubtarget<PPCSubtarget>();
+  if (Subtarget->getDarwinVers() > 9)
+    return PrivateGlobalPrefix;
+  else
+    return "";
+}
 
 PPCLinuxTargetAsmInfo::PPCLinuxTargetAsmInfo(const PPCTargetMachine &TM) :
   PPCTargetAsmInfo<ELFTargetAsmInfo>(TM) {
   CommentString = "#";
   GlobalPrefix = "";
-  PrivateGlobalPrefix = "";
+  PrivateGlobalPrefix = ".L";
   ConstantPoolSection = "\t.section .rodata.cst4\t";
   JumpTableDataSection = ".section .rodata.cst4";
   CStringSection = ".rodata.str";
index a533d5fc60e2f00a850f9183980b817f4f74c1ec..edf40c9346cf792d306f1860b2fd3f6ffe99b63e 100644 (file)
@@ -48,6 +48,7 @@ namespace llvm {
     explicit PPCDarwinTargetAsmInfo(const PPCTargetMachine &TM);
     virtual unsigned PreferredEHDataFormat(DwarfEncoding::Target Reason,
                                            bool Global) const;
+    virtual const char *getEHGlobalPrefix() const;
   };
 
   struct PPCLinuxTargetAsmInfo : public PPCTargetAsmInfo<ELFTargetAsmInfo> {
index feff9307be9345859cc904fd2d747155e6f6ceea..e3336509a766c2615b65a308c6ca1030dc0255da 100644 (file)
@@ -138,6 +138,16 @@ X86DarwinTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
     return DW_EH_PE_absptr;
 }
 
+const char *
+X86DarwinTargetAsmInfo::getEHGlobalPrefix() const
+{
+  const X86Subtarget* Subtarget = &TM.getSubtarget<X86Subtarget>();
+  if (Subtarget->getDarwinVers() > 9)
+    return PrivateGlobalPrefix;
+  else
+    return "";
+}
+
 X86ELFTargetAsmInfo::X86ELFTargetAsmInfo(const X86TargetMachine &TM):
   X86TargetAsmInfo<ELFTargetAsmInfo>(TM) {
 
index 806bcd5614aa4a4fc2dd18620f2d41505c910ea3..f89171d3da713535192da53e8aecde54b6de3530 100644 (file)
@@ -48,6 +48,7 @@ namespace llvm {
     explicit X86DarwinTargetAsmInfo(const X86TargetMachine &TM);
     virtual unsigned PreferredEHDataFormat(DwarfEncoding::Target Reason,
                                            bool Global) const;
+    virtual const char *getEHGlobalPrefix() const;
   };
 
   struct X86ELFTargetAsmInfo : public X86TargetAsmInfo<ELFTargetAsmInfo> {
@@ -72,4 +73,3 @@ namespace llvm {
 } // namespace llvm
 
 #endif
-
diff --git a/test/CodeGen/PowerPC/20081212.ll b/test/CodeGen/PowerPC/20081212.ll
new file mode 100644 (file)
index 0000000..21218f5
--- /dev/null
@@ -0,0 +1,10 @@
+; RUN: llvm-as < %s | llc -march=ppc32 -mtriple=powerpc-unknown-linux-gnu | grep ^.L_Z1fv.eh
+; RUN: llvm-as < %s | llc  -march=ppc32 -mtriple=powerpc-apple-darwin9 | grep ^__Z1fv.eh
+
+define void @_Z1fv() {
+entry:
+       br label %return
+
+return:
+       ret void
+}
diff --git a/test/CodeGen/X86/20081212.ll b/test/CodeGen/X86/20081212.ll
new file mode 100644 (file)
index 0000000..1a5cad9
--- /dev/null
@@ -0,0 +1,12 @@
+; RUN: llvm-as < %s | llc -march=x86-64 -mtriple=x86_64-unknown-linux-gnu | grep ^.L_Z1fv.eh
+; RUN: llvm-as < %s | llc -march=x86 -mtriple=i686-unknown-linux-gnu | grep ^.L_Z1fv.eh
+; RUN: llvm-as < %s | llc -march=x86-64 -mtriple=-mtriple=x86_64-apple-darwin9 | grep ^__Z1fv.eh
+; RUN: llvm-as < %s | llc -march=x86 -mtriple=-mtriple=i386-apple-darwin9 | grep ^__Z1fv.eh
+
+define void @_Z1fv() {
+entry:
+       br label %return
+
+return:
+       ret void
+}