Closed
Description
$ cat a.rs
fn main() { println("hello"); }
$ rustc.exe a.rs -o a.exe --link-args "-Wl,--subsystem,windows"
--subsystem windows
means the program does not have console, and _write(1, ...)
will return -1 with errno EBADF
.
So at fd_t::write() if nout < 0 as IoRet
is triggered, and error!()
and fail!()
are called.
However, while printing error, _write(2, ...)
also returns -1 and fd_t::write()
raises another error. It causes segfault:
$ gdb ./a.exe
(gdb) run
...
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 40012.0x8888]
0x7598d1d4 in KERNELBASE!FlushInstructionCache () from C:\Windows\SysWOW64\KernelBase.dll
(gdb) bt 10
#0 0x7598d1d4 in KERNELBASE!FlushInstructionCache () from C:\Windows\SysWOW64\KernelBase.dll
#1 0x7598d1ae in KERNELBASE!FlushInstructionCache () from C:\Windows\SysWOW64\KernelBase.dll
#2 0x7598d37f in KERNELBASE!GetConsoleScreenBufferInfoEx () from C:\Windows\SysWOW64\KernelBase.dll
#3 0x75c1c427 in printf () from C:\Windows\SysWOW64\msvcrt.dll
#4 0xfffffffe in ?? ()
#5 0x025750b4 in ?? ()
#6 0x75c1bf52 in write () from C:\Windows\SysWOW64\msvcrt.dll
#7 0x00000002 in ?? ()
#8 0x005e3810 in ?? ()
#9 0x6258e108 in io::Writer$fd_t::write::hfc348125316ee38egak::v0.8 ()
from C:\home\stone\rust\build\i686-pc-mingw32\stage2\bin\std-6c65cf4b443341b1-0.8.dll
(More stack frames follow...)
(gdb) bt -20
#9765 0x6258e321 in io::Writer$fd_t::write::hfc348125316ee38egak::v0.8 ()
from C:\home\stone\rust\build\i686-pc-mingw32\stage2\bin\std-6c65cf4b443341b1-0.8.dll
#9766 0x625c8394 in rt::logging::Logger$StdErrLogger::log::hdc331d7fb995175b7waL::v0.8 ()
from C:\home\stone\rust\build\i686-pc-mingw32\stage2\bin\std-6c65cf4b443341b1-0.8.dll
#9767 0x6258e321 in io::Writer$fd_t::write::hfc348125316ee38egak::v0.8 ()
from C:\home\stone\rust\build\i686-pc-mingw32\stage2\bin\std-6c65cf4b443341b1-0.8.dll
#9768 0x625c8394 in rt::logging::Logger$StdErrLogger::log::hdc331d7fb995175b7waL::v0.8 ()
from C:\home\stone\rust\build\i686-pc-mingw32\stage2\bin\std-6c65cf4b443341b1-0.8.dll
#9769 0x6258e321 in io::Writer$fd_t::write::hfc348125316ee38egak::v0.8 ()
from C:\home\stone\rust\build\i686-pc-mingw32\stage2\bin\std-6c65cf4b443341b1-0.8.dll
#9770 0x625c8394 in rt::logging::Logger$StdErrLogger::log::hdc331d7fb995175b7waL::v0.8 ()
from C:\home\stone\rust\build\i686-pc-mingw32\stage2\bin\std-6c65cf4b443341b1-0.8.dll
#9771 0x6258e321 in io::Writer$fd_t::write::hfc348125316ee38egak::v0.8 ()
from C:\home\stone\rust\build\i686-pc-mingw32\stage2\bin\std-6c65cf4b443341b1-0.8.dll
#9772 0x625c8394 in rt::logging::Logger$StdErrLogger::log::hdc331d7fb995175b7waL::v0.8 ()
from C:\home\stone\rust\build\i686-pc-mingw32\stage2\bin\std-6c65cf4b443341b1-0.8.dll
#9773 0x6258e321 in io::Writer$fd_t::write::hfc348125316ee38egak::v0.8 ()
from C:\home\stone\rust\build\i686-pc-mingw32\stage2\bin\std-6c65cf4b443341b1-0.8.dll
#9774 0x00401429 in main::hccef5615fba560d8af::v0.0 ()
#9775 0x625def1d in unstable::lang::start::anon::expr_fn::aD ()
from C:\home\stone\rust\build\i686-pc-mingw32\stage2\bin\std-6c65cf4b443341b1-0.8.dll
#9776 0x625e613f in rt::task::__extensions__::build_start_wrapper::anon::anon::expr_fn::aL ()
from C:\home\stone\rust\build\i686-pc-mingw32\stage2\bin\std-6c65cf4b443341b1-0.8.dll
#9777 0x625e4842 in rt::task::__extensions__::run::anon::expr_fn::a3 ()
from C:\home\stone\rust\build\i686-pc-mingw32\stage2\bin\std-6c65cf4b443341b1-0.8.dll
#9778 0x625e6409 in rt::task::Unwinder::try::try_fn::h2eb15e2727b07bNUaH::v0.8 ()
from C:\home\stone\rust\build\i686-pc-mingw32\stage2\bin\std-6c65cf4b443341b1-0.8.dll
#9779 0x6e142196 in rust_try (f=0x625e63d0 <rt::task::Unwinder::try::try_fn::h2eb15e2727b07bNUaH::v0.8>,
fptr=0x625e4810, env=0x275d360) at C:/home/stone/rust/src/rt/rust_builtin.cpp:531
#9780 0x625e46ef in rt::task::Unwinder::try::h199ab8d6eb226980NUa2::v0.8 ()
from C:\home\stone\rust\build\i686-pc-mingw32\stage2\bin\std-6c65cf4b443341b1-0.8.dll
#9781 0x625e4558 in rt::task::Task::run::h199ab8d6eb226980I3a1::v0.8 ()
from C:\home\stone\rust\build\i686-pc-mingw32\stage2\bin\std-6c65cf4b443341b1-0.8.dll
#9782 0x625e5d8e in rt::task::__extensions__::build_start_wrapper::anon::expr_fn::aC ()
from C:\home\stone\rust\build\i686-pc-mingw32\stage2\bin\std-6c65cf4b443341b1-0.8.dll
#9783 0x62631262 in rt::context::Context::new::task_start_wrapper::h1b9fdc38dc3bcfa4xQaw::v0.8 ()
from C:\home\stone\rust\build\i686-pc-mingw32\stage2\bin\std-6c65cf4b443341b1-0.8.dll
#9784 0x00000000 in ?? ()