www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 18816] New: [betterC] Standard Streams Unlinkable

https://issues.dlang.org/show_bug.cgi?id=18816

          Issue ID: 18816
           Summary: [betterC] Standard Streams Unlinkable
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: druntime
          Assignee: nobody puremagic.com
          Reporter: devddstuff gmail.com

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).

--
May 01 2018