Skip to content

Project compiled with GCC gets crash on parse errors since adding "-working-directory" argument in project.cc #457

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
thedracle opened this issue Aug 6, 2019 · 5 comments

Comments

@thedracle
Copy link

thedracle commented Aug 6, 2019

Observed behavior

"-working-directory" argument added in src/project.cc causes GCC based projects to get 'crash' errors when parsing, because it is not a valid option in gcc.

  • compile_commands.json or .ccls ([wiki/Project-Setup]
    {
    "directory": "/home/user/git-projects/event_collector",
    "arguments": [
    "/usr/bin/c++",
    "-Werror",
    "-std=c++14",
    "-g",
    "-D",
    "LINUX",
    "-Werror",
    "-std=c++14",
    "-g",
    "-I/usr/lib/llvm-6.0/include/../tools/clang/include",
    "-I./bcc/include/api/",
    "-I./bcc/include/",
    "-I./bcc/libbpf/include/uapi/",
    "-fvisibility=hidden",
    "-fvisibility-inlines-hidden",
    "-I/home/jthomas/.conan/data/boost/1.65.1/conan/stable/package/f13b8707a96902c3870d1d62327acbc46ec72985/include",
    "-I/home/jthomas/.conan/data/OpenSSL/1.0.2q/conan/stable/package/b781af3f476d0aa5070a0a35b544db7a3c193cc8/include",
    "-I/home/jthomas/.conan/data/bzip2/1.0.6/conan/stable/package/b27e2b40bcb70be2e7d6f0e0c6e43e35c530f8d3/include",
    "-I/home/jthomas/.conan/data/zlib/1.2.11/conan/stable/package/d50a0d523d98c15bb147b18fa7d203887c38be8b/include",
    "-DBOOST_USE_STATIC_LIBS",
    "-c",
    "-o",
    "src/event_collector.o",
    "src/event_collector.cpp"
    ],
    "file": "src/event_collector.cpp"
    }

Expected behavior

Previous versions of CCLS worked fine, and if I rebuild ccls removing the -working-directory args, everything works.

System information

  • gcc version
    gcc version 7.4.0 (Ubuntu 7.4.0-1ubuntu1~18.04.1)

  • ccls version:
    ccls version 0.20190314.1-21-g8b033217
    clang version 7.0.0-3~ubuntu0.18.04.1 (tags/RELEASE_700/final)

  • clang version:
    clang version 7.0.0-3~ubuntu0.18.04.1 (tags/RELEASE_700/final)

  • OS:
    Ubuntu 18.04

  • Editor:
    NeoVim
    (But reproduces just running "ccls -index=. -v=2")

  • Language client (and version):
    (Coc.vim) 0.0.73

@MaskRay
Copy link
Owner

MaskRay commented Aug 7, 2019

"-working-directory" argument added in src/project.cc causes GCC based projects to get 'crash' errors when parsing, because it is not a valid option in gcc.

I do not find -working-directory in your compile_commands.json. gcc does not recognize this option but it will not crash:

% gcc -working-directory /tmp -c a.c   
gcc: error: unrecognized command line option ‘-working-directory’; did you mean ‘-fworking-directory’?

Please check https://github.com/MaskRay/ccls/wiki/Debugging#logs

"-I/usr/lib/llvm-6.0/include/../tools/clang/include",

  • ccls dropped clang 6 support in Jan 21, 2019.
  • Generally you should not use: -IRESOURCE_DIR/include. It can shuffle search directory order (#include <...> search starts here: in clang -fsyntax-only -v -xc /dev/null output)

@thedracle
Copy link
Author

Hi MaskRay,

It is injected by src/project.cc:

ret.args.push_back(Intern("-working-directory=" + ret.directory));

args.push_back(Intern("-working-directory=" + entry.directory));

args.push_back(Intern("-working-directory=" + entry.directory));

By 'crash', I mean the log states when parsing those files 'clang crash'. I'm not sure where this error comes from exactly, but commenting out all of the lines in project.cc referring to -working-directory makes everything work correctly.

@MaskRay
Copy link
Owner

MaskRay commented Aug 7, 2019

clang crash

This mere information doesn't help identifying the problem. gdb --args ccls -index=. -v=2 and dump the stack.

Also, check #71

Use https://releases.llvm.org/download.html archive if that doesn't fix the issue.

@MaskRay MaskRay closed this as completed Aug 7, 2019
@thedracle
Copy link
Author

thedracle commented Aug 8, 2019

Here is an example crash, if you're interested. In this case of a simple C linux kernel module.
Maybe taking out the working directory stuff is just preventing clang from digging into some headers that are causing the underlying issue?

gcc -fno-pie -Wp,-MD,/home/user/git-projects/audit_hook/.fidelis.mod.o.d -nostdinc -isystem /usr/lib/gcc/x86_64-linux-gnu/7/include -I./arch/x86/include -I./arch/x86/include/generated -I./include -I./arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/kconfig.h -Iubuntu/include -D__KERNEL__ -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -fshort-wchar -Werror-implicit-function-declaration -Wno-format-security -std=gnu89 -fno-PIE -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -m64 -falign-jumps=1 -falign-loops=1 -mno-80387 -mno-fp-ret-in-387 -mpreferred-stack-boundary=3 -mskip-rax-setup -mtune=generic -mno-red-zone -mcmodel=kernel -funit-at-a-time -DCONFIG_X86_X32_ABI -DCONFIG_AS_CFI=1 -DCONFIG_AS_CFI_SIGNAL_FRAME=1 -DCONFIG_AS_CFI_SECTIONS=1 -DCONFIG_AS_FXSAVEQ=1 -DCONFIG_AS_SSSE3=1 -DCONFIG_AS_CRC32=1 -DCONFIG_AS_AVX=1 -DCONFIG_AS_AVX2=1 -DCONFIG_AS_AVX512=1 -DCONFIG_AS_SHA1_NI=1 -DCONFIG_AS_SHA256_NI=1 -pipe -Wno-sign-compare -fno-asynchronous-unwind-tables -mindirect-branch=thunk-extern -mindirect-branch-register -fno-delete-null-pointer-checks -Wno-frame-address -Wno-format-truncation -Wno-format-overflow -Wno-int-in-bool-context -O2 --param=allow-store-data-races=0 -DCC_HAVE_ASM_GOTO -Wframe-larger-than=1024 -fstack-protector-strong -Wno-unused-but-set-variable -Wno-unused-const-variable -fno-omit-frame-pointer -fno-optimize-sibling-calls -fno-var-tracking-assignments -pg -mfentry -DCC_USING_FENTRY -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-overflow -fno-merge-all-constants -fmerge-constants -fno-stack-check -fconserve-stack -Werror=implicit-int -Werror=strict-prototypes -Werror=date-time -Werror=incompatible-pointer-types -Werror=designated-init -std=gnu11 -Wdeclaration-after-statement -I/usr/include/linux/ -DKBUILD_BASENAME=fidelis.mod -DKBUILD_MODNAME=fidelis -DMODULE -c -o /home/user/git-projects/audit_hook/fidelis.mod.o /home/user/git-projects/audit_hook/fidelis.mod.c -working-directory=/usr/src/linux-headers-4.15.0-51-generic

Thread 7 "indexer2" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffefb16700 (LWP 74929)]
0x00005555564ac128 in clang::HeaderSearch::LookupFile(llvm::StringRef, clang::SourceLocation, bool, clang::DirectoryLookup const*, clang::DirectoryLookup const*&, llvm::ArrayRef<std::pair<clang::FileEntry const*, clang::DirectoryEntry const*> >, llvm::SmallVectorImpl, llvm::SmallVectorImpl, clang::Module*, clang::ModuleMap::KnownHeader*, bool*, bool, bool) ()
(gdb) where
#0 0x00005555564ac128 in clang::HeaderSearch::LookupFile(llvm::StringRef, clang::SourceLocation, bool, clang::DirectoryLookup const*, clang::DirectoryLookup const*&, llvm::ArrayRef<std::pair<clang::FileEntry const*, clang::DirectoryEntry const*> >, llvm::SmallVectorImpl, llvm::SmallVectorImpl, clang::Module*, clang::ModuleMap::KnownHeader*, bool*, bool, bool) ()
#1 0x00005555564e2d3a in clang::Preprocessor::LookupFile(clang::SourceLocation, llvm::StringRef, bool, clang::DirectoryLookup const*, clang::FileEntry const*, clang::DirectoryLookup const*&, llvm::SmallVectorImpl, llvm::SmallVectorImpl, clang::ModuleMap::KnownHeader*, bool*, bool) ()
#2 0x00005555564e8dc3 in clang::Preprocessor::HandleIncludeDirective(clang::SourceLocation, clang::Token&, clang::DirectoryLookup const*, clang::FileEntry const*, bool) ()
#3 0x00005555564f1fea in clang::Preprocessor::HandleDirective(clang::Token&) ()
#4 0x00005555564b59cd in clang::Lexer::LexTokenInternal(clang::Token&, bool) ()
#5 0x000055555652db5f in clang::Preprocessor::Lex(clang::Token&) ()
#6 0x0000555555ac1d2a in clang::ParseAST(clang::Sema&, bool, bool) ()
#7 0x0000555555a26fb6 in clang::FrontendAction::Execute() ()
#8 0x00005555557591f9 in ccls::idx::<lambda()>::operator()(void) const (__closure=0x7fffefb15030) at /home/user/git-projects/ccls/src/indexer.cc:1300
#9 0x000055555575d1d9 in llvm::function_ref<void()>::callback_fn<ccls::idx::Index(ccls::SemaManager*, ccls::WorkingFiles*, ccls::VFS*, const string&, const string&, const std::vector<char const*>&, const std::vector<std::pair<std::__cxx11::basic_string, std::_cxx11::basic_string > >&, bool, bool&)::<lambda()> >(intptr_t) (callable=140737214763056) at /usr/include/llvm-7/llvm/ADT/STLExtras.h:115
#10 0x00007ffff4782c83 in llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) () from /usr/lib/llvm-7/lib/libLLVM-7.so.1
#11 0x0000555555759a17 in ccls::idx::Index (manager=0x7fffffffd7e0, wfiles=0x7fffffffd650, vfs=0x7fffffffd6b0, opt_wdir="/usr/src/linux-headers-4.15.0-51-generic", main="/home/user/git-projects/audit_hook/src/kernmon.c",
args=std::vector of length 102, capacity 202 = {...}, remapped=std::vector of length 0, capacity 0, no_linkage=false, ok=@0x7fffefb15440: false) at /home/user/git-projects/ccls/src/indexer.cc:1306
#12 0x00005555557bbe9c in ccls::pipeline::(anonymous namespace)::Indexer_Parse (completion=0x7fffffffd7e0, wfiles=0x7fffffffd650, project=0x7fffffffd5f0, vfs=0x7fffffffd6b0, matcher=...) at /home/user/git-projects/ccls/src/pipeline.cc:367
#13 0x00005555557bd1b6 in ccls::pipeline::Indexer_Main (manager=0x7fffffffd7e0, vfs=0x7fffffffd6b0, project=0x7fffffffd5f0, wfiles=0x7fffffffd650) at /home/user/git-projects/ccls/src/pipeline.cc:478
#14 0x00005555558c9400 in ccls::(anonymous namespace)::Indexer (arg
=0x555556eb74e0) at /home/user/git-projects/ccls/src/messages/initialize.cc:264
#15 0x00007ffff37446db in start_thread (arg=0x7fffefb16700) at pthread_create.c:463
#16 0x00007ffff346d88f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

@MaskRay
Copy link
Owner

MaskRay commented Aug 13, 2019

This just looks like a clang 7 bug that was probably fixed in clang 8 or the upcoming clang 9. You can try https://releases.llvm.org/download.html archives. Don't get stuck on whatever old clang libraries your distribution provides.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants