MemorySanitizer complains about unitialized variable in RPC method names #17620

issue Sjors openend this issue on November 27, 2019
  1. Sjors commented at 3:17 pm on November 27, 2019: member

    I’m trying to get --with-sanitizers=memory to work on Ubuntu Bionic, since it might be useful to prevent stuff like #17568 and #17449.

    I installed LLVM 9 and clang using the instructions here. I then configured with:

    0./configure --enable-debug --with-sanitizers=memory CXX=clang++-9 CC=clang-9
    

    I can build just fine, but when I run bitcoind or bitcoin-cli it immediately bails out:

     0src/bitcoin-cli
     1Uninitialized bytes in MemcmpInterceptorCommon at offset 0 inside [0x705000000080, 11)
     2==25188==WARNING: MemorySanitizer: use-of-uninitialized-value
     3    [#0](/bitcoin-bitcoin/0/) 0x55734b322d9e in memcmp (/home/dev/bitcoin/src/bitcoin-cli+0x5ad9e)
     4    [#1](/bitcoin-bitcoin/1/) 0x7f633267abc7 in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::compare(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const (/usr/lib/x86_64-linux-gnu/libstdc++.so.6+0x126bc7)
     5    [#2](/bitcoin-bitcoin/2/) 0x55734b3e1042 in bool std::operator<<char, std::char_traits<char>, std::allocator<char> >(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0/../../../../include/c++/7.4.0/bits/basic_string.h:6097:20
     6    [#3](/bitcoin-bitcoin/3/) 0x55734b3e0e13 in bool std::operator<<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int>(std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int> const&, std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int> const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0/../../../../include/c++/7.4.0/bits/stl_pair.h:455:24
     7    [#4](/bitcoin-bitcoin/4/) 0x55734b3e05bc in std::less<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int> >::operator()(std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int> const&, std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int> const&) const /usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0/../../../../include/c++/7.4.0/bits/stl_function.h:386:20
     8    [#5](/bitcoin-bitcoin/5/) 0x55734b3e35e7 in std::_Rb_tree<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int>, std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int>, std::_Identity<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int> >, std::less<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int> >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int> > >::_M_get_insert_unique_pos(std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int> const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0/../../../../include/c++/7.4.0/bits/stl_tree.h:2038:13
     9    [#6](/bitcoin-bitcoin/6/) 0x55734b3e2df0 in std::pair<std::_Rb_tree_iterator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int> >, bool> std::_Rb_tree<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int>, std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int>, std::_Identity<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int> >, std::less<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int> >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int> > >::_M_insert_unique<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int> >(std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int>&&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0/../../../../include/c++/7.4.0/bits/stl_tree.h:2091:4
    10    [#7](/bitcoin-bitcoin/7/) 0x55734b3db513 in std::set<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int>, std::less<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int> >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int> > >::insert(std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int>&&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0/../../../../include/c++/7.4.0/bits/stl_set.h:511:9
    11    [#8](/bitcoin-bitcoin/8/) 0x55734b3d8de9 in CRPCConvertTable::CRPCConvertTable() /home/dev/bitcoin/src/rpc/client.cpp:200:17
    12    [#9](/bitcoin-bitcoin/9/) 0x55734b30dd8a in __cxx_global_var_init.165 /home/dev/bitcoin/src/rpc/client.cpp:207:25
    13    [#10](/bitcoin-bitcoin/10/) 0x55734b30de22 in _GLOBAL__sub_I_client.cpp /home/dev/bitcoin/src/rpc/client.cpp
    14    [#11](/bitcoin-bitcoin/11/) 0x55734b58b10c in __libc_csu_init (/home/dev/bitcoin/src/bitcoin-cli+0x2c310c)
    15    [#12](/bitcoin-bitcoin/12/) 0x7f63317c2b27 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:266
    16    [#13](/bitcoin-bitcoin/13/) 0x55734b312cf9 in _start (/home/dev/bitcoin/src/bitcoin-cli+0x4acf9)
    17
    18SUMMARY: MemorySanitizer: use-of-uninitialized-value (/home/dev/bitcoin/src/bitcoin-cli+0x5ad9e) in memcmp
    19Exiting
    

    The relevant code (line 200) doesn’t look wrong at first glance:

    https://github.com/bitcoin/bitcoin/blob/d8a66626d63135fd245d5afc524b88b9a94d208b/src/rpc/client.cpp#L194-L205

    The bitcoind issue seems similar:

     0src/bitcoind 
     1==25862==WARNING: MemorySanitizer: use-of-uninitialized-value
     2    [#0](/bitcoin-bitcoin/0/) 0x56472f55a4e0 in std::_Rb_tree<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::vector<CRPCCommand const*, std::allocator<CRPCCommand const*> > >, std::_Select1st<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::vector<CRPCCommand const*, std::allocator<CRPCCommand const*> > > >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::vector<CRPCCommand const*, std::allocator<CRPCCommand const*> > > > >::_M_lower_bound(std::_Rb_tree_node<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::vector<CRPCCommand const*, std::allocator<CRPCCommand const*> > > >*, std::_Rb_tree_node_base*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0/../../../../include/c++/7.4.0/bits/stl_tree.h:1871:7
     3    [#1](/bitcoin-bitcoin/1/) 0x56472f55a24b in std::_Rb_tree<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::vector<CRPCCommand const*, std::allocator<CRPCCommand const*> > >, std::_Select1st<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::vector<CRPCCommand const*, std::allocator<CRPCCommand const*> > > >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::vector<CRPCCommand const*, std::allocator<CRPCCommand const*> > > > >::lower_bound(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0/../../../../include/c++/7.4.0/bits/stl_tree.h:1187:16
     4    [#2](/bitcoin-bitcoin/2/) 0x56472f559519 in std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<CRPCCommand const*, std::allocator<CRPCCommand const*> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::vector<CRPCCommand const*, std::allocator<CRPCCommand const*> > > > >::lower_bound(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0/../../../../include/c++/7.4.0/bits/stl_map.h:1233:21
     5    [#3](/bitcoin-bitcoin/3/) 0x56472f4ee06d in std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::vector<CRPCCommand const*, std::allocator<CRPCCommand const*> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::vector<CRPCCommand const*, std::allocator<CRPCCommand const*> > > > >::operator[](std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0/../../../../include/c++/7.4.0/bits/stl_map.h:489:17
     6    [#4](/bitcoin-bitcoin/4/) 0x56472f4e3291 in CRPCTable::CRPCTable() /home/dev/bitcoin/src/rpc/server.cpp:255:9
     7    [#5](/bitcoin-bitcoin/5/) 0x56472ec17dda in __cxx_global_var_init.44 /home/dev/bitcoin/src/rpc/server.cpp:499:11
     8    [#6](/bitcoin-bitcoin/6/) 0x56472ec17e9a in _GLOBAL__sub_I_server.cpp /home/dev/bitcoin/src/rpc/server.cpp
     9    [#7](/bitcoin-bitcoin/7/) 0x564730ad1dac in __libc_csu_init (/home/dev/bitcoin/src/bitcoind+0x1f19dac)
    10    [#8](/bitcoin-bitcoin/8/) 0x7f4033472b27 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:266
    11    [#9](/bitcoin-bitcoin/9/) 0x56472ec3b659 in _start (/home/dev/bitcoin/src/bitcoind+0x83659)
    12
    13SUMMARY: MemorySanitizer: use-of-uninitialized-value /usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0/../../../../include/c++/7.4.0/bits/stl_tree.h:1871:7 in std::_Rb_tree<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::vector<CRPCCommand const*, std::allocator<CRPCCommand const*> > >, std::_Select1st<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::vector<CRPCCommand const*, std::allocator<CRPCCommand const*> > > >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::vector<CRPCCommand const*, std::allocator<CRPCCommand const*> > > > >::_M_lower_bound(std::_Rb_tree_node<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::vec
    14Exiting
    

    Relevant code (line 255):

    https://github.com/bitcoin/bitcoin/blob/d8a66626d63135fd245d5afc524b88b9a94d208b/src/rpc/server.cpp#L247-L257

    Maybe this is just a wild goose chase, if it turns out this sanitizer gets triggered all over the place. But @practicalswift successfully used it, so maybe theres’ a secret sauce?

  2. Sjors added the label Bug on Nov 27, 2019
  3. practicalswift commented at 3:29 pm on November 27, 2019: contributor

    @Sjors

    I think you’re seeing false positives due to MSAN being used only when compiling a subset of the code.

    Of the sanitizers MSAN is the most cumbersome to setup. Note that MSAN requires all code used to be compiled using -fsanitize=memory. That is really all code: including the C++ standard library. I usually link Bitcoin Core against a self-built MSAN-instrumented libc++ when using MSAN.

    In short: to get MSAN working without false positives you’ll have to make sure -fsanitize=memory is used when building a.) the standard library you’re using, b.) all dependencies in use, and c.) Bitcoin Core itself :)

  4. fanquake removed the label Bug on Nov 27, 2019
  5. practicalswift commented at 4:06 pm on November 27, 2019: contributor

    @Sjors

    I don’t have the time do it myself but if someone volunteers to add a MemorySanitizer build to Travis (we really really need that!) I can probably find time to document how I’ve gotten Bitcoin Core to work with MemorySanitizer in the past. The process is a bit hacky so it’ll require some cleaning up before being integrated in Travis - but at least the required steps will be shown.

  6. Sjors commented at 4:07 pm on November 27, 2019: member

    I agree it’s important to catch this class of bugs. Travis aside, it would be useful to document how to do this.

    Other than libc++ I suppose I should use /depends and build those with -fsanitize=memory too?

  7. practicalswift commented at 4:19 pm on November 27, 2019: contributor

    Travis aside, it would be useful to document how to do this.

    Agreed! I’ll try to guide you :)

    Start by compiling libc++ with MSAN instrumentation. You’ll get some hints here: https://github.com/google/sanitizers/wiki/MemorySanitizerLibcxxHowTo#instrumented-libc

    See if you are able to get Bitcoin Core link to link against the MSAN-instrumented libc++.

    After that we can tackle the depends :)

    Other than libc++ I suppose I should use /depends and build those with -fsanitize=memory too?

    Yes, exactly! Boost will need some hand holding, but we’ll get to that.

  8. Sjors commented at 4:25 pm on November 27, 2019: member

    Ironically I’m running into an uninitialized value error while compiling LLVM:

     0git clone https://github.com/llvm/llvm-project.git
     1git checkout llvmorg-9.0.0
     2cd llvm-project
     3mkdir libcxx_msan && cd libcxx_msan
     4cmake ../llvm -DCMAKE_BUILD_TYPE=Release -DLLVM_USE_SANITIZER=Memory -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
     5make -j10
     6
     7...
     8Scanning dependencies of target LipoOptsTableGen
     9SUMMARY: MemorySanitizer: use-of-uninitialized-value /usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0/../../../../include/c++/7.4.0/bits/stl_tree.h:1871:7 in _M_lower_bound
    10Exiting
    11tools/llvm-cvtres/CMakeFiles/CvtResTableGen.dir/build.make:93: recipe for target 'tools/llvm-cvtres/Opts.inc' failed
    12make[2]: *** [tools/llvm-cvtres/Opts.inc] Error 77
    13CMakeFiles/Makefile2:23514: recipe for target 'tools/llvm-cvtres/CMakeFiles/CvtResTableGen.dir/all' failed
    14make[1]: *** [tools/llvm-cvtres/CMakeFiles/CvtResTableGen.dir/all] Error 2
    15make[1]: *** Waiting for unfinished jobs....
    16[ 21%] Linking CXX executable ../../bin/not
    17[ 21%] Building LipoOpts.inc...
    18==19389==WARNING: MemorySanitizer: use-of-uninitialized-value
    19    [#0](/bitcoin-bitcoin/0/) 0xb8b543 in _M_lower_bound /usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0/../../../../include/c++/7.4.0/bits/stl_tree.h:1871:7
    20    [#1](/bitcoin-bitcoin/1/) 0xb8b543 in lower_bound /usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0/../../../../include/c++/7.4.0/bits/stl_tree.h:1187:16
    21    [#2](/bitcoin-bitcoin/2/) 0xb8b543 in lower_bound /usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0/../../../../include/c++/7.4.0/bits/stl_map.h:1233:21
    22    [#3](/bitcoin-bitcoin/3/) 0xb8b543 in std::map<long, llvm::IntInit*, std::less<long>, std::allocator<std::pair<long const, llvm::IntInit*> > >::operator[](long const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0/../../../../include/c++/7.4.0/bits/stl_map.h:489:17
    23    [#4](/bitcoin-bitcoin/4/) 0xb89714 in llvm::IntInit::get(long) /home/dev/src/llvm-project/llvm/lib/TableGen/Record.cpp:463:17
    24    [#5](/bitcoin-bitcoin/5/) 0xc06ecb in llvm::TGParser::ParseSimpleValue(llvm::Record*, llvm::RecTy*, llvm::TGParser::IDParseMode) /home/dev/src/llvm-project/llvm/lib/TableGen/TGParser.cpp:1783:27
    25    [#6](/bitcoin-bitcoin/6/) 0xbf2246 in llvm::TGParser::ParseValue(llvm::Record*, llvm::RecTy*, llvm::TGParser::IDParseMode) /home/dev/src/llvm-project/llvm/lib/TableGen/TGParser.cpp:2105:18
    26    [#7](/bitcoin-bitcoin/7/) 0xc0d072 in llvm::TGParser::ParseDeclaration(llvm::Record*, bool) /home/dev/src/llvm-project/llvm/lib/TableGen/TGParser.cpp:2414:17
    27    [#8](/bitcoin-bitcoin/8/) 0xc0edd6 in llvm::TGParser::ParseTemplateArgList(llvm::Record*) /home/dev/src/llvm-project/llvm/lib/TableGen/TGParser.cpp:2537:16
    28    [#9](/bitcoin-bitcoin/9/) 0xc13e2a in llvm::TGParser::ParseClass() /home/dev/src/llvm-project/llvm/lib/TableGen/TGParser.cpp:2846:9
    29    [#10](/bitcoin-bitcoin/10/) 0xc13465 in llvm::TGParser::ParseObject(llvm::MultiClass*) /home/dev/src/llvm-project/llvm/lib/TableGen/TGParser.cpp:3188:12
    30    [#11](/bitcoin-bitcoin/11/) 0xc1b3ec in ParseObjectList /home/dev/src/llvm-project/llvm/lib/TableGen/TGParser.cpp:3200:9
    31    [#12](/bitcoin-bitcoin/12/) 0xc1b3ec in llvm::TGParser::ParseFile() /home/dev/src/llvm-project/llvm/lib/TableGen/TGParser.cpp:3208:7
    32    [#13](/bitcoin-bitcoin/13/) 0xb7e4fe in llvm::TableGenMain(char*, bool (*)(llvm::raw_ostream&, llvm::RecordKeeper&)) /home/dev/src/llvm-project/llvm/lib/TableGen/Main.cpp:99:14
    33    [#14](/bitcoin-bitcoin/14/) 0xa7d445 in main /home/dev/src/llvm-project/llvm/utils/TableGen/TableGen.cpp:263:10
    34    [#15](/bitcoin-bitcoin/15/) 0x7f02d86e7b96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310
    35    [#16](/bitcoin-bitcoin/16/) 0x425f49 in _start (/home/dev/src/llvm-project/libcxx_msan/bin/llvm-tblgen+0x425f49)
    36
    37SUMMARY: MemorySanitizer: use-of-uninitialized-value /usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0/../../../../include/c++/7.4.0/bits/stl_tree.h:1871:7 in _M_lower_bound
    38Exiting
    39tools/llvm-lipo/CMakeFiles/LipoOptsTableGen.dir/build.make:93: recipe for target 'tools/llvm-lipo/LipoOpts.inc' failed
    40make[2]: *** [tools/llvm-lipo/LipoOpts.inc] Error 77
    

    Should I try an older version?

  9. practicalswift commented at 4:29 pm on November 27, 2019: contributor

    @Sjors

    Try this:

    0$ svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm
    1$ (cd llvm/projects && svn co http://llvm.org/svn/llvm-project/libcxx/trunk libcxx)
    2$ (cd llvm/projects && svn co http://llvm.org/svn/llvm-project/libcxxabi/trunk libcxxabi)
    3$ mkdir libcxx_msan && cd libcxx_msan
    4$ cmake ../llvm -DCMAKE_BUILD_TYPE=Release -DLLVM_USE_SANITIZER=Memory -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
    5$ make cxx -j12
    

    Does that work? :)

  10. Sjors commented at 4:30 pm on November 27, 2019: member
    Subversion, really?
  11. practicalswift commented at 4:32 pm on November 27, 2019: contributor
    I heard the OpenBSD people suggested going with cvs instead :)
  12. ryanofsky commented at 4:45 pm on November 27, 2019: member

    Subversion, really?

    Hey… I used to work on Subversion. Apparently I had 82 commits (https://fisheye.apache.org/committer/subversion/rey4). Even still subversion can work better than git if you have a large codebase.

  13. practicalswift commented at 4:57 pm on November 27, 2019: contributor

    @Sjors

    If you want to use git you can use the new LLVM monorepo (the one you cloned), but then you’ll have to opt-in to the specific subprojects you want to build by passing -DLLVM_ENABLE_PROJECTS=libcxx;libcxxabi to cmake.

    Does that work better? :)

  14. Sjors commented at 4:58 pm on November 27, 2019: member

    Anyway, the above compiles, but not sure how to get this into ./configure (or depends for that matter)

    I tried:

    0 ./configure --enable-debug --with-incompatible-bdb --without-gui --disable-bench CXXFLAGS="-Werror=unused-variable -I/home/dev/src/libcxx_msan/include -I/home/dev/src/libcxx_msan/include/c++/v1" --with-sanitizers=memory CXX=clang++-9 CC=clang-9
    

    This throws a bunch of rocks at me, e.g.:

    0configure: error: libdb_cxx headers missing, Bitcoin Core requires this library for wallet functionality (--disable-wallet to disable wallet functionality)
    

    Without wallet it gets stuck at Boost (maybe that’s where the hand holding comes in?):

    0configure: error: No working boost sleep implementation found.
    
  15. practicalswift commented at 5:14 pm on November 27, 2019: contributor

    @Sjors

    Great that libc++ is instrumented. That is a good start! :)

    Oh, we probably need to go with the depends first.

    See if you can get depends to build using CFLAGS and CXXFLAGS set to -fno-omit-frame-pointer -g -O1 -fno-optimize-sibling-calls -fsanitize-memory-track-origins=2 -fsanitize=memory -nostdinc++ -stdlib=libc++ -L${INSTRUMENTED_LIBCXX}/lib -lc++abi -I${INSTRUMENTED_LIBCXX}include -I${INSTRUMENTED_LIBCXX}/include/c++/v1 -lpthread -Wl,-rpath,${INSTRUMENTED_LIBCXX}/lib.

    To get Boost to build with MSAN you’ll have to do something along the lines of:

     0diff --git a/depends/packages/boost.mk b/depends/packages/boost.mk
     1index d360bb5ba..fcd138f92 100644
     2--- a/depends/packages/boost.mk
     3+++ b/depends/packages/boost.mk
     4@@ -19,7 +19,7 @@ $(package)_config_opts_i686_android=address-model=32
     5 $(package)_config_opts_aarch64_android=address-model=64
     6 $(package)_config_opts_x86_64_android=address-model=64
     7 $(package)_config_opts_armv7a_android=address-model=32
     8-$(package)_toolset_$(host_os)=gcc
     9+$(package)_toolset_$(host_os)=clang
    10 $(package)_archiver_$(host_os)=$($(package)_ar)
    11 $(package)_toolset_darwin=clang-darwin
    12 $(package)_config_libraries=chrono,filesystem,system,thread,test
    13@@ -29,17 +29,17 @@ $(package)_cxxflags_android=-fPIC
    14 endef
    15
    16 define $(package)_preprocess_cmds
    17-  echo "using $(boost_toolset_$(host_os)) : : $($(package)_cxx) : <cxxflags>\"$($(package)_cxxflags) $($(package)_cppflags)\" <linkflags>\"$($(package)_ldflags)\" <archiver>\"$(boost_archiver_$(host_os))\" <striper>\"$(host_STRIP)\"  <ranlib>\"$(host_RANLIB)\" <rc>\"$(host_WINDRES)\" : ;" > user-config.jam
    18+  echo "using clang : : clang++ : <cxxflags>\"$($(package)_cxxflags) -fno-omit-frame-pointer -g -O1 -fno-optimize-sibling-calls -fsanitize-memory-track-origins=2 -fsanitize=memory -nostdinc++ -stdlib=libc++ -LPATH_TO_YOUR_INSTRUMENTED_LIBCXX/lib -lc++abi -IPATH_TO_YOUR_INSTRUMENTED_LIBCXX/include -IPATH_TO_YOUR_INSTRUMENTED_LIBCXX/include/c++/v1 -lpthread -Wl,-rpath,PATH_TO_YOUR_INSTRUMENTED_LIBCXX/lib $($(package)_cppflags)\" <linkflags>\"$($(package)_ldflags)\" <archiver>\"$(boost_archiver_$(host_os))\" <striper>\"$(host_STRIP)\"  <ranlib>\"$(host_RANLIB)\" <rc>\"$(host_WINDRES)\" : ;" > user-config.jam
    19 endef
    20
    21 define $(package)_config_cmds
    22-  ./bootstrap.sh --without-icu --with-libraries=$(boost_config_libraries)
    23+  ./bootstrap.sh --without-icu --with-libraries=$(boost_config_libraries) toolset=clang
    24 endef
    25
    26 define $(package)_build_cmds
    27-  ./b2 -d2 -j2 -d1 --prefix=$($(package)_staging_prefix_dir) $($(package)_config_opts) stage
    28+  ./b2 -d2 -j2 -d1 --prefix=$($(package)_staging_prefix_dir) toolset=clang stage $($(package)_config_opts)
    29 endef
    30
    31 define $(package)_stage_cmds
    32-  ./b2 -d0 -j4 --prefix=$($(package)_staging_prefix_dir) $($(package)_config_opts) install
    33+  ./b2 -d0 -j4 --prefix=$($(package)_staging_prefix_dir) toolset=clang install $($(package)_config_opts)
    34 endef
    

    Try make NO_QT=1 NO_ZMQ=1 NO_UPNP=1 NO_WALLET=1 V=1.

    Does it build? :)

  16. Sjors commented at 5:30 pm on November 27, 2019: member

    V=1 is a typo? I was able to build depends with your patch and incantation.

    But building bitcoind still complains about missing boost sleep:

     0./configure --prefix=`pwd`/depends/x86_64-pc-linux-gnu --enable-debug --with-sanitizers=memory CXX=clang++-9 CC=clang-9
     1configure: loading site script /home/dev/bitcoin/depends/x86_64-pc-linux-gnu/share/config.site
     2checking build system type... x86_64-pc-linux-gnu
     3checking host system type... x86_64-pc-linux-gnu
     4...
     5checking whether to build Bitcoin Core GUI... no
     6checking for boostlib >= 1.47.0 (104700) includes in "/home/dev/bitcoin/depends/x86_64-pc-linux-gnu/share/../include"... yes
     7checking for boostlib >= 1.47.0 (104700) lib path in "/home/dev/bitcoin/depends/x86_64-pc-linux-gnu/share/../lib/x86_64-linux-gnu"... no
     8checking for boostlib >= 1.47.0 (104700) lib path in "/home/dev/bitcoin/depends/x86_64-pc-linux-gnu/share/../lib64"... no
     9checking for boostlib >= 1.47.0 (104700) lib path in "/home/dev/bitcoin/depends/x86_64-pc-linux-gnu/share/../libx32"... no
    10checking for boostlib >= 1.47.0 (104700) lib path in "/home/dev/bitcoin/depends/x86_64-pc-linux-gnu/share/../lib"... yes
    11checking for boostlib >= 1.47.0 (104700)... yes
    12checking whether the Boost::System library is available... yes
    13checking for exit in -lboost_system-mt-x64... yes
    14checking whether the Boost::Filesystem library is available... yes
    15checking for exit in -lboost_filesystem-mt-x64... yes
    16checking whether the Boost::Thread library is available... yes
    17checking for exit in -lboost_thread-mt-x64... yes
    18checking whether the Boost::Chrono library is available... yes
    19checking for exit in -lboost_chrono-mt-x64... yes
    20checking whether the Boost::Unit_Test_Framework library is available... yes
    21checking for dynamic linked boost test... no
    22checking for mismatched boost c++11 scoped enums... ok
    23configure: error: No working boost sleep implementation found.
    

    Maybe related #17478

  17. practicalswift commented at 7:16 pm on November 27, 2019: contributor

    @Sjors No V=1 is to get the commands executed printed – V is for verbose :)

    Please try:

    0$ FLAGS="-fno-omit-frame-pointer -g -O1 -fno-optimize-sibling-calls \
    1    -fsanitize-memory-track-origins=2 -fsanitize=memory -nostdinc++ \
    2    -stdlib=libc++ -L${INSTRUMENTED_LIBCXX}lib -lc++abi \
    3    -I${INSTRUMENTED_LIBCXX}include -I${INSTRUMENTED_LIBCXX}include/c++/v1 \
    4    -lpthread -Wl,-rpath,${INSTRUMENTED_LIBCXX}lib"
    5$ CC=clang-9 CXX=clang++-9 CFLAGS="${FLAGS}" CXXFLAGS="${FLAGS}" \
    6    ./configure --with-gui=no --disable-wallet --disable-zmq --disable-asm \
    7    --with-miniupnpc=no --prefix=$(pwd)/depends/x86_64-pc-linux-gnu
    

    Does that work? :)

  18. Sjors commented at 7:55 pm on November 27, 2019: member
    Configure works now, but build bails out with a huge error, e.g. make src/bitcoin-cli: https://gist.github.com/Sjors/37c5c35eeab351f57891f2e47d9cdf01
  19. practicalswift commented at 9:16 pm on November 27, 2019: contributor
    @Sjors Could that be due left-overs from a previous build? Can you retry after a make distclean or a new git clone?
  20. Sjors commented at 9:38 am on November 28, 2019: member
    That worked. Now plowing through false positives… #17627
  21. practicalswift commented at 8:32 am on March 12, 2020: contributor
    MSan setup is documented by the config in #18288 (“build: Add MemorySanitizer (MSan) in Travis to detect use of uninitialized memory”). @Sjors Would you mind reviewing and/or Concept ACK:ing #18288? :)
  22. MarcoFalke commented at 12:46 pm on April 28, 2020: member
    Is this still an issue with a recent version of Bitcoin Core? If yes, what are the steps to reproduce?
  23. MarcoFalke closed this on May 7, 2020

  24. Sjors commented at 1:19 pm on May 8, 2020: member
    I haven’t tried this recently.
  25. DrahtBot locked this on Feb 15, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-07-03 10:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me