[llvm] r275442 - X86: handle external tail calls in Windows JIT

Saleem Abdulrasool via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 14 10:27:06 PDT 2016


Author: compnerd
Date: Thu Jul 14 12:27:06 2016
New Revision: 275442

URL: http://llvm.org/viewvc/llvm-project?rev=275442&view=rev
Log:
X86: handle external tail calls in Windows JIT

If there was a tail call, we would incorrectly handle the relocation.  It would
end up indexing into the array with an incorrect section id.  The symbol was
external to the module, so the Section ID was UNDEFINED (-1).  We would then
index the SmallVector with this ID, triggering an assertion.  Use the Value
rather than the section load address in this case.

Modified:
    llvm/trunk/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFI386.h
    llvm/trunk/test/ExecutionEngine/RuntimeDyld/X86/COFF_i386.s

Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFI386.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFI386.h?rev=275442&r1=275441&r2=275442&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFI386.h (original)
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFI386.h Thu Jul 14 12:27:06 2016
@@ -174,8 +174,10 @@ public:
     }
     case COFF::IMAGE_REL_I386_REL32: {
       // 32-bit relative displacement to the target.
-      uint64_t Result = Sections[RE.Sections.SectionA].getLoadAddress() -
-                        Section.getLoadAddress() + RE.Addend - 4 - RE.Offset;
+      uint64_t Result = RE.Sections.SectionA == static_cast<uint32_t>(-1)
+                            ? Value
+                            : Sections[RE.Sections.SectionA].getLoadAddress();
+      Result = Result - Section.getLoadAddress() + RE.Addend - 4 - RE.Offset;
       assert(static_cast<int32_t>(Result) <= INT32_MAX &&
              "relocation overflow");
       assert(static_cast<int32_t>(Result) >= INT32_MIN &&

Modified: llvm/trunk/test/ExecutionEngine/RuntimeDyld/X86/COFF_i386.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ExecutionEngine/RuntimeDyld/X86/COFF_i386.s?rev=275442&r1=275441&r2=275442&view=diff
==============================================================================
--- llvm/trunk/test/ExecutionEngine/RuntimeDyld/X86/COFF_i386.s (original)
+++ llvm/trunk/test/ExecutionEngine/RuntimeDyld/X86/COFF_i386.s Thu Jul 14 12:27:06 2016
@@ -1,5 +1,5 @@
 // RUN: llvm-mc -triple i686-windows -filetype obj -o %t.obj %s
-// RUN: llvm-rtdyld -triple i686-windows -dummy-extern _OutputDebugStringA at 4=0xfffffffe -dummy-extern _ExitProcess at 4=0xffffffff -verify -check=%s %t.obj
+// RUN: llvm-rtdyld -triple i686-windows -dummy-extern _printf=0xfffffffd -dummy-extern _OutputDebugStringA at 4=0xfffffffe -dummy-extern _ExitProcess at 4=0xffffffff -verify -check=%s %t.obj
 
 	.text
 
@@ -13,7 +13,9 @@ rel1:
 	call _function				// IMAGE_REL_I386_REL32
 # rtdyld-check: decode_operand(rel1, 0) = (_function-_main-4-1)
 	xorl %eax, %eax
-	retl
+rel12:
+	jmp _printf
+# rtdyld-check: decode_operand(rel12, 0)[31:0] = (_printf-_main-4-8)
 
 	.def _function
 		.scl 2




More information about the llvm-commits mailing list