HomeFreeBSD

databases/postgresql15-server: fix build with clang 16 (as system compiler)

Description

databases/postgresql15-server: fix build with clang 16 (as system compiler)

databases/postgresql??-server: use the default LLVM

Always use the version of LLVM that is default for the ports tree,
if PostgreSQL builds with it. This simplifies the build process.

For i386, revert to using clang -msse2 instead of pulling in gcc. CPUs
older than Pentium5 do not support SSE2 and the binary will not run
there. We are not expected to support ancient hardware forever, so I've
added a comment recommending users of ancient CPUs to build from ports
using gcc.

During an exp-run for llvm 16 (see bug 271047), it turned out that
databases/postgresql15-server failed to build with clang 16 as the base
system compiler:

In file included from llvmjit.c:38:
../../../../src/include/jit/llvmjit_emit.h:112:23: warning: call to undeclared function 'LLVMBuildStructGEP'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
        LLVMValueRef v_ptr = LLVMBuildStructGEP(b, v, idx, "");
                             ^
../../../../src/include/jit/llvmjit_emit.h:112:15: error: incompatible integer to pointer conversion initializing 'LLVMValueRef' (aka 'struct LLVMOpaqueValue *') with an expression of type 'int' [-Wint-conversion]
        LLVMValueRef v_ptr = LLVMBuildStructGEP(b, v, idx, "");
                     ^       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../../../src/include/jit/llvmjit_emit.h:114:9: warning: call to undeclared function 'LLVMBuildLoad'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
        return LLVMBuildLoad(b, v_ptr, name);
               ^
../../../../src/include/jit/llvmjit_emit.h:114:9: error: incompatible integer to pointer conversion returning 'int' from a function with result type 'LLVMValueRef' (aka 'struct LLVMOpaqueValue *') [-Wint-conversion]
        return LLVMBuildLoad(b, v_ptr, name);
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

and many more similar errors. The same applies to the slave ports
postgresql11-server, postgresql12-server, postgresql13-server, and
postgresql14-server.

This is because PostgreSQL's llvmjit support is not yet ready for LLVM
16's API changes. In LLVM 15 functions like LLVMBuildStructGEP were
already declared deprecated, but in LLVM 16 these have been removed (and
replaced with LLVMBuildStructGEP2, etc).

Until PostgreSQL updates their llvmjit for the changed APIs, I would
like to reintroduce the LLVM version restriction that was removed in
https://cgit.freebsd.org/ports/commit/?id=1e19f00e5e46, but slightly
adjusted: there is no more need to check for LLVM ports below 10.

Another thing that is required is to pass a CLANG variable to the
configure script, pointing to the same version that is used for the LLVM
bindings. Otherwise, the .bc files will get compiled by the base system
compiler, and this can lead to a ThinLTO link error, if the base system
compiler is a newer version of llvm.

PR: 271498
Suggested by: dim@

Details

Provenance
girgenAuthored on May 30 2023, 10:52 PM
Parents
R11:4ee225f90aa3: databases/postgresql16-*: Introduce postgresql16 beta 1
Branches
Unknown
Tags
Unknown