ninja-build / ninja

a small build system with a focus on speed
https://ninja-build.org/
Apache License 2.0
11.33k stars 1.61k forks source link

Segfault when compiling a project #1978

Open Marenz opened 3 years ago

Marenz commented 3 years ago

Version: Ninja 1.10.0 - 1.10.2

This project on this branch crashes ninja, causing a segfault: https://github.com/ethereum/solidity/tree/ninja-crashes-here

But it seems only to be a certain cmake generated build directory that causes it, trying to reproduce it with a fresh build directory does not result in the issue. Non-the-less, I have a core dump for you: http://mare.nz/ninja.core

This core dump is from a binary built from c573f6b8b23593f46a08616b76325d3ce0175002. The built binary with debug symbols is also available here: http://mare.nz/ninja.bin

Marenz commented 3 years ago

I suppose I can also share a zip of that build directory if there is interest, but I think the absolute location & name of the build dir is important otherwise it will complain when trying to compile.

Marenz commented 3 years ago
Program received signal SIGSEGV, Segmentation fault.
0x00005555555873cd in DepsLog::Load (this=0x7fffffffe040, path=".ninja_deps", state=0x7fffffffdea8, err=0x7fffffffdd20)
    at /home/marenz/Projects/ninja/src/deps_log.cc:218
218         assert(nodes_[deps_data[i]]);
(gdb) bt
#0  0x00005555555873cd in DepsLog::Load (this=0x7fffffffe040, path=".ninja_deps", state=0x7fffffffdea8, err=0x7fffffffdd20)
    at /home/marenz/Projects/ninja/src/deps_log.cc:218
#1  0x000055555555f999 in (anonymous namespace)::NinjaMain::OpenDepsLog (this=0x7fffffffde90, recompact_only=false)
    at /home/marenz/Projects/ninja/src/ninja.cc:1186
#2  0x0000555555560d56 in (anonymous namespace)::real_main (argc=0, argv=0x7fffffffe1e8)
    at /home/marenz/Projects/ninja/src/ninja.cc:1461
#3  0x000055555556104c in main (argc=2, argv=0x7fffffffe1d8) at /home/marenz/Projects/ninja/src/ninja.cc:1509
e-kwsm commented 2 years ago

Today I encounter a similar issue in a different CMake project (ninja 1.10.1/Debian 11.2), i.e. ninja, ninja -t cleanded and ninja -t recompat fail with segmentation fault. The problem is fixed by removing .ninja_deps and .ninja_log, so I guess the former is the cause (malformed?) as shown in @Marenz's backtrace.

jonesmz commented 2 years ago

Are these crashes still happening in the latest release of ninja?if so, please provide a stacktrace if you can.

jcelerier commented 2 years ago

I' m still seeing this on a mac with ninja 1.11.1 (both from brew and official release from here), here's a stack trace; I attached the ninja files :

bug-ninja.tar.gz

* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x40)
    frame #0: 0x00000001000190e4 ninja`Node::AddOutEdge(Edge*) + 20
ninja`Node::AddOutEdge:
->  0x1000190e4 <+20>: movq   0x40(%rdi), %r14
    0x1000190e8 <+24>: cmpq   0x48(%rdi), %r14
    0x1000190ec <+28>: je     0x100019108               ; <+56>
    0x1000190ee <+30>: movq   %rsi, (%r14)
Target 0: (ninja) stopped.
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x40)
  * frame #0: 0x00000001000190e4 ninja`Node::AddOutEdge(Edge*) + 20
    frame #1: 0x0000000100022b88 ninja`ImplicitDepLoader::LoadDeps(Edge*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) + 1240
    frame #2: 0x0000000100021e22 ninja`DependencyScan::RecomputeNodeDirty(Node*, std::__1::vector<Node*, std::__1::allocator<Node*> >*, std::__1::vector<Node*, std::__1::allocator<Node*> >*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) + 850
    frame #3: 0x0000000100021eae ninja`DependencyScan::RecomputeNodeDirty(Node*, std::__1::vector<Node*, std::__1::allocator<Node*> >*, std::__1::vector<Node*, std::__1::allocator<Node*> >*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) + 990
    frame #4: 0x0000000100021eae ninja`DependencyScan::RecomputeNodeDirty(Node*, std::__1::vector<Node*, std::__1::allocator<Node*> >*, std::__1::vector<Node*, std::__1::allocator<Node*> >*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) + 990
    frame #5: 0x0000000100021eae ninja`DependencyScan::RecomputeNodeDirty(Node*, std::__1::vector<Node*, std::__1::allocator<Node*> >*, std::__1::vector<Node*, std::__1::allocator<Node*> >*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) + 990
    frame #6: 0x0000000100021eae ninja`DependencyScan::RecomputeNodeDirty(Node*, std::__1::vector<Node*, std::__1::allocator<Node*> >*, std::__1::vector<Node*, std::__1::allocator<Node*> >*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) + 990
    frame #7: 0x000000010001fe82 ninja`DependencyScan::RecomputeDirty(Node*, std::__1::vector<Node*, std::__1::allocator<Node*> >*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) + 882
    frame #8: 0x0000000100012c6a ninja`Builder::AddTarget(Node*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) + 58
    frame #9: 0x0000000100006cdc ninja`(anonymous namespace)::real_main(int, char**) + 6892
    frame #10: 0x00000001000051e9 ninja`main + 9
    frame #11: 0x000000010006152e dyld`start + 462
jcelerier commented 2 years ago

Rebuilding in debug yields:



Assertion failed: (deps_data[i] < (int)nodes_.size()), function Load, file deps_log.cc, line 217.
Process 19587 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = hit program assert
    frame #4: 0x000000010004f936 ninja`DepsLog::Load(this=0x00007ff7bfeff468, path=".ninja_deps", state=0x00007ff7bfeff348, err="") at deps_log.cc:217:9
   214
   215         Deps* deps = new Deps(mtime, deps_count);
   216         for (int i = 0; i < deps_count; ++i) {
-> 217           assert(deps_data[i] < (int)nodes_.size());
   218           assert(nodes_[deps_data[i]]);
   219           deps->nodes[i] = nodes_[deps_data[i]];
   220         }
Target 0: (ninja) stopped.
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = hit program assert
    frame #0: 0x00007ff80879000e libsystem_kernel.dylib`__pthread_kill + 10
    frame #1: 0x00007ff8087c61ff libsystem_pthread.dylib`pthread_kill + 263
    frame #2: 0x00007ff808711d24 libsystem_c.dylib`abort + 123
    frame #3: 0x00007ff8087110cb libsystem_c.dylib`__assert_rtn + 314
  * frame #4: 0x000000010004f936 ninja`DepsLog::Load(this=0x00007ff7bfeff468, path=".ninja_deps", state=0x00007ff7bfeff348, err="") at deps_log.cc:217:9
    frame #5: 0x000000010000536d ninja`(anonymous namespace)::NinjaMain::OpenDepsLog(this=0x00007ff7bfeff330, recompact_only=false) at ninja.cc:1278:39
    frame #6: 0x000000010000413b ninja`(anonymous namespace)::real_main(argc=0, argv=0x00007ff7bfeff848) at ninja.cc:1572:41
    frame #7: 0x0000000100003c02 ninja`main(argc=1, argv=0x00007ff7bfeff840) at ninja.cc:1620:3
    frame #8: 0x000000010032d52e dyld`start + 462

``` 
jcelerier commented 2 years ago

had this again suddenly - it seems that sometimes .ninja_deps gets corrupted, in a very random way: I was editing a .cpp file in my codebase. One edit it was building, the next one it didn't. Attached the buggy one (removing it allows to build)

bug.tar.gz

when I print ninja -t deps it segfaults after this:

/home/jcelerier/score/3rdparty/avendish/include/avnd/introspection/widgets.hpp

[1] 53988 segmentation fault (core dumped) ninja -t deps

gdb:

Program received signal SIGSEGV, Segmentation fault.
0x0000555555561b8b in (anonymous namespace)::NinjaMain::ToolDeps (this=0x7fffffffdb20, options=<optimized out>, argc=<optimized out>, argv=<optimized out>) at /home/jcelerier/projets/oss/ninja/src/ninja.cc:563
563       printf("    %s\n", deps->nodes[i]->path().c_str());
(gdb) bt
#0  0x0000555555561b8b in (anonymous namespace)::NinjaMain::ToolDeps (this=0x7fffffffdb20, 
    options=<optimized out>, argc=<optimized out>, argv=<optimized out>)
    at /home/jcelerier/projets/oss/ninja/src/ninja.cc:563
#1  0x0000555555564182 in (anonymous namespace)::real_main (argc=<optimized out>, argv=<optimized out>)
    at /home/jcelerier/projets/oss/ninja/src/ninja.cc:1576
#2  0x000055555555b8f9 in main (argc=<optimized out>, argv=<optimized out>)
    at /home/jcelerier/projets/oss/ninja/src/ninja.cc:1620