[Issue 14758] TypeInfo causes excessive binary bloat

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed Nov 11 15:14:56 PST 2015


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

--- Comment #14 from Mike <slavo5150 at yahoo.com> ---
I've tested this issue with DMD v2.069 and the results look good.  I had to
modify my test code.  For some reason I now have to add additional stubs for
Throwables, but that's a separate issue.  Here's the code to get a build.

// object.d
module object;

alias immutable(char)[] string;

class Object 
{ }

class TypeInfo 
{ 
    bool equals(in void* p1, in void* p2) const 
    { 
        return p1 == p2; 
    }

    int compare(in void* p1, in void* p2) const 
    { 
        return _xopCmp(p1, p2); 
    }
}

class TypeInfo_Class : TypeInfo
{
    ubyte[136] ignore;
}

alias TypeInfo_Class ClassInfo;

extern (C) Object _d_newclass(const ClassInfo ci)
{ 
    return null;
}

extern(C) void _d_throwc(Object h)
{ }

class Throwable
{ }

class Error : Throwable
{ 
    this(string x)
    { }
}

extern(C) void _d_dso_registry(void* data)
{ }

//test.d
module test;

long sys_write(long arg1, in void* arg2, long arg3)
{
    long result;

    asm
    {
        mov RAX, 1;
        mov RDI, arg1;
        mov RSI, arg2;
        mov RDX, arg3;
        syscall;
    }

    return result;
}

void write(in string text)
{
    sys_write(2, text.ptr, text.length);
}

void write(A...)(in A a)
{
    foreach(t; a)
    {
        write(t);
    }
}

final abstract class TestClass1 { }
final abstract class TestClass2 { }
final abstract class TestClass3 { }
final abstract class TestClass4 { }
final abstract class TestClass5 { }
final abstract class TestClass6 { }
final abstract class TestClass7 { }
final abstract class TestClass8 { }
final abstract class TestClass9 { }

extern(C) void main()
{
    write("Hello\n");
}

Compile on 64-bit Linux with ( This method compiles without phobos or druntime
to obtain the smallest possible binary):
dmd -m64 -defaultlib= -debuglib= -conf= -betterC -release object.d test.d
-oftest

Analyze with
objdump -s -j .rodata test

Contents of section .rodata:
 400760 01000200 00000000 00000000 00000000  ................
 400770 54797065 496e666f 2e657175 616c7320  TypeInfo.equals 
 400780 6973206e 6f742069 6d706c65 6d656e74  is not implement
 400790 65640054 79706549 6e666f2e 636f6d70  ed.TypeInfo.comp
 4007a0 61726520 6973206e 6f742069 6d706c65  are is not imple
 4007b0 6d656e74 65640048 656c6c6f 0a000000  mented.Hello....

As you can see the situation is MUCH improved, but there are still these
strange messages about TypeInfo.equals and TypeInfo.compare.  I think I'll file
a separate issue for that.

I'm hesitant to close this issue at the moment because the test case to
illustrate the issue uses DMD's backed, which doesn't support my platform (ARM
Cortex-M); I'm not sure if the change just swept the issue under the rug in
DMD's backend or genuinely addressed the problem.  I intend to test if the
changes also improved things for LDC and GDC, and will update this issue with
more information as I get results.

--


More information about the Digitalmars-d-bugs mailing list