[libcxx-commits] [PATCH] D94718: [libc++] Unbreak the debug mode

Reid Kleckner via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu Jan 14 14:29:13 PST 2021

rnk added a comment.

Thanks, I think this will solve the issue.

It's also worth noting that there is one _LIBCPP_ASSERT in locale:
But, missing that assert seems preferable to locale registration failure.

Here is the reproducer I came up with. I made a shared library and exe from these two cpp files and linked them with the shell script:

  $ cat facet_lib.cpp 
  #include <sstream>
  std::string __attribute__((visibility("default"))) numToString(int x);
  std::string numToString(int x) {
    std::stringstream ss;
    ss << x;
    return ss.str();
  $ cat facet.cpp 
  #include <string>
  #include <cstdio>
  std::string __attribute__((visibility("default"))) numToString(int x);
  int main() {
    std::string s = numToString(42);
    printf("should be 42: %s\n", s.c_str());
  $ cat linkit.sh 
  set -e
  clang++ -g -D_LIBCPP_DEBUG=1 -fvisibility=hidden -stdlib=libc++ -c facet_lib.cpp -fPIC -o facet_lib.o
  clang++ -stdlib=libc++ -fPIC facet_lib.o  -shared -o libfacet_lib.so
  clang++ -g -D_LIBCPP_DEBUG=1 -fvisibility=hidden -stdlib=libc++ facet.cpp libfacet_lib.so -o facet
  LD_LIBRARY_PATH=.:lib ./facet
  $ ./linkit.sh 
  should be 42: 
  # output is wrong

objdump can confirm that there is a hidden ::id global in the facet_lib.o, which I think is the issue (double facet registration):

  $ llvm-objdump -t facet_lib.o | c++filt | grep num_put.*::id
  0000000000000000  w    O .bss._ZNSt3__17num_putIcNS_19ostreambuf_iteratorIcNS_11char_traitsIcEEEEE2idE  0000000000000010 .hidden std::__1::num_put<char, std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> > >::id

After I apply this patch locally and relink, when I check the object file, I see that the id static data member is not defined in this object:

  $ llvm-objdump -t facet_lib.o | c++filt | grep num_put.*::id
  0000000000000000         *UND*  0000000000000000 std::__1::num_put<char, std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> > >::id

It is provided by the libc++ library instead, which is correct.

  rG LLVM Github Monorepo



More information about the libcxx-commits mailing list