[Bug libstdc++/126399] New: [15 regression] __gthread_trigger() is missing hidden visibility on FreeBSD/Solaris

vedran at miletic dot net via Gcc-bugs <[email protected]>
Newsgroups gmane.comp.gcc.bugs
Message-ID <[email protected]/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126399

            Bug ID: 126399
           Summary: [15 regression] __gthread_trigger() is missing hidden
                    visibility on FreeBSD/Solaris
           Product: gcc
           Version: 15.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vedran at miletic dot net
  Target Milestone: ---

On FreeBSD (and possibly also Solaris) std::call_once() throws
std::system_error("Unknown error: -1") and aborts the program when the
call_once call happens to live in a different shared object (.so) than other,
unrelated code that already forced the C++ runtime into "multithreaded" state
(e.g. constructing a std::shared_ptr, which internally checks
__gthread_active_p()).

This is a regression, observed in 15.2.0, likely related to PR115126. Also
reproduces on 16.1.0 and 17.0.0 20260705 experimental; does NOT reproduce on
14.2.0, 13.3.0, 12.4.0 (all versions are obtained from FreeBSD Ports).

Observed in OpenMM and RDKit. Minimized down to:

libwidget.cpp

#include <mutex>
std::once_flag once;
void initFn() {}
extern "C" void triggerOnce() { std::call_once(once, initFn); }

main.cpp

#include <memory>
std::shared_ptr<int> p1(new int(1));

extern "C" void triggerOnce();
int main() {
  triggerOnce();
  return 0;
}

% g++15 -fPIC -shared -o libwidget.so libwidget.cpp -lpthread
% g++15 -o main main.cpp -Wl,-rpath,. ./libwidget.so -lpthread
% ./main
terminate called after throwing an instance of 'std::system_error'
  what():  Unknown error: -1
Abort (core dumped)

For comparison:

% g++14 -fPIC -shared -o libwidget.so libwidget.cpp -lpthread
% g++14 -o main main.cpp -Wl,-rpath,. ./libwidget.so -lpthread
% ./main
(no crash)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.