Repository navigation
Closed
Labels
Description
Describe the bug
Running tests on 2.20.3 + ec5cc10 (to fix #8737) on Arch Linux results in a crash (heap corruption) in libnixstore-test-support.so.
Steps To Reproduce
- Check out 2.20.3
- Cherry-pick ec5cc10
- Compile sources in a clean Arch Linux chroot, using default Arch makepkg.conf flags
- Run
make checkormake libexpr-tests_RUN
Expected behavior
No crash.
Additional context
Backtrace (with -Og, without LTO):
#0 __pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=6, no_tid=no_tid@entry=0) at pthread_kill.c:44
#1 0x00007ffff6cab393 in __pthread_kill_internal (signo=6, threadid=<optimized out>) at pthread_kill.c:78
#2 0x00007ffff6c5a6c8 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#3 0x00007ffff6c424b8 in __GI_abort () at abort.c:79
#4 0x00007ffff6c43395 in __libc_message_impl (fmt=fmt@entry=0x7ffff6dbb2ea "%s\n") at ../sysdeps/posix/libc_fatal.c:132
#5 0x00007ffff6cb52a7 in malloc_printerr (str=str@entry=0x7ffff6dbe5c8 "double free or corruption (fasttop)") at malloc.c:5772
#6 0x00007ffff6cb755a in _int_free (av=0x7ffff6df6ac0 <main_arena>, p=<optimized out>, have_lock=have_lock@entry=0) at malloc.c:4607
#7 0x00007ffff6cb9e93 in __GI___libc_free (mem=<optimized out>) at malloc.c:3398
#8 0x00007ffff6c5c5a1 in __cxa_finalize (d=0x7ffff7eae000) at cxa_finalize.c:82
#9 0x00007ffff7e5a1a8 in ?? () from /mnt/ssd/Scratch/makepkg/nix/src/nix/tests/unit/libstore-support/libnixstore-test-support.so
#10 0x00007ffff7eaf000 in ?? ()
#11 0x00007ffff7fc90e2 in _dl_call_fini (closure_map=0x7fffffffd060, closure_map@entry=0x7ffff7eaf000) at dl-call_fini.c:43
#12 0x00007ffff7fccffe in _dl_fini () at dl-fini.c:114
#13 0x00007ffff6c5cb36 in __run_exit_handlers (status=0, listp=0x7ffff6df6680 <__exit_funcs>, run_list_atexit=run_list_atexit@entry=true, run_dtors=run_dtors@entry=true) at exit.c:108
#14 0x00007ffff6c5cc80 in __GI_exit (status=<optimized out>) at exit.c:138
#15 0x00007ffff6c43cd7 in __libc_start_call_main (main=main@entry=0x7ffff7f84020 <main(int, char**)>, argc=argc@entry=1, argv=argv@entry=0x7fffffffd498) at ../sysdeps/nptl/libc_start_call_main.h:74
#16 0x00007ffff6c43d8a in __libc_start_main_impl (main=0x7ffff7f84020 <main(int, char**)>, argc=1, argv=0x7fffffffd498, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffd488) at ../csu/libc-start.c:360
#17 0x00005555555d6f45 in _start ()
Valgrind memcheck report
==3441134== Invalid free() / delete / delete[] / realloc()
==3441134== at 0x48471A4: operator delete(void*) (vg_replace_malloc.c:1051)
==3441134== by 0x575D5A0: __cxa_finalize (cxa_finalize.c:82)
==3441134== by 0x496DDA7: ??? (in /home/intelfx/devel/ext/nix/tests/unit/libexpr-support/libnixexpr-test-support.so)
==3441134== by 0x40010E1: _dl_call_fini (dl-call_fini.c:43)
==3441134== by 0x4004FFD: _dl_fini (dl-fini.c:114)
==3441134== by 0x575DB35: __run_exit_handlers (exit.c:108)
==3441134== by 0x575DC7F: exit (exit.c:138)
==3441134== by 0x5744CD6: (below main) (libc_start_call_main.h:74)
==3441134== Address 0x7944740 is 0 bytes inside a block of size 24 free'd
==3441134== at 0x48471A4: operator delete(void*) (vg_replace_malloc.c:1051)
==3441134== by 0x575DB35: __run_exit_handlers (exit.c:108)
==3441134== by 0x575DC7F: exit (exit.c:138)
==3441134== by 0x5744CD6: (below main) (libc_start_call_main.h:74)
==3441134== Block was alloc'd at
==3441134== at 0x4843F73: operator new(unsigned long) (vg_replace_malloc.c:483)
==3441134== by 0x407617: void std::vector<std::vector<void (*)(), std::allocator<void (*)()> >, std::allocator<std::vector<void (*)(), std::allocator<void (*)()> > > >::_M_realloc_insert<>(__gnu_cxx::__normal_iterator<std::vector<void (*)(), std::allocator<void (*)()> >*, std::vector<std::vector<void (*)(), std::allocator<void (*)()> >, std::allocator<std::vector<void (*)(), std::allocator<void (*)()> > > > >) (in /home/intelfx/devel/ext/nix/tests/unit/libexpr/libnixexpr-tests)
==3441134== by 0x41E2C3: rc::gen::detail::ExecHandler::onGenerate(rc::Gen<rc::detail::Any> const&) (in /home/intelfx/devel/ext/nix/tests/unit/libexpr/libnixexpr-tests)
==3441134== by 0x4972B6A: rc::Gen<nix::StorePath>::operator*() const (Gen.hpp:85)
==3441134== by 0x4A33200: rc::Arbitrary<nix::DerivedPathOpaque, void>::arbitrary() (derived-path.cc:12)
==3441134== by 0x2FF32B: decltype (rc::Arbitrary<nix::DerivedPathOpaque, void>::arbitrary()) rc::gen::arbitrary<nix::DerivedPathOpaque>() (Arbitrary.hpp:14)
==3441134== by 0x3014E0: rc::gen::detail::DefaultArbitrary<std::tuple<nix::DerivedPathOpaque> >::arbitrary() (Tuple.hpp:123)
==3441134== by 0x3015B5: arbitrary (Arbitrary.hpp:23)
==3441134== by 0x3015B5: decltype (rc::Arbitrary<std::tuple<nix::DerivedPathOpaque>, void>::arbitrary()) rc::gen::arbitrary<std::tuple<nix::DerivedPathOpaque> >() (Arbitrary.hpp:14)
==3441134== by 0x302844: rc::detail::FunctionTraits<std::decay<rc::detail::PropertyAdapter<void (*)(nix::DerivedPathOpaque const&), void (nix::DerivedPathOpaque const&)> >::type>::ReturnType rc::gen::detail::execWithArguments<rc::detail::PropertyAdapter<void (*)(nix::DerivedPathOpaque const&), void (nix::DerivedPathOpaque const&)>, nix::DerivedPathOpaque const&>(rc::detail::PropertyAdapter<void (*)(nix::DerivedPathOpaque const&), void (nix::DerivedPathOpaque const&)> const&, rc::detail::TypeList<nix::DerivedPathOpaque const&>) (ExecRaw.hpp:21)
==3441134== by 0x302940: std::pair<rc::detail::FunctionTraitsImpl<std::decay<rc::detail::PropertyAdapter<void (*)(nix::DerivedPathOpaque const&), void (nix::DerivedPathOpaque const&)> >::type>::ReturnType, rc::gen::detail::Recipe> rc::gen::detail::execWithRecipe<rc::detail::PropertyAdapter<void (*)(nix::DerivedPathOpaque const&), void (nix::DerivedPathOpaque const&)> >(rc::detail::PropertyAdapter<void (*)(nix::DerivedPathOpaque const&), void (nix::DerivedPathOpaque const&)>, rc::gen::detail::Recipe) (ExecRaw.hpp:33)
==3441134== by 0x302A90: rc::gen::detail::shrinkableWithRecipe<rc::detail::PropertyAdapter<void (*)(nix::DerivedPathOpaque const&), void (nix::DerivedPathOpaque const&)> >(rc::detail::PropertyAdapter<void (*)(nix::DerivedPathOpaque const&), void (nix::DerivedPathOpaque const&)>, rc::gen::detail::Recipe)::{lambda()#1}::operator()() const (ExecRaw.hpp:49)
==3441134== by 0x302B1D: value (Create.hpp:40)
==3441134== by 0x302B1D: rc::Shrinkable<std::pair<rc::detail::TaggedResult, rc::gen::detail::Recipe> >::ShrinkableImpl<rc::shrinkable::detail::JustShrinkShrinkable<rc::gen::detail::shrinkableWithRecipe<rc::detail::PropertyAdapter<void (*)(nix::DerivedPathOpaque const&), void (nix::DerivedPathOpaque const&)> >(rc::detail::PropertyAdapter<void (*)(nix::DerivedPathOpaque const&), void (nix::DerivedPathOpaque const&)>, rc::gen::detail::Recipe)::{lambda()#1}, rc::gen::detail::shrinkableWithRecipe<rc::detail::PropertyAdapter<void (*)(nix::DerivedPathOpaque const&), void (nix::DerivedPathOpaque const&)> >(rc::detail::PropertyAdapter<void (*)(nix::DerivedPathOpaque const&), void (nix::DerivedPathOpaque const&)>, rc::gen::detail::Recipe)::{lambda(std::pair<rc::detail::TaggedResult, rc::gen::detail::Recipe>&&)#1}> >::value() const (Shrinkable.hpp:26)
==3441134==
==3441134== Invalid free() / delete / delete[] / realloc()
==3441134== at 0x48471A4: operator delete(void*) (vg_replace_malloc.c:1051)
==3441134== by 0x575D5A0: __cxa_finalize (cxa_finalize.c:82)
==3441134== by 0x4A33127: ??? (in /home/intelfx/devel/ext/nix/tests/unit/libstore-support/libnixstore-test-support.so)
==3441134== by 0x40010E1: _dl_call_fini (dl-call_fini.c:43)
==3441134== by 0x4004FFD: _dl_fini (dl-fini.c:114)
==3441134== by 0x575DB35: __run_exit_handlers (exit.c:108)
==3441134== by 0x575DC7F: exit (exit.c:138)
==3441134== by 0x5744CD6: (below main) (libc_start_call_main.h:74)
==3441134== Address 0x7944740 is 0 bytes inside a block of size 24 free'd
==3441134== at 0x48471A4: operator delete(void*) (vg_replace_malloc.c:1051)
==3441134== by 0x575DB35: __run_exit_handlers (exit.c:108)
==3441134== by 0x575DC7F: exit (exit.c:138)
==3441134== by 0x5744CD6: (below main) (libc_start_call_main.h:74)
==3441134== Block was alloc'd at
==3441134== at 0x4843F73: operator new(unsigned long) (vg_replace_malloc.c:483)
==3441134== by 0x407617: void std::vector<std::vector<void (*)(), std::allocator<void (*)()> >, std::allocator<std::vector<void (*)(), std::allocator<void (*)()> > > >::_M_realloc_insert<>(__gnu_cxx::__normal_iterator<std::vector<void (*)(), std::allocator<void (*)()> >*, std::vector<std::vector<void (*)(), std::allocator<void (*)()> >, std::allocator<std::vector<void (*)(), std::allocator<void (*)()> > > > >) (in /home/intelfx/devel/ext/nix/tests/unit/libexpr/libnixexpr-tests)
==3441134== by 0x41E2C3: rc::gen::detail::ExecHandler::onGenerate(rc::Gen<rc::detail::Any> const&) (in /home/intelfx/devel/ext/nix/tests/unit/libexpr/libnixexpr-tests)
==3441134== by 0x4972B6A: rc::Gen<nix::StorePath>::operator*() const (Gen.hpp:85)
==3441134== by 0x4A33200: rc::Arbitrary<nix::DerivedPathOpaque, void>::arbitrary() (derived-path.cc:12)
==3441134== by 0x2FF32B: decltype (rc::Arbitrary<nix::DerivedPathOpaque, void>::arbitrary()) rc::gen::arbitrary<nix::DerivedPathOpaque>() (Arbitrary.hpp:14)
==3441134== by 0x3014E0: rc::gen::detail::DefaultArbitrary<std::tuple<nix::DerivedPathOpaque> >::arbitrary() (Tuple.hpp:123)
==3441134== by 0x3015B5: arbitrary (Arbitrary.hpp:23)
==3441134== by 0x3015B5: decltype (rc::Arbitrary<std::tuple<nix::DerivedPathOpaque>, void>::arbitrary()) rc::gen::arbitrary<std::tuple<nix::DerivedPathOpaque> >() (Arbitrary.hpp:14)
==3441134== by 0x302844: rc::detail::FunctionTraits<std::decay<rc::detail::PropertyAdapter<void (*)(nix::DerivedPathOpaque const&), void (nix::DerivedPathOpaque const&)> >::type>::ReturnType rc::gen::detail::execWithArguments<rc::detail::PropertyAdapter<void (*)(nix::DerivedPathOpaque const&), void (nix::DerivedPathOpaque const&)>, nix::DerivedPathOpaque const&>(rc::detail::PropertyAdapter<void (*)(nix::DerivedPathOpaque const&), void (nix::DerivedPathOpaque const&)> const&, rc::detail::TypeList<nix::DerivedPathOpaque const&>) (ExecRaw.hpp:21)
==3441134== by 0x302940: std::pair<rc::detail::FunctionTraitsImpl<std::decay<rc::detail::PropertyAdapter<void (*)(nix::DerivedPathOpaque const&), void (nix::DerivedPathOpaque const&)> >::type>::ReturnType, rc::gen::detail::Recipe> rc::gen::detail::execWithRecipe<rc::detail::PropertyAdapter<void (*)(nix::DerivedPathOpaque const&), void (nix::DerivedPathOpaque const&)> >(rc::detail::PropertyAdapter<void (*)(nix::DerivedPathOpaque const&), void (nix::DerivedPathOpaque const&)>, rc::gen::detail::Recipe) (ExecRaw.hpp:33)
==3441134== by 0x302A90: rc::gen::detail::shrinkableWithRecipe<rc::detail::PropertyAdapter<void (*)(nix::DerivedPathOpaque const&), void (nix::DerivedPathOpaque const&)> >(rc::detail::PropertyAdapter<void (*)(nix::DerivedPathOpaque const&), void (nix::DerivedPathOpaque const&)>, rc::gen::detail::Recipe)::{lambda()#1}::operator()() const (ExecRaw.hpp:49)
==3441134== by 0x302B1D: value (Create.hpp:40)
==3441134== by 0x302B1D: rc::Shrinkable<std::pair<rc::detail::TaggedResult, rc::gen::detail::Recipe> >::ShrinkableImpl<rc::shrinkable::detail::JustShrinkShrinkable<rc::gen::detail::shrinkableWithRecipe<rc::detail::PropertyAdapter<void (*)(nix::DerivedPathOpaque const&), void (nix::DerivedPathOpaque const&)> >(rc::detail::PropertyAdapter<void (*)(nix::DerivedPathOpaque const&), void (nix::DerivedPathOpaque const&)>, rc::gen::detail::Recipe)::{lambda()#1}, rc::gen::detail::shrinkableWithRecipe<rc::detail::PropertyAdapter<void (*)(nix::DerivedPathOpaque const&), void (nix::DerivedPathOpaque const&)> >(rc::detail::PropertyAdapter<void (*)(nix::DerivedPathOpaque const&), void (nix::DerivedPathOpaque const&)>, rc::gen::detail::Recipe)::{lambda(std::pair<rc::detail::TaggedResult, rc::gen::detail::Recipe>&&)#1}> >::value() const (Shrinkable.hpp:26)
Priorities
Add 👍 to issues you find important.
Reacted by Sören Tempel
Activity
Ericson2314 commentedon Feb 27, 2024
@intelfx I am a bit confused, because I don't think
2.10.xhadlibnixstore-test-support.so?intelfx commentedon Feb 27, 2024
@Ericson2314 My apologies, that was a typo and the actual version is 2.20.3.
intelfx commentedon Feb 27, 2024
I have added a valgrind memcheck report. It seems as if two
*-test-support.soDSOs run finalizers that attempt to free the same block of memory.intelfx commentedon Feb 27, 2024
This crash goes away if rapidcheck is built as a shared library.
I do not precisely understand the cause as I'm not familiar with either nix or rapidcheck codebase, but I'm assuming this happens because rapidcheck makes use of static objects in templated functions — so what happens is probably a variation of the diamond problem, where each DSO that links in librapidcheck brings its own atexit handler for some static object in a function that's instantiated in both DSOs, but only one instance of the static/global is actually created at runtime because that function gets bound to one specific DSO.
Or maybe the above analysis is wildly incorrect, I do not know :-)
intelfx commentedon Feb 27, 2024
@alerque @grawlinson FYI — backporting ec5cc10 and rebuilding our
rapidcheckas a shared library (CMake built-in variable-DBUILD_SHARED_LIBS=ON) is enough to make nix 2.10.3 build and test.alerque commentedon Feb 27, 2024
@intelfx Thanks for the experiments, you're correct that combination worked. I don't understand why sometimes rapidcheck needs to be shared, sometimes not. We've needed it both ways for various versions. In any case 2.10.3 is in [extra-testing] now if you want to check it out. Also for future reference Arch packaging GitLab has MRs open now. Wink wink.
Ericson2314 commentedon Feb 27, 2024
Yes, that was my next guess. I did NixOS/nixpkgs@b2b9257 to ensure it was build shared.
That sounds right. I think building everything shared or everything static both work, but mixing shared (nix test libs) and static (rapidcheck libs) does not work.
intelfx commentedon Feb 28, 2024
@alerque Works (and builds) here.
Anyway, this turned out to be a packaging bug, so I'm closing it. #8737 probably should be closed once the backport is in a released version. Thanks!
alerque commentedon Mar 4, 2024
I was a bit surprised to find that ec5cc10 did not land in v2.20.4. Was that intentional?