Bug creation and email sending has been disabled, file new bugs at gcc.gnu.org/bugzilla
Bug 253 - Linker error when using -O
Summary: Linker error when using -O
Status: RESOLVED FIXED
Alias: None
Product: GDC
Classification: Unclassified
Component: gdc (show other bugs)
Version: 6.x
Hardware: ARM Linux
: --- normal
Assignee: Iain Buclaw
URL:
Depends on:
Blocks:
 
Reported: 2017-03-03 14:56 CET by gdc
Modified: 2017-03-04 22:08 CET (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description gdc 2017-03-03 14:56:03 CET
Compiling the example below with "gdc example.d some_class.d" works. When compiling with "gdc -O example.d some_class.d" I get a linker error:

/tmp/ccmXtlCq.o: In function `_DT24_D10some_class1B3fooMFHAyaAyaZv':
example.d:(.text._DT24_D10some_class1B3fooMFHAyaAyaZv[_DT24_D10some_class1B3fooMFHAyaAyaZv]+0x17): undefined reference to `_D10some_class1B3fooMFHAyaAyaZ12__dgliteral2MFNaNbNiNfZAya'
collect2: error: ld returned 1 exit status

Here are the two files. I wasn't able to reduce them further, although I think it should be possible...


example.d:

import some_class;

void main()
{
}

interface A
{
    abstract void foo(string[string] a);
}

interface C:A
{
}

class D:B,C
{
}

some_class.d:

import std.conv;
import example;

class B:A
{
    override void foo(string[string] a)
    {
        if (to!int(a.get("b","1"))!=1) return;
    }

}
Comment 1 Iain Buclaw 2017-03-04 14:23:25 CET
Confirmed.  (NB: _DT is a thunk)
Comment 2 Iain Buclaw 2017-03-04 16:33:10 CET
Reduced test:
---
import some_class;

interface A
{
    void foo(int[int]);
}

interface C:A
{
}

class D:B,C
{
}

---

import example;

class ConvException : Exception
{
    this(string s)
    {
        super(s);
    }
}

T to(T, A)(A)
{
    throw new ConvException(null);
}

class B : A
{
    void foo(int[int] a)
    {
        if (to!int(a.get(0, 1))) return;
    }

}
---

Happens because the thunk generated in 'example.d' inlines the function call to 'B.foo'.  However that doesn't work because it calls a lambda that is not externally visible outside of the compilation unit of 'some_class.d'.
Comment 3 Iain Buclaw 2017-03-04 16:45:18 CET
https://github.com/D-Programming-GDC/GDC/pull/409