Skip to content

Windows: stdout/stderr on --subsystem windows #9486

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
klutzy opened this issue Sep 25, 2013 · 5 comments
Closed

Windows: stdout/stderr on --subsystem windows #9486

klutzy opened this issue Sep 25, 2013 · 5 comments
Labels
O-windows Operating system: Windows

Comments

@klutzy
Copy link
Contributor

klutzy commented Sep 25, 2013

$ 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 ?? ()
@klutzy
Copy link
Contributor Author

klutzy commented Sep 25, 2013

I think stdout failure is ok, but we should not use stderr when it does not exist.

Seems that haskell redirects to "debug console".

@klutzy
Copy link
Contributor Author

klutzy commented Jan 22, 2014

cc #3309 since this is related to logging system: logger should not assume stderr is always available, and it should provide other way in the case.

@retep998
Copy link
Member

For comparison, C++ on windows without the console, cout and printf will continue to work fine, happily accepting your output without erroring.

@vadimcn
Copy link
Contributor

vadimcn commented Feb 20, 2015

Looks like this had been fixed.

@vadimcn
Copy link
Contributor

vadimcn commented Mar 2, 2015

cc @gankro, @huonw.

@huonw huonw closed this as completed Mar 2, 2015
flip1995 pushed a commit to flip1995/rust that referenced this issue Oct 6, 2022
[`unnecessary_lazy_eval`] Do not lint in external macros

fix rust-lang/rust-clippy#9485, fix rust-lang/rust-clippy#9439

I didn't find a way to add a test since fps occur due to an external crate.

changelog: [`unnecessary_lazy_eval`] Do not lint in external macros
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
O-windows Operating system: Windows
Projects
None yet
Development

No branches or pull requests

4 participants