D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 2837 - OPTLINK and LARGEADDRESSAWARE
Summary: OPTLINK and LARGEADDRESSAWARE
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: tools (show other issues)
Version: D2
Hardware: x86 Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: Optlink
: 5631 (view as issue list)
Depends on:
Blocks:
 
Reported: 2009-04-15 12:39 UTC by Walter Bright
Modified: 2017-01-10 01:38 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Walter Bright 2009-04-15 12:39:35 UTC
Vladimir Panteleev writes:

It seems that OPTLINK doesn't support the IMAGE_FILE_LARGE_ADDRESS_AWARE flag (enabled with /LARGEADDRESSAWARE when using Microsoft Link), even though the D runtime seems to support it.

Consider this simple program:

-----------------------------
import std.stdio;

void main()
{
    ubyte[][4096] a; // GC anchor
    for (int i=0;;i++)
    {
        writefln(i);
        a[i].length = 1024*1024;
    }
}
-----------------------------

This program crashes when it tries to allocate the 1618th megabyte, even though my PC has 6 GB of RAM and the 32-bit address space allows for much more.

I've patched the executable and enabled the IMAGE_FILE_LARGE_ADDRESS_AWARE flag. This flag is 0x0020 in the "Characteristics" field in the IMAGE_FILE_HEADER structure. In OPTLINK-generated executables, one can enable this flag manually by changing byte 0x76 from 0x8E to 0xAE in the executable file.

The result - the program can now allocate 3319 megabytes on my machine, thus practically doubling its address space.
(Why is it still not anywhere near the theoretical limit?)

I've patched my copy of the linker until the official linker is updated. If anyone wants to use more than 2 (or 1.6?) GB in their DMD/Windows programs, change the byte at 0x3CF0D in link.exe from 0x8F to 0xAF.
Comment 1 Vladimir Panteleev 2011-02-21 10:25:24 UTC
*** Issue 5631 has been marked as a duplicate of this issue. ***
Comment 2 yebblies 2012-11-01 01:26:47 UTC
Is there any reason we can't just have IMAGE_FILE_LARGE_ADDRESS_AWARE set by default?
Comment 3 Walter Bright 2012-11-02 01:30:36 UTC
Generally, a program that consumes all of memory can bring the system to a halt. So only if your program really needs it should it be turned on.
Comment 4 Rainer Schuetze 2013-11-23 02:36:52 UTC
/LARGEADDRESSAWARE was added in optlink 8.00.13 that comes with dmd 2.064.