Skip to content

nix-2.18 crashes on g++ STL assertions (-D_GLIBCXX_ASSERTIONS): string_view:234: operator[]: Assertion '__pos < this->_M_len' failed. #8824

Closed

Description

@trofi

Describe the bug

When nix is built with -D_GLIBCXX_ASSERTIONS define gcc's libstdc++ exposes invariant violations and crashes nix's test suite.

Steps To Reproduce

The simplest test is to patch the assert in:

--- a/Makefile
+++ b/Makefile
@@ -47,4 +47,4 @@ endif

 include mk/lib.mk

-GLOBAL_CXXFLAGS += -g -Wall -include config.h -std=c++2a -I src
+GLOBAL_CXXFLAGS += -g -Wall -include config.h -std=c++2a -I src -D_GLIBCXX_ASSERTIONS

and run the test:

$ nix build .#
warning: Git tree '/mnt/archive/big/git/nix' is dirty
error: builder for '/nix/store/zis6gz3lpvjqnff8rycm2hbjwzsly4jm-nix-2.18.0pre20230814_dirty.drv' failed with exit code 2;
       last 10 log lines:
       > [       OK ] SearchPathElem.parse_twoEqs (0 ms)
       > [ RUN      ] SearchPathElem.suffixIfPotentialMatch_justPath
       > [       OK ] SearchPathElem.suffixIfPotentialMatch_justPath (0 ms)
       > [ RUN      ] SearchPathElem.suffixIfPotentialMatch_misleadingPrefix1
       > [       OK ] SearchPathElem.suffixIfPotentialMatch_misleadingPrefix1 (0 ms)
       > [ RUN      ] SearchPathElem.suffixIfPotentialMatch_misleadingPrefix2
       > [       OK ] SearchPathElem.suffixIfPotentialMatch_misleadingPrefix2 (0 ms)
       > [ RUN      ] SearchPathElem.suffixIfPotentialMatch_partialPrefix
       > /nix/store/1gf2flfqnpqbr1b4p4qz2f72y42bs56r-gcc-11.3.0/include/c++/11.3.0/string_view:234: constexpr const value_type& std::basic_string_view<_CharT, _Traits>::operator[](std::basic_string_view<_CharT, _Traits>::size_type) const [with _CharT = char; _Traits = std::char_traits<char>; std::basic_string_view<_CharT, _Traits>::const_reference = const char&; std::basic_string_view<_CharT, _Traits>::size_type = long unsigned int]: Assertion '__pos < this->_M_len' failed.
       > make: *** [mk/lib.mk:120: libexpr-tests_RUN] Aborted (core dumped)
       For full logs, run 'nix log /nix/store/zis6gz3lpvjqnff8rycm2hbjwzsly4jm-nix-2.18.0pre20230814_dirty.drv'.

Additional context

The bug initially observed on Gentoo where gcc enables the asserts by default for all packages in certain configurations: https://discourse.nixos.org/t/error-while-installing-home-manager/31720/11

Priorities

Add 👍 to issues you find important.

Activity

  1. nixos-discourse commented on Aug 14, 2023

    @nixos-discourse
  2. trofi commented on Aug 14, 2023

    @trofi
    ContributorAuthor

    Extracted backtrace:

    $ gdb src/libexpr/tests/libnixexpr-tests
    Reading symbols from src/libexpr/tests/libnixexpr-tests...
    (gdb) break __glibcxx_assert_fail
    (gdb) run
    (gdb) bt
    #0  0x00007ffff762e590 in std::__glibcxx_assert_fail(char const*, int, char const*, char const*)@plt () from /mnt/archive/big/git/nix/src/libexpr/libnixexpr.so
    #1  0x00007ffff780bde9 in std::basic_string_view<char, std::char_traits<char> >::operator[] (this=0x7fffffff56c0, __pos=4)
        at /nix/store/r74fw2j8rx5idb0w8s1s6ynwwgs0qmh9-gcc-14.0.0/include/c++/14.0.0/string_view:258
    #2  0x00007ffff78c8a78 in nix::SearchPath::Prefix::suffixIfPotentialMatch (this=0x7fffffff5780, path=...) at src/libexpr/search-path.cc:15
    #3  0x00005555556b2be1 in nix::SearchPathElem_suffixIfPotentialMatch_partialPrefix_Test::TestBody (this=0x555555a17540) at src/libexpr/tests/search-path.cc:62
    #4  0x00007ffff7fa262d in void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) ()
       from /nix/store/v5lc4i5yx0w71w18vxj5zk5s09s463h1-gtest-1.12.1/lib/libgtest.so.1.12.1
    #5  0x00007ffff7f8a32e in testing::Test::Run() () from /nix/store/v5lc4i5yx0w71w18vxj5zk5s09s463h1-gtest-1.12.1/lib/libgtest.so.1.12.1
    #6  0x00007ffff7f8a4e5 in testing::TestInfo::Run() () from /nix/store/v5lc4i5yx0w71w18vxj5zk5s09s463h1-gtest-1.12.1/lib/libgtest.so.1.12.1
    #7  0x00007ffff7f8a605 in testing::TestSuite::Run() () from /nix/store/v5lc4i5yx0w71w18vxj5zk5s09s463h1-gtest-1.12.1/lib/libgtest.so.1.12.1
    #8  0x00007ffff7f97c57 in testing::internal::UnitTestImpl::RunAllTests() () from /nix/store/v5lc4i5yx0w71w18vxj5zk5s09s463h1-gtest-1.12.1/lib/libgtest.so.1.12.1
    #9  0x00007ffff7f8a7cf in testing::UnitTest::Run() () from /nix/store/v5lc4i5yx0w71w18vxj5zk5s09s463h1-gtest-1.12.1/lib/libgtest.so.1.12.1
    #10 0x00007ffff7fbe0c0 in main () from /nix/store/v5lc4i5yx0w71w18vxj5zk5s09s463h1-gtest-1.12.1/lib/libgtest_main.so.1.12.1
    #11 0x00007ffff642804e in __libc_start_call_main () from /nix/store/rx9a808bjg34w6pll5impbvw74y96qbd-glibc-2.38/lib/libc.so.6
    #12 0x00007ffff6428109 in __libc_start_main_impl () from /nix/store/rx9a808bjg34w6pll5impbvw74y96qbd-glibc-2.38/lib/libc.so.6
    #13 0x0000555555588b85 in _start ()
    
  3. trofi commented on Aug 14, 2023

    @trofi
    ContributorAuthor

    Proposed the fix as #8825

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions