Skip to content

Commit

Permalink
databases/db5: Add <stddef.h> to conftest.cpp for TLS check
Browse files Browse the repository at this point in the history
During an exp-run for llvm 15 (see bug 265425), it turned out that
databases/db5 failed to build with clang 15.

This is caused by db5's configure script attempting to detect TLS but
encountering internal compiler errors while compiling its test cases,
and then concluding TLS does not work at all:

    ...
    checking whether C++ supports the wstring class... checking for thread local storage (TLS) class... none
    ...

in config.log it shows what is happening:

    configure:19128: checking for thread local storage (TLS) class
    configure:19164: c++ -c -O2 -pipe -Wall -Wextra -fstack-protector-strong -fno-strict-aliasing    -D_THREAD_SAFE conftest.cpp >&5
    conftest.cpp:30:72: error: use of undeclared identifier 'NULL'
                  template<typename T>  __thread  T* TLSClass<T>::tlsvar = NULL;
                                                                           ^
    Assertion failed: (!isValueDependent() && "Expression evaluator can't be called on a dependent expression."), function isConstantInitializer, file /usr/src/contrib/llvm-project/clang/lib/AST/Expr.cpp, line 3184.
    PLEASE submit a bug report to https://bugs.freebsd.org/submit/ and include the crash backtrace, preprocessed source, and associated run script.
    Stack dump:
    0.      Program arguments: c++ -c -O2 -pipe -Wall -Wextra -fstack-protector-strong -fno-strict-aliasing -D_THREAD_SAFE conftest.cpp
    1.      conftest.cpp:30:76: current parser token ';'
    #0 0x00000000053fec51 PrintStackTrace
    #/usr/src/contrib/llvm-project/llvm/lib/Support/Unix/Signals.inc:569:13
    #1 0x00000000053fcf35 RunSignalHandlers
    #/usr/src/contrib/llvm-project/llvm/lib/Support/Signals.cpp:104:18
    #2 0x00000000053a591e HandleCrash
    #/usr/src/contrib/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:76:5
    #3 0x00000000053a5ae3 CrashRecoverySignalHandler
    #/usr/src/contrib/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:0:51
    #4 0x0000000006a1b05e handle_signal
    #/usr/src/lib/libthr/thread/thr_sig.c:0:3
    c++: error: clang frontend command failed with exit code 134 (use -v to see invocation)

Interestingly enough this compilation error with a fatal crash exists
for a very long time, even back to clang 10 and earlier! But for various
reasons the configure script has always ignored these errors and found
some workaround way to enable TLS anyway.

For now the problem can be fixed by including <stddef.h> at the top of
conftest.cpp, which will allow the TLS test to succeed normally, without
crashing, and the correct result will then be:

    configure:19128: checking for thread local storage (TLS) class
    configure:19165: c++ -c -O2 -pipe -Wall -Wextra -fstack-protector-strong -fno-strict-aliasing    -D_THREAD_SAFE conftest.cpp >&5
    conftest.cpp:33:35: warning: unused variable 'x' [-Wunused-variable]
                  static __thread int x = 0;
                                      ^
    1 warning generated.
    configure:19165: $? = 0
    configure:19220: result: modifier

PR:		267156
Approved by:	maintainer timeout (>1 month)
MFH:		2022Q4
  • Loading branch information
DimitryAndric committed Dec 5, 2022
1 parent a1f596a commit 42cfe5c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion databases/db5/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PORTNAME= db5
PORTVERSION= 5.3.28
PORTREVISION= 8
PORTREVISION= 9
CATEGORIES= databases java
MASTER_SITES= https://download.oracle.com/berkeley-db/
PKGNAMEPREFIX?=
Expand Down
8 changes: 8 additions & 0 deletions databases/db5/files/patch-dist_configure
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,11 @@
MAKEFILE_CXXLINK="\$(LIBTOOL) --mode=link ${MAKEFILE_CXXLINK}"


@@ -19144,6 +19144,7 @@ ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
test -z "$ax_tls_defn_keyword" && continue
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
+#include <stddef.h>
template <typename T>class TLSClass {
public: static $ax_tls_decl_keyword T *tlsvar;
};

0 comments on commit 42cfe5c

Please sign in to comment.