Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
jit: Don't inline functions that access thread-locals.
authorThomas Munro <tmunro@postgresql.org>
Thu, 22 Jul 2021 02:11:17 +0000 (14:11 +1200)
committerThomas Munro <tmunro@postgresql.org>
Thu, 22 Jul 2021 03:02:18 +0000 (15:02 +1200)
Code inlined by LLVM can crash or fail with "Relocation type not
implemented yet!" if it tries to access thread local variables.  Don't
inline such code.

Back-patch to 11, where LLVM arrived.  Bug #16696.

Author: Dmitry Marakasov <amdmi3@amdmi3.ru>
Reviewed-by: Andres Freund <andres@anarazel.de>
Discussion: https://postgr.es/m/16696-29d944a33801fbfe@postgresql.org

src/backend/jit/llvm/llvmjit_inline.cpp

index ea90fd5b24f4bb2f1f21a265e8e4986efeed67c2..6f03595db5a40823d7f55b105bf9ef31764d1adc 100644 (file)
@@ -608,6 +608,17 @@ function_inlinable(llvm::Function &F,
        if (rv->materialize())
            elog(FATAL, "failed to materialize metadata");
 
+       /*
+        * Don't inline functions that access thread local variables.  That
+        * doesn't work on current LLVM releases (but might in future).
+        */
+       if (rv->isThreadLocal())
+       {
+           ilog(DEBUG1, "cannot inline %s due to thread-local variable %s",
+                F.getName().data(), rv->getName().data());
+           return false;
+       }
+
        /*
         * Never want to inline externally visible vars, cheap enough to
         * reference.