Start adding basic support for emitting the call frame instructions.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122590 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola 2010-12-28 04:15:37 +00:00
parent 4213618088
commit 5bba084253
4 changed files with 66 additions and 2 deletions

View File

@ -16,6 +16,7 @@
#define LLVM_MC_MCDWARF_H
#include "llvm/ADT/StringRef.h"
#include "llvm/CodeGen/MachineLocation.h" // FIXME
#include "llvm/MC/MCObjectWriter.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/Dwarf.h"
@ -227,10 +228,13 @@ namespace llvm {
};
struct MCDwarfFrameInfo {
MCDwarfFrameInfo() : Begin(0), End(0), Personality(0), Lsda(0), Moves(),
PersonalityEncoding(0), LsdaEncoding(0) {}
MCSymbol *Begin;
MCSymbol *End;
const MCSymbol *Personality;
const MCSymbol *Lsda;
std::vector<MachineMove> Moves;
unsigned PersonalityEncoding;
unsigned LsdaEncoding;
};

View File

@ -460,9 +460,11 @@ static void EmitFrameMoves(MCStreamer &streamer,
if (BaseLabel && Label) {
MCSymbol *ThisSym = Label;
if (ThisSym != BaseLabel) {
// FIXME: We should relax this instead of using a DW_CFA_advance_loc4
// for every address change!
streamer.EmitIntValue(dwarf::DW_CFA_advance_loc4, 1);
const MCExpr *Length = MakeStartMinusEndExpr(streamer, *BaseLabel,
*ThisSym, 4);
*ThisSym, 0);
streamer.EmitValue(Length, 4);
BaseLabel = ThisSym;
}
@ -672,6 +674,8 @@ static MCSymbol *EmitFDE(MCStreamer &streamer,
streamer.EmitLabel(augmentationEnd);
// Call Frame Instructions
EmitFrameMoves(streamer, frame.Moves, frame.Begin, true);
// Padding
streamer.EmitValueToAlignment(4);

View File

@ -157,7 +157,7 @@ bool MCStreamer::EmitCFIStartProc() {
report_fatal_error("Starting a frame before finishing the previous one!");
return true;
}
MCDwarfFrameInfo Frame = {0, 0, 0, 0, 0, 0};
MCDwarfFrameInfo Frame;
Frame.Begin = getContext().CreateTempSymbol();
EmitLabel(Frame.Begin);
FrameInfos.push_back(Frame);
@ -174,6 +174,13 @@ bool MCStreamer::EmitCFIEndProc() {
bool MCStreamer::EmitCFIDefCfaOffset(int64_t Offset) {
EnsureValidFrame();
MCDwarfFrameInfo *CurFrame = getCurrentFrameInfo();
MCSymbol *Label = getContext().CreateTempSymbol();
EmitLabel(Label);
MachineLocation Dest(MachineLocation::VirtualFP);
MachineLocation Source(MachineLocation::VirtualFP, -Offset);
MachineMove Move(Label, Dest, Source);
CurFrame->Moves.push_back(Move);
return false;
}

View File

@ -0,0 +1,49 @@
// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump --dump-section-data | FileCheck %s
f:
.cfi_startproc
subq $8, %rsp
.cfi_def_cfa_offset 16
nop
addq $8, %rsp
.cfi_def_cfa_offset 8
ret
.cfi_endproc
// FIXME: This is a correct but really inefficient coding since
// we use a CFA_advance_loc4 for every address change!
// CHECK: # Section 0x00000004
// CHECK-NEXT: (('sh_name', 0x00000012) # '.eh_frame'
// CHECK-NEXT: ('sh_type', 0x00000001)
// CHECK-NEXT: ('sh_flags', 0x00000002)
// CHECK-NEXT: ('sh_addr', 0x00000000)
// CHECK-NEXT: ('sh_offset', 0x00000050)
// CHECK-NEXT: ('sh_size', 0x00000038)
// CHECK-NEXT: ('sh_link', 0x00000000)
// CHECK-NEXT: ('sh_info', 0x00000000)
// CHECK-NEXT: ('sh_addralign', 0x00000008)
// CHECK-NEXT: ('sh_entsize', 0x00000000)
// CHECK-NEXT: ('_section_data', '14000000 00000000 017a5200 01781001 1b0c0708 90010000 1c000000 1c000000 00000000 0a000000 00040400 00000e10 04050000 000e0800')
// CHECK-NEXT: ),
// CHECK: # Section 0x00000008
// CHECK-NEXT: (('sh_name', 0x00000036) # '.rela.eh_frame'
// CHECK-NEXT: ('sh_type', 0x00000004)
// CHECK-NEXT: ('sh_flags', 0x00000000)
// CHECK-NEXT: ('sh_addr', 0x00000000)
// CHECK-NEXT: ('sh_offset', 0x00000168)
// CHECK-NEXT: ('sh_size', 0x00000018)
// CHECK-NEXT: ('sh_link', 0x00000006)
// CHECK-NEXT: ('sh_info', 0x00000004)
// CHECK-NEXT: ('sh_addralign', 0x00000008)
// CHECK-NEXT: ('sh_entsize', 0x00000018)
// CHECK-NEXT: ('_relocations', [
// CHECK-NEXT: # Relocation 0x00000000
// CHECK-NEXT: (('r_offset', 0x00000020)
// CHECK-NEXT: ('r_sym', 0x00000002)
// CHECK-NEXT: ('r_type', 0x00000002)
// CHECK-NEXT: ('r_addend', 0x00000000)
// CHECK-NEXT: ),
// CHECK-NEXT: ])
// CHECK-NEXT: ),