[PATCH][X86_64/MC] Fix code offset for unwind code SET_FPREG and enable test

Kai Nacke kai.nacke at redstar.de
Sun Aug 25 21:21:06 PDT 2013


Please, could have one of the MC maintainers a look at my patch? Thank you!

Regards
Kai

On 20.08.2013 14:34, Charles Davis wrote:
>
> On Aug 12, 2013, at 12:07 AM, Kai Nacke wrote:
>
>> Hi!
>>
>> The code offset for unwind code SET_FPREG is wrong because it
>> is set to constant 0. The fix is to do the same as for the other
>> unwind codes: emit a label and later the absolute difference
>> between the label and the begin of the prologue.
>>
>> The attached patch fixes the issue and enables the associated test.
>>
>> Please review.
> LGTM.
>
> Chip
>
>>
>> Regards
>>
>> Kai
>> <0001-Fix-failing-test-seh.s.patch>_______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>

-------------- next part --------------
>From 9def28f105b6c69ee4f8a9124b9071875e94b3c1 Mon Sep 17 00:00:00 2001
From: kai <kai at redstar.de>
Date: Mon, 27 May 2013 07:32:17 +0200
Subject: [PATCH 1/1] Fix failing test seh.s

The code offset for unwind code SET_FPREG is wrong because it
is set to constant 0. The fix is to do the same as for the other
unwind codes: emit a label and later the absolute difference
between the label and the begin of the prologue.
---
 lib/MC/MCStreamer.cpp                       | 4 +++-
 lib/MC/MCWin64EH.cpp                        | 5 ++---
 test/MC/COFF/seh.s                          | 2 --
 test/tools/llvm-objdump/win64-unwind-data.s | 2 +-
 4 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/lib/MC/MCStreamer.cpp b/lib/MC/MCStreamer.cpp
index 6542f42..fb43a4a 100644
--- a/lib/MC/MCStreamer.cpp
+++ b/lib/MC/MCStreamer.cpp
@@ -470,7 +470,9 @@ 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, 0, Register, Offset);
+  MCSymbol *Label = getContext().CreateTempSymbol();
+  MCWin64EHInstruction Inst(Win64EH::UOP_SetFPReg, Label, Register, Offset);
+  EmitLabel(Label);
   CurFrame->LastFrameInst = CurFrame->Instructions.size();
   CurFrame->Instructions.push_back(Inst);
 }
diff --git a/lib/MC/MCWin64EH.cpp b/lib/MC/MCWin64EH.cpp
index c5b637c..8db1fa2 100644
--- a/lib/MC/MCWin64EH.cpp
+++ b/lib/MC/MCWin64EH.cpp
@@ -64,7 +64,7 @@ static void EmitAbsDifference(MCStreamer &streamer, MCSymbol *lhs,

 static void EmitUnwindCode(MCStreamer &streamer, MCSymbol *begin,
                            MCWin64EHInstruction &inst) {
-  uint8_t b1, b2;
+  uint8_t b2;
   uint16_t w;
   b2 = (inst.getOperation() & 0x0F);
   switch (inst.getOperation()) {
@@ -93,8 +93,7 @@ static void EmitUnwindCode(MCStreamer &streamer, MCSymbol *begin,
     streamer.EmitIntValue(b2, 1);
     break;
   case Win64EH::UOP_SetFPReg:
-    b1 = inst.getOffset() & 0xF0;
-    streamer.EmitIntValue(b1, 1);
+    EmitAbsDifference(streamer, inst.getLabel(), begin);
     streamer.EmitIntValue(b2, 1);
     break;
   case Win64EH::UOP_SaveNonVol:
diff --git a/test/MC/COFF/seh.s b/test/MC/COFF/seh.s
index bef425e..b1e61a9 100644
--- a/test/MC/COFF/seh.s
+++ b/test/MC/COFF/seh.s
@@ -1,7 +1,5 @@
 // This test checks that the SEH directives emit the correct unwind data.

-// TODO: Expected fail because SET_FPREG has a wrong offset.
-// XFAIL: *
 // RUN: llvm-mc -triple x86_64-pc-win32 -filetype=obj %s | llvm-readobj -s -u | FileCheck %s

 // CHECK:      Sections [
diff --git a/test/tools/llvm-objdump/win64-unwind-data.s b/test/tools/llvm-objdump/win64-unwind-data.s
index 1e4c742..a172bfc 100644
--- a/test/tools/llvm-objdump/win64-unwind-data.s
+++ b/test/tools/llvm-objdump/win64-unwind-data.s
@@ -13,7 +13,7 @@
 // CHECK-NEXT: Frame register: RBX
 // CHECK-NEXT: Frame offset: 0
 // CHECK-NEXT: Unwind Codes:
-// CHECK-NEXT: 0x00: UOP_SetFPReg
+// CHECK-NEXT: 0x12: UOP_SetFPReg
 // CHECK-NEXT: 0x0f: UOP_PushNonVol RBX
 // CHECK-NEXT: 0x0e: UOP_SaveXMM128 XMM8 [0x0000]
 // CHECK-NEXT: 0x09: UOP_SaveNonVol RSI [0x0010]
--
1.8.0.msysgit.0



More information about the llvm-commits mailing list