[libcxx-commits] [libcxx] [libc++] Speed up classic locale (PR #72112)

Dmitry Vyukov via libcxx-commits libcxx-commits at lists.llvm.org
Sun Nov 26 22:36:50 PST 2023


dvyukov wrote:

This caused the following error on bots.

@ldionne perhaps classic_locale_imp_ should be constinit?

https://lab.llvm.org/buildbot/#/builders/168/builds/17053
```
==1639930==ERROR: AddressSanitizer: initialization-order-fiasco on address 0x7f9576845828 at pc 0x7f95767c189d bp 0x7fff76544cb0 sp 0x7fff76544ca8
WRITE of size 8 at 0x7f9576845828 thread T0
    #0 0x7f95767c189c in __shared_count /b/sanitizer-x86_64-linux-bootstrap-asan/build/libcxx_build_asan/include/c++/v1/__memory/shared_ptr.h:160:11
    #1 0x7f95767c189c in facet /b/sanitizer-x86_64-linux-bootstrap-asan/build/libcxx_build_asan/include/c++/v1/__locale:150:11
    #2 0x7f95767c189c in std::__1::locale::__imp::__imp(unsigned long) /b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/libcxx/src/locale.cpp:169:7
    #3 0x7f95767c4382 in __emplace<unsigned int> /b/sanitizer-x86_64-linux-bootstrap-asan/build/libcxx_build_asan/include/c++/v1/__utility/no_destroy.h:41:19
    #4 0x7f95767c4382 in operator() /b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/libcxx/src/locale.cpp:554:40
    #5 0x7f95767c4382 in std::__1::locale::classic() /b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/libcxx/src/locale.cpp:552:69
    #6 0x7f95767cae5d in __global /b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/libcxx/src/locale.cpp:561:33
    #7 0x7f95767cae5d in std::__1::locale::locale() /b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/libcxx/src/locale.cpp:575:39
    #8 0x7f95767309f2 in std::__1::basic_streambuf<char, std::__1::char_traits<char>>::basic_streambuf() /b/sanitizer-x86_64-linux-bootstrap-asan/build/libcxx_build_asan/include/c++/v1/streambuf:314:35
    #9 0x7f9576762283 in __stdinbuf /b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/libcxx/src/std_stream.h:76:21
    #10 0x7f9576762283 in std::__1::DoIOSInit::DoIOSInit() /b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/libcxx/src/iostream.cpp:124:59
    #11 0x7f9576762e23 in std::__1::ios_base::Init::Init() /b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/libcxx/src/iostream.cpp:161:22
    #12 0x7f9576766450 in __cxx_global_var_init /b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/libcxx/src/iostream_init.h:2:31
    #13 0x7f9576766450 in _GLOBAL__I_000100 /b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/libcxx/src/iostream.cpp
    #14 0x7f9576a0f33d  (/lib64/ld-linux-x86-64.so.2+0x533d) (BuildId: cc23bad777ae59d26be0445659cd1c94244d6bc7)
    #15 0x7f9576a0f427  (/lib64/ld-linux-x86-64.so.2+0x5427) (BuildId: cc23bad777ae59d26be0445659cd1c94244d6bc7)
    #16 0x7f9576a26e0f  (/lib64/ld-linux-x86-64.so.2+0x1ce0f) (BuildId: cc23bad777ae59d26be0445659cd1c94244d6bc7)

0x7f9576845828 is located 8 bytes inside of global variable 'std::__1::locale::__imp::classic_locale_imp_' defined in '/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/libcxx/src/locale.cpp' (0x7f9576845820) of size 312
  registered at:
    #0 0x557b4c0dae06 in __asan_register_globals /b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/compiler-rt/lib/asan/asan_globals.cpp:369:3
    #1 0x557b4c0dbf29 in __asan_register_elf_globals /b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/compiler-rt/lib/asan/asan_globals.cpp:352:3
    #2 0x7f9576a0f33d  (/lib64/ld-linux-x86-64.so.2+0x533d) (BuildId: cc23bad777ae59d26be0445659cd1c94244d6bc7)

SUMMARY: AddressSanitizer: initialization-order-fiasco /b/sanitizer-x86_64-linux-bootstrap-asan/build/libcxx_build_asan/include/c++/v1/__memory/shared_ptr.h:160:11 in __shared_count
Shadow bytes around the buggy address:
  0x7f9576845580: 00 f9 f9 f9 00 00 00 00 00 00 00 00 00 00 00 00
  0x7f9576845600: f9 f9 f9 f9 00 f9 f9 f9 01 f9 f9 f9 00 f9 f9 f9
  0x7f9576845680: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x7f9576845700: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x7f9576845780: 00 00 00 00 00 00 00 00 00 00 00 00 00 f9 f9 f9
=>0x7f9576845800: 00 f9 f9 f9 f6[f6]f6 f6 f6 f6 f6 f6 f6 f6 f6 f6
  0x7f9576845880: f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6
  0x7f9576845900: f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6
```

https://github.com/llvm/llvm-project/pull/72112


More information about the libcxx-commits mailing list