Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #891 from AndrewEdwards/2.066
Browse files Browse the repository at this point in the history
Regression fixes for 2.066.0-b4
  • Loading branch information
9rnsr committed Jul 15, 2014
2 parents d8fc4a0 + e2c9626 commit e36d35c
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 40 deletions.
2 changes: 1 addition & 1 deletion posix.mak
Expand Up @@ -108,7 +108,7 @@ SRCS:=$(subst \,/,$(SRCS))
# NOTE: a pre-compiled minit.obj has been provided in dmd for Win32 and
# minit.asm is not used by dmd for Linux

OBJS= $(OBJDIR)/errno_c.o $(OBJDIR)/threadasm.o
OBJS= $(OBJDIR)/errno_c.o $(OBJDIR)/bss_section.o $(OBJDIR)/threadasm.o

######################## All of'em ##############################

Expand Down
65 changes: 32 additions & 33 deletions src/core/checkedint.d
Expand Up @@ -444,27 +444,28 @@ unittest

uint mulu(uint x, uint y, ref bool overflow)
{
uint r = x * y;
if (r && (r < x || r < y))
ulong r = ulong(x) * ulong(y);
if (r > uint.max)
overflow = true;
return r;
return cast(uint)r;
}

unittest
{
bool overflow;
assert(mulu(2, 3, overflow) == 6);
assert(!overflow);
assert(mulu(1, uint.max, overflow) == uint.max);
assert(!overflow);
assert(mulu(uint.min, 1, overflow) == uint.min);
assert(!overflow);
assert(mulu(uint.max, 2, overflow) == (uint.max * 2));
assert(overflow);
overflow = false;
assert(mulu(uint.min, -1, overflow) == uint.min);
assert(!overflow);
overflow = true;
void test(uint x, uint y, uint r, bool overflow) @nogc nothrow
{
bool o;
assert(mulu(x, y, o) == r);
assert(o == overflow);
}
test(2, 3, 6, false);
test(1, uint.max, uint.max, false);
test(0, 1, 0, false);
test(0, uint.max, 0, false);
test(uint.max, 2, 2 * uint.max, true);
test(1 << 16, 1U << 16, 0, true);

bool overflow = true;
assert(mulu(0, 0, overflow) == 0);
assert(overflow); // sticky
}
Expand All @@ -473,29 +474,27 @@ unittest
ulong mulu(ulong x, ulong y, ref bool overflow)
{
ulong r = x * y;
if (r && (r < x || r < y))
if (x && (r / x) != y)
overflow = true;
return r;
}

unittest
{
bool overflow;
assert(mulu(2UL, 3UL, overflow) == 6);
assert(!overflow);
assert(mulu(1, ulong.max, overflow) == ulong.max);
assert(!overflow);
assert(mulu(ulong.min, 1, overflow) == ulong.min);
assert(!overflow);
assert(mulu(ulong.max, 2, overflow) == (ulong.max * 2));
assert(overflow);
overflow = false;
assert(mulu(ulong.min, -1, overflow) == ulong.min);
assert(!overflow);
overflow = true;
void test(ulong x, ulong y, ulong r, bool overflow) @nogc nothrow
{
bool o;
assert(mulu(x, y, o) == r);
assert(o == overflow);
}
test(2, 3, 6, false);
test(1, ulong.max, ulong.max, false);
test(0, 1, 0, false);
test(0, ulong.max, 0, false);
test(ulong.max, 2, 2 * ulong.max, true);
test(1UL << 32, 1UL << 32, 0, true);

bool overflow = true;
assert(mulu(0UL, 0UL, overflow) == 0);
assert(overflow); // sticky
}



13 changes: 13 additions & 0 deletions src/core/memory.d
Expand Up @@ -433,6 +433,19 @@ struct GC
return gc_realloc( p, sz, ba, ti );
}

/// Issue 13111
unittest
{
enum size1 = 1 << 11 + 1; // page in large object pool
enum size2 = 1 << 22 + 1; // larger than large object pool size

auto data1 = cast(ubyte*)GC.calloc(size1);
auto data2 = cast(ubyte*)GC.realloc(data1, size2);

BlkInfo info = query(data2);
assert(info.size >= size2);
}


/**
* Requests that the managed memory block referenced by p be extended in
Expand Down
2 changes: 2 additions & 0 deletions src/gc/gc.d
Expand Up @@ -678,6 +678,8 @@ class GC
pool.freepages -= (newsz - psz);
debug(PRINTF) printFreeInfo(pool);
}
else
goto Lfallthrough; // does not fit into current pool
pool.updateOffsets(pagenum);
if (bits)
{
Expand Down
19 changes: 19 additions & 0 deletions src/rt/bss_section.c
@@ -0,0 +1,19 @@
/**
* This module is used to detect copy relocated ModuleInfos (located in .bss section).
*
* Copyright: Copyright Martin Nowak 2014-.
* License: <a href="http://www.boost.org/LICENSE_1_0.txt">Boost License 1.0</a>.
* Authors: Martin Nowak
* Source: $(DRUNTIMESRC src/rt/_sections_linux.d)
*/

/* These symbols are defined in the linker script and bracket the
* .bss, .lbss, .lrodata and .ldata sections.
*/
#if __linux__
// Need to use weak linkage to workaround a bug in ld.bfd (Bugzilla 13025).
extern int __attribute__((weak)) __bss_start, _end;

void* rt_get_bss_start() { return (void*)&__bss_start; }
void* rt_get_end() { return (void*)&_end; }
#endif
12 changes: 6 additions & 6 deletions src/rt/sections_linux.d
Expand Up @@ -739,9 +739,8 @@ const(char)[] dsoName(const char* dlpi_name)

extern(C)
{
// .bss, .lbss, .lrodata, .ldata
extern __gshared void* __bss_start;
extern __gshared void* _end;
void* rt_get_bss_start() @nogc nothrow;
void* rt_get_end() @nogc nothrow;
}

nothrow
Expand All @@ -751,13 +750,14 @@ body
{
immutable(ModuleInfo)* conflicting;

auto bss_start = cast(void*)&__bss_start;
immutable bss_size = cast(void*)&_end - bss_start;
auto bss_start = rt_get_bss_start();
immutable bss_size = rt_get_end() - bss_start;
assert(bss_size >= 0);

foreach (m; modules)
{
auto addr = cast(const(void*))m;
if (cast(size_t)(addr - bss_start) < bss_size)
if (cast(size_t)(addr - bss_start) < cast(size_t)bss_size)
{
// Module is in .bss of the exe because it was copy relocated
}
Expand Down

0 comments on commit e36d35c

Please sign in to comment.