Hello,

While building PostgreSQL 15 RC 1 with LLVM 15, I got a build failure as
follows:

cc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement
-Werror=vla -Werror=unguarded-availability-new -Wendif-labels
-Wmissing-format-attribute -Wcast-function-type -Wformat-security
-fno-strict-aliasing -fwrapv -Wno-unused-command-line-argument
-Wno-compound-token-split-by-macro -O2 -pipe  -O3 -funroll-loops
-fstack-protector-strong -fno-strict-aliasing  -Wno-deprecated-declarations
-fPIC -DPIC -D__STDC_LIMIT_MACROS -D__STDC_FORMAT_MACROS
-D__STDC_CONSTANT_MACROS -I/usr/local/llvm15/include
 -I../../../../src/include -I/usr/local/include  -I/usr/local/include
-I/usr/local/include/libxml2 -I/usr/local/include -I/usr/local/include
-I/usr/local/include -I/usr/local/include  -c -o llvmjit.o llvmjit.c
llvmjit.c:1115:50: error: use of undeclared identifier
'LLVMJITCSymbolMapPair'
        LLVMOrcCSymbolMapPairs symbols =
palloc0(sizeof(LLVMJITCSymbolMapPair) * LookupSetSize);
                                                        ^
llvmjit.c:1233:81: error: too few arguments to function call, expected 3,
have 2
        ref_gen =
LLVMOrcCreateCustomCAPIDefinitionGenerator(llvm_resolve_symbols, NULL);
                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            ^
/usr/local/llvm15/include/llvm-c/Orc.h:997:31: note:
'LLVMOrcCreateCustomCAPIDefinitionGenerator' declared here
LLVMOrcDefinitionGeneratorRef LLVMOrcCreateCustomCAPIDefinitionGenerator(
                              ^
2 errors generated.
gmake: *** [<builtin>: llvmjit.o] Error 1
*** Error code 2

I've prepared a patch (attached) to fix the build issue with LLVM 15 or
above. It is also available at
https://people.FreeBSD.org/~sunpoet/patch/postgres/0001-Fix-build-with-LLVM-15-or-above.patch
Thanks.

Regards,
sunpoet
From bd2f6d2ec5369b5e33c6bf41560cdae3f8088f07 Mon Sep 17 00:00:00 2001
From: Po-Chuan Hsieh <sunpoet@sunpoet.net>
Date: Sat, 1 Oct 2022 22:23:41 +0800
Subject: [PATCH] Fix build with LLVM 15 or above

- Upstream has fixed the struct name prefix from LLVMJIT to LLVMOrc [1].
- Upstream has changed the API of LLVMOrcCreateCustomCAPIDefinitionGenerator [2].

Reference:	https://github.com/llvm/llvm-project/commit/b425f556935c1105dea59871a46caa7af2d378ad [1]
		https://github.com/llvm/llvm-project/commit/14b7c108a2bf46541efc3a5c9cbd589b3afc18e6 [2]
---
 src/backend/jit/llvm/llvmjit.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/backend/jit/llvm/llvmjit.c b/src/backend/jit/llvm/llvmjit.c
index fd3eecf27d..731b28a4c9 100644
--- a/src/backend/jit/llvm/llvmjit.c
+++ b/src/backend/jit/llvm/llvmjit.c
@@ -1112,7 +1112,11 @@ llvm_resolve_symbols(LLVMOrcDefinitionGeneratorRef GeneratorObj, void *Ctx,
 					 LLVMOrcJITDylibRef JD, LLVMOrcJITDylibLookupFlags JDLookupFlags,
 					 LLVMOrcCLookupSet LookupSet, size_t LookupSetSize)
 {
+#if LLVM_VERSION_MAJOR >= 15
+	LLVMOrcCSymbolMapPairs symbols = palloc0(sizeof(LLVMOrcCSymbolMapPair) * LookupSetSize);
+#else
 	LLVMOrcCSymbolMapPairs symbols = palloc0(sizeof(LLVMJITCSymbolMapPair) * LookupSetSize);
+#endif
 	LLVMErrorRef error;
 	LLVMOrcMaterializationUnitRef mu;
 
@@ -1230,7 +1234,11 @@ llvm_create_jit_instance(LLVMTargetMachineRef tm)
 	 * Symbol resolution support for "special" functions, e.g. a call into an
 	 * SQL callable function.
 	 */
+#if LLVM_VERSION_MAJOR >= 15
+	ref_gen = LLVMOrcCreateCustomCAPIDefinitionGenerator(llvm_resolve_symbols, NULL, NULL);
+#else
 	ref_gen = LLVMOrcCreateCustomCAPIDefinitionGenerator(llvm_resolve_symbols, NULL);
+#endif
 	LLVMOrcJITDylibAddGenerator(LLVMOrcLLJITGetMainJITDylib(lljit), ref_gen);
 
 	return lljit;
-- 
2.35.2

Reply via email to