Skip to content

Segfault building libcore with stage1 rustc and RUSTFLAGS="-g" #15156

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
luqmana opened this issue Jun 24, 2014 · 12 comments
Closed

Segfault building libcore with stage1 rustc and RUSTFLAGS="-g" #15156

luqmana opened this issue Jun 24, 2014 · 12 comments
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.

Comments

@luqmana
Copy link
Member

luqmana commented Jun 24, 2014

As of the last LLVM update RUSTFLAGS="-g" is once again broken:

I bisected LLVM and traced it down to this commit rust-lang/llvm@503af43

Here is a backtrace:

-> % gdb --args x86_64-unknown-linux-gnu/stage1/bin/rustc --cfg stage1 -g -O --cfg rtopt --cfg debug -C prefer-dynamic --target=x86_64-unknown-linux-gnu  -D warnings -L "x86_64-unknown-linux-gnu/rt" -L "/scratch/laden/rust/build/x86_64-unknown-linux-gnu/llvm/Debug+Asserts/lib" -L ""  --out-dir x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib /scratch/laden/rust/src/libcore/lib.rs
GNU gdb (GDB) 7.4.1-debian
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /scratch/laden/rust/build/x86_64-unknown-linux-gnu/stage1/bin/rustc...done.
(gdb) r
Starting program: /scratch/laden/rust/build/x86_64-unknown-linux-gnu/stage1/bin/rustc --cfg stage1 -g -O --cfg rtopt --cfg debug -C prefer-dynamic --target=x86_64-unknown-linux-gnu -D warnings -L x86_64-unknown-linux-gnu/rt -L /scratch/laden/rust/build/x86_64-unknown-linux-gnu/llvm/Debug+Asserts/lib -L '' --out-dir x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib /scratch/laden/rust/src/libcore/lib.rs
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff1bff480 (LWP 5578)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff1bff480 (LWP 5578)]
0x00007ffff572d772 in llvm::PointerIntPair<llvm::Value*, 2u, unsigned int, llvm::PointerLikeTypeTraits<llvm::Value*> >::getPointer (this=0xb8) at /scratch/laden/rust/src/llvm/include/llvm/ADT/PointerIntPair.h:76
76                               reinterpret_cast<void*>(Value & PointerBitMask));
(gdb) bt
#0  0x00007ffff572d772 in llvm::PointerIntPair<llvm::Value*, 2u, unsigned int, llvm::PointerLikeTypeTraits<llvm::Value*> >::getPointer (this=0xb8) at /scratch/laden/rust/src/llvm/include/llvm/ADT/PointerIntPair.h:76
#1  0x00007ffff571fe0c in llvm::ValueHandleBase::getValPtr (this=0xa8) at /scratch/laden/rust/src/llvm/include/llvm/IR/ValueHandle.h:103
#2  0x00007ffff5f515b0 in llvm::AssertingVH<llvm::MDNode const>::getValPtr (this=0xa8) at /scratch/laden/rust/src/llvm/include/llvm/IR/ValueHandle.h:195
#3  0x00007ffff5f49874 in llvm::AssertingVH<llvm::MDNode const>::operator llvm::MDNode const* (this=0xa8) at /scratch/laden/rust/src/llvm/include/llvm/IR/ValueHandle.h:222
#4  0x00007ffff5f3a0b0 in llvm::LexicalScope::getScopeNode (this=0xa0) at /scratch/laden/rust/src/llvm/include/llvm/CodeGen/LexicalScopes.h:59
#5  0x00007ffff5f43af5 in llvm::DwarfDebug::endFunction (this=0x3eb1840, MF=0x2572620) at /scratch/laden/rust/src/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp:1528
#6  0x00007ffff5f264a4 in llvm::AsmPrinter::EmitFunctionBody (this=0x2401390) at /scratch/laden/rust/src/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp:864
#7  0x00007ffff5bf8547 in llvm::X86AsmPrinter::runOnMachineFunction (this=0x2401390, MF=...) at /scratch/laden/rust/src/llvm/lib/Target/X86/X86AsmPrinter.cpp:64
#8  0x00007ffff609e1eb in llvm::MachineFunctionPass::runOnFunction (this=0x2401390, F=...) at /scratch/laden/rust/src/llvm/lib/CodeGen/MachineFunctionPass.cpp:33
#9  0x00007ffff6784eab in llvm::FPPassManager::runOnFunction (this=0x1378560, F=...) at /scratch/laden/rust/src/llvm/lib/IR/LegacyPassManager.cpp:1545
#10 0x00007ffff678509c in llvm::FPPassManager::runOnModule (this=0x1378560, M=...) at /scratch/laden/rust/src/llvm/lib/IR/LegacyPassManager.cpp:1565
#11 0x00007ffff67853f9 in (anonymous namespace)::MPPassManager::runOnModule (this=0x372e0e0, M=...) at /scratch/laden/rust/src/llvm/lib/IR/LegacyPassManager.cpp:1623
#12 0x00007ffff6785aaf in llvm::legacy::PassManagerImpl::run (this=0x24230f0, M=...) at /scratch/laden/rust/src/llvm/lib/IR/LegacyPassManager.cpp:1730
#13 0x00007ffff6785cd5 in llvm::legacy::PassManager::run (this=0x32fc3b0, M=...) at /scratch/laden/rust/src/llvm/lib/IR/LegacyPassManager.cpp:1767
#14 0x00007ffff571b397 in LLVMRustWriteOutputFile (Target=0x45197d0, PMR=0x32fc3b0, M=0x539ec0, path=<optimized out>, FileType=llvm::TargetMachine::CGFT_ObjectFile) at /scratch/laden/rust/src/rustllvm/PassWrapper.cpp:202
#15 0x00007ffff55756ed in rustc::back::link::write_output_file (sess=0x7ffff1bf4be8, target=0x45197d0, pm=0x32fc3b0, m=0x539ec0, output=<optimized out>, file_type=ObjectFile) at /scratch/laden/rust/src/librustc/back/link.rs:78
#16 0x00007ffff557d170 in fn105947 (cpm=0x32fc3b0) at /scratch/laden/rust/src/librustc/back/link.rs:341
#17 with_codegen (tm=0x45197d0, llmod=0x539ec0, no_builtins=<optimized out>, f=<optimized out>) at /scratch/laden/rust/src/librustc/back/link.rs:288
#18 fn105943 () at /scratch/laden/rust/src/librustc/back/link.rs:340
#19 0x00007ffff5577b89 in rustc::back::link::write::run_passes (sess=0x25db070, trans=<optimized out>, output=<optimized out>, output_types=...) at /scratch/laden/rust/src/librustc/back/link.rs:337
#20 0x00007ffff56c3751 in fn117831 () at /scratch/laden/rust/src/librustc/driver/driver.rs:436
#21 0x00007ffff562aeb1 in rustc::driver::driver::phase_5_run_llvm_passes (sess=<optimized out>, trans=<optimized out>, outputs=<optimized out>) at /scratch/laden/rust/src/librustc/driver/driver.rs:435
#22 0x00007ffff561f9f0 in rustc::driver::driver::compile_input (sess=..., cfg=..., input=<optimized out>, outdir=<optimized out>, output=<optimized out>) at /scratch/laden/rust/src/librustc/driver/driver.rs:100
#23 0x00007ffff56e5b29 in rustc::driver::run_compiler (args=...) at /scratch/laden/rust/src/librustc/driver/mod.rs:104
#24 0x00007ffff56e3446 in fn118655 () at /scratch/laden/rust/src/librustc/driver/mod.rs:40
#25 0x00007ffff56f875b in task::TaskBuilder$LT$S$GT$::try_future::closure.119840 () from /scratch/laden/rust/build/x86_64-unknown-linux-gnu/stage1/bin/../lib/librustc-d252d482-0.11.0-pre.so
#26 0x00007ffff56f8603 in task::TaskBuilder$LT$S$GT$::spawn_internal::closure.119821 () from /scratch/laden/rust/build/x86_64-unknown-linux-gnu/stage1/bin/../lib/librustc-d252d482-0.11.0-pre.so
#27 0x00007ffff7fc5c6c in fn7705 () at /scratch/laden/rust/src/libnative/task.rs:95
#28 0x00007ffff4235948 in task::Task::run::closure.5378 () from /scratch/laden/rust/build/x86_64-unknown-linux-gnu/stage1/bin/../lib/librustrt-d8560cb2-0.11.0-pre.so
#29 0x00007ffff429beac in rust_try () from /scratch/laden/rust/build/x86_64-unknown-linux-gnu/stage1/bin/../lib/librustrt-d8560cb2-0.11.0-pre.so
#30 0x00007ffff423838a in rustrt::unwind::try (f=<optimized out>) at /scratch/laden/rust/src/librustrt/unwind.rs:151
#31 0x00007ffff42357fa in rustrt::task::Task::run (self=0x7ffff1c1d1e0, f=<optimized out>) at /scratch/laden/rust/src/librustrt/local.rs:32
#32 0x00007ffff7fc5ae3 in fn7679 () at /scratch/laden/rust/src/libnative/task.rs:95
#33 0x00007ffff42379c7 in thread::thread_start::h1f70d5c4c9ce8948kdd::v0.11.0.pre () at /scratch/laden/rust/src/librustrt/thread.rs:49
#34 0x00007ffff39d0b50 in start_thread (arg=<optimized out>) at pthread_create.c:304
#35 0x00007ffff3f0f0ed in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:112
#36 0x0000000000000000 in ?? ()
(gdb)

cc @michaelwoerister

@michaelwoerister
Copy link
Member

I've been able to reproduce this and it seems that bug is triggered by the function inlining pass. When not using -O the crash does not occur. The LLVM commit you found, @luqmana, seems to suggest that something illegal is done to source locations, in particular that the scope-debuginfo a location is associated with is invalid. I don't think though that the new code introduced with the given commit actually does something wrong (it's pretty straightforward) but just uncovers some edge-case that was not encountered before.

@michaelwoerister
Copy link
Member

@luqmana Thanks a lot for even bisecting LLVM, very helpful! 👍 👍

@luqmana
Copy link
Member Author

luqmana commented Jul 2, 2014

bors added a commit that referenced this issue Jul 3, 2014
…=luqmana

So far, type names generated for debuginfo where a bit sketchy. It was not clearly defined when a name should be fully qualified and when not, if region parameters should be shown or not, and other things like that.
This commit makes the debuginfo module responsible for creating type names instead of using `ppaux::ty_to_str()` and brings type names (as they show up in the DWARF information) in line with GCC and Clang:

* The name of the type being described is unqualified. It's path is defined by its position in the namespace hierarchy.
* Type arguments are always fully qualified, no matter if they would actually be in scope at the type definition location.

Care is also taken to make type names consistent across crate boundaries. That is, the code now tries make the type name the same, regardless if the type is in the local crate or reconstructed from metadata. Otherwise LLVM will complain about violating the one-definition-rule when using link-time-optimization.

This commit also removes all source location information from type descriptions because these cannot be reconstructed for types instantiated from metadata. Again, with LTO enabled, this can lead to two versions of the debuginfo type description, one with and one without source location information, which then triggers the LLVM ODR assertion.
Fortunately, source location information about types is rarely used, so this has little impact. Once source location information is preserved in metadata (#1972) it can also be re-enabled for type descriptions.

`RUSTFLAGS=-g make check` no works again for me locally, including the LTO test cases (note that I've taken care of #15156 by reverting the change in LLVM that @luqmana identified as the culprit for that issue).
@michaelwoerister
Copy link
Member

The work on this area on the LLVM side is ongoing:
llvm-mirror/llvm@3a39415
llvm-mirror/llvm@231537a
llvm-mirror/llvm@a422113
I think it's best to wait until this settles down and try again then.

@michaelwoerister
Copy link
Member

I just tested with a current version (83a8a56) and I do not get an error when running RUSTFLAGS=-g make rustc. It might well be that it breaks again with the next LLVM update, since the troublesome code is still changed every few days.

I'm always interested in the results others get when trying to compile all of Rust with debuginfo...

@michaelwoerister
Copy link
Member

Update: I'm getting a different assertion now:

Assertion failed: (DISubprogram(Scope).describes(MF->getFunction())), function getOrCreateRegularScope, file /Users/mw/rust/src/llvm/lib/CodeGen/LexicalScopes.cpp, line 179.

Debuginfo handling in LLVM seems to be rather unstable at the moment :(

@farcaller
Copy link
Contributor

FWIW, I can reproduce even without -O and with --debuginfo=1 suggested in #16483:

rustc -Z no-landing-pads --cfg cfg_mcu_has_spi --cfg mcu_lpc17xx --cfg arch_cortex_m3 --target thumbv7m-linux-eabi -Ctarget-cpu=cortex-m3 -C relocation_model=static --debuginfo=1 -Z lto  --emit obj  -L /Users/farcaller/src/zinc/build  -o /Users/farcaller/src/zinc/build/intermediate/test/app_test.o  /Users/farcaller/src/zinc/apps/app_test.rs
Assertion failed: (DISubprogram(Scope).describes(MF->getFunction())), function getOrCreateRegularScope, file /Users/rustbuild/src/rust-buildbot/slave/nightly-mac/build/src/llvm/lib/CodeGen/LexicalScopes.cpp, line 179.

@michaelwoerister
Copy link
Member

@farcaller If you have #[inline(always)] functions in the code, then turning off optimizations unfortunately won't sidestep the issue.

@farcaller
Copy link
Contributor

Oh, that does explain it for me then.

@nrc
Copy link
Member

nrc commented Sep 9, 2014

Could we ignore inline(always) if we specify -g ? Or maybe have another flag to prevent all ignoring including override inline(always)? It's an annoying bug not to have debuginfo :-(

@pnkfelix
Copy link
Member

cc me

@michaelwoerister
Copy link
Member

The root issue causing these crashes (#15156, #15816, and #16483) is now documented and tracked in #17201. I hope to find the time for a fix soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.
Projects
None yet
Development

No branches or pull requests

5 participants