[PATCH][MC/X86_64] Implement Win64 exception handling

Nico Rieck nico.rieck at gmail.com
Sun Dec 22 03:54:38 PST 2013


Hi Kai!

On 04.12.2013 11:27, Kai Nacke wrote:
> Further, it seems that LLVM does not generate a LEA instruction in the
> frame setup which legally triggers my new code. At least I was unable to
> create a test for this. Any suggestion here is welcome.

You can use -mcpu=atom to trigger using LEA for SP updates, though this 
only covers one half. MOV64mr and MOVAPSmr are also never used by LLVM 
AFAICS.

+  case X86::MOV64mr:
+  case X86::MOVAPSmr:
+    DReg = MI->getOperand(0).getReg();
+    Offset = MI->getOperand(0).getOffset();
+    SReg = MI->getOperand(1).getReg();

An operand cannot be both a register and an offset. This will assert. 
Both instructions use a ModRM byte and thus have 6 operands. Of interest 
here are 0 for base, 3 for offset/disp and 5 for source register. The 
rest should be enforced to default values.

+  case X86::LEA64r:
+    DReg = MI->getOperand(0).getReg();
+    Offset = MI->getOperand(0).getOffset();
+    SReg = MI->getOperand(1).getReg();
+    if (SReg == RI->getStackRegister()) {
+      if (DReg == RI->getFrameRegister(*MF)) {
+        OutStreamer.EmitWin64EHSetFrame(RI->getSEHRegNum(DReg), Offset);
+      } else if (DReg == RI->getStackRegister()) {
+        OutStreamer.EmitWin64EHAllocStack(Offset);
+      }
+      else
+        llvm_unreachable("X86::X86::LEA64r not allowed with these 
operands");
+    }

The LEA offsets here are (and must be) negative and must be explicitly 
negated. And I think DReg should be checked against the stack register 
first for those cases when there is no frame register.

Overall there are still a few else-clauses missing to reject.

I saw you landed the __chkstk_ms change, which simplifies the last three 
cases. But I'm stating the obvious here. :)

-Nico



More information about the llvm-commits mailing list