-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
format_args! with certain arguments segfaults at run-time on x86_64-unknown-linux-gnux32 #59220
Comments
cc @malbarbo who I believe initially added this target Since this is not a tier 1 target I am not nominating for the compiler team to take a look (we don't have the resources to support it at this point). |
Some additional information:
rm 32
rustc -C opt-level=0 -g --emit=llvm-ir main.rs -o x32.ll --target x86_64-unknown-linux-gnux32
LLVM_HOME=/usr/lib/llvm/10/
$LLVM_HOME/bin/llvm-as x32.ll
$LLVM_HOME/bin/opt -load ~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnux32/lib/libtest-1b777edb18de95a1.so -o x32.bc x32.bc
$LLVM_HOME/bin/llc -filetype=obj x32.bc
$LLVM_HOME/bin/clang -g -o 32 -mx32 x32.o -L ~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnux32/lib/ -lstd-f6f0a67eb2dc7ef6
LD_LIBRARY_PATH=~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnux32/lib/ ./32
rm 32
rustc main.rs -C opt-level=0 -o 32 -g --emit=llvm-ir -O -C no-prepopulate-passes -C codegen-units=1 --target x86_64-unknown-linux-gnux32
$LLVM_HOME/bin/llvm-as x32.ll
$LLVM_HOME/bin/opt -load ~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnux32/lib/libtest-1b777edb18de95a1.so -o x32.bc x32.bc
$LLVM_HOME/bin/llc -filetype=obj x32.bc
$LLVM_HOME/bin/clang -g -o 32 -mx32 x32.o -L ~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnux32/lib/ -lstd-f6f0a67eb2dc7ef6
LD_LIBRARY_PATH=~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnux32/lib/ ./32
rm 32
rustc -C opt-level=0 -g --emit=llvm-bc main.rs -o x32.bc --target x86_64-unknown-linux-gnux32
$LLVM_HOME/bin/llc -filetype=obj x32.bc
$LLVM_HOME/bin/clang -g -o 32 -mx32 x32.o -L ~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnux32/lib/ -lstd-f6f0a67eb2dc7ef6
LD_LIBRARY_PATH=~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnux32/lib/ ./32 All this parts build x32 binary that work fine. And debugging original binary builded from rustc with gdb. I set breakpoint on main and disassemble code. I check 4 variants with
There are <<&T as core::fmt::Display>::fmt> in the beginning of main::main In correct binaries. But in corrupted there isn't.
|
This should be fixed automatically the next time rust updates to a newer LLVM. I have recently committed patches to fix x32 codegen to upstream LLVM and am locally running rust with those same patches applied. The test case in this issue works fine here, as do various bigger rust programs such as ripgrep, and with a few trivial patches, rustc itself. |
@hvdijk this is about |
Yes, those are the only modifications needed on the Rust side of things (as opposed to the LLVM side) to get a working x32 rustc binary. The |
@hvdijk can you say version of llvm or hash with fix? |
LLVM 12 will have the fixes. |
#81451 was merged and I checked that this issue was indeed fixed. |
Trying to display most types causes a segmentation fault at run time when compiled in debug mode for x32 ABI
Example:
println!
,format!
andformat_args!
equally affected,.to_string()
is not.i8
tou128
,f32
,f64
,bool
,char
andfmt::Argument
, but not with references to those types orstr
,String
and raw pointers."{:?}"
,"{:#?}"
and"{:p}"
) are not affect, but all other format traits ("{:x}"
,"{:02}",
"{:#b}"`) all result in a segfault.Debugging attempt & assembly
The segfault happens at the second instruction in main;
here's what that area looks like with
... --emit asm
:and after disassembling: (
objcopy -dr rust_out | rg -A10 'rust_out.*?main'
With
-O
the compiler emitsFor
println!("{:?}", 0)
:and for
println!("{}", &0)
Meta
The text was updated successfully, but these errors were encountered: