From 4d45f1ed0d9d67979b44626ede1fee01ac90d222 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Thu, 14 Jul 2016 17:27:06 +0000 Subject: [PATCH] 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@275442 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../RuntimeDyld/Targets/RuntimeDyldCOFFI386.h | 6 ++++-- test/ExecutionEngine/RuntimeDyld/X86/COFF_i386.s | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFI386.h b/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFI386.h index 92fbb7c67d0..44fda87e0f9 100644 --- a/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFI386.h +++ b/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFI386.h @@ -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(-1) + ? Value + : Sections[RE.Sections.SectionA].getLoadAddress(); + Result = Result - Section.getLoadAddress() + RE.Addend - 4 - RE.Offset; assert(static_cast(Result) <= INT32_MAX && "relocation overflow"); assert(static_cast(Result) >= INT32_MIN && diff --git a/test/ExecutionEngine/RuntimeDyld/X86/COFF_i386.s b/test/ExecutionEngine/RuntimeDyld/X86/COFF_i386.s index c2273da63dd..ddf154e4320 100644 --- a/test/ExecutionEngine/RuntimeDyld/X86/COFF_i386.s +++ b/test/ExecutionEngine/RuntimeDyld/X86/COFF_i386.s @@ -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@4=0xfffffffe -dummy-extern _ExitProcess@4=0xffffffff -verify -check=%s %t.obj +// RUN: llvm-rtdyld -triple i686-windows -dummy-extern _printf=0xfffffffd -dummy-extern _OutputDebugStringA@4=0xfffffffe -dummy-extern _ExitProcess@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