[cfe-users] Seg fault building with clang++ and -femulated-tls against gcc std lib
Dave Gittins via cfe-users
cfe-users at lists.llvm.org
Tue Jan 7 15:45:37 PST 2020
I am having a problem building on OSX with clang, against the gcc
standard library (there are project constraints behind why I am doing
this). I am using homebrew packages for both clang and gcc. This
pattern worked fine until a recent gcc package upgrade and I would at
least like to understand better what has happened.
Here's my example.cpp:
#include <mutex>
#include <iostream>
int main()
{
std::once_flag flag;
std::call_once(flag, [](){ std::cout << "Foo\n"; });
return 0;
}
Now if I brew install llvm 7.1.0 and gcc 7.5.0, I can successfully
build as follows:
> /usr/local/Cellar/llvm at 7/7.1.0_1/bin/clang++ -isystem /usr/local/Cellar/gcc at 7/7.5.0/include/c++/7.5.0 -isystem /usr/local/Cellar/gcc at 7/7.5.0/include/c++/7.5.0/x86_64-apple-darwin18.7.0 -isystem /usr/local/Cellar/gcc at 7/7.5.0/include/c++/7.5.0/backward -L /usr/local/Cellar/gcc at 7/7.5.0/lib/gcc/7 -nostdinc++ -stdlib=libstdc++ -std=c++17 example.cpp -o example -femulated-tls
I have to add -femulated-tls, because we need to link to symbols such
as ___emutls_v._ZSt11__once_call in the gcc std lib (without this
option, it fails to link because it can't find _ZSt11__once_call).
However this fails at runtime:
> ./example
Segmentation fault: 11 (core dumped)
I am not sure where to go next with this!
Some other notes:
* Building this example with gcc 7.5.0 against its own std lib works fine.
* Building this example against the std lib from gcc 7.4.0 (without
-femulated-tls) works fine, because that gcc version was built with
_GLIBCXX_HAVE_TLS not defined and therefore uses a different
implementation of std::once_call. I am still not sure if this change
in the gcc package is intentional (have asked on gcc mailing list).
Any help would be very much appreciated!
Thanks
Dave
More information about the cfe-users
mailing list