Bug 261976 - databases/postgresql14-server: Fails to build with LLVM 14 (ports and base): multiple errors
Summary: databases/postgresql14-server: Fails to build with LLVM 14 (ports and base): ...
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Some People
Assignee: Palle Girgensohn
URL:
Keywords: needs-patch, needs-qa
Depends on:
Blocks: 261742
  Show dependency treegraph
 
Reported: 2022-02-15 20:43 UTC by Dimitry Andric
Modified: 2022-03-16 18:41 UTC (History)
5 users (show)

See Also:
koobs: merge-quarterly?


Attachments
postgres-261976.diff (986 bytes, patch)
2022-02-15 22:53 UTC, Palle Girgensohn
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dimitry Andric freebsd_committer freebsd_triage 2022-02-15 20:43:14 UTC
During an exp-run for llvm 14 (see bug 261742), it turned out that databases/postgresql14-server and the other slaved postgresql-server ports fail to build when the base system compiler is clang 14  (note this is from the i386 exp-run, after devel/llvm14 was introduced:

...
g++10 -Wall -Wpointer-arith -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wcast-function-type -Wformat-security -fno-strict-aliasing -fwrapv -O2 -pipe  -fstack-protector-strong -Wl,-rpath=/usr/local/lib/gcc10  -nostdinc++ -isystem /usr/include/c++/v1 -Wl,-rpath=/usr/local/lib/gcc10  -std=c++14 -fPIC -DPIC -D__STDC_LIMIT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_CONSTANT_MACROS -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -I/usr/local/llvm14/include  -I../../../../src/include -I/usr/local/include  -I/usr/local/include -I/usr/local/include -I/usr/local/include -I/usr/local/include  -c -o llvmjit_error.o llvmjit_error.cpp
llvmjit_error.cpp:28:13: error: 'new_handler' in namespace 'std' does not name a type
   28 | static std::new_handler old_new_handler = NULL;
      |             ^~~~~~~~~~~
llvmjit_error.cpp:32:64: error: 'string' in namespace 'std' does not name a type
   32 | static void fatal_llvm_new_handler(void *user_data, const std::string& reason, bool gen_crash_diag);
      |                                                                ^~~~~~
llvmjit_error.cpp:25:1: note: 'std::string' is defined in header '<string>'; did you forget to '#include <string>'?
   24 | #include "jit/llvmjit.h"
  +++ |+#include <string>
   25 |
llvmjit_error.cpp:34:66: error: 'string' in namespace 'std' does not name a type
   34 | static void fatal_llvm_error_handler(void *user_data, const std::string& reason, bool gen_crash_diag);
      |                                                                  ^~~~~~
llvmjit_error.cpp:34:61: note: 'std::string' is defined in header '<string>'; did you forget to '#include <string>'?
   34 | static void fatal_llvm_error_handler(void *user_data, const std::string& reason, bool gen_crash_diag);
      |                                                             ^~~
llvmjit_error.cpp: In function 'void llvm_enter_fatal_on_oom()':
llvmjit_error.cpp:60:3: error: 'old_new_handler' was not declared in this scope
   60 |   old_new_handler = std::set_new_handler(fatal_system_new_handler);
      |   ^~~~~~~~~~~~~~~
llvmjit_error.cpp:60:26: error: 'set_new_handler' is not a member of 'std'
   60 |   old_new_handler = std::set_new_handler(fatal_system_new_handler);
      |                          ^~~~~~~~~~~~~~~
llvmjit_error.cpp:62:41: error: invalid conversion from 'void (*)(void*, const int&, bool)' to 'llvm::fatal_error_handler_t' {aka 'void (*)(void*, const char*, bool)'} [-fpermissive]
   62 |   llvm::install_bad_alloc_error_handler(fatal_llvm_new_handler);
      |                                         ^~~~~~~~~~~~~~~~~~~~~~
      |                                         |
      |                                         void (*)(void*, const int&, bool)

There seem to be a few changes in the LLVM C and C++ APIs, and until upstream postgresql adapts to these changes, I think it is necessary to specifically limit the PG_LLVM_VERSION to a maximum of 13.
Comment 1 Kubilay Kocak freebsd_committer freebsd_triage 2022-02-15 22:36:28 UTC
Thanks for the report Dim. Note that build fixes are:

Approved by: portmgr (blanket: build fix)
MFH: <branch|No> (reason)

And don't require maintainer approval

If you'd like additional review (always good), throw up a diff so we can unblock quickly
Comment 2 Palle Girgensohn freebsd_committer freebsd_triage 2022-02-15 22:51:44 UTC
Is this what you're suggesting?

diff --git a/databases/postgresql14-server/Makefile b/databases/postgresql14-server/Makefile
index c55a077634ac..c8d97cafd294 100644
--- a/databases/postgresql14-server/Makefile
+++ b/databases/postgresql14-server/Makefile
@@ -266,15 +266,26 @@ LLVM_PORT_SUFFIX= ${COMPILER_VERSION:C/.$//}
 .if ${COMPILER_VERSION} > ${LLVM_DEFAULT_VERSION}
 # LLVM versions in ports are, in order, 70, 80 90, 10, 11, 12... where 10 > 90. [sic]
 .  if ${LLVM_PORT_SUFFIX} < 70
+#    PR 261976 postgresql fails to build with LLVM 14
+.    if ${LLVM_PORT_SUFFIX} > 13
+PG_LLVM_VERSION=13
+PG_COMPILER_VERSION=13
+.    else
 PG_LLVM_VERSION=${LLVM_PORT_SUFFIX}
 PG_COMPILER_VERSION=${LLVM_PORT_SUFFIX}
+.    endif
 .  else
 PG_LLVM_VERSION=11
 PG_COMPILER_VERSION=11
 .  endif
 .else
+.  if ${LLVM_PORT_SUFFIX} > 13
+PG_LLVM_VERSION=13
+PG_COMPILER_VERSION=13
+.  else
 PG_LLVM_VERSION=${LLVM_DEFAULT}
 PG_COMPILER_VERSION=${LLVM_PORT_SUFFIX}
+.  endif
 .endif
 
 .if ${DISTVERSION:C/([0-9]*).*/\1/} >= 11
Comment 3 Palle Girgensohn freebsd_committer freebsd_triage 2022-02-15 22:53:38 UTC
Created attachment 231847 [details]
postgres-261976.diff
Comment 4 Palle Girgensohn freebsd_committer freebsd_triage 2022-02-28 08:28:29 UTC
@dim see suggested patch, is this what you are suggesting?
Comment 5 Dimitry Andric freebsd_committer freebsd_triage 2022-02-28 18:20:38 UTC
(In reply to Palle Girgensohn from comment #4)
Yes, this works for me here on the llvm-14-update branch (where base llvm is 14.0.0):

===>  Applying FreeBSD patches for postgresql14-server-14.2 from /share/dim/ports/databases/postgresql14-server/files
===>   postgresql14-server-14.2 depends on package: gmake>=4.3 - found
===>   postgresql14-server-14.2 depends on package: pkgconf>=1.3.0_1 - found
===>   postgresql14-server-14.2 depends on package: llvm13>0 - found
===>   postgresql14-server-14.2 depends on executable: llvm-config13 - found
===>   postgresql14-server-14.2 depends on executable: gcc11 - found
...
gmake[1]: Leaving directory '/wrkdirs/share/dim/ports/databases/postgresql14-server/work/postgresql-14.2/src/backend/jit/llvm'
====> Compressing man pages (compress-man)
===> Staging rc.d startup script(s)

Command exit status: 0

Thanks!
Comment 6 Dimitry Andric freebsd_committer freebsd_triage 2022-03-10 19:57:08 UTC
Ping, please commit the fix. :)
Comment 7 commit-hook freebsd_committer freebsd_triage 2022-03-16 18:38:39 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=dbafe427a49b7feef6049e10e3398a0681c8ccd5

commit dbafe427a49b7feef6049e10e3398a0681c8ccd5
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2022-03-16 18:28:57 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2022-03-16 18:28:57 +0000

    databases/postgresql14-server: Avoid using llvm14

    When the base system compiler is clang 14, the postgresql ports attempt
    to build against the devel/llvm14 port. This will fail with several
    compile errors as there are a few incompatible changes in the LLVM 14 C
    and C++ APIs. Until upstream postgresql adapts to these changes, limit
    the PG_LLVM_VERSION to a maximum of 13.

    PR:              261976
    Approved by:    maintainer timeout (2 weeks)
    MFH:            2022Q1

 databases/postgresql14-server/Makefile | 11 +++++++++++
 1 file changed, 11 insertions(+)