[llvm] r206236 - [MC] Emit an error if cfi_startproc is used before a symbol is defined.

Quentin Colombet qcolombet at apple.com
Mon Apr 14 18:17:45 PDT 2014


Author: qcolombet
Date: Mon Apr 14 20:17:45 2014
New Revision: 206236

URL: http://llvm.org/viewvc/llvm-project?rev=206236&view=rev
Log:
[MC] Emit an error if cfi_startproc is used before a symbol is defined.
Currently, we bind those directives with the last symbol, so if none
has been defined, this would lead to a crash of the compiler.

<rdar://problem/15939159>

Added:
    llvm/trunk/test/MC/AsmParser/cfi-invalid-startproc.s
Modified:
    llvm/trunk/lib/MC/MCStreamer.cpp
    llvm/trunk/test/MC/ARM/dwarf-cfi-initial-state.s
    llvm/trunk/test/MC/MachO/debug_frame.s
    llvm/trunk/test/MC/PowerPC/ppc64-initial-cfa.s

Modified: llvm/trunk/lib/MC/MCStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCStreamer.cpp?rev=206236&r1=206235&r2=206236&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCStreamer.cpp Mon Apr 14 20:17:45 2014
@@ -278,6 +278,10 @@ void MCStreamer::EmitCFIStartProcImpl(MC
 }
 
 void MCStreamer::RecordProcStart(MCDwarfFrameInfo &Frame) {
+  // Report an error if we haven't seen a symbol yet where we'd bind
+  // .cfi_startproc.
+  if (!LastSymbol)
+    report_fatal_error("No symbol to start a frame");
   Frame.Function = LastSymbol;
   // We need to create a local symbol to avoid relocations.
   Frame.Begin = getContext().CreateTempSymbol();

Modified: llvm/trunk/test/MC/ARM/dwarf-cfi-initial-state.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ARM/dwarf-cfi-initial-state.s?rev=206236&r1=206235&r2=206236&view=diff
==============================================================================
--- llvm/trunk/test/MC/ARM/dwarf-cfi-initial-state.s (original)
+++ llvm/trunk/test/MC/ARM/dwarf-cfi-initial-state.s Mon Apr 14 20:17:45 2014
@@ -1,6 +1,7 @@
 # RUN: llvm-mc < %s -triple=armv7-linux-gnueabi -filetype=obj -o - \
 # RUN:     | llvm-dwarfdump - | FileCheck %s
 
+_proc:
 .cfi_sections .debug_frame
 .cfi_startproc
 bx lr

Added: llvm/trunk/test/MC/AsmParser/cfi-invalid-startproc.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AsmParser/cfi-invalid-startproc.s?rev=206236&view=auto
==============================================================================
--- llvm/trunk/test/MC/AsmParser/cfi-invalid-startproc.s (added)
+++ llvm/trunk/test/MC/AsmParser/cfi-invalid-startproc.s Mon Apr 14 20:17:45 2014
@@ -0,0 +1,16 @@
+# RUN: not llvm-mc -triple=x86_64-apple-macosx10.8 -filetype=obj -o %t %s 2>&1 | FileCheck %s
+# Check that the cfi_startproc is declared after the beginning of
+# a procedure, otherwise it will reference an invalid symbol for
+# emitting the relocation.
+# <rdar://problem/15939159>
+
+# CHECK: No symbol to start a frame
+.text
+.cfi_startproc
+.globl _someFunction
+_someFunction:
+.cfi_def_cfa_offset 16
+.cfi_offset %rbp, -16
+.cfi_def_cfa_register rbp
+  ret
+.cfi_endproc

Modified: llvm/trunk/test/MC/MachO/debug_frame.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/MachO/debug_frame.s?rev=206236&r1=206235&r2=206236&view=diff
==============================================================================
--- llvm/trunk/test/MC/MachO/debug_frame.s (original)
+++ llvm/trunk/test/MC/MachO/debug_frame.s Mon Apr 14 20:17:45 2014
@@ -3,6 +3,7 @@
 // Make sure MC can handle file level .cfi_startproc and .cfi_endproc that creates
 // an empty frame.
 // rdar://10017184
+_proc:
 .cfi_startproc
 .cfi_endproc
 

Modified: llvm/trunk/test/MC/PowerPC/ppc64-initial-cfa.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/PowerPC/ppc64-initial-cfa.s?rev=206236&r1=206235&r2=206236&view=diff
==============================================================================
--- llvm/trunk/test/MC/PowerPC/ppc64-initial-cfa.s (original)
+++ llvm/trunk/test/MC/PowerPC/ppc64-initial-cfa.s Mon Apr 14 20:17:45 2014
@@ -7,6 +7,7 @@
 # RUN: llvm-mc -triple=powerpc64le-unknown-linux-gnu -filetype=obj -relocation-model=pic %s | \
 # RUN: llvm-readobj -s -sr -sd | FileCheck %s -check-prefix=PIC -check-prefix=PIC-LE
 
+_proc:
         .cfi_startproc
         nop
         .cfi_endproc





More information about the llvm-commits mailing list