Re: [PATCH] Fix build with LLVM 15 or above - Mailing list pgsql-hackers

From Thomas Munro
Subject Re: [PATCH] Fix build with LLVM 15 or above
Date
Msg-id CA+hUKGJpnh4ROcXVRmyjo4zJohCOrns-J9PNa4LNGHfGbb97Rg@mail.gmail.com
Whole thread Raw
In response to [PATCH] Fix build with LLVM 15 or above  (Po-Chuan Hsieh <sunpoet@sunpoet.net>)
Responses Re: [PATCH] Fix build with LLVM 15 or above  (Andres Freund <andres@anarazel.de>)
List pgsql-hackers
On Mon, Oct 3, 2022 at 4:56 PM Po-Chuan Hsieh <sunpoet@sunpoet.net> wrote:
> 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

Hi,

Unfortunately that is only the tip of a mini iceberg.  While that
change makes it compile, there are other API changes that are required
to make our use of LLVM ORC actually work.  We can't get through 'make
check', because various code paths in LLVM 15 abort, because we're
using a bunch of APIs from before the big change to "opaque pointers"
https://llvm.org/docs/OpaquePointers.html.  I've been trying to get to
a patch to fix that -- basically a few simple-looking changes like
LLVMBuildLoad() to LLVMBuildLoad2() as described there -- that gain an
argument where you have to tell it the type of the pointer (whereas
before it knew the type of pointers automatically).  Unfortunately I
had to work on other problems that came up recently and it's probably
going to be at least a week before I can get back to this and post a
patch.

One option I thought about as a stopgap measure is to use
LLVMContextSetOpaquePointers(context, false) to turn the new code
paths off, but it doesn't seem to work for me and I couldn't figure
out why yet (it still aborts -- probably there are more 'contexts'
around that I didn't handle, something like that).  That option is
available for LLVM 15 but will be taken out in LLVM 16, so that's
supposed to be the last chance to stop using pre-opaque pointers; see
the bottom of the page I linked above for that, where they call it
setOpaquePointers(false) (the C++ version of
LLVMContextSetOpaquePointers()).  I don't really want to go with that
if we can avoid it, though, because it says "Opaque pointers are
enabled by default. Typed pointers are still available, but only
supported on a best-effort basis and may be untested" so I expect it
to be blighted with problems.

Here's my attempt at that minimal change, which is apparently still
missing something (if you can get this to build and pass all tests
against LLVM 15 then it might still be interesting to know about):

https://github.com/macdice/postgres/tree/llvm15-min

Here's my WIP unfinished branch where I'm trying to get the real code
change done.  It needs more work on function pointer types, which are
a bit tedious to deal with and I haven't got it all right in here yet
as you can see from failures if you build against 15:

https://github.com/macdice/postgres/tree/llvm15

Hopefully more next week...



pgsql-hackers by date:

Previous
From: Julien Rouhaud
Date:
Subject: Re: proposal: possibility to read dumped table's name from file
Next
From: Michael Paquier
Date:
Subject: Re: pg_upgrade test failure