Bug 18816 – [betterC] Standard Streams Unlinkable

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
All
OS
Windows
Creation time
2018-05-01T22:41:04Z
Last change time
2022-02-14T09:34:36Z
Keywords
pull
Assigned to
No Owner
Creator
dd86k

Comments

Comment #0 by devddstuff — 2018-05-01T22:41:04Z
The standard streams (stdin, stdout, and stdout) are unlinkable when strictly using -betterC when compiling with MS-COFF and ELF formats (tested). This affects usage of fputs, but not puts, regardless used with core.stdc.stdio or manually extern'd in source. Consider this code on Windows (as e.d): ``` import core.stdc.stdio : fputs, stdout; extern(C) void main() { fputs("test", stdout); } ``` By default, it generates an OMF image and runs 100% fine. Under -m32mscoff and -m64, the Microsoft Linker mentions `_stdout` being unresolved. This affects LDC wholesomely since it only uses MS-COFF files (and the Microsoft Linker). For the last few days, I've checked my SDK, Visual Studio, and DMD+LDC installs. The required library gets included just fine. Rebinding _iob has not been successful for me (extern/extern (C), __gshared/shared, etc.). I've even tried go follow stdio.h in my SDK install (FILE[_IOB_ENTRIES]). Furthest I got was it to compile and link with: ``` private extern __gshared FILE[_IOB_ENTRIES] _iob; // ._ptr enum stdin = &_iob[0]; /// Standard input stream enum stdout = &_iob[1]; /// Standard output stream ``` If I name _iob as iob or __iob, the linker can't resolve _iob, so it at least finds the reference in the library that it includes (Microsoft C Runtime stuff). However I kept getting access violations (C000_0005h).
Comment #1 by greensunny12 — 2018-08-15T23:50:36Z
FYI: this works just fine under Linux/-betterC (see e.g. https://run.dlang.io/is/ys1XcZ), so it looks like this is solely a Windows problem (changing the labels accordingly)
Comment #2 by devddstuff — 2018-08-16T02:33:20Z
Forgot about this ticket. I made it work under Windows, see https://github.com/dd86k/dd-dos/blob/master/src/ddc/ddc.d#L63-L69 (and _NFILE). I almost pulled the repo and make a pull request, so feel free to base a pull request off of my ddc.d source. For people refusing to click on the Github link: enum _NFILE = 20; ... private extern extern(C) shared FILE[_NFILE] _iob; shared stdin = &_iob[0]; shared stdout = &_iob[1]; shared stderr = &_iob[2]; shared stdaux = &_iob[3]; shared stdprn = &_iob[4]; I had to play with the source a lot, but I'm happy to say my (temporary?) source works for -m32mscoff and -m64 under DMD and LDC2. -m32 under DMD remains unaffected since it uses the DigitalMars C runtime. Works on my Windows 10 1506 machine. Might be different runtime version, who knows.
Comment #3 by dlang-bot — 2022-02-12T11:19:38Z
@rainers created dlang/druntime pull request #3740 "fix issue 19933 and 18816: MSVC: Undefined std{in,out,err} with -betterC" fixing this issue: - fix issue 19933 and 18816: MSVC: Undefined std{in,out,err} with -betterC moved C runtime check into template function https://github.com/dlang/druntime/pull/3740
Comment #4 by dlang-bot — 2022-02-14T09:34:36Z
dlang/druntime pull request #3740 "fix issue 19933 and 18816: MSVC: Undefined std{in,out,err} with -betterC" was merged into master: - e7e6800babed4ff51b6c3b57dfa7e54cb76247f7 by Rainer Schuetze: fix issue 19933 and 18816: MSVC: Undefined std{in,out,err} with -betterC made stdin/out/err template function return value https://github.com/dlang/druntime/pull/3740