llvm / llvm/llvm-project

clang-tidy crash running dynamically loaded check (ClazyClangTidy.so)

Open
#187,284 2 comments 0 reactions 0 assignees View on GitHub
clang-tidy crash
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

clang-tidy is crashing after running checks in a dynamically loaded check. clang-tidy is run with `-load=/path/to/clazy/lib/ClazyClangTidy.so`

The crash happens regardless of the type of clazy check done.
The standalone clazy runs fine.
This happens with the latest build of llvm and clazy (today, from master branch), but also happens with earlier builds.

This is the output of clang-tidy
```
/usr/local/llvm-test/bin/clang-tidy core_compressor.cpp @build_x86_64_debug_tidy/core_compressor.tidy.args
1345 warnings generated.
[...]
Suppressed 1477 warnings (1342 in non-user code, 135 NOLINT).
Use -header-filter=.* or leave it as default to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
3 warnings treated as errors
free(): invalid pointer
pure virtual method called
terminate called without an active exception
```

(Note the invalid free. In different builds of llvm I think I may have see a double free, but not 100% sure)

This is the backtrace (I've built a RelWithDebInfo version of llvm):
```
(gdb) bt
#0 __pthread_kill_implementation (no_tid=0, signo=6, threadid=) at ./nptl/pthread_kill.c:44
#1 __pthread_kill_internal (signo=6, threadid=) at ./nptl/pthread_kill.c:78
#2 __GI___pthread_kill (threadid=, signo=signo@entry=6) at ./nptl/pthread_kill.c:89
#3 0x00007d4dabe4527e in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#4 0x00007d4dabe288ff in __GI_abort () at ./stdlib/abort.c:79
#5 0x00007d4dac2a5ff5 in ?? () from /lib/x86_64-linux-gnu/libstdc++.so.6
#6 0x00007d4dac2bb0da in ?? () from /lib/x86_64-linux-gnu/libstdc++.so.6
#7 0x00007d4dac2a5a55 in std::terminate() () from /lib/x86_64-linux-gnu/libstdc++.so.6
#8 0x00007d4dac2bbfc3 in __cxa_pure_virtual () from /lib/x86_64-linux-gnu/libstdc++.so.6
#9 0x0000563847e42ef8 in llvm::raw_ostream::write (this=this@entry=0x56384ae08dc0 ,
Ptr=Ptr@entry=0x56384801dae8 "PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and instructions to reproduce the bug.\n", Size=Size@entry=146)
at /home/catdev/cathexis/llvm/github/llvm-project/llvm/lib/Support/raw_ostream.cpp:240
#10 0x0000563847dce925 in llvm::raw_ostream::operator<< (Str=..., this=0x56384ae08dc0 ) at /home/catdev/cathexis/llvm/github/llvm-project/llvm/include/llvm/Support/raw_ostream.h:231
#11 llvm::raw_ostream::operator<< (Str=0x56384801dae8 "PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and instructions to reproduce the bug.\n", this=0x56384ae08dc0 )
at /home/catdev/cathexis/llvm/github/llvm-project/llvm/include/llvm/Support/raw_ostream.h:258
#12 CrashHandler () at /home/catdev/cathexis/llvm/github/llvm-project/llvm/lib/Support/PrettyStackTrace.cpp:166
#13 0x0000563847e5f0a4 in llvm::sys::RunSignalHandlers () at /home/catdev/cathexis/llvm/github/llvm-project/llvm/lib/Support/Signals.cpp:107
#14 0x0000563847e5f9d1 in SignalHandler (Sig=, Info=0x56384f3c0770, Context=) at /home/catdev/cathexis/llvm/github/llvm-project/llvm/lib/Support/Unix/Signals.inc:431
#15
#16 __pthread_kill_implementation (no_tid=0, signo=6, threadid=) at ./nptl/pthread_kill.c:44
#17 __pthread_kill_internal (signo=6, threadid=) at ./nptl/pthread_kill.c:78
#18 __GI___pthread_kill (threadid=, signo=signo@entry=6) at ./nptl/pthread_kill.c:89
#19 0x00007d4dabe4527e in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#20 0x00007d4dabe288ff in __GI_abort () at ./stdlib/abort.c:79
#21 0x00007d4dabe297b6 in __libc_message_impl (fmt=fmt@entry=0x7d4dabfce8d7 "%s\n") at ../sysdeps/posix/libc_fatal.c:134
#22 0x00007d4dabea8ff5 in malloc_printerr (str=str@entry=0x7d4dabfcc672 "free(): invalid pointer") at ./malloc/malloc.c:5775
#23 0x00007d4dabeab38c in _int_free (av=, p=, have_lock=0) at ./malloc/malloc.c:4507
#24 0x00007d4dabeaddce in __GI___libc_free (mem=0x56384f3c57c0) at ./malloc/malloc.c:3398
#25 0x00005638447996e7 in llvm::MallocAllocator::Deallocate (Alignment=8, Size=, Ptr=, this=0x56384add4610 )
at /home/catdev/cathexis/llvm/github/llvm-project/llvm/include/llvm/Support/AllocatorBase.h:100
#26 llvm::StringMapEntry::Destroy (allocator=..., this=) at /home/catdev/cathexis/llvm/github/llvm-project/llvm/include/llvm/ADT/StringMapEntry.h:146
#27 llvm::StringMap::~StringMap (this=0x56384add4610 , __in_chrg=)
at /home/catdev/cathexis/llvm/github/llvm-project/llvm/include/llvm/ADT/StringMap.h:207
#28 llvm::StringSet::~StringSet (this=0x56384add4610 , __in_chrg=) at /home/catdev/cathexis/llvm/github/llvm-project/llvm/include/llvm/ADT/StringSet.h:25
#29 0x00007d4dabe47a76 in __run_exit_handlers (status=1, listp=, run_list_atexit=run_list_atexit@entry=true, run_dtors=run_dtors@entry=true) at ./stdlib/exit.c:108
#30 0x00007d4dabe47bbe in __GI_exit (status=) at ./stdlib/exit.c:138
#31 0x00007d4dabe2a1d1 in __libc_start_call_main (main=main@entry=0x563844341380 , argc=argc@entry=3, argv=argv@entry=0x7ffe1d30eaa8) at ../sysdeps/nptl/libc_start_call_main.h:74
#32 0x00007d4dabe2a28b in __libc_start_main_impl (main=0x563844341380 , argc=3, argv=0x7ffe1d30eaa8, init=, fini=, rtld_fini=, stack_end=0x7ffe1d30ea98) at ../csu/libc-start.c:360
#33 0x00005638443aba85 in _start ()
```

Contributor guide

Open the contributing guide

Research direction

Reproduce clang-tidy with -load=/path/to/clazy/lib/ClazyClangTidy.so and the reported core_compressor.cpp arguments, then inspect the shutdown path shown in llvm/lib/Support/raw_ostream.cpp, PrettyStackTrace.cpp, and Signals.cpp. Done means the dynamically loaded check completes without the invalid free, pure virtual call, or termination shown in the report.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.