<div dir="ltr">Thanks very much <span style="font-size:13px;font-family:arial,sans-serif">Swaroop! And thanks Reid for the review.</span><div><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div><div><font face="arial, sans-serif">If this fixes </font><span style="font-size:13px;font-family:arial,sans-serif"> </span><a href="http://llvm.org/PR5053" target="_blank" style="font-size:13px;font-family:arial,sans-serif">http://llvm.org/PR5053</a>, please go ahead and mark it resolved.</div><div><br></div><div>Cheers,</div><div>Lang.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Nov 13, 2014 at 3:32 PM, Reid Kleckner <span dir="ltr"><<a href="mailto:reid@kleckner.net" target="_blank">reid@kleckner.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: rnk<br>
Date: Thu Nov 13 17:32:52 2014<br>
New Revision: 221947<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=221947&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=221947&view=rev</a><br>
Log:<br>
Fix symbol resolution of floating point libc builtins in MCJIT<br>
<br>
Fix for LLI failure on Windows\X86: <a href="http://llvm.org/PR5053" target="_blank">http://llvm.org/PR5053</a><br>
<br>
LLI.exe crashes on Windows\X86 when single precession floating point<br>
intrinsics like the following are used: acos, asin, atan, atan2, ceil,<br>
copysign, cos, cosh, exp, floor, fmin, fmax, fmod, log, pow, sin, sinh,<br>
sqrt, tan, tanh<br>
<br>
The above intrinsics are defined as inline-expansions in math.h, and are<br>
not exported by msvcr120.dll (Win32 API GetProcAddress returns null).<br>
<br>
For an FREM instruction, the JIT compiler generates a call to a stub for<br>
the fmodf() intrinsic, and adds a relocation to fixup at load time. The<br>
loader searches the libraries for the function, but fails because the<br>
symbol is not exported. So, the call target remains NULL and the<br>
execution crashes.<br>
<br>
Since the math functions are loaded at JIT/runtime, the JIT can patch<br>
CALL instruction directly instead of the searching the libraries'<br>
exported symbols.  However, this fix caused build failures due to<br>
unresolved symbols like _fmodf at link time.<br>
<br>
Therefore, the current fix defines helper functions in the Runtime<br>
link/load library to perform the above operations.  The address of these<br>
helper functions are used to patch up the CALL instruction at load time.<br>
<br>
Reviewers: lhames, rnk<br>
<br>
Reviewed By: rnk<br>
<br>
Differential Revision: <a href="http://reviews.llvm.org/D5387" target="_blank">http://reviews.llvm.org/D5387</a><br>
<br>
Patch by Swaroop Sridhar!<br>
<br>
Added:<br>
    llvm/trunk/test/ExecutionEngine/frem.ll<br>
Modified:<br>
    llvm/trunk/lib/Support/Windows/DynamicLibrary.inc<br>
    llvm/trunk/lib/Support/Windows/explicit_symbols.inc<br>
<br>
Modified: llvm/trunk/lib/Support/Windows/DynamicLibrary.inc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Windows/DynamicLibrary.inc?rev=221947&r1=221946&r2=221947&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Windows/DynamicLibrary.inc?rev=221947&r1=221946&r2=221947&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Support/Windows/DynamicLibrary.inc (original)<br>
+++ llvm/trunk/lib/Support/Windows/DynamicLibrary.inc Thu Nov 13 17:32:52 2014<br>
@@ -94,10 +94,24 @@ DynamicLibrary DynamicLibrary::getPerman<br>
   extern "C" { extern void *SYM; }<br>
 #define EXPLICIT_SYMBOL2(SYMFROM, SYMTO) EXPLICIT_SYMBOL(SYMTO)<br>
<br>
+#ifdef _M_IX86<br>
+// Win32 on x86 implements certain single-precision math functions as macros.<br>
+// These functions are not exported by the DLL, but will still be needed<br>
+// for symbol-resolution by the JIT loader. Therefore, this Support libray<br>
+// provides helper functions with the same implementation.<br>
+<br>
+#define INLINE_DEF_SYMBOL1(TYP, SYM)                                           \<br>
+  extern "C" TYP inline_##SYM(TYP _X) { return SYM(_X); }<br>
+#define INLINE_DEF_SYMBOL2(TYP, SYM)                                           \<br>
+  extern "C" TYP inline_##SYM(TYP _X, TYP _Y) { return SYM(_X, _Y); }<br>
+#endif<br>
+<br>
 #include "explicit_symbols.inc"<br>
<br>
 #undef EXPLICIT_SYMBOL<br>
 #undef EXPLICIT_SYMBOL2<br>
+#undef INLINE_DEF_SYMBOL1<br>
+#undef INLINE_DEF_SYMBOL2<br>
<br>
 void* DynamicLibrary::SearchForAddressOfSymbol(const char* symbolName) {<br>
   SmartScopedLock<true> Lock(*SymbolsMutex);<br>
@@ -121,22 +135,32 @@ void* DynamicLibrary::SearchForAddressOf<br>
     }<br>
   }<br>
<br>
-  #define EXPLICIT_SYMBOL(SYM)                    \<br>
-    if (!strcmp(symbolName, #SYM)) return (void*)&SYM;<br>
-  #define EXPLICIT_SYMBOL2(SYMFROM, SYMTO)        \<br>
-    if (!strcmp(symbolName, #SYMFROM)) return (void*)&SYMTO;<br>
+#define EXPLICIT_SYMBOL(SYM)                                                   \<br>
+  if (!strcmp(symbolName, #SYM))                                               \<br>
+    return (void *)&SYM;<br>
+#define EXPLICIT_SYMBOL2(SYMFROM, SYMTO)                                       \<br>
+  if (!strcmp(symbolName, #SYMFROM))                                           \<br>
+    return (void *)&SYMTO;<br>
+<br>
+#ifdef _M_IX86<br>
+#define INLINE_DEF_SYMBOL1(TYP, SYM)                                           \<br>
+  if (!strcmp(symbolName, #SYM))                                               \<br>
+    return (void *)&inline_##SYM;<br>
+#define INLINE_DEF_SYMBOL2(TYP, SYM) INLINE_DEF_SYMBOL1(TYP, SYM)<br>
+#endif<br>
<br>
   {<br>
-    #include "explicit_symbols.inc"<br>
+#include "explicit_symbols.inc"<br>
   }<br>
<br>
-  #undef EXPLICIT_SYMBOL<br>
-  #undef EXPLICIT_SYMBOL2<br>
+#undef EXPLICIT_SYMBOL<br>
+#undef EXPLICIT_SYMBOL2<br>
+#undef INLINE_DEF_SYMBOL1<br>
+#undef INLINE_DEF_SYMBOL2<br>
<br>
   return 0;<br>
 }<br>
<br>
-<br>
 void *DynamicLibrary::getAddressOfSymbol(const char *symbolName) {<br>
   if (!isValid())<br>
     return NULL;<br>
@@ -145,5 +169,4 @@ void *DynamicLibrary::getAddressOfSymbol<br>
   return (void *)(intptr_t)GetProcAddress((HMODULE)Data, symbolName);<br>
 }<br>
<br>
-<br>
 }<br>
<br>
Modified: llvm/trunk/lib/Support/Windows/explicit_symbols.inc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Windows/explicit_symbols.inc?rev=221947&r1=221946&r2=221947&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Windows/explicit_symbols.inc?rev=221947&r1=221946&r2=221947&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Support/Windows/explicit_symbols.inc (original)<br>
+++ llvm/trunk/lib/Support/Windows/explicit_symbols.inc Thu Nov 13 17:32:52 2014<br>
@@ -63,4 +63,32 @@<br>
 /* msvcrt */<br>
 #if defined(_MSC_VER)<br>
   EXPLICIT_SYMBOL2(alloca, _alloca_probe)<br>
+<br>
+#ifdef _M_IX86<br>
+#define INLINE_DEF_FLOAT_SYMBOL(SYM, ARGC) INLINE_DEF_SYMBOL##ARGC(float, SYM)<br>
+  INLINE_DEF_FLOAT_SYMBOL(acosf, 1)<br>
+  INLINE_DEF_FLOAT_SYMBOL(asinf, 1)<br>
+  INLINE_DEF_FLOAT_SYMBOL(atanf, 1)<br>
+  INLINE_DEF_FLOAT_SYMBOL(atan2f, 2)<br>
+  INLINE_DEF_FLOAT_SYMBOL(ceilf, 1)<br>
+#if (_MSC_VER==1800)<br>
+  INLINE_DEF_FLOAT_SYMBOL(copysignf, 2)<br>
+#endif<br>
+  INLINE_DEF_FLOAT_SYMBOL(cosf, 1)<br>
+  INLINE_DEF_FLOAT_SYMBOL(coshf, 1)<br>
+  INLINE_DEF_FLOAT_SYMBOL(expf, 1)<br>
+  INLINE_DEF_FLOAT_SYMBOL(floorf, 1)<br>
+  INLINE_DEF_FLOAT_SYMBOL(fminf, 2)<br>
+  INLINE_DEF_FLOAT_SYMBOL(fmaxf, 2)<br>
+  INLINE_DEF_FLOAT_SYMBOL(fmodf, 2)<br>
+  INLINE_DEF_FLOAT_SYMBOL(logf, 1)<br>
+  INLINE_DEF_FLOAT_SYMBOL(powf, 2)<br>
+  INLINE_DEF_FLOAT_SYMBOL(sinf, 1)<br>
+  INLINE_DEF_FLOAT_SYMBOL(sinhf, 1)<br>
+  INLINE_DEF_FLOAT_SYMBOL(sqrtf, 1)<br>
+  INLINE_DEF_FLOAT_SYMBOL(tanf, 1)<br>
+  INLINE_DEF_FLOAT_SYMBOL(tanhf, 1)<br>
+#undef INLINE_DEF_FLOAT_SYMBOL<br>
+#endif<br>
+<br>
 #endif<br>
<br>
Added: llvm/trunk/test/ExecutionEngine/frem.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ExecutionEngine/frem.ll?rev=221947&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ExecutionEngine/frem.ll?rev=221947&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/ExecutionEngine/frem.ll (added)<br>
+++ llvm/trunk/test/ExecutionEngine/frem.ll Thu Nov 13 17:32:52 2014<br>
@@ -0,0 +1,20 @@<br>
+; LLI.exe used to crash on Windows\X86 when certain single precession<br>
+; floating point intrinsics (defined as macros) are used.<br>
+; This unit test guards against the failure.<br>
+;<br>
+; RUN: %lli %s | FileCheck %s<br>
+<br>
+@flt = internal global float 12.0e+0<br>
+@str = internal constant [18 x i8] c"Double value: %f\0A\00"<br>
+<br>
+declare i32 @printf(i8* nocapture, ...) nounwind<br>
+<br>
+define i32 @main() {<br>
+  %flt = load float* @flt<br>
+  %float2 = frem float %flt, 5.0<br>
+  %double1 = fpext float %float2 to double<br>
+  call i32 (i8*, ...)* @printf(i8* getelementptr ([18 x i8]* @str, i32 0, i64 0), double %double1)<br>
+  ret i32 0<br>
+}<br>
+<br>
+; CHECK: Double value: 2.0<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>