aports/community/postgresql12/jit-datalayout-mismatch-on-s390x.patch
Jakub Jirutka c771744822 community/postgresql12: replace poor JIT patch with better one
Disable use of host specific CPU features when creating the JIT only on
s390x, not on other architectures that are not affected by this issue.

See 23236a1c555090fcb7d9f8c0813fb5110cf04b43
2021-12-19 00:20:16 +01:00

31 lines
1.4 KiB
Diff

From: Jakub Jirutka <jakub@jirutka.cz>
Date: Sat, 18 Dec 2021 23:35:00 +0100
Subject: [PATCH] jit: Workaround datalayout mismatch on s390x
LLVM's s390x target uses a different datalayout for z13 and newer processors.
If llvmjit_types.bc is compiled to target a processor older than z13, and
then the JIT runs on a z13 or newer processor, then there will be a mismatch
in datalayouts between llvmjit_types.bc and the JIT engine. This mismatch
causes the JIT to fail at runtime.
This patch is inspired by https://src.fedoraproject.org/rpms/postgresql/pull-request/29.
We couldn't use https://src.fedoraproject.org/rpms/postgresql/blob/f35/f/postgresql-datalayout-mismatch-on-s390.patch
because it doesn't compile on PostgreSQL 12 (llvm_types_module is undeclared).
diff --git a/src/backend/jit/llvm/llvmjit.c b/src/backend/jit/llvm/llvmjit.c
--- a/src/backend/jit/llvm/llvmjit.c
+++ b/src/backend/jit/llvm/llvmjit.c
@@ -780,10 +780,12 @@
* latter is needed because some CPU architectures default to enabling
* features not all CPUs have (weird, huh).
*/
+#if !defined(__s390__) && !defined(__s390x__) // XXX: quick workaround for s390x
cpu = LLVMGetHostCPUName();
features = LLVMGetHostCPUFeatures();
elog(DEBUG2, "LLVMJIT detected CPU \"%s\", with features \"%s\"",
cpu, features);
+#endif
opt0_tm =
LLVMCreateTargetMachine(llvm_targetref, llvm_triple, cpu, features,