codebrowser icon indicating copy to clipboard operation
codebrowser copied to clipboard

woboq codebrowser_generator segfaultsin llvm::sys::fs::detail::directory_iterator_construct(llvm::sys::fs::detail::DirIterState&, llvm::StringRef, bool)

Open dm8tbr opened this issue 5 years ago • 3 comments

Wanted to give this a spin and run it on the http://icecast.org codebase. Tried it both with clang 5.0.2 and 6.0.1 (Debian testing). json generated by help of scripts/fake_compiler.sh

Starting program: /home/tbr/src/woboq_codebrowser/build/generator/codebrowser_generator -b /home/tbr/src/icecast -a -o /home/src/icecast/foo -p codebrowser:/home/tbr/src/icecast:v2.4.3-23-g4e13c27
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Skipping file not included by any project /dev/null
Skipping file not included by any project /home/tbr/src/icecast
[5%] Processing /home/tbr/src/icecast/conftest

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff4ce31c2 in llvm::sys::fs::detail::directory_iterator_construct(llvm::sys::fs::detail::DirIterState&, llvm::StringRef, bool) () from /usr/lib/llvm-6.0/lib/libLLVM-6.0.so.1
(gdb) bt
#0  0x00007ffff4ce31c2 in llvm::sys::fs::detail::directory_iterator_construct(llvm::sys::fs::detail::DirIterState&, llvm::StringRef, bool) () from /usr/lib/llvm-6.0/lib/libLLVM-6.0.so.1
#1  0x000055555642d716 in (anonymous namespace)::RealFileSystem::dir_begin(llvm::Twine const&, std::error_code&) ()
#2  0x00005555566b9716 in clang::driver::toolchains::Generic_GCC::GCCInstallationDetector::ScanLibDirForGCCTriple(llvm::Triple const&, llvm::opt::ArgList const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, llvm::StringRef, bool) ()
#3  0x00005555566ba4aa in clang::driver::toolchains::Generic_GCC::GCCInstallationDetector::init(llvm::Triple const&, llvm::opt::ArgList const&, llvm::ArrayRef<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >) ()
#4  0x00005555566c5a20 in clang::driver::toolchains::Linux::Linux(clang::driver::Driver const&, llvm::Triple const&, llvm::opt::ArgList const&) ()
#5  0x000055555663df18 in clang::driver::Driver::getToolChain(llvm::opt::ArgList const&, llvm::Triple const&) const ()
#6  0x000055555664a810 in clang::driver::Driver::BuildCompilation(llvm::ArrayRef<char const*>) ()
#7  0x00005555564ccc65 in clang::tooling::ToolInvocation::run() ()
#8  0x00005555559bb8fe in proceedCommand(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, llvm::StringRef, llvm::StringRef, clang::FileManager*, DatabaseType) ()
#9  0x00005555559bd33b in main ()

Let me know if you need additional information.

dm8tbr avatar Jul 26 '18 10:07 dm8tbr

I suspect the problem is that clang crashes while parsing the compilation database. Can you try running valgrind, this will probably show some more details about what pointer was invalid.

Can you also run clang-tidy with this compilation database, if it crashes too that would confirm my assumption:

clang-tidy -p /home/tbr/src/icecast /home/tbr/src/icecast/conftest

Can you paste what is the compilation database for the file conftest ? I have noticed that sometimes, empty file in the compilation database can cause problem.

You can use this line to remove the empty files and see if it fixes the problem

sed -i '/"file": ""/d' compile_commands.json

This might be caused by a bug in fake_compiler.sh that fails to parse the entry.

ogoffart avatar Jul 26 '18 11:07 ogoffart

@dm8tbr Any news?

guruz avatar Jun 14 '19 13:06 guruz

This had dropped off my radar, sorry. I now updated both icecast and woboq sources to latest master, rebuilt both properly.

It still segfaults right after starting. After I ran @ogoffart's sed one-liner output changed mildly, but it still crashes.

tbr@puck:~/src/woboq_codebrowser$ build/generator/codebrowser_generator -b ~/compile_commands.json  -a -p icecast:/home/tbr/src/icecast -o testfoo
Skipping file not included by any project /dev/null
[2%] Processing /home/tbr/src/icecast/src/acl.c
Segmentation fault

dm8tbr avatar Jun 15 '19 12:06 dm8tbr