Skip to content
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

1.55.0 segfault compiling stage1 rustc_codegen_llvm on powerpc64le #89744

Open
infinity0 opened this issue Oct 10, 2021 · 22 comments
Open

1.55.0 segfault compiling stage1 rustc_codegen_llvm on powerpc64le #89744

infinity0 opened this issue Oct 10, 2021 · 22 comments
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. O-PowerPC Target: PowerPC processors T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@infinity0
Copy link
Contributor

Failure log (warning very large): 1.55

There was no failure on 1.54; the same version of LLVM was used in both cases - 12.0.1 (Debian version 1:12.0.1-9)

The only change made to rustc_codegen_llvm between 1.54 and 1.55 was #86416 so CC @Amanieu .

There was a later MR #88350 to fix something on powerpc64, however this just mentions "lack of support" rather than a segfault, so I don't know if this is related. Shall I try backporting it onto 1.55 in the meantime?

I will continue trying to debug the segfault.

The output contains the following stack-trace-like dump, not sure if it's useful:

/<<PKGBUILDDIR>>/build/powerpc64le-unknown-linux-gnu/stage1/lib/librustc_driver-8a51db685c3a3652.so(+0x786b6c)[0x7fffa65f6b6c]
linux-vdso64.so.1(__kernel_sigtramp_rt64+0x0)[0x7fffaa190514]
/<<PKGBUILDDIR>>/build/powerpc64le-unknown-linux-gnu/stage1/lib/librustc_driver-8a51db685c3a3652.so(+0x2b16f64)[0x7fffa8986f64]
/<<PKGBUILDDIR>>/build/powerpc64le-unknown-linux-gnu/stage1-rustc/release/deps/libcstr-786feb209dfce7ae.so(+0xc433c)[0x7fff87f7433c]
/<<PKGBUILDDIR>>/build/powerpc64le-unknown-linux-gnu/stage1-rustc/release/deps/libcstr-786feb209dfce7ae.so(+0xb1e50)[0x7fff87f61e50]
/<<PKGBUILDDIR>>/build/powerpc64le-unknown-linux-gnu/stage1-rustc/release/deps/libcstr-786feb209dfce7ae.so(_ZN10proc_macro12token_stream95_$LT$impl$u20$core..iter..traits..collect..IntoIterator$u20$for$u20$proc_macro..TokenStream$GT$9
into_iter17h32ab5102ba0e87e0E+0x28)[0x7fff87f47978]
/<<PKGBUILDDIR>>/build/powerpc64le-unknown-linux-gnu/stage1-rustc/release/deps/libcstr-786feb209dfce7ae.so(_ZN91_$LT$proc_macro2..imp..TokenStream$u20$as$u20$core..iter..traits..collect..IntoIterator$GT$9into_iter17h2efdc81b2e8ae367E+
0x1e0)[0x7fff87f35280]
/<<PKGBUILDDIR>>/build/powerpc64le-unknown-linux-gnu/stage1-rustc/release/deps/libcstr-786feb209dfce7ae.so(_ZN11proc_macro212token_stream96_$LT$impl$u20$core..iter..traits..collect..IntoIterator$u20$for$u20$proc_macro2..TokenStream$GT
$9into_iter17h315ff4dea038bfc3E+0x54)[0x7fff87f3ab84]
/<<PKGBUILDDIR>>/build/powerpc64le-unknown-linux-gnu/stage1-rustc/release/deps/libcstr-786feb209dfce7ae.so(+0x6a200)[0x7fff87f1a200]
/<<PKGBUILDDIR>>/build/powerpc64le-unknown-linux-gnu/stage1-rustc/release/deps/libcstr-786feb209dfce7ae.so(+0x6bfa0)[0x7fff87f1bfa0]
/<<PKGBUILDDIR>>/build/powerpc64le-unknown-linux-gnu/stage1-rustc/release/deps/libcstr-786feb209dfce7ae.so(+0x6dbf8)[0x7fff87f1dbf8]
/<<PKGBUILDDIR>>/build/powerpc64le-unknown-linux-gnu/stage1-rustc/release/deps/libcstr-786feb209dfce7ae.so(+0x6e654)[0x7fff87f1e654]
/<<PKGBUILDDIR>>/build/powerpc64le-unknown-linux-gnu/stage1-rustc/release/deps/libcstr-786feb209dfce7ae.so(+0x6d478)[0x7fff87f1d478]
/<<PKGBUILDDIR>>/build/powerpc64le-unknown-linux-gnu/stage1/lib/librustc_driver-8a51db685c3a3652.so(+0x2a474f0)[0x7fffa88b74f0]
/<<PKGBUILDDIR>>/build/powerpc64le-unknown-linux-gnu/stage1/lib/librustc_driver-8a51db685c3a3652.so(_ZN89_$LT$rustc_expand..proc_macro..BangProcMacro$u20$as$u20$rustc_expand..base..ProcMacro$GT$6expand17h4da03810eb58a713E+0x12c)[0x7ff
fa889171c]
/<<PKGBUILDDIR>>/build/powerpc64le-unknown-linux-gnu/stage1/lib/librustc_driver-8a51db685c3a3652.so(_ZN12rustc_expand6expand13MacroExpander21fully_expand_fragment17hf42bf6c7c5cee112E+0x17f0)[0x7fffa8875590]
/<<PKGBUILDDIR>>/build/powerpc64le-unknown-linux-gnu/stage1/lib/librustc_driver-8a51db685c3a3652.so(_ZN12rustc_expand6expand13MacroExpander12expand_crate17h900deade1746e5d6E+0x6e0)[0x7fffa8873540]
/<<PKGBUILDDIR>>/build/powerpc64le-unknown-linux-gnu/stage1/lib/librustc_driver-8a51db685c3a3652.so(+0x855080)[0x7fffa66c5080]
/<<PKGBUILDDIR>>/build/powerpc64le-unknown-linux-gnu/stage1/lib/librustc_driver-8a51db685c3a3652.so(+0x88ed34)[0x7fffa66fed34]
/<<PKGBUILDDIR>>/build/powerpc64le-unknown-linux-gnu/stage1/lib/librustc_driver-8a51db685c3a3652.so(_ZN15rustc_interface7queries7Queries9expansion17h4bcb4cf9c0b271cfE+0x38c)[0x7fffa672a07c]
/<<PKGBUILDDIR>>/build/powerpc64le-unknown-linux-gnu/stage1/lib/librustc_driver-8a51db685c3a3652.so(+0x6fd664)[0x7fffa656d664]
/<<PKGBUILDDIR>>/build/powerpc64le-unknown-linux-gnu/stage1/lib/librustc_driver-8a51db685c3a3652.so(+0x6e53fc)[0x7fffa65553fc]
/<<PKGBUILDDIR>>/build/powerpc64le-unknown-linux-gnu/stage1/lib/librustc_driver-8a51db685c3a3652.so(+0x6fed88)[0x7fffa656ed88]
/<<PKGBUILDDIR>>/build/powerpc64le-unknown-linux-gnu/stage1/lib/librustc_driver-8a51db685c3a3652.so(+0x6f59a8)[0x7fffa65659a8]
/<<PKGBUILDDIR>>/build/powerpc64le-unknown-linux-gnu/stage1/lib/librustc_driver-8a51db685c3a3652.so(+0x75d010)[0x7fffa65cd010]
/<<PKGBUILDDIR>>/build/powerpc64le-unknown-linux-gnu/stage1/lib/librustc_driver-8a51db685c3a3652.so(+0x6db274)[0x7fffa654b274]
/<<PKGBUILDDIR>>/build/powerpc64le-unknown-linux-gnu/stage1/lib/libstd-5259f91ddc4e5b37.so(rust_metadata_std_f9b0c9e9385aeadc6c2155a37e531624+0x8df54)[0x7fffa5ccdf54]
/lib/powerpc64le-linux-gnu/libpthread.so.0(+0x90a4)[0x7fff9f5e90a4]
/lib/powerpc64le-linux-gnu/libc.so.6(clone+0x74)[0x7fffa5b4d054]
@infinity0 infinity0 added the C-bug Category: This is a bug. label Oct 10, 2021
@Mark-Simulacrum
Copy link
Member

That stack trace looks like it's coming from procmacro expansion (cstr), though it doesn't look like that dependency changed. It doesn't seem like anything in particular changed with the proc macro code, either...

It would be good to get a better stack trace - at least symbols...

@infinity0
Copy link
Contributor Author

Here is a stack trace of the failing command. It's a bit spammy; I have the session still open if you want to explore e.g. the local variables or something, let me know what I should run.

GNU gdb (Debian 10.1-2) 10.1.90.20210103-git
[..]
Reading symbols from /home/infinity0/rustc/build/powerpc64le-unknown-linux-gnu/stage1/bin/rustc...
warning: Missing auto-load script at offset 0 in section .debug_gdb_scripts
of file /home/infinity0/rustc/build/powerpc64le-unknown-linux-gnu/stage1/bin/rustc.
Use `info auto-load python-scripts [REGEXP]' to list them.
Starting program: /home/infinity0/rustc/build/powerpc64le-unknown-linux-gnu/stage1/bin/rustc --crate-name rustc_codegen_llvm --edition=2018 compiler/rustc_codegen_llvm/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no -C debuginfo=2 -C metadata=a0f8a5ce0ffb9405 -C extra-filename=-a0f8a5ce0ffb9405 --out-dir /home/infinity0/rustc/build/powerpc64le-unknown-linux-gnu/stage1-rustc/powerpc64le-unknown-linux-gnu/release/deps --target powerpc64le-unknown-linux-gnu -C linker=powerpc64le-linux-gnu-gcc -L dependency=/home/infinity0/rustc/build/powerpc64le-unknown-linux-gnu/stage1-rustc/powerpc64le-unknown-linux-gnu/release/deps -L dependency=/home/infinity0/rustc/build/powerpc64le-unknown-linux-gnu/stage1-rustc/release/deps --extern bitflags=/home/infinity0/rustc/build/powerpc64le-unknown-linux-gnu/stage1-rustc/powerpc64le-unknown-linux-gnu/release/deps/libbitflags-0f94127248fffc9d.rmeta --extern cstr=/home/infinity0/rustc/build/powerpc64le-unknown-linux-gnu/stage1-rustc/release/deps/libcstr-f6bea2880dd7718c.so --extern libc=/home/infinity0/rustc/build/powerpc64le-unknown-linux-gnu/stage1-rustc/powerpc64le-unknown-linux-gnu/release/deps/liblibc-7c269ea4a9fc2214.rmeta --extern measureme=/home/infinity0/rustc/build/powerpc64le-unknown-linux-gnu/stage1-rustc/powerpc64le-unknown-linux-gnu/release/deps/libmeasureme-066a5f2f13edc4f4.rmeta --extern rustc_demangle=/home/infinity0/rustc/build/powerpc64le-unknown-linux-gnu/stage1-rustc/powerpc64le-unknown-linux-gnu/release/deps/librustc_demangle-247ac0f360f67bcb.rmeta --extern rustc_ast=/home/infinity0/rustc/build/powerpc64le-unknown-linux-gnu/stage1-rustc/powerpc64le-unknown-linux-gnu/release/deps/librustc_ast-e121d85ccd1a64d0.rmeta --extern rustc_attr=/home/infinity0/rustc/build/powerpc64le-unknown-linux-gnu/stage1-rustc/powerpc64le-unknown-linux-gnu/release/deps/librustc_attr-303e1522532fa990.rmeta --extern rustc_codegen_ssa=/home/infinity0/rustc/build/powerpc64le-unknown-linux-gnu/stage1-rustc/powerpc64le-unknown-linux-gnu/release/deps/librustc_codegen_ssa-90e2d769bd05fb55.rmeta --extern rustc_data_structures=/home/infinity0/rustc/build/powerpc64le-unknown-linux-gnu/stage1-rustc/powerpc64le-unknown-linux-gnu/release/deps/librustc_data_structures-d7f0505d6db6c0a8.rmeta --extern rustc_errors=/home/infinity0/rustc/build/powerpc64le-unknown-linux-gnu/stage1-rustc/powerpc64le-unknown-linux-gnu/release/deps/librustc_errors-724f2ceacef136f1.rmeta --extern rustc_fs_util=/home/infinity0/rustc/build/powerpc64le-unknown-linux-gnu/stage1-rustc/powerpc64le-unknown-linux-gnu/release/deps/librustc_fs_util-8ecaae709daadfb8.rmeta --extern rustc_hir=/home/infinity0/rustc/build/powerpc64le-unknown-linux-gnu/stage1-rustc/powerpc64le-unknown-linux-gnu/release/deps/librustc_hir-66e497c34ad0fbcc.rmeta --extern rustc_index=/home/infinity0/rustc/build/powerpc64le-unknown-linux-gnu/stage1-rustc/powerpc64le-unknown-linux-gnu/release/deps/librustc_index-6708adbdbe8c5839.rmeta --extern rustc_llvm=/home/infinity0/rustc/build/powerpc64le-unknown-linux-gnu/stage1-rustc/powerpc64le-unknown-linux-gnu/release/deps/librustc_llvm-3d7c24d0753fba41.rmeta --extern rustc_metadata=/home/infinity0/rustc/build/powerpc64le-unknown-linux-gnu/stage1-rustc/powerpc64le-unknown-linux-gnu/release/deps/librustc_metadata-5cb609062c9cff03.rmeta --extern rustc_middle=/home/infinity0/rustc/build/powerpc64le-unknown-linux-gnu/stage1-rustc/powerpc64le-unknown-linux-gnu/release/deps/librustc_middle-bf102a055987078a.rmeta --extern rustc_serialize=/home/infinity0/rustc/build/powerpc64le-unknown-linux-gnu/stage1-rustc/powerpc64le-unknown-linux-gnu/release/deps/librustc_serialize-35b7eafe1f685f6b.rmeta --extern rustc_session=/home/infinity0/rustc/build/powerpc64le-unknown-linux-gnu/stage1-rustc/powerpc64le-unknown-linux-gnu/release/deps/librustc_session-56a2929db906a8a1.rmeta --extern rustc_span=/home/infinity0/rustc/build/powerpc64le-unknown-linux-gnu/stage1-rustc/powerpc64le-unknown-linux-gnu/release/deps/librustc_span-67a862338efdbe7d.rmeta --extern rustc_target=/home/infinity0/rustc/build/powerpc64le-unknown-linux-gnu/stage1-rustc/powerpc64le-unknown-linux-gnu/release/deps/librustc_target-c9d98e7040edf8b7.rmeta --extern smallvec=/home/infinity0/rustc/build/powerpc64le-unknown-linux-gnu/stage1-rustc/powerpc64le-unknown-linux-gnu/release/deps/libsmallvec-a1cd9730a92c2db9.rmeta --extern snap=/home/infinity0/rustc/build/powerpc64le-unknown-linux-gnu/stage1-rustc/powerpc64le-unknown-linux-gnu/release/deps/libsnap-3deba377bb543db8.rmeta --extern tracing=/home/infinity0/rustc/build/powerpc64le-unknown-linux-gnu/stage1-rustc/powerpc64le-unknown-linux-gnu/release/deps/libtracing-f863a5510a5c2743.rmeta --cap-lints=warn -Clink-args=-Wl,-z,relro -Zmacro-backtrace -Ztls-model=initial-exec -Zunstable-options '-Wrustc::internal' -Cprefer-dynamic -Zbinary-dep-depinfo -L native=/home/infinity0/rustc/build/powerpc64le-unknown-linux-gnu/stage1-rustc/powerpc64le-unknown-linux-gnu/release/build/psm-928384bbbf2b32bc/out -L native=/home/infinity0/rustc/build/powerpc64le-unknown-linux-gnu/stage1-rustc/powerpc64le-unknown-linux-gnu/release/build/rustc_llvm-9112792927bd9fe0/out -L native=/usr/lib/llvm-12/lib
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/powerpc64le-linux-gnu/libthread_db.so.1".
[New Thread 0x7fffe933ec00 (LWP 5146)]

Thread 2 "rustc" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffe933ec00 (LWP 5146)]
proc_macro::bridge::closure::{{impl}}::from::call<proc_macro::bridge::buffer::Buffer<u8>,proc_macro::bridge::buffer::Buffer<u8>,closure-0> (env=0x141a, arg=...) at /usr/src/rustc-1.55.0/library/proc_macro/src/bridge/closure.rs:19
19                  (*(env as *mut _ as *mut F))(arg)
(gdb) bt
#0  proc_macro::bridge::closure::{{impl}}::from::call<proc_macro::bridge::buffer::Buffer<u8>,proc_macro::bridge::buffer::Buffer<u8>,closure-0> (env=0x141a, arg=...) at /usr/src/rustc-1.55.0/library/proc_macro/src/bridge/closure.rs:19
#1  0x00007fffd5cc9c0c in proc_macro::bridge::closure::Closure<proc_macro::bridge::buffer::Buffer<u8>, proc_macro::bridge::buffer::Buffer<u8>>::call<proc_macro::bridge::buffer::Buffer<u8>, proc_macro::bridge::buffer::Buffer<u8>> (
    self=<optimized out>, arg=...) at library/proc_macro/src/bridge/closure.rs:27
#2  proc_macro::bridge::client::{impl#154}::into_iter::{closure#0} (bridge=<optimized out>) at library/proc_macro/src/bridge/client.rs:244
#3  proc_macro::bridge::client::{impl#9}::with::{closure#0}<proc_macro::bridge::client::TokenStreamIter, proc_macro::bridge::client::{impl#154}::into_iter::{closure#0}> (state=0x7fffe932fe28)
    at library/proc_macro/src/bridge/client.rs:336
#4  proc_macro::bridge::client::{impl#8}::with::{closure#0}::{closure#0}<proc_macro::bridge::client::TokenStreamIter, proc_macro::bridge::client::{impl#9}::with::{closure#0}> (state=...) at library/proc_macro/src/bridge/client.rs:293
#5  proc_macro::bridge::scoped_cell::ScopedCell<proc_macro::bridge::client::BridgeStateL>::replace<proc_macro::bridge::client::BridgeStateL, proc_macro::bridge::client::TokenStreamIter, proc_macro::bridge::client::{impl#8}::with::{closure#0}::{closure#0}> (self=<optimized out>, replacement=..., f=...) at library/proc_macro/src/bridge/scoped_cell.rs:75
#6  0x00007fffd5cc1760 in proc_macro::bridge::client::{impl#8}::with::{closure#0}<proc_macro::bridge::client::TokenStreamIter, proc_macro::bridge::client::{impl#9}::with::{closure#0}> (state=<optimized out>)
    at library/proc_macro/src/bridge/client.rs:291
#7  std::thread::local::LocalKey<proc_macro::bridge::scoped_cell::ScopedCell<proc_macro::bridge::client::BridgeStateL>>::try_with<proc_macro::bridge::scoped_cell::ScopedCell<proc_macro::bridge::client::BridgeStateL>, proc_macro::bridge::client::{impl#8}::with::{closure#0}, proc_macro::bridge::client::TokenStreamIter> (self=<optimized out>, f=...) at /usr/src/rustc-1.55.0/library/std/src/thread/local.rs:399
#8  std::thread::local::LocalKey<proc_macro::bridge::scoped_cell::ScopedCell<proc_macro::bridge::client::BridgeStateL>>::with<proc_macro::bridge::scoped_cell::ScopedCell<proc_macro::bridge::client::BridgeStateL>, proc_macro::bridge::client::{impl#8}::with::{closure#0}, proc_macro::bridge::client::TokenStreamIter> (self=<optimized out>, f=...) at /usr/src/rustc-1.55.0/library/std/src/thread/local.rs:375
#9  0x00007fffd5ca7978 in proc_macro::bridge::client::BridgeState::with<proc_macro::bridge::client::TokenStreamIter, proc_macro::bridge::client::{impl#9}::with::{closure#0}> (f=...) at library/proc_macro/src/bridge/client.rs:290
#10 proc_macro::bridge::Bridge::with<proc_macro::bridge::client::TokenStreamIter, proc_macro::bridge::client::{impl#154}::into_iter::{closure#0}> (f=...) at library/proc_macro/src/bridge/client.rs:329
#11 proc_macro::bridge::client::TokenStream::into_iter (self=...) at library/proc_macro/src/bridge/client.rs:237
#12 proc_macro::token_stream::{impl#1}::into_iter (self=...) at library/proc_macro/src/lib.rs:259
#13 0x00007fffd5c95320 in proc_macro2::imp::{impl#19}::into_iter (self=...) at /usr/src/rustc-1.55.0/vendor/proc-macro2/src/wrapper.rs:314
#14 0x00007fffd5c9ac24 in proc_macro2::token_stream::{impl#2}::into_iter (self=...) at /usr/src/rustc-1.55.0/vendor/proc-macro2/src/lib.rs:1267
#15 0x00007fffd5c7a200 in cstr::parse::parse_input (input=...) at /usr/src/rustc-1.55.0/vendor/cstr/src/parse.rs:13
#16 0x00007fffd5c7bfa0 in cstr::build_byte_str (input=...) at /usr/src/rustc-1.55.0/vendor/cstr/src/lib.rs:56
#17 cstr::cstr (input=...) at /usr/src/rustc-1.55.0/vendor/cstr/src/lib.rs:39
#18 0x00007fffd5c7d8d8 in core::ops::function::FnOnce::call_once<fn(proc_macro::TokenStream) -> proc_macro::TokenStream, (proc_macro::TokenStream)> () at /usr/src/rustc-1.55.0/library/core/src/ops/function.rs:227
#19 proc_macro::bridge::client::{impl#10}::expand1::run::{closure#0}<fn(proc_macro::TokenStream) -> proc_macro::TokenStream> (input=...) at /usr/src/rustc-1.55.0/library/proc_macro/src/bridge/client.rs:410
#20 proc_macro::bridge::client::run_client::{closure#0}::{closure#0}<proc_macro::bridge::client::TokenStream, proc_macro::bridge::client::TokenStream, proc_macro::bridge::client::{impl#10}::expand1::run::{closure#0}> ()
    at /usr/src/rustc-1.55.0/library/proc_macro/src/bridge/client.rs:377
#21 proc_macro::bridge::scoped_cell::{impl#3}::set::{closure#0}<proc_macro::bridge::client::BridgeStateL, (), proc_macro::bridge::client::run_client::{closure#0}::{closure#0}> ()
    at /usr/src/rustc-1.55.0/library/proc_macro/src/bridge/scoped_cell.rs:80
#22 proc_macro::bridge::scoped_cell::ScopedCell<proc_macro::bridge::client::BridgeStateL>::replace<proc_macro::bridge::client::BridgeStateL, (), proc_macro::bridge::scoped_cell::{impl#3}::set::{closure#0}> (self=<optimized out>, 
    f=..., replacement=<error reading variable: Cannot access memory at address 0x38>) at /usr/src/rustc-1.55.0/library/proc_macro/src/bridge/scoped_cell.rs:75
#23 proc_macro::bridge::scoped_cell::ScopedCell<proc_macro::bridge::client::BridgeStateL>::set<proc_macro::bridge::client::BridgeStateL, (), proc_macro::bridge::client::run_client::{closure#0}::{closure#0}> (self=<optimized out>, 
    value=..., f=...) at /usr/src/rustc-1.55.0/library/proc_macro/src/bridge/scoped_cell.rs:80
#24 0x00007fffd5c7e334 in proc_macro::bridge::client::{impl#9}::enter::{closure#1}<(), proc_macro::bridge::client::run_client::{closure#0}::{closure#0}> (state=<optimized out>)
    at /usr/src/rustc-1.55.0/library/proc_macro/src/bridge/client.rs:325
#25 std::thread::local::LocalKey<proc_macro::bridge::scoped_cell::ScopedCell<proc_macro::bridge::client::BridgeStateL>>::try_with<proc_macro::bridge::scoped_cell::ScopedCell<proc_macro::bridge::client::BridgeStateL>, proc_macro::bridge::client::{impl#9}::enter::{closure#1}, ()> (f=..., self=<optimized out>) at /usr/src/rustc-1.55.0/library/std/src/thread/local.rs:399
#26 std::thread::local::LocalKey<proc_macro::bridge::scoped_cell::ScopedCell<proc_macro::bridge::client::BridgeStateL>>::with<proc_macro::bridge::scoped_cell::ScopedCell<proc_macro::bridge::client::BridgeStateL>, proc_macro::bridge::client::{impl#9}::enter::{closure#1}, ()> (f=..., self=<optimized out>) at /usr/src/rustc-1.55.0/library/std/src/thread/local.rs:375
#27 proc_macro::bridge::Bridge::enter<(), proc_macro::bridge::client::run_client::{closure#0}::{closure#0}> (self=..., f=...) at /usr/src/rustc-1.55.0/library/proc_macro/src/bridge/client.rs:325
#28 0x00007fffd5c7ccc8 in proc_macro::bridge::client::run_client::{closure#0}<proc_macro::bridge::client::TokenStream, proc_macro::bridge::client::TokenStream, proc_macro::bridge::client::{impl#10}::expand1::run::{closure#0}> ()
    at /usr/src/rustc-1.55.0/library/proc_macro/src/bridge/client.rs:370
#29 std::panic::{impl#30}::call_once<(), proc_macro::bridge::client::run_client::{closure#0}> (self=..., _args=<optimized out>) at /usr/src/rustc-1.55.0/library/std/src/panic.rs:347
#30 std::panicking::try::do_call<std::panic::AssertUnwindSafe<proc_macro::bridge::client::run_client::{closure#0}>, ()> (data=<optimized out>) at /usr/src/rustc-1.55.0/library/std/src/panicking.rs:401
#31 std::panicking::try<(), std::panic::AssertUnwindSafe<proc_macro::bridge::client::run_client::{closure#0}>> (f=...) at /usr/src/rustc-1.55.0/library/std/src/panicking.rs:365
#32 std::panic::catch_unwind<std::panic::AssertUnwindSafe<proc_macro::bridge::client::run_client::{closure#0}>, ()> (f=...) at /usr/src/rustc-1.55.0/library/std/src/panic.rs:434
#33 proc_macro::bridge::client::run_client<proc_macro::bridge::client::TokenStream, proc_macro::bridge::client::TokenStream, proc_macro::bridge::client::{impl#10}::expand1::run::{closure#0}> (bridge=..., f=...)
    at /usr/src/rustc-1.55.0/library/proc_macro/src/bridge/client.rs:369
#34 proc_macro::bridge::client::{impl#10}::expand1::run<fn(proc_macro::TokenStream) -> proc_macro::TokenStream> (bridge=..., f=0x7fffd5c7bf20 <cstr::cstr>) at /usr/src/rustc-1.55.0/library/proc_macro/src/bridge/client.rs:410
#35 0x00007ffff66975f0 in proc_macro::bridge::server::{{impl}}::run_bridge_and_client<fn(proc_macro::TokenStream) -> proc_macro::TokenStream,proc_macro::bridge::server::Dispatcher<proc_macro::bridge::server::MarkedTypes<rustc_expand::proc_macro_server::Rustc>>> (self=<optimized out>, dispatcher=0x7fffe9330868, run_client=0x7fffd5c7cc40 <proc_macro::bridge::client::{impl#10}::expand1::run<fn(proc_macro::TokenStream) -> proc_macro::TokenStream>>, 
    client_data=0x7fffd5c7bf20 <cstr::cstr>, force_show_panics=false, input=...) at /usr/src/rustc-1.55.0/library/proc_macro/src/bridge/server.rs:155
#36 proc_macro::bridge::server::run_server<rustc_expand::proc_macro_server::Rustc,proc_macro::bridge::Marked<rustc_ast::tokenstream::TokenStream, proc_macro::bridge::client::TokenStream>,proc_macro::bridge::Marked<rustc_ast::tokenstream::TokenStream, proc_macro::bridge::client::TokenStream>,fn(proc_macro::TokenStream) -> proc_macro::TokenStream,proc_macro::bridge::server::SameThread> (strategy=<optimized out>, handle_counters=<optimized out>, server=..., 
    input=..., run_client=0x7fffd5c7cc40 <proc_macro::bridge::client::{impl#10}::expand1::run<fn(proc_macro::TokenStream) -> proc_macro::TokenStream>>, client_data=0x7fffd5c7bf20 <cstr::cstr>, force_show_panics=<optimized out>)
    at /usr/src/rustc-1.55.0/library/proc_macro/src/bridge/server.rs:291
#37 0x00007ffff667181c in proc_macro::bridge::client::Client<fn(proc_macro::TokenStream) -> proc_macro::TokenStream>::run<rustc_expand::proc_macro_server::Rustc,proc_macro::bridge::server::SameThread> (self=<optimized out>, 
    strategy=<optimized out>, server=..., input=..., force_show_panics=<optimized out>) at /usr/src/rustc-1.55.0/library/proc_macro/src/bridge/server.rs:311
#38 rustc_expand::proc_macro::{{impl}}::expand (self=<optimized out>, ecx=0x7fffe9332208, span=..., input=...) at compiler/rustc_expand/src/proc_macro.rs:28
#39 0x00007ffff6655690 in rustc_expand::expand::MacroExpander::expand_invoc (self=0x7fffe93323e0, invoc=..., ext=<optimized out>) at compiler/rustc_expand/src/expand.rs:671
#40 rustc_expand::expand::MacroExpander::fully_expand_fragment (self=0x7fffe93323e0, input_fragment=...) at compiler/rustc_expand/src/expand.rs:497
#41 0x00007ffff6653640 in rustc_expand::expand::MacroExpander::expand_crate (self=0x7fffe9332330, krate=...) at compiler/rustc_expand/src/expand.rs:396
#42 0x00007ffff44a5080 in rustc_interface::passes::configure_and_expand::{{closure}}::{{closure}} () at compiler/rustc_interface/src/passes.rs:334
#43 rustc_data_structures::profiling::VerboseTimingGuard::run<rustc_ast::ast::Crate,closure-2> (self=..., f=...) at /usr/src/rustc-1.55.0/compiler/rustc_data_structures/src/profiling.rs:611
#44 rustc_session::session::Session::time<rustc_ast::ast::Crate,closure-2> (self=<optimized out>, what=..., f=...) at /usr/src/rustc-1.55.0/compiler/rustc_session/src/utils.rs:16
#45 rustc_interface::passes::configure_and_expand::{{closure}} () at compiler/rustc_interface/src/passes.rs:334
#46 rustc_data_structures::profiling::VerboseTimingGuard::run<core::result::Result<rustc_ast::ast::Crate, rustc_errors::ErrorReported>,closure-1> (self=..., f=...)
    at /usr/src/rustc-1.55.0/compiler/rustc_data_structures/src/profiling.rs:611
#47 rustc_session::session::Session::time<core::result::Result<rustc_ast::ast::Crate, rustc_errors::ErrorReported>,closure-1> (self=<optimized out>, what=..., f=...) at /usr/src/rustc-1.55.0/compiler/rustc_session/src/utils.rs:16
#48 0x00007ffff44ded34 in rustc_interface::passes::configure_and_expand (sess=<optimized out>, lint_store=<optimized out>, krate=..., crate_name=..., resolver=<optimized out>) at compiler/rustc_interface/src/passes.rs:280
#49 0x00007ffff450a07c in rustc_interface::queries::{{impl}}::expansion::{{closure}}::{{closure}} (resolver=<optimized out>) at compiler/rustc_interface/src/queries.rs:184
#50 rustc_interface::passes::boxed_resolver::BoxedResolver::access<closure-0,core::result::Result<rustc_ast::ast::Crate, rustc_errors::ErrorReported>> (self=0x7fffe93329a8, f=...) at compiler/rustc_interface/src/passes.rs:142
#51 rustc_interface::queries::{{impl}}::expansion::{{closure}} () at compiler/rustc_interface/src/queries.rs:183
#52 rustc_interface::queries::Query<(alloc::rc::Rc<rustc_ast::ast::Crate>, alloc::rc::Rc<core::cell::RefCell<rustc_interface::passes::boxed_resolver::BoxedResolver>>, alloc::rc::Rc<rustc_lint::context::LintStore>)>::compute<(alloc::rc::Rc<rustc_ast::ast::Crate>, alloc::rc::Rc<core::cell::RefCell<rustc_interface::passes::boxed_resolver::BoxedResolver>>, alloc::rc::Rc<rustc_lint::context::LintStore>),closure-0> (self=<optimized out>, f=...)
    at compiler/rustc_interface/src/queries.rs:38
#53 rustc_interface::queries::Queries::expansion (self=0x7fffe9332c08) at compiler/rustc_interface/src/queries.rs:172
#54 0x00007ffff434d664 in rustc_driver::run_compiler::{{closure}}::{{closure}} (queries=0x7fffe9332c08) at compiler/rustc_driver/src/lib.rs:364
#55 rustc_interface::interface::Compiler::enter<closure-2,core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_errors::ErrorReported>> (self=0x7fffe933a420, f=...)
    at /usr/src/rustc-1.55.0/compiler/rustc_interface/src/queries.rs:390
#56 0x00007ffff43353fc in rustc_driver::run_compiler::{{closure}} (compiler=<optimized out>) at compiler/rustc_driver/src/lib.rs:312
#57 rustc_interface::interface::create_compiler_and_run::{{closure}}<core::result::Result<(), rustc_errors::ErrorReported>,closure-1> () at /usr/src/rustc-1.55.0/compiler/rustc_interface/src/interface.rs:209
#58 rustc_span::with_source_map<core::result::Result<(), rustc_errors::ErrorReported>,closure-0> (source_map=..., f=...) at /usr/src/rustc-1.55.0/compiler/rustc_span/src/lib.rs:911
#59 0x00007ffff434ed88 in rustc_interface::interface::create_compiler_and_run<core::result::Result<(), rustc_errors::ErrorReported>,closure-1> (config=..., f=...) at /usr/src/rustc-1.55.0/compiler/rustc_interface/src/interface.rs:203
#60 0x00007ffff43459a8 in rustc_interface::interface::run_compiler::{{closure}}<core::result::Result<(), rustc_errors::ErrorReported>,closure-1> () at /usr/src/rustc-1.55.0/compiler/rustc_interface/src/interface.rs:225
#61 rustc_interface::util::setup_callbacks_and_run_in_thread_pool_with_globals::{{closure}}::{{closure}}<closure-0,core::result::Result<(), rustc_errors::ErrorReported>> ()
    at /usr/src/rustc-1.55.0/compiler/rustc_interface/src/util.rs:157
#62 scoped_tls::ScopedKey<rustc_span::SessionGlobals>::set<rustc_span::SessionGlobals,closure-0,core::result::Result<(), rustc_errors::ErrorReported>> (self=<optimized out>, t=<optimized out>, f=...)
    at /usr/src/rustc-1.55.0/vendor/scoped-tls/src/lib.rs:137
#63 0x00007ffff43ad010 in rustc_span::create_session_globals_then<core::result::Result<(), rustc_errors::ErrorReported>,closure-0> (edition=<optimized out>, f=...) at /usr/src/rustc-1.55.0/compiler/rustc_span/src/lib.rs:105
#64 rustc_interface::util::setup_callbacks_and_run_in_thread_pool_with_globals::{{closure}}<closure-0,core::result::Result<(), rustc_errors::ErrorReported>> () at /usr/src/rustc-1.55.0/compiler/rustc_interface/src/util.rs:155
#65 rustc_interface::util::scoped_thread::{{closure}}<closure-0,core::result::Result<(), rustc_errors::ErrorReported>> () at /usr/src/rustc-1.55.0/compiler/rustc_interface/src/util.rs:130
#66 std::sys_common::backtrace::__rust_begin_short_backtrace<closure-0,()> (f=...) at /usr/src/rustc-1.55.0/library/std/src/sys_common/backtrace.rs:125
#67 0x00007ffff432b274 in std::thread::{{impl}}::spawn_unchecked::{{closure}}::{{closure}}<closure-0,()> () at /usr/src/rustc-1.55.0/library/std/src/thread/mod.rs:476
#68 std::panic::{{impl}}::call_once<(),closure-0> (self=..., _args=<optimized out>) at /usr/src/rustc-1.55.0/library/std/src/panic.rs:347
#69 std::panicking::try::do_call<std::panic::AssertUnwindSafe<closure-0>,()> (data=<optimized out>) at /usr/src/rustc-1.55.0/library/std/src/panicking.rs:401
#70 std::panicking::try<(),std::panic::AssertUnwindSafe<closure-0>> (f=...) at /usr/src/rustc-1.55.0/library/std/src/panicking.rs:365
#71 std::panic::catch_unwind<std::panic::AssertUnwindSafe<closure-0>,()> (f=...) at /usr/src/rustc-1.55.0/library/std/src/panic.rs:434
#72 std::thread::{{impl}}::spawn_unchecked::{{closure}}<closure-0,()> () at /usr/src/rustc-1.55.0/library/std/src/thread/mod.rs:475
#73 core::ops::function::FnOnce::call_once<closure-0,()> () at /usr/src/rustc-1.55.0/library/core/src/ops/function.rs:227
#74 0x00007ffff3aadf54 in alloc::boxed::{{impl}}::call_once<(),FnOnce<()>,alloc::alloc::Global> (self=..., args=<optimized out>) at /usr/src/rustc-1.55.0/library/alloc/src/boxed.rs:1572
#75 alloc::boxed::{{impl}}::call_once<(),alloc::boxed::Box<FnOnce<()>, alloc::alloc::Global>,alloc::alloc::Global> (self=0x1000de4e0, args=<optimized out>) at /usr/src/rustc-1.55.0/library/alloc/src/boxed.rs:1572
#76 std::sys::unix::thread::{{impl}}::new::thread_start (main=0x1000de4e0) at library/std/src/sys/unix/thread.rs:74
#77 0x00007fffed3c90a4 in start_thread () from /lib/powerpc64le-linux-gnu/libpthread.so.0
#78 0x00007ffff392d054 in clone () from /lib/powerpc64le-linux-gnu/libc.so.6

@Mark-Simulacrum
Copy link
Member

Hm, yeah, that definitely seems like something is going wrong with the procedural macro interface, but I'm not sure what would be responsible.

It looks like

IntoIter(self.0.into_iter())
is segfaulting (well, not directly there, but that's the "root" of the normal code that then calls into the proc macro C ABI shuffling code...

It seems like the segfault suggests that env is not a valid pointer here (it does look a bit too small / wrong, but not sure if that's typical on powerpc)...

proc_macro::bridge::closure::{{impl}}::from::call<proc_macro::bridge::buffer::Buffer<u8>,proc_macro::bridge::buffer::Buffer<u8>,closure-0> (env=0x141a, arg=...) at /usr/src/rustc-1.55.0/library/proc_macro/src/bridge/closure.rs:19
19                  (*(env as *mut _ as *mut F))(arg)

@Mark-Simulacrum
Copy link
Member

It seems unlikely (AFAICT, the closure code here doesn't use any unstable details) but perhaps #81360 is somehow at fault? (cc @Aaron1011)

Maybe you can check a temporary revert of that...

@infinity0
Copy link
Contributor Author

I've minimised the segfaulting code to:

pub use rustc_target;

fn test() {
  cstr::cstr!("cmse_nonsecure_call");
}

Deleting either the function or the use statement makes the compilation go successfully; the import can also be replaced by one of the other rustc_* modules e.g. _codegen_ssa or _middle, but switching it to e.g. std makes the segfault also go away...

@infinity0
Copy link
Contributor Author

Further found out that rustc_data_structures as the import also works to preserve the segfault, but using any of its dependencies makes it go away. If this raises any bells let me know - I don't know what to do after that, so I'll wipe this build directory and retry with #81360 reverted.

@infinity0
Copy link
Contributor Author

@Mark-Simulacrum unfortunately the build still fails with the same error, after reverting that PR specifically on top of 1.55.0.

Wondering if @cuviper has any ideas; apparently 1.55 built fine on Fedora https://kojipkgs.fedoraproject.org//packages/rust/1.55.0/1.el7/data/logs/ppc64le/build.log (though there are more test failures than we usually have on ppc64el in Debian).

@infinity0
Copy link
Contributor Author

I am trying to figure out if there are any significant differences between rust and Debian's LLVM; is it just the [rust] commits in https://github.com/rust-lang/llvm-project/commits/bdb386270f55cb8e95793daa296f27a95a6d4834 ?

@infinity0
Copy link
Contributor Author

I can work around the problem by patching away the calls to cstr! in rustc_codegen_llvm to instead directly say what the proc-macro would have generated (or actually, doing it with a regular macro also works). The rest of the rustc build then works. Do you think this is acceptable?

Separately, is there a proc-macro heavy crate or system of crates I can test this against, to ensure it doesn't break them?

@cuviper
Copy link
Member

cuviper commented Oct 11, 2021

I noticed that you have a very old cargo ppc64el 0.47.0-3+b1, where cargo -V reports 1.46.0. It is generally expected that Rust and Cargo versions should be in sync, and while it might work with some drift, it is not going to be well-supported.

To that end, I can reproduce the crash in a debian:sid container using the system rustc, cargo, and llvm-12. However, if I configure it to use the upstream binary for cargo 1.54.0, still with system rustc and llvm-12, then it builds fine. I don't know what specifically changed in cargo that would affect this, nor why that would only affect powerpc64le.

@infinity0
Copy link
Contributor Author

Thanks for that, then it seems I could probably use the work-around mentioned above, then un-apply it after we do find the time to update cargo in Debian.

FWIW I did check over the release notes of cargo and didn't notice anything that stood out. As I understand, the interface between rustc and cargo is a high-level interface involving basic interprocess UNIX things like envvars and command-line flags. (As opposed to, low-level ABI things like linking and CPU/hardware-specific details.) Even if cargo is out-of-sync with rustc, it would just be supplying unexpected command-line options or envvars or something along these lines, which a user could have done manually. Indeed when reproducing this segfault manually for debugging and minimisation, I am only calling rustc and not dealing with cargo at all. Even the dependencies that it's using, were ultimately directly produced by rustc, and only indirectly via cargo. So along these lines, I would imagine that rustc is not supposed to be segfaulting even if cargo goes wildly out-of-date with it, and there is still a bug somewhere?

@cuviper
Copy link
Member

cuviper commented Oct 11, 2021

It also fails with upstream 0.47.0 / 1.46.0, but it works with cargo 0.48.0 / 1.47.0, and this does have a relevant change:

  • By default, build scripts and proc-macros are now built with opt-level=0 and the default codegen units, even in release mode. #8500

So if there's a powerpc64le optimization bug arising in proc-macros, as your investigation has pinpointed in cstr, then newer cargo will avoid it by not optimizing. That's not very satisfying...

So along these lines, I would imagine that rustc is not supposed to be segfaulting even if cargo goes wildly out-of-date with it, and there is still a bug somewhere?

Yes, I agree, failures due to version mismatch should be much more obvious / less harmful than a segfault.

@cuviper cuviper added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. O-PowerPC Target: PowerPC processors T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 11, 2021
@cuviper
Copy link
Member

cuviper commented Oct 12, 2021

Another test: using the system cargo and rustc, and the bundled LLVM, it still crashes in the same place.

@infinity0
Copy link
Contributor Author

Thanks for that, I've also reproduced the same crash with Debian rustc + upstream cargo 1.55.0 by setting export CARGO_PROFILE_RELEASE_BUILD_OVERRIDE_OPT_LEVEL=3 as that PR says. Calling it a night now but the next thing would be to try it with the upstream rustc.

@infinity0
Copy link
Contributor Author

The crash does not reproduce with plain upstream rustc 1.55, using upstream rustc+cargo 1.54 as bootstrap. I'll try to figure out what the difference is with the Debian rustc that might be triggering this.

@infinity0
Copy link
Contributor Author

OK, I can reproduce the crash with plain upstream (non-Debian) rustc 1.55 using the following minimal config.toml, and setting CARGO_PROFILE_RELEASE_BUILD_OVERRIDE_OPT_LEVEL=3:

[build]
extended = true
tools = ["cargo"]

The segfault reproduces with either rls, clippy, rustfmt in place of cargo in tools, and goes away (compiles OK) when replaced with analysis or src.

To confirm, the segfault is during building stage1 rustc_codegen_llvm, before the build even gets to building the tools so this is a bit confusing. Would you have any theories @Mark-Simulacrum ?

@Mark-Simulacrum
Copy link
Member

The segfault reproduces with either rls, clippy, rustfmt in place of cargo in tools, and goes away (compiles OK) when replaced with analysis or src.

This definitely seems.. surprising, I wouldn't expect that stage of the build to even be affected by which tools are enabled/disabled. This is deterministic? Is there any difference in logs (e.g., maybe the features set by Cargo are different for some crate?)

I did just notice one interesting thing, that might be worth checking. The compile log you showed above has -Ztls-model=initial-exec being passed, but on our current master, we've disabled that for powerpc targets after #81334 was filed -- #85807 landed in 1.56, so it would not have been included in 1.55. However we added that to the build system in 1.49 (#78201) so I would have expected this problem to arise earlier...

Given that the problem seems to be proc-macro related, it seems at least plausible that the cause is due to lacking support in LLVM that has been undetected until now. Procedural macros definitely make extensive use of TLS to hold state while passing it back and forth, so it wouldn't surprise me too much if the bugs are related.

So I think next steps:

  • Let's try disabling the -Ztls-model=initial-exec for your 1.55 builds
  • If that doesn't work, let's see if we can add extra logging or compare existing logs to make sure the builds with the two failing and working tools options are the same up until that point.

@cuviper
Copy link
Member

cuviper commented Oct 13, 2021

That change for "powerpc-" would only affect 32-bit, not powerpc64le.

@Mark-Simulacrum
Copy link
Member

Ah, good catch. Still seems worth finding out if we should actually disable on 64-bit as well...

@infinity0
Copy link
Contributor Author

We've actually been including #85807 in Debian since 1.49 but yeah that's only for 32-bit ppc. I amended it to include 64-bit ppc but the segfault remains. (And in my original testing, the segfault reproduced without any special flags, although that was just repeatedly attempting to compile rustc_codgen_llvm and leaving the already-built dependencies alone.)

In the meantime I've found that the segfault reproduces with CARGO_PROFILE_RELEASE_BUILD_OVERRIDE_OPT_LEVEL=2 but not with =1.

Also the extended / tools thing was a just red herring, it was just because I was running ./x.py build without any explicit targets, it wasn't even building stage 1 rustc in the cases where it "succeeded". If I run ./x.py build compiler/rustc the segfault reproduces even without any config.toml, i.e. from a clean extraction of the release tarball (with OPT=2 or 3).

Next, I will try to figure out which particular crate's build.rs switching between OPT 1 vs 2 makes the difference.

@cuviper
Copy link
Member

cuviper commented Oct 13, 2021

Can you see if beta and nightly also fail? Beta has LLVM 13, and nightly has further enabled the new pass manager.

@infinity0
Copy link
Contributor Author

Beta segfaults, nightly works (with beta as bootstrap). Tested with CARGO_PROFILE_RELEASE_BUILD_OVERRIDE_OPT_LEVEL=3.

Next, I will try to figure out which particular crate's build.rs switching between OPT 1 vs 2 makes the difference.

It seems cargo doesn't support per-crate overrides, only whole-workspace overrides, so I can't easily track this down. https://doc.rust-lang.org/cargo/reference/profiles.html#overrides Since it's fixed on nightly, perhaps I'll leave the investigation here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. O-PowerPC Target: PowerPC processors T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants