Skip to content

Commit

Permalink
Merge pull request #6503 from WalterBright/fix14859
Browse files Browse the repository at this point in the history
reboot #6081: Fix issue 14859 - 16MiB size limit for static array
  • Loading branch information
andralex committed Feb 11, 2017
2 parents f08c368 + 07855a2 commit 14ba1f6
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 8 deletions.
7 changes: 4 additions & 3 deletions src/mtype.d
Expand Up @@ -4780,13 +4780,14 @@ extern (C++) final class TypeSArray : TypeArray
if (d1 != d2)
{
Loverflow:
error(loc, "%s size %llu * %llu exceeds 16MiB size limit for static array", toChars(), cast(ulong)tbn.size(loc), cast(ulong)d1);
error(loc, "%s size %llu * %llu exceeds 0x%llx size limit for static array",
toChars(), cast(ulong)tbn.size(loc), cast(ulong)d1, Target.maxStaticDataSize);
goto Lerror;
}
Type tbx = tbn.baseElemOf();
if (tbx.ty == Tstruct && !(cast(TypeStruct)tbx).sym.members || tbx.ty == Tenum && !(cast(TypeEnum)tbx).sym.members)
{
/* To avoid meaningess error message, skip the total size limit check
/* To avoid meaningless error message, skip the total size limit check
* when the bottom of element type is opaque.
*/
}
Expand All @@ -4796,7 +4797,7 @@ extern (C++) final class TypeSArray : TypeArray
* run on them for the size, since they may be forward referenced.
*/
bool overflow = false;
if (mulu(tbn.size(loc), d2, overflow) >= 0x100_0000 || overflow) // put a 'reasonable' limit on it
if (mulu(tbn.size(loc), d2, overflow) >= Target.maxStaticDataSize || overflow)
goto Loverflow;
}
}
Expand Down
17 changes: 17 additions & 0 deletions src/target.d
Expand Up @@ -32,6 +32,7 @@ struct Target
extern (C++) static __gshared int c_longsize; // size of a C 'long' or 'unsigned long' type
extern (C++) static __gshared int c_long_doublesize; // size of a C 'long double'
extern (C++) static __gshared int classinfosize; // size of 'ClassInfo'
extern (C++) static __gshared ulong maxStaticDataSize; // maximum size of static data

template FPTypeProperties(T)
{
Expand Down Expand Up @@ -66,6 +67,15 @@ struct Target
// adjusted for 64 bit code.
ptrsize = 4;
classinfosize = 0x4C; // 76

/* gcc uses int.max for 32 bit compilations, and long.max for 64 bit ones.
* Set to int.max for both, because the rest of the compiler cannot handle
* 2^64-1 without some pervasive rework. The trouble is that much of the
* front and back end uses 32 bit ints for sizes and offsets. Since C++
* silently truncates 64 bit ints to 32, finding all these dependencies will be a problem.
*/
maxStaticDataSize = int.max;

if (global.params.isLP64)
{
ptrsize = 8;
Expand All @@ -92,6 +102,13 @@ struct Target
realalignsize = 2;
reverseCppOverloads = true;
c_longsize = 4;
if (ptrsize == 4)
{
/* Optlink cannot deal with individual data chunks
* larger than 16Mb
*/
maxStaticDataSize = 0x100_0000; // 16Mb
}
}
else
assert(0);
Expand Down
1 change: 1 addition & 0 deletions src/target.h
Expand Up @@ -33,6 +33,7 @@ struct Target
static int c_longsize; // size of a C 'long' or 'unsigned long' type
static int c_long_doublesize; // size of a C 'long double'
static int classinfosize; // size of 'ClassInfo'
static unsigned long long maxStaticDataSize; // maximum size of static data

static void init();
// Type sizes and support.
Expand Down
4 changes: 2 additions & 2 deletions src/toobj.d
Expand Up @@ -851,9 +851,9 @@ void toObjFile(Dsymbol ds, bool multiobj)
vd.error("size overflow");
return;
}
if (sz64 >= 0x1000000) // there has to be some 'reasonable' limit on the size
if (sz64 >= Target.maxStaticDataSize)
{
vd.error("size of x%llx exceeds max allowed size 0x100_0000", sz64);
vd.error("size of 0x%llx exceeds max allowed size 0x%llx", sz64, Target.maxStaticDataSize);
}
uint sz = cast(uint)sz64;

Expand Down
3 changes: 1 addition & 2 deletions test/fail_compilation/fail4611.d
@@ -1,7 +1,6 @@
/*
TEST_OUTPUT:
---
fail_compilation/fail4611.d(15): Error: Vec[1000000000] size 4 * 1000000000 exceeds 16MiB size limit for static array
fail_compilation/fail4611.d(15): Error: Vec[1000000000] size 4 * 1000000000 exceeds 0x7fffffff size limit for static array
---
*/

Expand Down
1 change: 0 additions & 1 deletion test/fail_compilation/staticarrayoverflow.d
@@ -1,7 +1,6 @@
/*
REQUIRED_ARGS: -m64
PERMUTE_ARGS:
TEST_OUTPUT:
---
fail_compilation/staticarrayoverflow.d(21): Error: static array S[1879048192] size overflowed to 7516192768000
fail_compilation/staticarrayoverflow.d(21): Error: variable staticarrayoverflow.y size overflow
Expand Down

0 comments on commit 14ba1f6

Please sign in to comment.