[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>


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206236 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Quentin Colombet 2014-04-15 01:17:45 +00:00
parent e8603c43f2
commit 67ed710684
5 changed files with 23 additions and 0 deletions

View File

@ -278,6 +278,10 @@ void MCStreamer::EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame) {
} }
void MCStreamer::RecordProcStart(MCDwarfFrameInfo &Frame) { 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; Frame.Function = LastSymbol;
// We need to create a local symbol to avoid relocations. // We need to create a local symbol to avoid relocations.
Frame.Begin = getContext().CreateTempSymbol(); Frame.Begin = getContext().CreateTempSymbol();

View File

@ -1,6 +1,7 @@
# RUN: llvm-mc < %s -triple=armv7-linux-gnueabi -filetype=obj -o - \ # RUN: llvm-mc < %s -triple=armv7-linux-gnueabi -filetype=obj -o - \
# RUN: | llvm-dwarfdump - | FileCheck %s # RUN: | llvm-dwarfdump - | FileCheck %s
_proc:
.cfi_sections .debug_frame .cfi_sections .debug_frame
.cfi_startproc .cfi_startproc
bx lr bx lr

View File

@ -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

View File

@ -3,6 +3,7 @@
// Make sure MC can handle file level .cfi_startproc and .cfi_endproc that creates // Make sure MC can handle file level .cfi_startproc and .cfi_endproc that creates
// an empty frame. // an empty frame.
// rdar://10017184 // rdar://10017184
_proc:
.cfi_startproc .cfi_startproc
.cfi_endproc .cfi_endproc

View File

@ -7,6 +7,7 @@
# RUN: llvm-mc -triple=powerpc64le-unknown-linux-gnu -filetype=obj -relocation-model=pic %s | \ # 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 # RUN: llvm-readobj -s -sr -sd | FileCheck %s -check-prefix=PIC -check-prefix=PIC-LE
_proc:
.cfi_startproc .cfi_startproc
nop nop
.cfi_endproc .cfi_endproc