Bug 267156 - databases/db5: fix build with clang 15
Summary: databases/db5: fix build with clang 15
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: Dimitry Andric
URL:
Keywords:
Depends on:
Blocks: 265425
  Show dependency treegraph
 
Reported: 2022-10-17 18:39 UTC by Dimitry Andric
Modified: 2022-12-05 17:27 UTC (History)
1 user (show)

See Also:


Attachments
Add <stddef.h> to conftest.cpp for TLS check (672 bytes, patch)
2022-10-17 18:40 UTC, Dimitry Andric
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-10-17 18:39:16 UTC
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 /share/dim/src/freebsd/llvm-15-update/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 /share/dim/src/freebsd/llvm-15-update/contrib/llvm-project/llvm/lib/Support/Unix/Signals.inc:569:13
#1 0x00000000053fcf35 RunSignalHandlers /share/dim/src/freebsd/llvm-15-update/contrib/llvm-project/llvm/lib/Support/Signals.cpp:104:18
#2 0x00000000053a591e HandleCrash /share/dim/src/freebsd/llvm-15-update/contrib/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:76:5
#3 0x00000000053a5ae3 CrashRecoverySignalHandler /share/dim/src/freebsd/llvm-15-update/contrib/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:0:51
#4 0x0000000006a1b05e handle_signal /share/dim/src/freebsd/llvm-15-update/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
Comment 1 Dimitry Andric freebsd_committer freebsd_triage 2022-10-17 18:40:14 UTC
Created attachment 237422 [details]
Add <stddef.h> to conftest.cpp for TLS check
Comment 2 Fernando Apesteguía freebsd_committer freebsd_triage 2022-10-18 05:09:21 UTC
^Triage: reporter is committer, assign accordingly.
Comment 3 commit-hook freebsd_committer freebsd_triage 2022-12-05 17:26:34 UTC
A commit in branch main references this bug:

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

commit 42cfe5c18c235a5e8d95bb89060db0f09f43c7b2
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2022-12-05 17:20:32 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2022-12-05 17:26:02 +0000

    databases/db5: Add <stddef.h> to conftest.cpp for TLS check

    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

 databases/db5/Makefile                   | 2 +-
 databases/db5/files/patch-dist_configure | 8 ++++++++
 2 files changed, 9 insertions(+), 1 deletion(-)