On Darwin, ams printer should output a second label before a jump table so the linker...
authorEvan Cheng <evan.cheng@apple.com>
Thu, 18 Jun 2009 20:37:15 +0000 (20:37 +0000)
committerEvan Cheng <evan.cheng@apple.com>
Thu, 18 Jun 2009 20:37:15 +0000 (20:37 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@73720 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/AsmPrinter/AsmPrinter.cpp
lib/Target/ARM/ARMTargetAsmInfo.cpp
lib/Target/PowerPC/PPCTargetAsmInfo.cpp
lib/Target/X86/X86TargetAsmInfo.cpp
test/CodeGen/X86/pic_jumptable.ll

index 15511c4615b2f1455f00c188db309795f94b4e81..7ab775e26a4bc4ee4e3cee9cd67c865ab4686271 100644 (file)
@@ -347,8 +347,9 @@ void AsmPrinter::EmitJumpTableInfo(MachineJumpTableInfo *MJTI,
   const char* JumpTableDataSection = TAI->getJumpTableDataSection();
   const Function *F = MF.getFunction();
   unsigned SectionFlags = TAI->SectionFlagsForGlobal(F);
+  bool JTInDiffSection = false;
   if ((IsPic && !(LoweringInfo && LoweringInfo->usesGlobalOffsetTable())) ||
-     !JumpTableDataSection ||
+      !JumpTableDataSection ||
       SectionFlags & SectionFlags::Linkonce) {
     // In PIC mode, we need to emit the jump table to the same section as the
     // function body itself, otherwise the label differences won't make sense.
@@ -357,6 +358,7 @@ void AsmPrinter::EmitJumpTableInfo(MachineJumpTableInfo *MJTI,
     SwitchToSection(TAI->SectionForGlobal(F));
   } else {
     SwitchToDataSection(JumpTableDataSection);
+    JTInDiffSection = true;
   }
   
   EmitAlignment(Log2_32(MJTI->getAlignment()));
@@ -380,8 +382,10 @@ void AsmPrinter::EmitJumpTableInfo(MachineJumpTableInfo *MJTI,
     // before each jump table.  The first label is never referenced, but tells
     // the assembler and linker the extents of the jump table object.  The
     // second label is actually referenced by the code.
-    if (const char *JTLabelPrefix = TAI->getJumpTableSpecialLabelPrefix())
-      O << JTLabelPrefix << "JTI" << getFunctionNumber() << '_' << i << ":\n";
+    if (JTInDiffSection) {
+      if (const char *JTLabelPrefix = TAI->getJumpTableSpecialLabelPrefix())
+        O << JTLabelPrefix << "JTI" << getFunctionNumber() << '_' << i << ":\n";
+    }
     
     O << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber() 
       << '_' << i << ":\n";
index 4107dccd2a693e8ae2d08744809c9c7200cd8995..a4419682ef7cfab6155eca8998b68777b584c72a 100644 (file)
@@ -74,10 +74,10 @@ ARMDarwinTargetAsmInfo::ARMDarwinTargetAsmInfo(const ARMTargetMachine &TM):
 
   // In non-PIC modes, emit a special label before jump tables so that the
   // linker can perform more accurate dead code stripping.
-  if (TM.getRelocationModel() != Reloc::PIC_) {
-    // Emit a local label that is preserved until the linker runs.
-    JumpTableSpecialLabelPrefix = "l";
-  }
+  // Emit a local label that is preserved until the linker runs.
+  // We do not check the relocation model here since it can be overridden
+  // later.
+  JumpTableSpecialLabelPrefix = "l";
 
   NeedsSet = true;
   DwarfAbbrevSection = ".section __DWARF,__debug_abbrev,regular,debug";
index c69e591a6632d81eab00925033c17dc3e1e22c74..c8d1132314e38b17b2cd2b6f1874663c5e378c03 100644 (file)
@@ -68,10 +68,9 @@ PPCDarwinTargetAsmInfo::PPCDarwinTargetAsmInfo(const PPCTargetMachine &TM):
   
   // In non-PIC modes, emit a special label before jump tables so that the
   // linker can perform more accurate dead code stripping.
-  if (TM.getRelocationModel() != Reloc::PIC_) {
-    // Emit a local label that is preserved until the linker runs.
-    JumpTableSpecialLabelPrefix = "l";
-  }
+  // We do not check the relocation model here since it can be overridden
+  // later.
+  JumpTableSpecialLabelPrefix = "l";
 }
 
 /// PreferredEHDataFormat - This hook allows the target to select data
index 5dda5f4e49b02a2133e82e63636c01ed7321bd9d..0c474e122810cf689ed5e66dd41f46bfe3ee0520 100644 (file)
@@ -99,10 +99,10 @@ X86DarwinTargetAsmInfo::X86DarwinTargetAsmInfo(const X86TargetMachine &TM):
 
   // In non-PIC modes, emit a special label before jump tables so that the
   // linker can perform more accurate dead code stripping.
-  if (TM.getRelocationModel() != Reloc::PIC_) {
-    // Emit a local label that is preserved until the linker runs.
-    JumpTableSpecialLabelPrefix = "l";
-  }
+  // Emit a local label that is preserved until the linker runs.
+  // We do not check the relocation model here since it can be overridden
+  // later.
+  JumpTableSpecialLabelPrefix = "l";
 
   SupportsDebugInformation = true;
   NeedsSet = true;
index 1731feb58e91d29239746eeb06c63533024f62a3..229865bb71b9cdf073bcd305bab87b68e440529a 100644 (file)
@@ -1,6 +1,8 @@
 ; RUN: llvm-as < %s | llc -relocation-model=pic -mtriple=i386-linux-gnu -asm-verbose=false | not grep -F .text
 ; RUN: llvm-as < %s | llc -relocation-model=pic -mtriple=i686-apple-darwin -asm-verbose=false | not grep lea
 ; RUN: llvm-as < %s | llc -relocation-model=pic -mtriple=i686-apple-darwin -asm-verbose=false | grep add | count 2
+; RUN: llvm-as < %s | llc                       -mtriple=x86_64-apple-darwin | not grep 'lJTI'
+; rdar://6971437
 
 declare void @_Z3bari(i32)