Assume .cfi_startproc is the first thing in a function. If the function is
authorRafael Espindola <rafael.espindola@gmail.com>
Tue, 2 Aug 2011 20:24:22 +0000 (20:24 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Tue, 2 Aug 2011 20:24:22 +0000 (20:24 +0000)
externally visable, create a local symbol to use in the CFE. If not, use the
function label itself.

Fixes PR10420.

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

include/llvm/MC/MCStreamer.h
lib/MC/MCStreamer.cpp
test/CodeGen/X86/pr10420.ll [new file with mode: 0644]

index a38a5a46e4857c70cddfe4030e492c942e892280..c5c7583f1034394927835cc75e46784534b3ab15 100644 (file)
@@ -64,7 +64,7 @@ namespace llvm {
     void setCurrentW64UnwindInfo(MCWin64EHUnwindInfo *Frame);
     void EnsureValidW64UnwindInfo();
 
-    const MCSymbol* LastNonPrivate;
+    MCSymbol* LastSymbol;
 
     /// SectionStack - This is stack of current and previous section
     /// values saved by PushSection.
index 4a717ed12e54cd8f3468227ba19ee1f5f606feff..5295d0f58f3aa8edec725ef3e87a451c2b169ba7 100644 (file)
@@ -171,10 +171,7 @@ void MCStreamer::EmitLabel(MCSymbol *Symbol) {
   assert(!Symbol->isVariable() && "Cannot emit a variable symbol!");
   assert(getCurrentSection() && "Cannot emit before setting section!");
   Symbol->setSection(*getCurrentSection());
-
-  StringRef Prefix = getContext().getAsmInfo().getPrivateGlobalPrefix();
-  if (!Symbol->getName().startswith(Prefix))
-    LastNonPrivate = Symbol;
+  LastSymbol = Symbol;
 }
 
 void MCStreamer::EmitCompactUnwindEncoding(uint32_t CompactUnwindEncoding) {
@@ -194,9 +191,19 @@ void MCStreamer::EmitCFIStartProc() {
   if (CurFrame && !CurFrame->End)
     report_fatal_error("Starting a frame before finishing the previous one!");
   MCDwarfFrameInfo Frame;
-  Frame.Begin = getContext().CreateTempSymbol();
-  Frame.Function = LastNonPrivate;
-  EmitLabel(Frame.Begin);
+
+  Frame.Function = LastSymbol;
+
+  // If the function is externally visible, we need to create a local
+  // symbol to avoid relocations.
+  StringRef Prefix = getContext().getAsmInfo().getPrivateGlobalPrefix();
+  if (LastSymbol->getName().startswith(Prefix)) {
+    Frame.Begin = LastSymbol;
+  } else {
+    Frame.Begin = getContext().CreateTempSymbol();
+    EmitLabel(Frame.Begin);
+  }
+
   FrameInfos.push_back(Frame);
 }
 
diff --git a/test/CodeGen/X86/pr10420.ll b/test/CodeGen/X86/pr10420.ll
new file mode 100644 (file)
index 0000000..3993f24
--- /dev/null
@@ -0,0 +1,21 @@
+; RUN: llc < %s -mtriple=x86_64-apple-macosx -disable-cfi | FileCheck %s
+
+define private void @foo() {
+       ret void
+}
+
+define void @bar() {
+       call void @foo()
+       ret void;
+}
+
+; CHECK: _bar:                                   ## @bar
+; CHECK-NEXT: Ltmp2:
+
+; CHECK: Ltmp12:
+; CHECK-NEXT: Ltmp13 = L_foo-Ltmp12                   ## FDE initial location
+; CHECK-NEXT:         .quad   Ltmp13
+
+; CHECK: Ltmp19:
+; CHECK-NEXT: Ltmp20 = Ltmp2-Ltmp19                   ## FDE initial location
+; CHECK-NEXT:         .quad   Ltmp20