SHA256
1
0
forked from pool/postgresql13

- bsc#1185952: fix build with llvm12 on s390x.

0001-jit-Workaround-potential-datalayout-mismatch-on-s390.patch

OBS-URL: https://build.opensuse.org/package/show/server:database:postgresql/postgresql13?expand=0&rev=32
This commit is contained in:
Reinhard Max 2021-08-31 11:16:37 +00:00 committed by Git OBS Bridge
parent 23b6a7a2e6
commit f38a89dc2c
3 changed files with 107 additions and 0 deletions

View File

@ -0,0 +1,99 @@
From 0edaa982336823d4d7af8f10b91579fe0099ef3d Mon Sep 17 00:00:00 2001
From: Tom Stellard <tstellar@redhat.com>
Date: Tue, 20 Apr 2021 20:14:21 -0700
Subject: [PATCH] jit: Workaround potential 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.
---
src/backend/jit/llvm/llvmjit.c | 46 ++++++++++++++++++++++++++++++++--
1 file changed, 44 insertions(+), 2 deletions(-)
diff --git a/src/backend/jit/llvm/llvmjit.c b/src/backend/jit/llvm/llvmjit.c
index 98a27f08bf..05b6438ba8 100644
--- a/src/backend/jit/llvm/llvmjit.c
+++ b/src/backend/jit/llvm/llvmjit.c
@@ -776,6 +776,35 @@ llvm_compile_module(LLVMJitContext *context)
errhidecontext(true)));
}
+/*
+ * For the systemz target, LLVM uses a different datalayout for z13 and newer
+ * CPUs than it does for older CPUs. This can cause a mismatch in datalayouts
+ * in the case where the llvm_types_module is compiled with a pre-z13 CPU
+ * and the JIT is running on z13 or newer.
+ * See computeDataLayout() function in
+ * llvm/lib/Target/SystemZ/SystemZTargetMachine.cpp for information on the
+ * datalayout differences.
+ */
+static bool
+needs_systemz_workaround(void)
+{
+ bool ret = false;
+ LLVMContextRef llvm_context;
+ LLVMTypeRef vec_type;
+ LLVMTargetDataRef llvm_layoutref;
+ if (strncmp(LLVMGetTargetName(llvm_targetref), "systemz", strlen("systemz")))
+ {
+ return false;
+ }
+
+ llvm_context = LLVMGetModuleContext(llvm_types_module);
+ vec_type = LLVMVectorType(LLVMIntTypeInContext(llvm_context, 32), 4);
+ llvm_layoutref = LLVMCreateTargetData(llvm_layout);
+ ret = (LLVMABIAlignmentOfType(llvm_layoutref, vec_type) == 16);
+ LLVMDisposeTargetData(llvm_layoutref);
+ return ret;
+}
+
/*
* Per session initialization.
*/
@@ -785,6 +814,7 @@ llvm_session_initialize(void)
MemoryContext oldcontext;
char *error = NULL;
char *cpu = NULL;
+ char *host_features = NULL;
char *features = NULL;
LLVMTargetMachineRef opt0_tm;
LLVMTargetMachineRef opt3_tm;
@@ -816,10 +846,17 @@ llvm_session_initialize(void)
* features not all CPUs have (weird, huh).
*/
cpu = LLVMGetHostCPUName();
- features = LLVMGetHostCPUFeatures();
+ features = host_features = LLVMGetHostCPUFeatures();
elog(DEBUG2, "LLVMJIT detected CPU \"%s\", with features \"%s\"",
cpu, features);
+ if (needs_systemz_workaround())
+ {
+ const char *no_vector =",-vector";
+ features = malloc(sizeof(char) * (strlen(host_features) + strlen(no_vector) + 1));
+ sprintf(features, "%s%s", host_features, no_vector);
+ }
+
opt0_tm =
LLVMCreateTargetMachine(llvm_targetref, llvm_triple, cpu, features,
LLVMCodeGenLevelNone,
@@ -833,8 +870,13 @@ llvm_session_initialize(void)
LLVMDisposeMessage(cpu);
cpu = NULL;
- LLVMDisposeMessage(features);
+ if (features != host_features)
+ {
+ free(features);
+ }
features = NULL;
+ LLVMDisposeMessage(host_features);
+ host_features = NULL;
/* force symbols in main binary to be loaded */
LLVMLoadLibraryPermanently(NULL);
--
2.27.0

View File

@ -1,3 +1,9 @@
-------------------------------------------------------------------
Tue Aug 31 11:14:53 UTC 2021 - Reinhard Max <max@suse.com>
- bsc#1185952: fix build with llvm12 on s390x.
0001-jit-Workaround-potential-datalayout-mismatch-on-s390.patch
------------------------------------------------------------------- -------------------------------------------------------------------
Tue Aug 24 12:45:53 UTC 2021 - Marcus Rueckert <mrueckert@suse.de> Tue Aug 24 12:45:53 UTC 2021 - Marcus Rueckert <mrueckert@suse.de>

View File

@ -151,6 +151,7 @@ Patch8: postgresql-testsuite-keep-results-file.patch
Patch9: postgresql-var-run-socket.patch Patch9: postgresql-var-run-socket.patch
%if %{with llvm} %if %{with llvm}
Patch10: postgresql-llvm-optional.patch Patch10: postgresql-llvm-optional.patch
Patch11: 0001-jit-Workaround-potential-datalayout-mismatch-on-s390.patch
%endif %endif
URL: https://www.postgresql.org/ URL: https://www.postgresql.org/
BuildRoot: %{_tmppath}/%{name}-%{version}-build BuildRoot: %{_tmppath}/%{name}-%{version}-build
@ -460,6 +461,7 @@ touch -r configure tmp
%patch9 %patch9
%if %{with llvm} %if %{with llvm}
%patch10 %patch10
%patch11
%endif %endif
touch -r tmp configure touch -r tmp configure
rm tmp rm tmp