[llvm-commits] [llvm] r122590 - in /llvm/trunk: include/llvm/MC/MCDwarf.h lib/MC/MCDwarf.cpp lib/MC/MCStreamer.cpp test/MC/ELF/cfi-def-cfa-offset.s
Rafael Espindola
rafael.espindola at gmail.com
Mon Dec 27 20:15:37 PST 2010
Author: rafael
Date: Mon Dec 27 22:15:37 2010
New Revision: 122590
URL: http://llvm.org/viewvc/llvm-project?rev=122590&view=rev
Log:
Start adding basic support for emitting the call frame instructions.
Added:
llvm/trunk/test/MC/ELF/cfi-def-cfa-offset.s
Modified:
llvm/trunk/include/llvm/MC/MCDwarf.h
llvm/trunk/lib/MC/MCDwarf.cpp
llvm/trunk/lib/MC/MCStreamer.cpp
Modified: llvm/trunk/include/llvm/MC/MCDwarf.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCDwarf.h?rev=122590&r1=122589&r2=122590&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCDwarf.h (original)
+++ llvm/trunk/include/llvm/MC/MCDwarf.h Mon Dec 27 22:15:37 2010
@@ -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 @@
};
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;
};
Modified: llvm/trunk/lib/MC/MCDwarf.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCDwarf.cpp?rev=122590&r1=122589&r2=122590&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCDwarf.cpp (original)
+++ llvm/trunk/lib/MC/MCDwarf.cpp Mon Dec 27 22:15:37 2010
@@ -460,9 +460,11 @@
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 @@
streamer.EmitLabel(augmentationEnd);
// Call Frame Instructions
+ EmitFrameMoves(streamer, frame.Moves, frame.Begin, true);
+
// Padding
streamer.EmitValueToAlignment(4);
Modified: llvm/trunk/lib/MC/MCStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCStreamer.cpp?rev=122590&r1=122589&r2=122590&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCStreamer.cpp Mon Dec 27 22:15:37 2010
@@ -157,7 +157,7 @@
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::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;
}
Added: llvm/trunk/test/MC/ELF/cfi-def-cfa-offset.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/cfi-def-cfa-offset.s?rev=122590&view=auto
==============================================================================
--- llvm/trunk/test/MC/ELF/cfi-def-cfa-offset.s (added)
+++ llvm/trunk/test/MC/ELF/cfi-def-cfa-offset.s Mon Dec 27 22:15:37 2010
@@ -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: ),
More information about the llvm-commits
mailing list