[PATCH] D56275: x86 interrupt calling convention: Fix argument offsets

Philipp Oppermann via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 3 08:46:37 PST 2019


phil-opp created this revision.
phil-opp added reviewers: craig.topper, rnk.
Herald added a subscriber: JDevlieghere.

The x86 interrupt calling convention uses custom stack offsets for the parameters because they are pushed directly by the CPU. Thus the calling convention requires `MFI.setObjectOffset(FI, Offset)` calls before all returns in `LowerMemArgument` in order to set the correct offset. Commit 4c3428b604324ed1528a78dbc31c8c8805d3c3e6 introduced new code paths without `MFI.setObjectOffset(FI, Offset)`, which broke the argument passing for the x86 interrupt calling convention in some cases.

For example, it resulted in incorrect error code arguments in Rust binaries, but only when compiled without optimizations: https://github.com/rust-lang/rust/issues/57270

This patch fixes this bug by adding the `setObjectOffset` calls to the two new code paths.


Repository:
  rL LLVM

https://reviews.llvm.org/D56275

Files:
  lib/Target/X86/X86ISelLowering.cpp


Index: lib/Target/X86/X86ISelLowering.cpp
===================================================================
--- lib/Target/X86/X86ISelLowering.cpp
+++ lib/Target/X86/X86ISelLowering.cpp
@@ -2999,6 +2999,10 @@
       // argument is in memory, the rest will also be in memory.
       int FI = MFI.CreateFixedObject(ArgVT.getStoreSize(), VA.getLocMemOffset(),
                                      /*Immutable=*/false);
+      // Adjust SP offset of interrupt parameter.
+      if (CallConv == CallingConv::X86_INTR) {
+        MFI.setObjectOffset(FI, Offset);
+      }                                     
       PartAddr = DAG.getFrameIndex(FI, PtrVT);
       return DAG.getLoad(
           ValVT, dl, Chain, PartAddr,
@@ -3021,6 +3025,10 @@
         SDValue Addr =
             DAG.getNode(ISD::ADD, dl, PtrVT, DAG.getFrameIndex(FI, PtrVT),
                         DAG.getIntPtrConstant(Ins[i].PartOffset, dl));
+        // Adjust SP offset of interrupt parameter.
+        if (CallConv == CallingConv::X86_INTR) {
+          MFI.setObjectOffset(FI, Offset);
+        }
         return DAG.getLoad(
             ValVT, dl, Chain, Addr,
             MachinePointerInfo::getFixedStack(DAG.getMachineFunction(), FI,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56275.180064.patch
Type: text/x-patch
Size: 1216 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190103/09d8ddc1/attachment.bin>


More information about the llvm-commits mailing list