util: Fix compilation errors in support/lockedpool.cpp #16161

pull jkczyz wants to merge 3 commits into bitcoin:master from jkczyz:2019-06-arena-walk changing 3 files +8 −4
  1. jkczyz commented at 11:19 PM on June 6, 2019: contributor

    Changes in #12048 cause a compilation error in Arena::walk() when ARENA_DEBUG is defined. Specifically, Arena's chunks_free map was changed to have a different value type.

    Additionally, missing includes cause other compilation errors when ARENA_DEBUG is defined.

    Reproduced with:

    make CPPFLAGS=-DARENA_DEBUG

  2. jkczyz force-pushed on Jun 7, 2019
  3. fanquake added the label Utils/log/libs on Jun 7, 2019
  4. MarcoFalke renamed this:
    Trivial: Fix compilation errors in support/lockedpool.cpp
    debug: Fix compilation errors in support/lockedpool.cpp
    on Jun 7, 2019
  5. MarcoFalke renamed this:
    debug: Fix compilation errors in support/lockedpool.cpp
    util: Fix compilation errors in support/lockedpool.cpp
    on Jun 7, 2019
  6. Empact commented at 2:00 AM on June 10, 2019: member

    How about a test case?

  7. jkczyz commented at 8:01 PM on June 10, 2019: contributor

    @Empact Would it be sufficient to remove #ifdef ARENA_DEBUG from this code to ensure the compilation error is caught in the future? Not sure if this goes against conventions for debug code.

  8. Empact commented at 8:59 PM on June 10, 2019: member

    No, the guards are there for a reason, just would be nice to exercise the guarded code at some point so such a failure is caught in the future.

    The guiding principle is: “test anything that might fail and everything that does”.

    May not be practical, but one possibility is treating one of the Travis test runs with ARENA_DEBUG.

  9. jkczyz force-pushed on Jun 11, 2019
  10. jkczyz commented at 4:06 PM on June 11, 2019: contributor

    I defined ARENA_DEBUG for a couple environments. Wasn't sure which environments, so I just added it to ones that were already setting CPPFLAGS. The Travis CI build failures seem unrelated.

    I had to update the Arena's test to use allocated memory to prevent a segfault. Figured this may have been needed as I observed it locally.

  11. DrahtBot commented at 9:23 PM on June 12, 2019: member

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #17517 (ci: Bump to clang-8 for asan build to avoid segfaults on ppc64le by MarcoFalke)
    • #16834 (Fetch Headers over DNS by TheBlueMatt)
    • #16762 (Rust-based Backup over-REST block downloader by TheBlueMatt)
    • #16195 (util: Use void* throughout support/lockedpool.h by jkczyz)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  12. in src/test/allocator_tests.cpp:20 in 910e605711 outdated
      19 | -    // without actually using memory.
      20 | -    void *synth_base = reinterpret_cast<void*>(0x08000000);
      21 |      const size_t synth_size = 1024*1024;
      22 | -    Arena b(synth_base, synth_size, 16);
      23 | +    std::unique_ptr<char[]> synth_base(new char[synth_size]());
      24 | +    Arena b(synth_base.get(), synth_size, 16);
    


    laanwj commented at 9:07 AM on June 17, 2019:

    Using a fake address here was on purpose, it would catch accesses to the underlying memory by causing a segfault. Also it leaks a MB of memory now.


    jkczyz commented at 4:27 PM on June 17, 2019:

    Using a fake address here was on purpose, it would catch accesses to the underlying memory by causing a segfault.

    Ah, that wasn't so clear to me from the code comment. Mission accomplished, I suppose. :) Since the access occurs when calling walk, those calls aren't very useful in this test given they cause a segfault.

    Also it leaks a MB of memory now.

    Won't the memory be deleted when the unique_ptr goes out of scope since I'm using get and not release?

    That said, I see the fake address is used later in the test, so perhaps it would be better to leave it as it was and remove the calls to walk given the segfault. Not sure what value walk has if never called though. Thoughts?


    laanwj commented at 11:28 AM on July 3, 2019:

    I'm slightly confused. I don't think walk is supposed to access the contents of the memory, it is supposed to be a debugging function that prints the allocation metadata, addresses and such, which is intentionally stored outside of the arena (to save on scarce page-locked memory). If it accesses the underlying memory, or even dereferences the pointer, that seems like a bug to me.


    jkczyz commented at 11:46 PM on July 3, 2019:

    I'm not sure why, but Inserting base into std::cout inside printchunk causes the segfault when executed with make CPPFLAGS=-DARENA_DEBUG check:

    Entering test module "Bitcoin Core Test Suite"
    test/allocator_tests.cpp(14): Entering test suite "allocator_tests"
    test/allocator_tests.cpp(16): Entering test case "arena_tests"
    0xunknown location(0): fatal error: in "allocator_tests/arena_tests": memory access violation at address: 0x080ffc10: no mapping at fault address                                        
    test/allocator_tests.cpp(16): last checkpoint: "arena_tests" entry.
    Test is aborted
    test/allocator_tests.cpp(16): Leaving test case "arena_tests"; testing time: 8196us
    Test is aborted
    test/allocator_tests.cpp(14): Leaving test suite "allocator_tests"; testing time: 8231us
    Test is aborted
    

    The segfault does not occur if I remove base from being inserted into the stream.


    jkczyz commented at 6:54 PM on November 16, 2019:

    Turns out this segfault can be avoided instead by changing printchunk to take void* rather than char*, which is what I had been doing in #16195. Updated in 30fb598.

  13. laanwj added the label Tests on Jun 17, 2019
  14. laanwj commented at 9:09 AM on June 17, 2019: member

    Thanks for catching this and fixing the build with -DARENA_DEBUG, not 100% sure about the build system and test changes.

  15. DrahtBot added the label Needs rebase on Aug 19, 2019
  16. DrahtBot commented at 1:56 PM on August 19, 2019: member

    <!--cf906140f33d8803c4a75a2196329ecb-->Needs rebase

  17. fanquake commented at 4:07 PM on November 16, 2019: member

    Concept ACK. @jkczyz could you rebase this?

    Compiling on macOS with ARENA_DEBUG:

      CXX      support/libbitcoin_util_a-lockedpool.o
    support/lockedpool.cpp:141:10: error: no member named 'cout' in namespace 'std'
        std::cout <<
        ~~~~~^
    support/lockedpool.cpp:142:22: error: no member named 'hex' in namespace 'std'
            "0x" << std::hex << std::setw(16) << std::setfill('0') << base <<
                    ~~~~~^
    support/lockedpool.cpp:142:34: error: no member named 'setw' in namespace 'std'
            "0x" << std::hex << std::setw(16) << std::setfill('0') << base <<
                                ~~~~~^
    support/lockedpool.cpp:142:51: error: no member named 'setfill' in namespace 'std'
            "0x" << std::hex << std::setw(16) << std::setfill('0') << base <<
                                                 ~~~~~^
    support/lockedpool.cpp:143:23: error: no member named 'hex' in namespace 'std'
            " 0x" << std::hex << std::setw(16) << std::setfill('0') << sz <<
                     ~~~~~^
    support/lockedpool.cpp:143:35: error: no member named 'setw' in namespace 'std'
            " 0x" << std::hex << std::setw(16) << std::setfill('0') << sz <<
                                 ~~~~~^
    support/lockedpool.cpp:143:52: error: no member named 'setfill' in namespace 'std'
            " 0x" << std::hex << std::setw(16) << std::setfill('0') << sz <<
                                                  ~~~~~^
    support/lockedpool.cpp:144:31: error: no member named 'endl' in namespace 'std'
            " 0x" << used << std::endl;
                             ~~~~~^
    support/lockedpool.cpp:150:10: error: no member named 'cout' in namespace 'std'
        std::cout << std::endl;
        ~~~~~^
    support/lockedpool.cpp:150:23: error: no member named 'endl' in namespace 'std'
        std::cout << std::endl;
                     ~~~~~^
    support/lockedpool.cpp:152:9: error: no matching function for call to 'printchunk'
            printchunk(chunk.first, chunk.second, false);
            ^~~~~~~~~~
    support/lockedpool.cpp:140:13: note: candidate function not viable: no known conversion from 'const std::__1::__map_const_iterator<std::__1::__tree_const_iterator<std::__1::__value_type<unsigned long, char *>, std::__1::__tree_node<std::__1::__value_type<unsigned long, char *>, void *> *, long> >' to 'size_t' (aka 'unsigned long') for 2nd argument
    static void printchunk(char* base, size_t sz, bool used) {
                ^
    support/lockedpool.cpp:153:10: error: no member named 'cout' in namespace 'std'
        std::cout << std::endl;
        ~~~~~^
    support/lockedpool.cpp:153:23: error: no member named 'endl' in namespace 'std'
        std::cout << std::endl;
                     ~~~~~^
    13 errors generated.
    
  18. Empact commented at 4:27 PM on November 16, 2019: member

    Concept ACK

  19. jkczyz force-pushed on Nov 16, 2019
  20. Fix compilation errors in support/lockedpool.cpp
    Changes in #12048 cause a compilation error in Arena::walk() when
    ARENA_DEBUG is defined. Specifically, Arena's chunks_free map was
    changed to have a different value type.
    
    Additionally, missing includes cause other compilation errors when
    ARENA_DEBUG is defined.
    
    Reproduced with:
    
    make CPPFLAGS=-DARENA_DEBUG
    ad71548822
  21. Define ARENA_DEBUG in Travis test runs
    The definition and uses of Arena::walk() are compiled only if
    ARENA_DEBUG is defined. Configure Travis to define ARENA_DEBUG so
    compilation errors do not go unnoticed.
    15c84f53f4
  22. jkczyz force-pushed on Nov 16, 2019
  23. jkczyz commented at 4:45 PM on November 16, 2019: contributor

    Concept ACK. @jkczyz could you rebase this?

    Done.

  24. fanquake removed the label Needs rebase on Nov 16, 2019
  25. Fix segfault in allocator_tests/arena_tests
    The test uses reinterpret_cast<void*> on unallocated memory. Using this
    memory in printchunk as char* causes a segfault, so have printchunk take
    void* instead.
    30fb598737
  26. jkczyz force-pushed on Nov 16, 2019
  27. laanwj commented at 11:57 AM on November 20, 2019: member

    ACK 30fb598737f6efb7802d707a1fa989872e7f8b7b

    I like how minimal this change has become.

  28. fanquake approved
  29. fanquake commented at 2:53 PM on November 20, 2019: member

    ACK 30fb598737f6efb7802d707a1fa989872e7f8b7b - thanks for following up jkczyz.

    src/test/test_bitcoin --run_test=allocator_tests
    Running 3 test cases...
    0x00000000x80ffc10 0x00000000000003f0 0x1
    
    0x00000000x8000000 0x00000000000ffc10 0x0
    
    
    0x00000000x8000000 0x0000000000100000 0x0
    
    0x00000000x80ffc80 0x0000000000000200 0x1
    0x00000000x80ffe80 0x0000000000000100 0x1
    0x00000000x80fff80 0x0000000000000080 0x1
    
    0x00000000x8000000 0x00000000000ffc80 0x0
    
    0x00000000x80ffc80 0x0000000000000200 0x1
    0x00000000x80ffe80 0x0000000000000100 0x1
    
    0x00000000x80fff80 0x0000000000000080 0x0
    0x00000000x8000000 0x00000000000ffc80 0x0
    
    0x00000000x80fff80 0x0000000000000080 0x1
    0x00000000x80ffc80 0x0000000000000200 0x1
    
    0x00000000x80ffe80 0x0000000000000100 0x0
    0x00000000x8000000 0x00000000000ffc80 0x0
    
    
    0x00000000x8000000 0x0000000000100000 0x0
    
  30. fanquake referenced this in commit 76e777df83 on Nov 20, 2019
  31. fanquake merged this on Nov 20, 2019
  32. fanquake closed this on Nov 20, 2019

  33. sidhujag referenced this in commit 4c31537b75 on Nov 20, 2019
  34. deadalnix referenced this in commit 08f8796875 on Jan 9, 2020
  35. zkbot referenced this in commit 5ef5d8d268 on Jul 31, 2020
  36. zkbot referenced this in commit 7d94064616 on Sep 29, 2020
  37. PastaPastaPasta referenced this in commit c8f7333c93 on Oct 22, 2020
  38. PastaPastaPasta referenced this in commit bedce7256a on Oct 27, 2020
  39. sidhujag referenced this in commit 39e180866d on Nov 10, 2020
  40. furszy referenced this in commit 19d00a6ed4 on Sep 11, 2021
  41. MarcoFalke locked this on Dec 16, 2021

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: 2026-04-13 15:14 UTC

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