Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

llvm::cl::ParseCommandLineOptions casue double free or corruption when in multithread #25734

Open Quuxplusone opened 8 years ago

Quuxplusone commented 8 years ago
Bugzilla Link PR25735
Status NEW
Importance P normal
Reported by Xiuli Pan (xiulipan@outlook.com)
Reported on 2015-12-04 01:53:35 -0800
Last modified on 2018-04-10 15:24:44 -0700
Version 3.7
Hardware PC Linux
CC amit@thoughtspot.com, llvm-bugs@lists.llvm.org
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
We are using clang as a frontend, and we tried to use it in multithread, but
the llvm::cl::ParseCommandLineOptions will cause
double free or corruption (fasttop): 0x00007f36e40041d0 ***

dump core backtrace shows that:
(gdb) bt
#0  0x00007f478493bf79 in __GI_raise (sig=sig@entry=6) at
../nptl/sysdeps/unix/sysv/linux/raise.c:56
#1  0x00007f478493f388 in __GI_abort () at abort.c:89
#2  0x00007f4784f416b5 in __gnu_cxx::__verbose_terminate_handler() ()
   from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#3  0x00007f4784f3f836 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#4  0x00007f4784f3f863 in std::terminate() () from /usr/lib/x86_64-linux-
gnu/libstdc++.so.6
#5  0x00007f4784f4033f in __cxa_pure_virtual () from /usr/lib/x86_64-linux-
gnu/libstdc++.so.6
#6  0x00007f4780ca6885 in llvm::cl::Option::addOccurrence (this=0x7f47829a0c20
<InlineLimit>, pos=1,
    ArgName=..., Value=..., MultiArg=false) at /home/pxl/llvm/lib/Support/CommandLine.cpp:1140
#7  0x00007f4780ca1942 in CommaSeparateAndAddOccurrence (Handler=0x7f47829a0c20
<InlineLimit>, pos=1,
    ArgName=..., Value=..., MultiArg=false) at /home/pxl/llvm/lib/Support/CommandLine.cpp:348
#8  0x00007f4780ca1c1e in ProvideOption (Handler=0x7f47829a0c20 <InlineLimit>,
ArgName=..., Value=...,
    argc=2, argv=0x7f477af6c3b8, i=@0x7f477af6bc98: 1) at /home/pxl/llvm/lib/Support/CommandLine.cpp:389
#9  0x00007f4780ca4f25 in (anonymous
namespace)::CommandLineParser::ParseCommandLineOptions (
    this=0x19d0160, argc=2, argv=0x7f477af6c3b8, Overview=0x0)
    at /home/pxl/llvm/lib/Support/CommandLine.cpp:990
#10 0x00007f4780ca3c18 in llvm::cl::ParseCommandLineOptions (argc=2,
argv=0x7f475c004680, Overview=0x0)
    at /home/pxl/llvm/lib/Support/CommandLine.cpp:813

This bug does not happen in LLVM3.6, it seems the ParseCommandLineOptions was
refined and it is wrapped by a static manager:
[CommandLine.cpp]

00213 static ManagedStatic<CommandLineParser> GlobalParser;

00811 void cl::ParseCommandLineOptions(int argc, const char *const *argv,
00812                                  const char *Overview) {
00813   GlobalParser->ParseCommandLineOptions(argc, argv, Overview);
00814 }

And this static manager make each thread using the same CommandLineParser
object and cause this error.
May be the GlobalParser should be a TLS to make sure it is a thread safe as
other llvm component.
Quuxplusone commented 8 years ago
Is it a bug or it is designed to behave this way. If someone can give a word
please?
The code shows that it is not thread safe at all, but the older version (for
llv3.6 and older) is thread safe. Should they behave the same?
Quuxplusone commented 6 years ago

We use LLVM for JITing our SQL queries. We have been hit by this bug while trying to upgrade LLVM as well. Would greatly appreciate any info on this.