aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorCharles Davis <cdavis@mines.edu>2011-05-27 03:25:01 +0000
committerCharles Davis <cdavis@mines.edu>2011-05-27 03:25:01 +0000
commitc4cbf9b6aa95cf861a5a80bfccf615ff5c53e4ef (patch)
tree81bc296a672d3cdbf8e8c178bc7392bab8b6c60d /lib
parentef60724ddc7726da8044d711c2a126197f4a0965 (diff)
Start keeping track of where the various unwind instructions are in the prolog.
Use them to calculate the offset inside the prolog. Emit this value when emitting the unwind codes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@132177 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/MC/MCStreamer.cpp22
-rw-r--r--lib/MC/MCWin64EH.cpp39
2 files changed, 39 insertions, 22 deletions
diff --git a/lib/MC/MCStreamer.cpp b/lib/MC/MCStreamer.cpp
index 881bc8eaba..974e885aac 100644
--- a/lib/MC/MCStreamer.cpp
+++ b/lib/MC/MCStreamer.cpp
@@ -385,7 +385,9 @@ void MCStreamer::EmitWin64EHHandlerData() {
void MCStreamer::EmitWin64EHPushReg(unsigned Register) {
EnsureValidW64UnwindInfo();
MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo;
- MCWin64EHInstruction Inst(Win64EH::UOP_PushNonVol, Register);
+ MCSymbol *Label = getContext().CreateTempSymbol();
+ MCWin64EHInstruction Inst(Win64EH::UOP_PushNonVol, Label, Register);
+ EmitLabel(Label);
CurFrame->Instructions.push_back(Inst);
}
@@ -396,7 +398,7 @@ void MCStreamer::EmitWin64EHSetFrame(unsigned Register, unsigned Offset) {
report_fatal_error("Frame register and offset already specified!");
if (Offset & 0x0F)
report_fatal_error("Misaligned frame pointer offset!");
- MCWin64EHInstruction Inst(Win64EH::UOP_SetFPReg, Register, Offset);
+ MCWin64EHInstruction Inst(Win64EH::UOP_SetFPReg, NULL, Register, Offset);
CurFrame->LastFrameInst = CurFrame->Instructions.size();
CurFrame->Instructions.push_back(Inst);
}
@@ -406,7 +408,9 @@ void MCStreamer::EmitWin64EHAllocStack(unsigned Size) {
if (Size & 7)
report_fatal_error("Misaligned stack allocation!");
MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo;
- MCWin64EHInstruction Inst(Size);
+ MCSymbol *Label = getContext().CreateTempSymbol();
+ MCWin64EHInstruction Inst(Label, Size);
+ EmitLabel(Label);
CurFrame->Instructions.push_back(Inst);
}
@@ -415,9 +419,11 @@ void MCStreamer::EmitWin64EHSaveReg(unsigned Register, unsigned Offset) {
if (Offset & 7)
report_fatal_error("Misaligned saved register offset!");
MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo;
+ MCSymbol *Label = getContext().CreateTempSymbol();
MCWin64EHInstruction Inst(
Offset > 512*1024-8 ? Win64EH::UOP_SaveNonVolBig : Win64EH::UOP_SaveNonVol,
- Register, Offset);
+ Label, Register, Offset);
+ EmitLabel(Label);
CurFrame->Instructions.push_back(Inst);
}
@@ -426,9 +432,11 @@ void MCStreamer::EmitWin64EHSaveXMM(unsigned Register, unsigned Offset) {
if (Offset & 0x0F)
report_fatal_error("Misaligned saved vector register offset!");
MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo;
+ MCSymbol *Label = getContext().CreateTempSymbol();
MCWin64EHInstruction Inst(
Offset > 512*1024-16 ? Win64EH::UOP_SaveXMM128Big : Win64EH::UOP_SaveXMM128,
- Register, Offset);
+ Label, Register, Offset);
+ EmitLabel(Label);
CurFrame->Instructions.push_back(Inst);
}
@@ -437,7 +445,9 @@ void MCStreamer::EmitWin64EHPushFrame(bool Code) {
MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo;
if (CurFrame->Instructions.size() > 0)
report_fatal_error("If present, PushMachFrame must be the first UOP");
- MCWin64EHInstruction Inst(Win64EH::UOP_PushMachFrame, Code);
+ MCSymbol *Label = getContext().CreateTempSymbol();
+ MCWin64EHInstruction Inst(Win64EH::UOP_PushMachFrame, Label, Code);
+ EmitLabel(Label);
CurFrame->Instructions.push_back(Inst);
}
diff --git a/lib/MC/MCWin64EH.cpp b/lib/MC/MCWin64EH.cpp
index 2511e91b85..c7141f7ad3 100644
--- a/lib/MC/MCWin64EH.cpp
+++ b/lib/MC/MCWin64EH.cpp
@@ -47,18 +47,31 @@ static uint8_t CountOfUnwindCodes(std::vector<MCWin64EHInstruction> &instArray){
return count;
}
-static void EmitUnwindCode(MCStreamer &streamer, MCWin64EHInstruction &inst) {
+static void EmitAbsDifference(MCStreamer &streamer, MCSymbol *lhs,
+ MCSymbol *rhs) {
+ MCContext &context = streamer.getContext();
+ const MCExpr *diff = MCBinaryExpr::CreateSub(MCSymbolRefExpr::Create(
+ lhs, context),
+ MCSymbolRefExpr::Create(
+ rhs, context),
+ context);
+ streamer.EmitAbsValue(diff, 1);
+
+}
+
+static void EmitUnwindCode(MCStreamer &streamer, MCSymbol *begin,
+ MCWin64EHInstruction &inst) {
uint8_t b1, b2;
uint16_t w;
b2 = (inst.getOperation() & 0x0F) << 4;
switch (inst.getOperation()) {
case Win64EH::UOP_PushNonVol:
- streamer.EmitIntValue(0, 1);
+ EmitAbsDifference(streamer, inst.getLabel(), begin);
b2 |= inst.getRegister() & 0x0F;
streamer.EmitIntValue(b2, 1);
break;
case Win64EH::UOP_AllocLarge:
- streamer.EmitIntValue(0, 1);
+ EmitAbsDifference(streamer, inst.getLabel(), begin);
if (inst.getSize() > 512*1024-8) {
b2 |= 1;
streamer.EmitIntValue(b2, 1);
@@ -72,8 +85,8 @@ static void EmitUnwindCode(MCStreamer &streamer, MCWin64EHInstruction &inst) {
streamer.EmitIntValue(w, 2);
break;
case Win64EH::UOP_AllocSmall:
- b2 |= (inst.getSize() >> 3) & 0x0F;
- streamer.EmitIntValue(0, 1);
+ b2 |= ((inst.getSize()-8) >> 3) & 0x0F;
+ EmitAbsDifference(streamer, inst.getLabel(), begin);
streamer.EmitIntValue(b2, 1);
break;
case Win64EH::UOP_SetFPReg:
@@ -84,7 +97,7 @@ static void EmitUnwindCode(MCStreamer &streamer, MCWin64EHInstruction &inst) {
case Win64EH::UOP_SaveNonVol:
case Win64EH::UOP_SaveXMM128:
b2 |= inst.getRegister() & 0x0F;
- streamer.EmitIntValue(0, 1);
+ EmitAbsDifference(streamer, inst.getLabel(), begin);
streamer.EmitIntValue(b2, 1);
w = inst.getOffset() >> 3;
if (inst.getOperation() == Win64EH::UOP_SaveXMM128)
@@ -94,7 +107,7 @@ static void EmitUnwindCode(MCStreamer &streamer, MCWin64EHInstruction &inst) {
case Win64EH::UOP_SaveNonVolBig:
case Win64EH::UOP_SaveXMM128Big:
b2 |= inst.getRegister() & 0x0F;
- streamer.EmitIntValue(0, 1);
+ EmitAbsDifference(streamer, inst.getLabel(), begin);
streamer.EmitIntValue(b2, 1);
if (inst.getOperation() == Win64EH::UOP_SaveXMM128Big)
w = inst.getOffset() & 0xFFF0;
@@ -107,7 +120,7 @@ static void EmitUnwindCode(MCStreamer &streamer, MCWin64EHInstruction &inst) {
case Win64EH::UOP_PushMachFrame:
if (inst.isPushCodeFrame())
b2 |= 1;
- streamer.EmitIntValue(0, 1);
+ EmitAbsDifference(streamer, inst.getLabel(), begin);
streamer.EmitIntValue(b2, 1);
break;
}
@@ -144,13 +157,7 @@ static void EmitUnwindInfo(MCStreamer &streamer, MCWin64EHUnwindInfo *info) {
}
streamer.EmitIntValue(flags, 1);
- // Build up the prolog size expression.
- const MCExpr *prologSize = MCBinaryExpr::CreateSub(MCSymbolRefExpr::Create(
- info->PrologEnd, context),
- MCSymbolRefExpr::Create(
- info->Begin, context),
- context);
- streamer.EmitAbsValue(prologSize, 1);
+ EmitAbsDifference(streamer, info->PrologEnd, info->Begin);
uint8_t numCodes = CountOfUnwindCodes(info->Instructions);
streamer.EmitIntValue(numCodes, 1);
@@ -169,7 +176,7 @@ static void EmitUnwindInfo(MCStreamer &streamer, MCWin64EHUnwindInfo *info) {
for (uint8_t c = 0; c < numInst; ++c) {
MCWin64EHInstruction inst = info->Instructions.back();
info->Instructions.pop_back();
- EmitUnwindCode(streamer, inst);
+ EmitUnwindCode(streamer, info->Begin, inst);
}
if (flags & Win64EH::UNW_ChainInfo)