[llvm-dev] help please: how to sort the contents of a "SymbolTableListTraits<GlobalVariable>"?
Abe Skolnik via llvm-dev
llvm-dev at lists.llvm.org
Thu Aug 4 11:27:07 PDT 2016
Dear sir,
Thanks for your reply. I apologize for taking a few days to reply.
> Crashed how?
Please see the below.
> Have you turned on ASan?
Not yet, but thanks for the suggestion. I guess I will try to rebuild my modified Clang+LLVM
with addr. san. and see what happens.
> I recommend attaching a minimal reproduction...
Well, since I`m hacking on LLVM itself, this is not 100% trivial. I will explain.
The first hurdle I had to overcome was the fact that the "GlobalVariable" class had an
explicitly-deleted copy ctor and no move ctor. I dealt with this by writing a copy ctor; I`ll
paste that in below.
A perhaps-important point is that I don`t know _why_ the "GlobalVariable" class had an
explicitly-deleted copy ctor and no move ctor. As an experiment, I moved forward with the
hypothesis that this was simply because neither was needed at the time and the default [i.e.
compiler-inserted] copy ctor would have been wrong. I hope the one _I_ wrote is _right_. ;-)
> I assume you can reproduce this in a unit test?
Well, it doesn`t take a long program-under-compilation to make this fail. As before, I will
paste something in after my sign-off.
Regards,
Abe
----- added near the end of "OptimizeGlobalVars" in "llvm/lib/Transforms/IPO/GlobalOpt.cpp",
amongst many other things I added to that routine -----
struct GV_alignment_comparator {
bool operator()(const GlobalVariable& L, const GlobalVariable& R) {
return L.getAlignment() < R.getAlignment();
}
};
if (unsorted) {
M.getGlobalList().sort( GV_alignment_comparator() );
Changed = true;
}
----- added to "llvm/lib/IR/Globals.cpp" [and commented out the relevant deletion in
"llvm/include/llvm/IR/GlobalVariable.h"] -----
GlobalVariable::GlobalVariable(const GlobalVariable& GV) : GlobalVariable( GV.getValueType(),
GV.isConstant(), GV.getLinkage() ) { // copy ctor
copyAttributesFrom(&GV);
}
main_with_3_globals.c
---------------------
int foo;
char bar;
long baz;
int main(){return foo;}
----- error dump from compiler driver -----
> ../build_003/bin/clang main_with_3_globals.c -O3
Abe was here: max. profitable alignment: 16
Abe was here: found a global value that DOES have a name [“foo”],
with alignment 4,
no named section [double-check: should be empty string: “”],
which is a pointer to a NON-array
and with pointee type getTypeStoreSize -> 4
Abe was here: found a global value that DOES have a name [“bar”],
with alignment 1,
no named section [double-check: should be empty string: “”],
which is a pointer to a NON-array
and with pointee type getTypeStoreSize -> 1
Abe was here: found a global value that DOES have a name [“baz”],
with alignment 8,
no named section [double-check: should be empty string: “”],
which is a pointer to a NON-array
and with pointee type getTypeStoreSize -> 8
===== Abe was here: the globals above are NOT in ascending-alignment order. =====
0 clang-3.9 0x0000000002853ebc llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 60
1 clang-3.9 0x00000000028543a9
2 clang-3.9 0x0000000002852a83 llvm::sys::RunSignalHandlers() + 131
3 clang-3.9 0x00000000028546f4
4 libpthread.so.0 0x00007fc595318330
5 clang-3.9 0x00000000027fbe12 llvm::StringMapImpl::LookupBucketFor(llvm::StringRef) + 466
6 clang-3.9 0x0000000002320fa4
7 clang-3.9 0x0000000002320a10 llvm::ValueSymbolTable::reinsertValue(llvm::Value*) + 112
8 clang-3.9 0x00000000022f0551
llvm::SymbolTableListTraits<llvm::GlobalVariable>::transferNodesFromList(llvm::SymbolTableListTraits<llvm::GlobalVariable>&,
llvm::ilist_iterator<llvm::GlobalVariable>, llvm::ilist_iterator<llvm::GlobalVariable>) + 273
9 clang-3.9 0x00000000023b1fd9
10 clang-3.9 0x00000000023b1c45
11 clang-3.9 0x00000000023a8e40
12 clang-3.9 0x000000000239e77c
13 clang-3.9 0x000000000239d88e
14 clang-3.9 0x00000000023a9f8c
15 clang-3.9 0x00000000022ac02a
16 clang-3.9 0x00000000022abb56 llvm::legacy::PassManagerImpl::run(llvm::Module&) + 342
17 clang-3.9 0x00000000022ac541 llvm::legacy::PassManager::run(llvm::Module&) + 33
18 clang-3.9 0x0000000002adf7c5
19 clang-3.9 0x0000000002adeda6 clang::EmitBackendOutput(clang::DiagnosticsEngine&,
clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&,
llvm::DataLayout const&, llvm::Module*, clang::BackendAction,
std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream> >) + 150
20 clang-3.9 0x00000000035d622f
21 clang-3.9 0x0000000004259504 clang::ParseAST(clang::Sema&, bool, bool) + 820
22 clang-3.9 0x00000000030f011a clang::ASTFrontendAction::ExecuteAction() + 314
23 clang-3.9 0x00000000035d4bf5 clang::CodeGenAction::ExecuteAction() + 2357
24 clang-3.9 0x00000000030efc00 clang::FrontendAction::Execute() + 112
25 clang-3.9 0x0000000003094c81
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 1025
26 clang-3.9 0x0000000003241ba1
clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 1473
27 clang-3.9 0x0000000000c33bc8 cc1_main(llvm::ArrayRef<char const*>, char const*, void*)
+ 920
28 clang-3.9 0x0000000000c27c2a
29 clang-3.9 0x0000000000c26ae2 main + 2642
30 libc.so.6 0x00007fc593e80f45 __libc_start_main + 245
31 clang-3.9 0x0000000000c25f44
Stack dump:
0. Program arguments:
/work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/build_003/bin/clang-3.9
-cc1 -triple x86_64-unknown-linux-gnu -emit-obj -disable-free -main-file-name
main_with_3_globals.c -mrelocation-model static -mthread-model posix -fmath-errno -masm-verbose
-mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64
-momit-leaf-frame-pointer -dwarf-column-info -debugger-tuning=gdb -resource-dir
/work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/build_003/bin/../lib/clang/3.9.0
-internal-isystem /usr/local/include -internal-isystem
/work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/build_003/bin/../lib/clang/3.9.0/include
-internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include
-internal-externc-isystem /usr/include -O3 -fdebug-compilation-dir
/work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/tmp
-ferror-limit 19 -fmessage-length 144 -fobjc-runtime=gcc -fdiagnostics-show-option
-fcolor-diagnostics -vectorize-loops -vectorize-slp -o /tmp/main_with_3_globals-cef92e.o -x c
main_with_3_globals.c
1. <eof> parser at end of file
2. Per-module optimization passes
3. Running pass 'Global Variable Optimizer' on module 'main_with_3_globals.c'.
clang-3.9: error: unable to execute command: Segmentation fault
clang-3.9: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 3.9.0
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir:
/work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/tmp/../build_003/bin
clang-3.9: note: diagnostic msg: PLEASE submit a bug report to http://llvm.org/bugs/ and
include the crash backtrace, preprocessed source, and associated run script.
clang-3.9: note: diagnostic msg:
********************
PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-3.9: note: diagnostic msg: /tmp/main_with_3_globals-841619.c
clang-3.9: note: diagnostic msg: /tmp/main_with_3_globals-841619.sh
clang-3.9: note: diagnostic msg:
********************
GDB backtrace from the "-cc1" part of another run of the same-as-the-preceding compilation attempt
--------------------------------------------------------------------------------------------------
Program received signal SIGSEGV, Segmentation fault.
0x00000000027fbe12 in llvm::StringMapImpl::LookupBucketFor (this=0x82f00e8, Name=...)
at
/work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/lib/Support/StringMap.cpp:102
102 } else if (LLVM_LIKELY(HashTable[BucketNo] == FullHashValue)) {
(gdb) bt
#0 0x00000000027fbe12 in llvm::StringMapImpl::LookupBucketFor (this=0x82f00e8, Name=...)
at
/work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/lib/Support/StringMap.cpp:102
#1 0x0000000002320fa4 in llvm::StringMap<llvm::Value*, llvm::MallocAllocator>::insert
(this=0x82f00e8, KeyValue=0x8312cb0)
at
/work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/include/llvm/ADT/StringMap.h:345
#2 0x0000000002320a10 in llvm::ValueSymbolTable::reinsertValue (this=0x82f00e8, V=0x830cfd8)
at
/work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/lib/IR/ValueSymbolTable.cpp:59
#3 0x00000000022f0551 in
llvm::SymbolTableListTraits<llvm::GlobalVariable>::transferNodesFromList (this=0x7fffffffabd8,
L2=..., first=...,
last=...)
at
/work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/lib/IR/SymbolTableListTraitsImpl.h:102
#4 0x00000000023b1fd9 in llvm::iplist<llvm::GlobalVariable,
llvm::SymbolTableListTraits<llvm::GlobalVariable> >::transfer (
this=0x7fffffffabd8, position=..., L2=..., first=..., last=...)
at
/work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/include/llvm/ADT/ilist.h:532
#5 0x00000000023b1c45 in llvm::iplist<llvm::GlobalVariable,
llvm::SymbolTableListTraits<llvm::GlobalVariable> >::splice (this=0x7fffffffabd8,
where=..., L2=..., first=..., last=...)
at
/work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/include/llvm/ADT/ilist.h:587
#6 0x00000000023a8e40 in llvm::iplist<llvm::GlobalVariable,
llvm::SymbolTableListTraits<llvm::GlobalVariable> >::sort<OptimizeGlobalVars(llvm::Module&,
llvm::TargetLibraryInfo*, llvm::function_ref<llvm::DominatorTree& (llvm::Function&)>,
llvm::SmallSet<llvm::Comdat const*, 8u, std::less<llvm::Comdat const*>
>&)::GV_alignment_comparator>(OptimizeGlobalVars(llvm::Module&, llvm::TargetLibraryInfo*,
llvm::function_ref<llvm::DominatorTree& (llvm::Function&)>, llvm::SmallSet<llvm::Comdat const*,
8u, std::less<llvm::Comdat const*> >&)::GV_alignment_comparator) (
this=0x82b1f98, comp=...)
at
/work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/include/llvm/ADT/ilist.h:632
#7 0x000000000239e77c in OptimizeGlobalVars(llvm::Module&, llvm::TargetLibraryInfo*,
llvm::function_ref<llvm::DominatorTree& (llvm::Function&)>, llvm::SmallSet<llvm::Comdat const*,
8u, std::less<llvm::Comdat const*> >&) (M=..., TLI=0x8293860, LookupDomTree=...,
NotDiscardableComdats=...)
at
/work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/lib/Transforms/IPO/GlobalOpt.cpp:2199
#8 0x000000000239d88e in optimizeGlobalsInModule(llvm::Module&, llvm::DataLayout const&,
llvm::TargetLibraryInfo*, llvm::function_ref<llvm::DominatorTree& (llvm::Function&)>) (M=...,
DL=..., TLI=0x8293860, LookupDomTree=...)
at
/work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/lib/Transforms/IPO/GlobalOpt.cpp:2655
#9 0x00000000023a9f8c in (anonymous namespace)::GlobalOptLegacyPass::runOnModule
(this=0x8294f10, M=...)
at
/work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/lib/Transforms/IPO/GlobalOpt.cpp:2705
#10 0x00000000022ac02a in (anonymous namespace)::MPPassManager::runOnModule (this=0x831de40, M=...)
at
/work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/lib/IR/LegacyPassManager.cpp:1603
#11 0x00000000022abb56 in llvm::legacy::PassManagerImpl::run (this=0x83237d0, M=...)
at
/work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/lib/IR/LegacyPassManager.cpp:1706
#12 0x00000000022ac541 in llvm::legacy::PassManager::run (this=0x7fffffffb500, M=...)
at
/work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/lib/IR/LegacyPassManager.cpp:1737
#13 0x0000000002adf7c5 in (anonymous namespace)::EmitAssemblyHelper::EmitAssembly
(this=0x7fffffffb7a8, Action=clang::Backend_EmitObj, OS=...)
at
/work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/tools/cfe/lib/CodeGen/BackendUtil.cpp:734
#14 0x0000000002adeda6 in clang::EmitBackendOutput (Diags=..., CGOpts=..., TOpts=...,
LOpts=..., TDesc=..., M=0x82b1f90,
Action=clang::Backend_EmitObj, OS=...)
at
/work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/tools/cfe/lib/CodeGen/BackendUtil.cpp:751
#15 0x00000000035d622f in clang::BackendConsumer::HandleTranslationUnit (this=0x82b1a80, C=...)
at
/work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/tools/cfe/lib/CodeGen/CodeGenAction.cpp:179
#16 0x0000000004259504 in clang::ParseAST (S=..., PrintStats=false, SkipFunctionBodies=false)
at
/work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/tools/cfe/lib/Parse/ParseAST.cpp:167
#17 0x00000000030f011a in clang::ASTFrontendAction::ExecuteAction (this=0x8297f20)
at
/work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/tools/cfe/lib/Frontend/FrontendAction.cpp:556
#18 0x00000000035d4bf5 in clang::CodeGenAction::ExecuteAction (this=0x8297f20)
at
/work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/tools/cfe/lib/CodeGen/CodeGenAction.cpp:853
#19 0x00000000030efc00 in clang::FrontendAction::Execute (this=0x8297f20)
at
/work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/tools/cfe/lib/Frontend/FrontendAction.cpp:457
#20 0x0000000003094c81 in clang::CompilerInstance::ExecuteAction (this=0x827df40, Act=...)
at
/work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/tools/cfe/lib/Frontend/CompilerInstance.cpp:867
#21 0x0000000003241ba1 in clang::ExecuteCompilerInvocation (Clang=0x827df40)
at
/work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/tools/cfe/lib/FrontendTool/ExecuteCompilerInvocation.cpp:241
#22 0x0000000000c33bc8 in cc1_main (Argv=...,
Argv0=0x7fffffffe3f9
"/work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/tmp/clang",
MainAddr=0xc26010 <GetExecutablePath(char const*, bool)>)
at
/work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/tools/cfe/tools/driver/cc1_main.cpp:116
#23 0x0000000000c27c2a in ExecuteCC1Tool (argv=..., Tool=...)
at
/work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/tools/cfe/tools/driver/driver.cpp:301
#24 0x0000000000c26ae2 in main (argc_=52, argv_=0x7fffffffdfb8)
at
/work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/tools/cfe/tools/driver/driver.cpp:382
----- /tmp/main_with_3_globals-841619.c -----
# 1 "<built-in>"
# 1 "main_with_3_globals.c"
int foo;
char bar;
long baz;
int main(){return foo;}
----- /tmp/main_with_3_globals-841619.sh -----
# Crash reproducer for clang version 3.9.0
# Driver args: "main_with_3_globals.c" "-O3"
# Original command:
"/work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/build_003/bin/clang-3.9"
"-cc1" "-triple" "x86_64-unknown-linux-gnu" "-emit-obj" "-disable-free" "-main-file-name"
"main_with_3_globals.c" "-mrelocation-model" "static" "-mthread-model" "posix" "-fmath-errno"
"-masm-verbose" "-mconstructor-aliases" "-munwind-tables" "-fuse-init-array" "-target-cpu"
"x86-64" "-momit-leaf-frame-pointer" "-dwarf-column-info" "-debugger-tuning=gdb"
"-resource-dir"
"/work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/build_003/bin/../lib/clang/3.9.0"
"-internal-isystem" "/usr/local/include" "-internal-isystem"
"/work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/build_003/bin/../lib/clang/3.9.0/include"
"-internal-externc-isystem" "/usr/include/x86_64-linux-gnu" "-internal-externc-isystem"
"/include" "-internal-externc-isystem" "/usr/include" "-O3" "-fdebug-compilation-dir"
"/work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/tmp"
"-ferror-limit" "19" "-fmessage-length" "144" "-fobjc-runtime=gcc" "-fdiagnostics-show-option"
"-fcolor-diagnostics" "-vectorize-loops" "-vectorize-slp" "-o"
"/tmp/main_with_3_globals-cef92e.o" "-x" "c" "main_with_3_globals.c"
"/work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/build_003/bin/clang-3.9"
"-cc1" "-triple" "x86_64-unknown-linux-gnu" "-emit-obj" "-disable-free" "-main-file-name"
"main_with_3_globals.c" "-mrelocation-model" "static" "-mthread-model" "posix" "-fmath-errno"
"-masm-verbose" "-mconstructor-aliases" "-munwind-tables" "-fuse-init-array" "-target-cpu"
"x86-64" "-momit-leaf-frame-pointer" "-dwarf-column-info" "-debugger-tuning=gdb" "-O3"
"-ferror-limit" "19" "-fmessage-length" "144" "-fobjc-runtime=gcc" "-fdiagnostics-show-option"
"-fcolor-diagnostics" "-vectorize-loops" "-vectorize-slp" "-x" "c" "main_with_3_globals-841619.c"
[the previous 3 sections, i.e. error dump + preprocessed C code + shell code: much the same
with an AArch64 target, using "-target aarch64-gnu-linux" and containing the output line
"Target: aarch64--linux-gnu"]
More information about the llvm-dev
mailing list